Stream: cranelift

Topic: Stack traces in Cranelift


view this post on Zulip Yorick Peterse (Oct 28 2022 at 14:52):

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).

Drawbacks of --stackTrace: --stackTrace incurs significant runtime overhead, and in fact {.push stacktrace:off.} is used at several places in nim codebase (eg lib/system/gc.nim). One reason for thi...

view this post on Zulip Yorick Peterse (Oct 28 2022 at 14:53):

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

view this post on Zulip Yorick Peterse (Oct 28 2022 at 15:14):

Alternatively perhaps backtrace-rs is an option :thinking:

view this post on Zulip Chris Fallin (Oct 28 2022 at 17:23):

We have support for emitting DWARF info for frames; Wasmtime used to use this, before it grew its own backtracer

view this post on Zulip Chris Fallin (Oct 28 2022 at 17:23):

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

view this post on Zulip Chris Fallin (Oct 28 2022 at 17:24):

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

view this post on Zulip Yorick Peterse (Oct 28 2022 at 18:43):

Ah thanks, I'll dig around to see if I could do something similar :smile:


Last updated: Nov 22 2024 at 17:03 UTC