Does Cranelift have anything to make it easier to maintain stacktraces that map back to your source files? Right now in my interpreter I essentially maintain a mapping of instruction indexes to locations in a separate data structure. From what I gather this would require fiddling with dwarf/libunwind? The other option is to insert a bunch of code in places where necessary. This is sort of what Nim does, but apparently this comes with quite a bit of overhead (https://github.com/nim-lang/Nim/issues/12702).
Basically how my setup works now is that every frame stores the method it belongs to, and the method has a mapping of instruction index => location
. Building a stacktrace is then a matter of walking those frames and finding an entry for the current index in each frame. Mind you I only need traces in the event of a panic in my language, they're not used for e.g. exceptions, so maximum performance isn't my main interest
Alternatively perhaps backtrace-rs is an option :thinking:
We have support for emitting DWARF info for frames; Wasmtime used to use this, before it grew its own backtracer
Right now what we do in Wasmtime is turn on the Cranelift option to always use frame pointers; then we can trace the linked list of (fp, return addr) tuples very quickly, and look up the addresses
separately, srclocs get mapped to offsets in the output code and so you can correlate PCs back to whatever source-level info your srclocs represent
Ah thanks, I'll dig around to see if I could do something similar :smile:
Last updated: Dec 23 2024 at 12:05 UTC