I'm trying to generate Rust-like backtraces (a list of function symbols is enough for now, no line number) with libunwind. However; whenever I try to fetch symbol names with unw_get_proc_name
i get the general unspecified error
error code. I suspect this is because I'm not generating unwind information correctly from cranelift. However; I cannot figure out where the problem sits.
For now I copied Rustc's cranelift backends implementation for adding unwind information and then add it after defining each function . Then in my language's standard library I invoke the libunwind functions which I think are meant to retrieve that information. After copying Rustc's libunwind code I no longer get the missing unwind information
error code but now instead just always get EUNSPEC
(unspecified error).
Strangely, when I try calling the unw_get_proc_name
function the same way in Rust (on the musl target which has the unw_*
symbols) I get exactly the same EUNSPEC error. https://github.com/luminalang/lumina/blob/libunwind/rust-replication/src/main.rs so this problem might not even be related to how I use cranelift. Or; Rust doesn't generate this unwind information either and does something completely different to create its backtraces?
Regardless; I'm very lost in what I'm supposed to do to achieve this goal and what I'm doing wrong in my attempts to do so.
Rust uses the _Unwind_* family of functions to generate backtraces. llvm-libunwind supports this too. I have no idea how the unw_* family of functions is supposed to be used.
Also for translating function addresses to human readable function names rust uses it's own debuginfo parsing code through the addr2line crate.
hm ok. llvm-libunwind seems to use dladdr
to get the symbol names which is probably very limited. Seems like parsing the dwarf debuginfo manually after unwinding, using the addresses given by libunwind would be the way to go. I'll look whether writing the minimal dwarf parsing code I'd need would be simple enough, if not I could just depend on addr2line
as a hack for now.
Last updated: Nov 22 2024 at 16:03 UTC