bytecodealliance / wasm-tools

CLI and Rust libraries for low-level manipulation of WebAssembly modules
Apache License 2.0
1.21k stars 224 forks source link

Implement DWARF support in text-to-binary #1632

Closed alexcrichton closed 6 days ago

alexcrichton commented 1 week ago

This commit implements support to emit DWARF debugging information when the WebAssembly text format is converted to binary. Currently there is otherwise no means of translating a binary offset in a WebAssembly file back to the text format that it came from. This support is implemented with a few API knobs here and there as well as two new CLI flags for all the commands that support the text format as input: -g and --generate-dwarf lines|full.

The original motivation of this commit is that I was curious to learn more about DWARF and it seemed like a neat little feature that wouldn't be too hard to maintain. The inspiration was bytecodealliance/wasmtime#8658 which this does not implement as-is (e.g. not custom DWARF, just wasm-text-DWARF). Otherwise though I've realized that this can be useful for development in a few situations:

This commit implements knobs for "full" or "line" support in DWARF. The "line" support should be as complete as it can be (DWARF can only provide information for the code section). The "full" support is somewhat basic still but my hope is that it can be expanded in the future as needed.