-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
teach std.debug to convert addresses to ELF symbols #22077
base: master
Are you sure you want to change the base?
Conversation
df2397a
to
3a34582
Compare
|
Oh, good catch. Had to add ~/code/zig/build-example-elfsymtab-backtrace> ../release/bin/zig build-exe main.zig -OReleaseSafe -fno-strip -fno-omit-frame-pointer -6 11/25/2024 04:46:46 PM
~/code/zig/build-example-elfsymtab-backtrace> objcopy --strip-debug main main_strip-debug 11/25/2024 04:47:23 PM ~/code/zig/build-example-elfsymtab-backtrace> ./main 11/25/2024 04:47:25 PM
thread 772168 panic: integer overflow
Unwind error at address `exe:0x101a803` (error.MissingFDE), trace may be incomplete
/home/geemili/code/zig/build-example-elfsymtab-backtrace/main.zig:4:14: 0x100be87 in foo (main)
return x * x;
^
/home/geemili/code/zig/build-example-elfsymtab-backtrace/main.zig:8:15: 0x100bc98 in bar (main)
return foo(std.math.maxInt(u32));
^
/home/geemili/code/zig/build-example-elfsymtab-backtrace/main.zig:12:32: 0x100bc88 in main (main)
std.debug.print("{}", .{bar()});
^
/home/geemili/code/zig/lib/std/start.zig:617:37: 0x100bbc2 in posixCallMainAndExit (main)
const result = root.main() catch |err| {
^
/home/geemili/code/zig/lib/std/start.zig:248:5: 0x100b89d in _start (main)
asm volatile (switch (native_arch) {
^
Error: nu::shell::core_dumped
× External command core dumped
╭─[entry #148:1:1]
1 │ ./main
· ───┬──
· ╰── core dumped with SIGABRT (6)
╰──── ~/code/zig/build-example-elfsymtab-backtrace> ./main_strip-debug -6 11/25/2024 04:47:28 PM
thread 772213 panic: integer overflow
Unwind information for `exe:0x101a803` was not available, trace may be incomplete
???:?:?: 0x100be87 in main.foo (???)
???:?:?: 0x100bc98 in main.bar (???)
???:?:?: 0x100bc88 in main.main (???)
???:?:?: 0x100bbc2 in start.posixCallMainAndExit (???)
???:?:?: 0x100b89d in _start (???)
Error: nu::shell::core_dumped
× External command core dumped
╭─[entry #149:1:1]
1 │ ./main_strip-debug
· ─────────┬────────
· ╰── core dumped with SIGABRT (6)
╰──── |
not sure if this would cause too much duplicated code but thoughts on omitting those |
The minimum change would be here: zig/lib/std/debug/ElfSymTab.zig Lines 223 to 225 in 3a34582
Setting the Lines 44 to 48 in 3a34582
And then it would produce something like: :0:0: 0x100b89d in _start () Further changes would require some more thought |
Are there any existing tests that could be extended to cover the new behavior? |
3a34582
to
958bf92
Compare
On that last point, ~/code/zig/build-example-elfsymtab-backtrace> try { ./main_strip-debug }
thread 98264 panic: integer overflow
Unwind information for `exe:0x101b443` was not available, trace may be incomplete
~/code/zig/build-example-elfsymtab-backtrace> readelf -S main_strip-debug | rg eh
[ 2] .eh_frame_hdr PROGBITS 0000000001007da4 00007da4
[ 3] .eh_frame PROGBITS 0000000001008448 00008448 Of course, that could be pushed off to another PR, as you can work around this by using ~/code/zig/build-example-elfsymtab-backtrace> ../release/bin/zig build-exe main.zig -OReleaseSafe -fno-strip -fno-omit-frame-pointer
~/code/zig/build-example-elfsymtab-backtrace> objcopy --strip-debug main main_strip-debug
~/code/zig/build-example-elfsymtab-backtrace> try { ./main_strip-debug }
thread 99117 panic: integer overflow
Unwind information for `exe:0x101a803` was not available, trace may be incomplete
???:?:?: 0x100be87 in main.foo (???)
???:?:?: 0x100bc98 in main.bar (???)
???:?:?: 0x100bc88 in main.main (???)
???:?:?: 0x100bbc2 in start.posixCallMainAndExit (???)
???:?:?: 0x100b89d in _start (???) |
90754c9
to
973af8c
Compare
7afec07
to
7c8d0b9
Compare
I think this pull request is ready for review. Current state:
Some caveats:
|
f03fead
to
d97c614
Compare
I removed the commit that skipped testing on aarch64, as commit e62aac3 fixes it by making |
Now that CI has passed, my plan is to work on a draft PR for |
d97c614
to
f497573
Compare
04a2793
to
7fee893
Compare
When reading `std.debug.Dwarf ` fails, `std.debug.SelfInfo` will now try to load function names from `symtab`.
This makes it possible for executables built with `-fstrip=debuginfo` to unwind frames. No need to specify `-fno-omit-frame-pointer`! This is only possible because the `eh_frame` and `eh_frame_hdr` sections are not stripped when `-fstrip=debuginfo`.
…fo` the error set
7fee893
to
2b6c55e
Compare
When reading
std.debug.Dwarf
fails,std.debug.SelfInfo
will now try to load function names fromsymtab
.See related issue #18520
Example
Further work
.eh_frame
is included but other Dwarf debuginfo is missing.[ ] Makestd.debug.ElfSymTab
read from.dynsym
section as well?.dynsym
is meant to be a subset of.symtab
, for nowdebug.ElfSymTab
assumes.symtab
is intentionally left in.These changes have been moved out of this branch and into their own
fdebuginfo
branch:[x] change-fstrip
to allow-fstrip=debuginfo
, which would remove the DWARF debug info but retain the ELF symbol table[x] make similar changes for thestd.Build
API.symtab
, so I think this would fit better into an issue about graceful degradation of stack traces.[x] remove-fstrip
,-gdwarf32
,-gdwarf64
; replace with-fdebuginfo=none
,-fdebuginfo=symbols
,-fdebuginfo=dwarf32
, etc.?[ ] less noisy stack trace format? Perhaps based on std: add std.options.debug_stacktrace_kind #19650 ?makes more sense as separate PR based on std: add std.options.debug_stacktrace_kind #19650[ ] check thatmove into-fstrip=debuginfo
works onmacos
andwindows
?fdebuginfo
PR once that existsThis work is licensed on the same terms as the Zig project.
Copyright © 2024 TigerBeetle, Inc.
This code was written under contract for TigerBeetle. As a work made for hire, authorship and copyright goes to TigerBeetle.
Author certificate