Skip to content
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 support in text-to-binary #1632

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

alexcrichton
Copy link
Member

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:

  • Wasmtime's backtraces can now mention filenames/line numbers of the WebAssembly text format.
  • Validation errors can use addr2line to print a filename/line number of a WebAssembly text file.
  • Wasmtime doesn't have a native debugger nor does LLDB/GDB know about WebAssembly. Through Wasmtime's DWARF transformation this enables debugging WebAssembly text files.

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.

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:

* Wasmtime's backtraces can now mention filenames/line numbers of the
  WebAssembly text format.
* Validation errors can use `addr2line` to print a filename/line number
  of a WebAssembly text file.
* Wasmtime doesn't have a native debugger nor does LLDB/GDB know about
  WebAssembly. Through Wasmtime's DWARF transformation this enables
  debugging WebAssembly text files.

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.
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@fitzgen fitzgen added this pull request to the merge queue Jun 26, 2024
Merged via the queue into bytecodealliance:main with commit bee5a7c Jun 26, 2024
27 checks passed
@alexcrichton alexcrichton deleted the wat-dwarf branch June 27, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants