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

bad location list debug info #67992

Closed
xdje42 opened this issue Jan 8, 2020 · 1 comment · Fixed by #115174
Closed

bad location list debug info #67992

xdje42 opened this issue Jan 8, 2020 · 1 comment · Fixed by #115174
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xdje42
Copy link

xdje42 commented Jan 8, 2020

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).

@jonas-schievink jonas-schievink added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2020
@wesleywiser wesleywiser added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority labels Aug 21, 2023
@wesleywiser
Copy link
Member

Visited during wg-debugging triage. This seems to be resolved as both the current .debug_loc looks correct:

Contents of the .debug_loc section:

    Offset   Begin            End              Expression
    00000000 ffffffffffffffff 0000000000008ae0 (base address)
    00000010 0000000000008ae8 0000000000008aed (DW_OP_breg7 (rsp): 0; DW_OP_deref)
    00000025 0000000000008aed 0000000000008afe (DW_OP_breg5 (rdi): 0)
    00000039 0000000000008afe 0000000000008b30 (DW_OP_breg7 (rsp): 0; DW_OP_deref)
    0000004e <End of list>

and gdb itself no longer crashes and it able to display the value of a throughout the function as well. Marking this as E-needs-test as it would be great to have a regression test for this.

davidtwco added a commit to davidtwco/rust that referenced this issue Aug 25, 2023
Signed-off-by: David Wood <david@davidtw.co>
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 29, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#111580 (Don't ICE on layout computation failure)
 - rust-lang#114923 (doc: update lld-flavor ref)
 - rust-lang#115174 (tests: add test for rust-lang#67992)
 - rust-lang#115187 (Add new interface to smir)
 - rust-lang#115300 (Tweaks and improvements on SMIR around generics_of and predicates_of)
 - rust-lang#115340 (some more is_zst that should be is_1zst)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in d5b12a2 Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants