3

Is is possible to debug a wasm module through node?

I am using vscode and compiling with emcc -g4 --source-map-base. Putting a breakpoint in the C source file is ineffective. Trying to debug with node inspector node --inspect through Chrome doesn't allow me to use breakpoints either, although it is possible to debug wasm modules from regular web pages in Chrome.

I am using nodejs v10.13.

dim
  • 623
  • 8
  • 19

2 Answers2

3

enter image description here

WebAssembly Source Maps is supported by both Firefox Developer Edition (in screenshot) and Chrome 71.

What you forgot is, to include a path to the source map. For example:

emcc -g4 --source-map-base http://localhost:8000/

Every source files path is prefixed with http://localhost:8000/ with this option. So replace this with your source directory.

Bumsik Kim
  • 5,853
  • 3
  • 23
  • 39
  • I did put a path (although I didn't mention it explicitly in the question) but I put a url with file://. I thought it was the way to go. Thanks, I'll try again. – dim Dec 13 '18 at 06:01
  • @dim Yeah, I mean your source code must be transffered through HTTP/S just like your JS files. Make sure your web server can access your source code and you can access the files on the browsers. – Bumsik Kim Dec 13 '18 at 09:21
  • 1
    The thing is, I have no web server currently. I'm using node.js directly on my local computer. So any HTTP URL wouldn't make sense. Of course, I can set up a small webserver just for that, but that would be annoying. – dim Dec 13 '18 at 09:42
2

So, I managed to get something working. I installed:

  • Node v11.4
  • Chrome beta 71 (because of this)

And launched the node process with node --inspect, for attaching the Chrome DevTools.

Moreover, in my code, instead of doing WebAssembly.instantiate in one shot (supplying directly the bitcode), I do it in two steps: WebAssembly.compile first, and then WebAssembly.instantiate. As soon as compile gets executed, there are some "wasm" sources being made available in the DevTools. This is the WebAssembly in wast text form, in which breakpoints can be set before it gets executed by instantiate.

But you can't debug from the original C-source files, Chrome DevTools only shows the decompiled wast yet. This feels like the stone age of debugging, but it is still possible to debug.

Edit 2020: This article https://developers.google.com/web/updates/2019/12/webassembly seems to indicate you should now be able to debug in devtools, from the original C source files. I did not try it, though.

dim
  • 623
  • 8
  • 19