-
Notifications
You must be signed in to change notification settings - Fork 267
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
Implement DWARF parser for better backtraces #58
Comments
Hi @mathetake |
@r8d8 I think this definitely is still relevant, and we'd want to start with backtrace enhancement. If I understand you correctly, you are interested in contributing this? If so, I'd recommend starting small as this may touch a few different spots and iterating small can give you less burden especially in an area that is not 100pct defined in spec. @mathetake https://github.com/yurydelendik/webassembly-dwarf is abandoned and the author isn't replying to issues anymore. We should ask the actual spec about this and cite something with a future to avoid compatibility drift, possibly asking other implementers which "specs" they plan to use. We can tentatively use the dead one of course, but some time before 1.0 we need to firm this up. wdyt? |
DWARF in Wasm is added in tool-conventions which says:
Meaning there won't be any formal specification, but instead we have to follow the (personally hosted) specification (https://yurydelendik.github.io/webassembly-dwarf/). So we’ll have to choose a way and possibly compare against another implementation. Fortunately the implementation is stable in the sense that major wasm runtimes and compilers implement it (clang/LLVM, wasmtime, V8). As for contribution, I think this could be multiple weeks or even months of full-time work. This includes; implementing a binary parser for DWARF 5 (note that there's nothing we can reference or use in the exiting Go ecosystem meaning that we have to implement literally from scratch), refactor the JIT compiler and interpreter so they can track original Wasm instruction address to the our runtime representation), etc. That said, I would recommend as @codefromthecrypt suggested to start small rather than an overwhelming one like this. |
@codefromthecrypt @mathetake |
As a general thought, there were DWARF 5 pieces added to the main Go tool chain a while back:
So, things might not be completely from scratch. 😄 |
Oh that's cool! Thank you for the info! @justinclift |
Background
LLVM-based compilers for Wasm, for examples C/C++, Rust, Zig, TinyGo (virtually 100% of viable languages),
emit DWARF information into
.debug_*
custom sections. The following is the sections contained in a TinyGo binary:By reading debug sections, we can associate "each wasm instruction" in functions to a specific line of a source code which the binary is compiled from.
Why?
Some of the de-facto Wasm tools have already supported the DWARF format. For example Google Chrome[3] has allowed users to debug Wasm programs on the browser. Another example is Wasmtime -- when you run the panic example in this repo with
WASMTIME_BACKTRACE_DETAILS=1
, you can see the backtrace with source code info mation:On the other hand, at the moment of this writing, our backtrace is not using DWARF, but just parsing "name" custom sections and attach each function name:
This will be much more useful when users run non-TinyGo Wasms -- usually the function names are mangled by compilers (luckily TinyGo does not!) so they are basically not human-readable. For example, Rust binary's backtrace with custom sections would look like this:
With DWARF information, we don't need to parse "name" custom section therefore we won't suffer this mangled dirty symbols and instead we can emit each trace with human-readable function names plus source code info.
How?
Wasm DWARF format[1] is almost same as the standard DWARF specification version 5?[2] with the difference where the address should be interpreted as an offset from the beginning of "the code section" vs the beginning of "the binary" in non-Wasm format.
So it should be simple to write parser by getting insights from other DWARF implementations.
Links
[1] https://yurydelendik.github.io/webassembly-dwarf/
[2] https://dwarfstd.org/doc/DWARF5.pdf pdf!
[3] https://twitter.com/ChromeDevTools/status/1192803818024710145
The text was updated successfully, but these errors were encountered: