Closed Bug 1628352 Opened 5 years ago Closed 4 years ago

Make sure devtools works with multi-value WebAssembly

Categories

(Core :: JavaScript: WebAssembly, task, P1)

task

Tracking

()

RESOLVED FIXED
mozilla78
Tracking Status
firefox78 --- fixed

People

(Reporter: wingo, Assigned: wingo)

References

Details

Attachments

(1 file)

In https://bugzilla.mozilla.org/show_bug.cgi?id=1628321 we are looking to ship multi-value WebAssembly and need to make sure that devtools is usable for multi-value WebAssembly modules. :yury on cc at suggestion of :lth.

Current status is unknown to me.

Did a little testing with bbouvier.

If you load this one: https://wingolog.org/pub/return-three.wasm, instantiate with no imports, and call the "run" export, then you should get the array [52, 10, 0].

If you load https://wingolog.org/pub/sub-three.wasm, which requires imports {env: {f: () => [52, 10, 0]}}, then calling run() should return 42.

If you load https://wingolog.org/pub/sum.wasm, no imports, and call run(), it should return 55. (It has a multi-value loop inside it.)

bbouvier says they all work, that stepping appears to work, though you can't see the contents of the virtual stack.

Depends on: 1628426
Priority: -- → P1
Blocks: 1628321
Assignee: nobody → wingo
Status: NEW → ASSIGNED
Blocks: 1637894

I honestly think this one is done. The debugging experience is not great, if I understand it right, but it's no worse than the rest of wasm.

To test, visit https://wingolog.org/pub/, then open a console.

async function loadWasm(url, imports) {
  let {module, instance} = await WebAssembly.instantiateStreaming(fetch(url), imports);
  return instance.exports.run;
}

// Return three vals to JS
var returnThree = await loadWasm("https://wingolog.org/pub/return-three.wasm");
returnThree();
// => Array(3) [ 0.5, 52.5, 10.5 ]

// Require 3 vals from JS
var subThree = await loadWasm("https://wingolog.org/pub/sub-three.wasm",
                              {env: {f: () => [52, 10, 0]}});
subThree();
// => 42

// A multi-value loop
var sum = await loadWasm("https://wingolog.org/pub/sum.wasm");
sum();
// 55

I don't know how to single-step in wasm, or to view the wasm stack. Changing subThree's import to return the wrong number of values does allow the debugger to break on the exception, but I can't do much interesting. What am I missing? :)

I did succeed in the end via the "debug a tab" option. One error, the disassembler raised an exception on disassembling sum.wasm:

console.error: (new Error("Unexpected type 1", "resource://devtools/client/shared/vendor/WasmDis.js", 40))
console.warn: "Action loadSourceText had an exception:" (new Error("Unexpected type 1", "resource://devtools/client/shared/vendor/WasmDis.js", 40))

Filed https://github.com/wasdk/wasmparser/issues/40 for the WasmDis.js bug.

I checked and with the patch above, disassembly and single-stepping do now work with multi-value. Thanks, Yury!

\o/

Pushed by wingo@igalia.com: https://hg.mozilla.org/integration/autoland/rev/e03cd0468eaa Update wasmparser to version 0.14.0 r=yury
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla78
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: