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

Cannot debug with GDB; DWARF data seems corrupted #1

Open
sgray004 opened this issue Mar 26, 2018 · 12 comments
Open

Cannot debug with GDB; DWARF data seems corrupted #1

sgray004 opened this issue Mar 26, 2018 · 12 comments

Comments

@sgray004
Copy link

With a fresh build of github.com/riscv-rust/rust, I can successfully compile, deploy, and run each riscv-crates/example to a HiFive1 board. However, I cannot debug using GDB. For example, building hello_world, uploading, running openocd, and then running:

make gdb

Connects to openocd correctly, loads the Rust pretty printers successfully, but GDB emits:

Dwarf Error: Cannot find DIE at 0x48d referenced from DIE at 0x693 [in module /home/foo/riscv-crates/target/riscv32imac-unknown-none/debug/examples/hello_world]

Because of this, symbols don't appear to be loaded, breakpoints cannot be set, etc.

Running llvm-dwarfdump -verify against riscv-crates/target/riscv32imac-unknown-none/debug/examples/hello_world seems to show several DIE errors, including an ...invalid DIE reference 0x0000048d... error similar to the one emitted by GDB above.

Any suggestions?

@dvc94ch
Copy link
Member

dvc94ch commented Mar 27, 2018

I've seen this before. I haven't gotten round to debug it in detail.

Which commit of rust/llvm are u using? Debugging debug info can be really annoying. A llvm backend only emits CFI info, everything else should be handled by the generic backend that should be the same across platforms. It could be a nightly rustc regression for example. If you want to debug this, then you want to check the various stages to see where the corruption occurs. ie. is the rlib metadata ok is the metadata ok before linking, etc.

@sgray004
Copy link
Author

Thanks for the info. I built off your rust-riscv-master branch at commit ab24013.

I had some success eliminating the DWARF errors experimenting with various options around LTO. But I couldn't get to a combination that worked cleanly and wanted to make sure I wasn't missing something simple.

I'll push on this a bit farther. Thanks.

@dvc94ch
Copy link
Member

dvc94ch commented Mar 28, 2018

Are you sure it still happens with commit ab24013? Currently works for me... Have you tried xargo clean?

@sgray004
Copy link
Author

Yes, I can confirm that git log reports I'm on ab24013. I often run xargo clean to make sure I'm not picking up old builds. To ensure I wasn't accidentally picking up partially old build pieces of the tooling, I built the RISC-V tools and RISC-V Rust fork on a fresh VM from scratch (Ubuntu 16.04.4) and I'm still getting the Dwarf Error within GDB.

@dvc94ch
Copy link
Member

dvc94ch commented Mar 29, 2018

fyi got the error again. did you get anywhere with it?

@dvc94ch
Copy link
Member

dvc94ch commented Mar 29, 2018

Weirdly it only seems to happen when the binary reaches a certain size (.text > 60000 when running llvm-size).

@dvc94ch
Copy link
Member

dvc94ch commented Mar 29, 2018

Worked around it by adding this:
[profile.dev]
opt-level = 3

@dvc94ch
Copy link
Member

dvc94ch commented Mar 30, 2018

Ok so it seems like the error occurs when rust expects a function to be inlined but it isn't because the llvm optimization level is set too low.

Fixed most debug info errors by disabling inlining by increasing the inline-threshold in .cargo/config:

  "-C", "inline-threshold=255",

@sgray004
Copy link
Author

These workarounds are a definite improvement--GDB is happier.

I'm seeing some issues with the example project where debug symbols aren't present or otherwise seem to be "mismatched." Sometimes I can set a breakpoint on a function symbol, sometimes not. Sometimes the breakpoint hits, sometimes not. Sometimes GDB dumps core. Nothing reproducible yet. I'll spend trying to figure out what's going on.

Do you have a specific GDB debug scenario that is "known good" with these workarounds so that I can validate in my environment to make sure my config is correct?

Much thanks!

@dvc94ch
Copy link
Member

dvc94ch commented Mar 31, 2018 via email

@dvc94ch
Copy link
Member

dvc94ch commented Mar 31, 2018

So I pushed my changes. They are still a work in progress, but I think they should "mostly work". Due to so many issues with miscompilation and debugging I'm going to focus on other stuff for the time being. Proper atomic support in llvm should allow enabling the rustc testsuite, to help track down the issues.

@sgray004
Copy link
Author

sgray004 commented Apr 2, 2018

Latest changes appear to be working, although as you mentioned, "mostly work" is accurate. I can build, deploy, and set breakpoints on hello_world in GDB and it appears to be working. I do have to boot the HiFive1 using safe mode, for some reason, before I can do uploads.

I'm seeing some oddities around resulting target binary file sizes of 2GB (huge data segments) and sometimes missing .text segments when lto = false. I will continue to investigate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants