workers-rs icon indicating copy to clipboard operation
workers-rs copied to clipboard

Debugging Rust code

Open DenWav opened this issue 5 months ago • 4 comments

There's been some work in this area and it does appear possible to debug code built with wasm-pack using the Chrome DevTools C++ DWARF debugging extension: https://github.com/haraldreingruber-dedalus/rust-wasm-dwarf-debugging

So I have 2 questions - first, is this doable right now? I have been trying to get debugging to work and nothing has worked so far.

Second question is, if it doesn't work yet, is this something that could be put on the radar?

DenWav avatar Jul 24 '25 06:07 DenWav

I added a note a while back about preserving DWARF debugging symbols in CPU profiling at https://developers.cloudflare.com/workers/observability/dev-tools/cpu-usage/#taking-a-profile.

For setting breakpoints in VSCode with rust-analyzer, I haven't been able to get it working myself but @zebp said at one point he was able to get something like this to work:

  1. Enable dwarf debug symbols in Cargo.toml
  2. npx wrangler dev
  3. In VSCode do cmd + shift + p and run Debug: Attach to node process and then you should be able to select breakpoints (but when I tried this breakpoints still showed up as unattached, so not quite working).

If you do manage to get breakpoints working, do feel free to submit a docs PR like https://github.com/cloudflare/cloudflare-docs/pull/21347.

You might also find https://blog.cloudflare.com/wasm-coredumps/ useful for debugging production code.

lukevalenta avatar Jul 24 '25 10:07 lukevalenta

Yep I had the same experience, I was able to attach to the node process but wasn't able to attach breakpoints. In the sources section of the chrome debug window it doesn't show the rust code, so something is missing I think, whether it's just some source maps or something else.

DenWav avatar Jul 24 '25 21:07 DenWav

Actually never mind - in VSCode with this extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode.wasm-dwarf-debugging and the configuration needed to include DWARF symbols in the wasm did allow me to debug Rust code from VSCode.

It's not a great experience since I can't really run anything in the console, but it's something.

I generally prefer Jetbrains products so I was trying to do it in RustRover, but that doesn't seem to be supported unfortunately: https://youtrack.jetbrains.com/issue/RUST-15886/Cant-debug-rust-compiled-to-wasm-with-attached-chrome

DenWav avatar Jul 24 '25 21:07 DenWav

RustRover

I went down the exact same path, with the same outcome. Really wish RustRover would have been a full solution as I really liked it, but Cursor changed the game.

PeterMHammond avatar Jul 24 '25 21:07 PeterMHammond