Skip to content

Display in browsers and tools for addresses of functions and instructions #990

Closed
@dschuff

Description

@dschuff

Currently if you have a trap or validation error in your wasm binary, V8 gives you error output like
Compiling WASM function #26:<?> failed:Result = expected 1 elements on the stack for fallthru to @3 @+58 or at (<WASM>[3]+156).
SpiderMonkey says something like CompileError: wasm validation error: at offset 4214: type mismatch: expression has type void but expected i32

Meanwhile if you want to look at your binary with WABT's wasmdump tool, you will see something like

000015 func[0]:
 000017: 0c 00                      | br 0
 000019: 02 7f                      | block i32

WABT shows functions as indices in the (import+function) function index space, and all the "addresses" as hexadecimal file offsets.
If I understand correctly, V8 is giving you function index (in same function index space) + decimal function offset in the stack representation and... something else... in the validation error text.
SpiderMonkey gives you no function name or index, and a (file?) offset.

So to debug anything you might have to look at the source code of your favorite browser engine to determine what information you are getting, and then use your favorite programmers' calculator to convert between file and function offset and number bases. Needless to say this is a suboptimal user experience.

#814 had some discussion of normalizing the content of Error.stack, and I understand that's somewhat fraught. My goal here is simultaneously more ambitious (in that we should include tools as well as browsers) and less ambitious (see below).

Here are possible things we might agree on (where the definition of "agree" is also negotiable).

  1. Representation of function ID (name and/or index)
  2. Representation of function and instruction addresses (offset relative to file, section, or function; hex or decimal)
  3. Representation of section ID (may or may not be needed in browsers, but will be used in tools)
  4. Representation of module ID (stack traces can contain frames from 2 or more different wasm instances dynamically linked together)
  5. Exact or partial format of some string that is emitted in stack traces, exception messages (e.g. LinkError and CompileError text), and even dev tools.
  6. Whether exceptions are precise
  7. ???

I think getting 2 and 4 is the absolute bare minimum, so a user can dump their binary and find (an approximation of) the faulting address or (the exact, hopefully) the invalid address, without having to do base conversions and arithmetic. 1 and 3 would be nice too, and seems like they ought to be pretty easy to agree on and implement. 5 and 6 would in principle be nice too, but as long as the other conditions are met, the incremental benefit is fairly small and the cost might be higher. I'm fine if we want to punt those.

As to the definition of "agree", there is:

  1. Normative text in the most-formal relevant spec (I guess that would be JS.md for browser behavior for now)
  2. Some suggested/non-normative text in JS.md, or elsewhere in the design repo (which would give it some kind of official guideline or weight)
  3. Some text somewhere else (perhaps tool-conventions) which would be a non-source-code description, but less official.
  4. Nothing written anywhere, the browsers and tools written by us just all do the same thing.

Honestly even 4 would be fine. Whatever we do, other tools will probably follow for their own convenience, and users (who aren't going to look for specs unless they are confused) will be happy.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions