https://andrewkelley.me/post/zig-stack-traces-kernel-panic-bare-bones-os.html
I wanted to do this but using zig 13 does anyone have an idea how?
The useful functions that you can call as-is are:
@returnAddress
Callers addressstd.debug.captureStackTrace
Captures a stack tracestd.debug.getSelfDebugInfo
Loads debugging info from ELF
The functions that have all the printing code for a terminal and you might need to adapt for your display or serial port:
std.debug.printSourceAtAddress
Prints source file and line number for an address using debug info from ELFstd.debug.writeStackTrace
Iterates a stack trace and callsprintSourceAtAddress
to print source file and line number for the entire call stack
3 Likes
I’ve been trying to look into this for myself…
std.debug.captureStackTrace
seems to crash for me on aarch64/freestanding for a raspi3b.
std.debug.getSelfDebugInfo
throws compilation error:
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/posix.zig:60:21: error: struct 'posix.system__struct_3745' has no member named 'E'
pub const E = system.E;
~~~~~~^~
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/std/posix.zig:48:13: note: struct declared here
else => struct {},
^~~~~~~~~
A lot has changed in Zig since Andrew wrote that article… It’s hard to keep up, but I’m slowly trying to re-figure stuff out