Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the newly fixed debugging information #3698

Open
daxpedda opened this issue Nov 10, 2023 · 4 comments
Open

Use the newly fixed debugging information #3698

daxpedda opened this issue Nov 10, 2023 · 4 comments
Labels
docs Issues related to documentation enhancement

Comments

@daxpedda
Copy link
Collaborator

daxpedda commented Nov 10, 2023

Just dropping some random thoughts before I forget them.

  • Using it in wasm-bindgen-test instead of console_error_panic_hook (don't replace it entirely because we still need the panic message).
  • Add a new documentation page noting how to actually deploy it.
    • Generate sourcemaps, e.g. using wasm2map.
    • Strip DWARF in case of sourcemaps.
    • Notes on browser support and how to serve source files if not bundled.
  • Maybe think about adding an option to generate source maps or split debug info directly in wasm-bindgen, but I would argue this would be more the domain of wasm-pack and co.
@ranile
Copy link
Collaborator

ranile commented Nov 18, 2023

A page in the documentation about this information would be very helpful

@xxshady
Copy link

xxshady commented Aug 27, 2024

for some reason wasm2map generates empty sourcemap file when i call it on .wasm generated by wasm-pack
{"version":3,"names":[],"sources":[""],"sourcesContent":[],"mappings":""}

commands i use:
wasm-pack build --dev --target no-modules
cargo wasm2map --bundle-sources -p <generated .wasm> -b http://127.0.0.1:8080

it generates correct sourcemap for .wasm from target/wasm32-unknown-unknown/debug though (but its not usable with wasm-pack's .wasm)

@daxpedda
Copy link
Collaborator Author

You have to use the --keep-debug CLI option to not discard the DWARF information when post-processing with wasm-bindgen.

How to do that with wasm-pack is something you might want to ask there.

@xxshady
Copy link

xxshady commented Aug 28, 2024

yeah, thank you, with --keep-debug wasm2map generates correct sourcemap, i did not found how to enable it in wasm-pack, but using wasm-bindgen CLI directly it worked:

  1. cargo build --target wasm32-unknown-unknown
  2. wasm-bindgen --target <your target> --out-dir pkg --keep-debug target/wasm32-unknown-unknown/debug/<crate name>.wasm
    (if you don't have wasm-bindgen CLI installed: cargo install wasm-bindgen-cli)
  3. cargo wasm2map pkg/<crate name>_bg.wasm
    (you probably also need to provide other flags if your target is browser or nodejs, see wasm2map example)
  4. sourcemap should be available in pkg/<crate name>_bg.wasm.map

note: i only tested it with wasm-bindgen --target no-modules, not sure if others will work the same

also, if you are building something outside of browser or nodejs (like me) where sourcemaps are not supported out of the box, here is how you can use sourcemap manually to get original source code line and column:

  1. cargo wasm2map pkg/<crate name>.wasm --bundle-sources --patch --base-url blabla
    (--base-url blabla because it doesnt matter anyway, but required by --bundle-sources)

  2. for example we have this frame:
    at rust_wasm.wasm.rust_wasm::script_events::test_script_events::____test_panic4____::he9b091250693a65d (wasm://wasm/rust_wasm.wasm-01976b8a:wasm-function[2428]:0xbf5ed)
    0xbf5ed is the column, the line is always 1 (because .wasm is binary as i understand)

  3. now you can pass line and colum your sourcemap resolver (anything that can resolve sourcemaps v3)

  4. i'm gonna use source-map-cli for it

  5. source-map-cli doesn't support hex numbers, so converting column to decimal first: 783853

  6. npx source-map-cli resolve pkg/rust_wasm_bg.wasm.map 1 783853

Maps to .../src/script_events.rs:300:4 

    panic!("test panic");
    ^

note: cargo wasm2map pkg/<crate name>_bg.wasm is already enough to get sourcemap but source-map-cli requires bundled source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Issues related to documentation enhancement
Projects
None yet
Development

No branches or pull requests

3 participants