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

Backtrace with SourceSpan #19

Open
oovm opened this issue Mar 7, 2024 · 4 comments
Open

Backtrace with SourceSpan #19

oovm opened this issue Mar 7, 2024 · 4 comments

Comments

@oovm
Copy link

oovm commented Mar 7, 2024

Is it possible to append source span information to generate a backtrace that jumps to the source language?

Assume the following syntax:

(func $source-function
    (result i32)
    (i32.const 0)
    (@name "package::module::function-name")
    (@file "language-source.file") ;; or shared source id, the path will appear multiple times
    (@line 12) (@column 4)         ;; if source is utf8 text file, use line and utf8 width
    (@offset 114)                  ;; if not a text file or non-utf8 encoding
)

Then the following log will be generated during trap, and the IDE can recognize and generate a local link:

0: 0x00000100 - unreachable or other trap name
1: 0x00000104 - in package::module::function-name(input1, input2)
                at language-source.file:114
2: 0x00000108 - in package::module::function-caller(input1, input2, input3)
                at language-source.file:514

It seems that the browser can use source-map or DWARF, but this is not part of the wasm standard, and it does not fit the features of wasm very well.

Should the wasm standard define a standardized set of debugger metainfo?

@dschuff dschuff transferred this issue from WebAssembly/proposals Mar 8, 2024
@dschuff
Copy link
Member

dschuff commented Mar 8, 2024

I think there hasn't been too much appetite for this (i.e. a standardized way to specify source-mapping information) so far mostly because source maps and DWARF have worked well enough. It's not completely ideal, and there are some known deficiencies (e.g. the fact that sourcemap's line/column format doesn't map perfectly to wasm's binary format, and the fact that DWARF can't currently assign source information to constant initializers), but it works well enough for many use cases.

I think it would be pretty straightforward to document a text syntax something like your example using the annotations proposal, and perhaps a binary equivalent using the compilation hints proposal. It could be useful for use cases where DWARF or sourcemaps aren't a good fit, but it would be unlikely to replace them for cases where they are already used. It wouldn't need to go through the full formal process to be useful; it could end up as a document in the tool-conventions.

@fitzgen
Copy link

fitzgen commented Mar 8, 2024

Another tricky bit is that the debug info can be split out from the debuggee artifact and might require e.g. fetching the debug info over the network.

In the context of a JS embedding of Wasm, does this mean that the trap (and the associated JS error message) should block on that network request? Or would it be nondeterministic whether you get Wasm-level information or source-level information? Or would there be a new method that returns a promise of an error message with source-level information?

@oovm
Copy link
Author

oovm commented Mar 9, 2024

There seems to be no tool that can debug at the wat level. If you switch to wasm, all redundant information will be erased and the source location will also need to be remapped.

@kripken
Copy link
Member

kripken commented Mar 9, 2024

@oovm I'm not sure what you mean by "debug at the wat level", but binaryen has support for source annotations in wat files using JS-style //@ FILE:LINE:COL. For example

;;@ src.cpp:200:2
(local.set $temp
  ..
)

That means that local.set is from src.cpp at line 200 and column 2. Example test:

https://github.com/WebAssembly/binaryen/blob/b671b6ce2ccbff5e1b735293bcf7fe94a5b65971/test/lit/debug/replace-keep.wat#L61-L70

Those are equivalent to source maps, but can be embedded in the wat.

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

No branches or pull requests

4 participants