microsoft / vscode-js-debug

A DAP-compatible JavaScript debugger. Used in VS Code, VS, + more
MIT License
1.67k stars 281 forks source link

WASM debugging support #1789

Closed connor4312 closed 1 year ago

connor4312 commented 1 year ago

js-debug should be able to debug WebAssembly.

There's two parts of this. The base devtools experience allows users to step into and around WebAssembly, displayed as WAT. Supporting this can be done pretty easily.

The next step is giving source-level support for debugging. The Chromium team recently made their DWARF debugger open source. While this very sadly doesn't work out of the box for Rust yet, it should eventually (we can hope), and it does support any other language that outputs DWARF symbols.

While the extension is built for integration in Chrome devtools, it looks like it's architected in a way that pretty much all the work happens in the DevToolsPluginWorker. I think that we could package this up into an node module that the extension could consume and run in a Node worker_thread.

The downside is the the DWARF SymbolBackend includes(?) chunks from LLVM and even compressed is pretty hefty at 11MB, so we may not want to have it included in vscode by default like js-debug is. My thought is that we can have an extension that exports a known API for js-debug to consume, alongside an npm package that ships only the types in the package (or maybe I just copy the types directly into js-debug). We can try to both require('vscode').extensions.getExtension('ms-vscode.js-debug-dwarf') as well as require('@vscode/dwarf-debugging') to enable pure DAP consumers to get this too. And of course we can prompt the user to install this extension when they first step into WASM code.

  1. [x] Enable basic debugging with WAT
  2. [x] Create a module bundling the devtools c/++ worker debugger
  3. [x] Integrate the module into js-debug
  4. [x] Externalize the module into an extension with suggestions
connor4312 commented 1 year ago

This is largely done now in PRs #1804 through #1808. Tomorrow I will do some final cleanup and try to get some tests going, and then it will ship in the nightly.

fleabitten232 commented 1 year ago

Does this currently support the "path substitution" feature from the Chrome plugin? I compile in a container, which means that the source file paths are incorrect for the machine I want to debug on.

Appreciate all the work that's been done on this and I'm eager to try it out!

connor4312 commented 1 year ago

The path goes through the usual path mapping logic in js-debug, so for your case you'd want to set the localRoot/remoteRoot in your launch.json as described in https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_remote-debugging