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

preserve variable names in debug output #763

Open
art-in opened this issue Jan 7, 2020 · 5 comments
Open

preserve variable names in debug output #763

art-in opened this issue Jan 7, 2020 · 5 comments
Labels
needs design needs discussion question Further information is requested

Comments

@art-in
Copy link

art-in commented Jan 7, 2020

currently when building with debug info resulting wasm lacks original names for local / global variables and function parameters.

my_lib/src/lib.rs

fn add_two(param1: i32, param2: i32) -> i32 {
    param1 + param2
}

compiling to wasm

wasm-pack build --dev

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling my-lib v0.1.0 (D:\projects\wasm\my-lib)
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
[INFO]: Installing wasm-bindgen...
[INFO]: :-) Done in 0.48s
[INFO]: :-) Your wasm pkg is ready to publish at .\pkg.

converting wasm to wat

wasm2wat pkg/my_lib_bg.wasm
cat pkg/my_lib_bg.wat

...
(func $my_lib::add_two::hf6c60c59956375f2 (type $t6) (param $p0 i32) (param $p1 i32) (result i32)
  (local $l0 i32) (local $l1 i32) (local $l2 i32) (local $l3 i32) (local $l4 i32) ...
...

I can easily find my add_two function, but names of variables / parameters are gone, which is why it's hard to read and debug.

I believe those $p0, $p1, $l0, $l1 names are autogenerated by wasm2wat, since original wasm uses indices instead of custom names.

is it possible to preserve original names?

@danwilhelm
Copy link
Member

danwilhelm commented Jan 9, 2020

This requires that (1) wasm-pack exports the parameter names to WASM (in this case as DWARF debug symbols), and (2) wasm2wat supports extracting them from the DWARF info.

Note that wasm-pack can export parameter names, but not by default:

  1. Although --dev adds some debug info, it currently does not export parameter names. You can verify this: hexdump -C my_lib_bg.wasm.

  2. That said, you can export param names via wasm-pack by adding a few lines to your Cargo.toml (This adds the --keep-debug flag when calling wasm-bindgen.):

[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
dwarf-debug-info = true

I assume this default was intentional, since it is documented in the --dev release notes.

So, this question might be better asked to wasm2wat. (I ran a quick test and also did not see the original param names in the WAT, even when they were included in the WASM file.)

@art-in
Copy link
Author

art-in commented Jan 9, 2020

@danwilhelm

thanks, i've tried same investigation myself and see same results. posted issue to wasm2wat (WebAssembly/wabt#1290)

and i'm still curios why would dwarf-debug-info be disabled by default.
maybe it's not stable, and that's why wasm2wat cannot read debug symbols. hmmm....

@ashleygwilliams
Copy link
Member

hey folks! it seems like we've found a resolution for this- do we think additional documentation would be helpful to other users here? let me know and i can make this a ticket for that! otherwise we can close :)

@ashleygwilliams ashleygwilliams added waiting on response question Further information is requested labels Feb 8, 2020
@art-in
Copy link
Author

art-in commented Feb 8, 2020

here's main unanswered question from WebAssembly/wabt#1290 (comment)

what's more appropriate to do right now? ask wasm-pack to generate Name section, or wasm2wat to read DWARF section?

@ashleygwilliams
Copy link
Member

@art-in thanks for clarifying! that's definitely an interesting question. @fitzgen do you have any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs design needs discussion question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants