Closed
Description
Compiling this program produces bad debug info in the location list entry for argument "a" of function "foo". GDB crashes on it, which is GDB's problem (https://sourceware.org/bugzilla/show_bug.cgi?id=25353), but Rust should also not generate bad debug info.
const ARRAY_SIZE: usize = 1024;
struct Foo {
x: [u64; ARRAY_SIZE],
}
fn foo(a: Foo, i: usize) -> u64 {
a.x[i]
}
fn main() {
println!("Hello, world!");
println!("{}", foo(Foo{x: [0; ARRAY_SIZE]}, 42));
}
bash$ cargo build
bash$ readelf -w target/debug/location-lists
-->
<2><cb0>: Abbrev Number: 3 (DW_TAG_subprogram)
...
<cc3> DW_AT_name : (indirect string, offset: 0x7cb): foo
...
<3><ccd>: Abbrev Number: 4 (DW_TAG_formal_parameter)
<cce> DW_AT_location : 0x0 (location list)
<cd2> DW_AT_name : (indirect string, offset: 0x85bf2): a
<cd6> DW_AT_decl_file : 1
<cd7> DW_AT_decl_line : 7
<cd8> DW_AT_type : <0xd24>
...
Contents of the .debug_loc section:
Offset Begin End Expression
00000000 0000000000004469 000000000000447f (DW_OP_breg5 (rdi): 0)
00000014 000000000000447f 0000000000004490 (DW_OP_breg7 (rsp): 8; DW_OP_deref)
00000029 0000000000004490 0000000000004499 (DW_OP_reg2 (rcx))
0000003c 0000000000004499 00000000000044b0 (DW_OP_breg7 (rsp): 8; DW_OP_deref)
00000051 00000000000044b0 00000000000044b2 (DW_OP_reg4 (rsi))
00000064 <End of list>
Note the entries saying "a" lives in rcx and rsi (that is the value of "a" lives in the register, not its address).