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

Add --wasm-debug flag #255

Merged
merged 2 commits into from
Mar 1, 2024
Merged

Add --wasm-debug flag #255

merged 2 commits into from
Mar 1, 2024

Conversation

paul-hansen
Copy link
Contributor

@paul-hansen paul-hansen commented Feb 23, 2024

Summary

This adds a --wasm-debug flag which enables embedding DWARF debug info and rust's normal debug info to enable source maps in the Wasm file.

This can be used by browsers to show the file and line numbers in backtraces and use the Rust source in debuggers.

How to use

Currently I've only figured out how to use this with Chrome (lmk if anyone gets it working with Firefox!)

  • Make sure your project uses console_error_panic_hook (if you used a Leptos template it should already)
  • Install the C/C++ devtools support (DWARF) extension.
  • Restart Chrome
  • Make sure cargo-leptos is updated
    cargo install cargo-leptos --locked --force
    
  • Run your project with the new flag
    cargo leptos watch --wasm-debug
    

Warning

Make sure you haven't disabled Rust's debug symbols, don't forget to check your global ~/.cargo/config.toml.
If you don't see debuginfo when your build finishes e.g. Finished dev [unoptimized + debuginfo] target(s), you will need to re-enable this.

  • Open your project in chrome and do something that causes a panic in your Rust code (can just add a panic in one of your components. The second error message should now have clickable links to the Rust files instead of the wasm symbols.
    image

This blog post goes over most of these steps with more detail/pictures: https://developer.chrome.com/blog/wasm-debugging-2020/

Comment on lines +116 to +117
.debug(proj.wasm_debug)
.keep_debug(proj.wasm_debug)
Copy link
Contributor Author

@paul-hansen paul-hansen Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: If we wanted we could split these up into two flags, but I think most people will want to enable both. If you enable keep_debug but not debug you get file names in stack traces but clicking them no longer opens the Rust source files.

@benwis benwis force-pushed the main branch 2 times, most recently from 7ac3f38 to 99895ed Compare February 29, 2024 23:17
@paul-hansen
Copy link
Contributor Author

paul-hansen commented Mar 1, 2024

CI failures should be fixed. Ran cargo insta review to accept the changes to the config snapshots. Also rebased on latest main again just for good measure.
cargo test --features=full_tests is now passing locally.

@benwis
Copy link
Contributor

benwis commented Mar 1, 2024

This all looks good, the last failure is a missing param in a windows test.

@benwis benwis merged commit 95e4a7b into leptos-rs:main Mar 1, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants