Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix meaning of generated .debug_loc sections #8753

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/cranelift/src/debug/transform/range_info_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,20 @@ impl RangeInfoBuilder {
for (begin, end) in ranges {
result.extend(addr_tr.translate_ranges(*begin, *end));
}
if result.len() != 1 {

// If we're seeing the ranges for a `DW_TAG_compile_unit` DIE
// then don't use `DW_AT_low_pc` and `DW_AT_high_pc`. These
// attributes, if set, will configure the base address of all
// location lists that this unit refers to. Currently this
// debug transform does not take this base address into account
// when generate the `.debug_loc` section. Consequently when a
// compile unit is configured here the `DW_AT_ranges` attribute
// is unconditionally used instead of
// `DW_AT_low_pc`/`DW_AT_high_pc`.
let is_attr_for_compile_unit =
out_unit.get(current_scope_id).tag() == gimli::DW_TAG_compile_unit;

if result.len() != 1 || is_attr_for_compile_unit {
let range_list = result
.iter()
.map(|tr| write::Range::StartLength {
Expand Down
14 changes: 14 additions & 0 deletions crates/test-programs/src/bin/dwarf_multiple_codegen_units.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fn main() {
let a = 3;
foo::bar(a);
}

mod foo {
pub fn bar(x: u32) -> u32 {
let mut sum = 0;
for i in 0..x {
sum += i;
}
sum
}
}
42 changes: 42 additions & 0 deletions tests/all/debug/lldb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,46 @@ check: exited with status = 0
fn dwarf_shared_memory() -> Result<()> {
test_dwarf_simple(DWARF_SHARED_MEMORY, &[])
}

#[test]
#[ignore]
fn dwarf_multiple_codegen_units() -> Result<()> {
for wasm in [
DWARF_MULTIPLE_CODEGEN_UNITS,
DWARF_MULTIPLE_CODEGEN_UNITS_COMPONENT,
] {
println!("testing {wasm:?}");
let output = lldb_with_script(
&["-Ccache=n", "-Oopt-level=0", "-Ddebug-info", wasm],
r#"
breakpoint set --file dwarf_multiple_codegen_units.rs --line 3
breakpoint set --file dwarf_multiple_codegen_units.rs --line 10
r
fr v
c
fr v
breakpoint delete 2
finish
c"#,
)?;

check_lldb_output(
&output,
r#"
check: Breakpoint 1: no locations (pending)
check: Breakpoint 2: no locations (pending)
check: stop reason = breakpoint 1.1
check: foo::bar(a)
check: a = 3
check: sum += i
check: x = 3
check: sum = 0
check: 1 breakpoints deleted
check: Return value: $(=.*) 3
check: exited with status = 0
"#,
)?;
}
Ok(())
}
}