Fix Issue 18068 - No file names and line numbers in stack trace #2172
Conversation
Thanks for your pull request, @wilzbach! Bugzilla references
|
Nice work! I think you can use https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/baselib-dladdr-3.html It's already bound in the druntime at druntime/src/core/sys/linux/dlfcn.d Line 293 in 05944a2
|
However, using the first result from |
Tested locally. DMD test17559 finally passes. In fact for the first time, the entire DMD test suite passes when run locally on my PC. Great! |
Did a little more testing locally. This is working great. |
I had a go at this too as one of the fixes in #2151. I was unsure about how to obtain the base address too and came up with cumbersome parsing of
|
src/rt/backtrace/dwarf.d
Outdated
} | ||
ElfObj elfObj; | ||
dl_iterate_phdr(&dl_iterate_phdr_cb_ngc_tracehandler, &elfObj); | ||
ElfW!"Addr" offset = elfObj.l_addr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto
?
src/rt/backtrace/dwarf.d
Outdated
else | ||
{ | ||
// non-ASLR fallback | ||
size_t offset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= 0
?
FYI @MartinNowak and I looked at the implementation in FreeBSD and Linux and FreeBSD: https://github.com/freebsd/freebsd/blob/d9ac9c210e73d5141195a5497d3e96dfc755d1dc/libexec/rtld-elf/rtld.c#L572 Linux: https://github.com/bminor/glibc/blob/15c19147a8361b7281519b9784b3b823c447cf7a/elf/dl-iteratephdr.c#L32 (
That's a shame to have this work duplicated :/
@MartinNowak recommended to only to use the executable code segment (and not the entire DSO), but apparently that currently fails on the CIs. I'm not sure that's actually necessary. Can the binary segment order really be dynamically changed by the loader? |
Good, my main point was that the fix shouldn't be Linux-only.
I expected the bot to add something to the dlang issue. - Glad the maps-file parsing can be avoided, so it did pay off. :)
No idea, but I'd have considered it unnecessary as well. My concern was that offsetting the addresses for non-relocatable executables may likely be wrong, but I see that you added the check now. - CI fails because of missing I'd suggest applying the offset to the DWARF addresses in |
cee17a2
to
65cbc66
Compare
309ddda
to
a0abca3
Compare
I actually removed the check for now as it didn't seem to make a difference. BTW I also added a test for shared libraries and it seems like debug symbols from shared libraries don't work at all (and have never worked). I still added the test, s.t. it's easier to fix this in a follow-up. |
@@ -58,6 +58,62 @@ struct Image | |||
|
|||
return null; | |||
} | |||
|
|||
@property size_t baseAddress() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awful lot of logic for a property, and would be run needlessly if called multiple times by a caller that isn't aware of the implementation. The baseAddress shouldn't change during the lifetime of an Image
, so wouldn't it be better to put this in the constructor, and store the result as a field?
I see 2 remaining problems with the current backtrace code (in general, unrelated to this PR):
|
What's the status of this? |
Sorry. I haven't had much time for this lately, but I will get to this once I am back from my hiking trip (~end of next week). |
Why are you replying here during your hike 😃. |
(Because it takes about 12h to get there and luckily there's free roaming in Europe nowadays :) ) |
Ping! Is this ready to go? It'd be awesome to get this in the upcoming release. |
Superseded by #2230 |
Turns out all that changed was PIE and the addresses with ASLR.
Example:
So we finally get our line number back in the stack trace on Linux:
CC @JinShil @ZombineDev
This is a PoC because I'm not sure on the best way to get the base offset of the binary.