12

I am testing a simple todo app in Rust using the YEW framework. When I get an error, the browser console (Devmode) shows JavaScript or assembler (I tried both Chrome and Firefox). How can I get the Rust code? Do I have to setup source maps somewhere?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
dilvan
  • 2,109
  • 2
  • 20
  • 32
  • Not sure if this kind of tool exists for now... – Boiethios Jun 06 '18 at 13:39
  • 3
    [Firefox Nightly's Javascript debugger now supports debugging and source maps for Rust compiled to WASM](https://www.reddit.com/r/rust/comments/7jvoj3/firefox_nightlys_javascript_debugger_now_supports/) from last year Mozilla All Hands Austin, but I couldn't find any information about it. – dilvan Jun 06 '18 at 13:59
  • [OMG `@FirefoxNightly's` JavaScript Debugger supports debugging & source maps for `@rustlang` in `#WebAssemby-compiled` web code!](https://twitter.com/slsoftworks/status/941400137921949696)‏ `@slsoftworks` 14 Dec 2017 afaict you just just emscripten (not the direct rustc wasm backend) and it just works. /cc `@yurydelendik` `@jasonlaster11 `@kripken` – dilvan Jun 06 '18 at 15:42
  • This question was [cross-posted to the Rust user's forum](https://users.rust-lang.org/t/how-to-see-rust-source-code-when-debugging-webassembly-in-a-browser/17933?u=shepmaster). – Shepmaster Jun 06 '18 at 17:57
  • The example in the OP's cross-posted question shows that it is already possible: the webpage [here](https://yurydelendik.github.io/old-man-sandbox/rust-wasm-hey/hey.html), source repo [here](https://github.com/yurydelendik/old-man-sandbox/tree/master/rust-wasm-hey). – ShreevatsaR Apr 29 '22 at 16:27
  • See also the comments on [this issue](https://github.com/rustwasm/wasm-bindgen/issues/2389). – ShreevatsaR May 02 '22 at 00:53

2 Answers2

8

To achieve this you’d need WebAssembly to support sourcemaps. This is something that is being considered for future tooling, but I don’t think much progress has been made yet.

There is also an open issue for Rust sourcemap support

ColinE
  • 68,894
  • 15
  • 164
  • 232
  • 2
    In OPs [cross-posted question](https://users.rust-lang.org/t/how-to-see-rust-source-code-when-debugging-webassembly-in-a-browser/17933?u=shepmaster), they claim that it's already possible. – Shepmaster Jun 06 '18 at 17:58
  • 1
    Seems that the issue you linked has been closed. Relevant/related links: https://github.com/WebAssembly/debugging | https://medium.com/oasislabs/webassembly-debugging-bec0aa93f8c6 | https://github.com/rustwasm/team/issues/26 – joe Aug 20 '19 at 10:04
3

This is possible now for C++. See this post. You need to install this extension and pass -g to generate debug info when compiling the C++.

Unfortunately it doesn't work in Rust yet (at least if you're using wasm-bindgen which you probably are) because wasm-bindgen discards all the DWARF info. See this post and this linked issue.

Timmmm
  • 88,195
  • 71
  • 364
  • 509