WebAssembly / WebAssembly/wabt
wasm2wat can't read debug names of params / vars
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.1k
- Forks
- 827
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 18
Description
i'm compiling rust project to wasm with wasm-pack, then converting resulting wasm to wat and trying to read it.
currently I can find functions by their original names, but function params and variables lack original names.
so for this rust function
pub fn add_two(my_param: i32) -> i32 {
let my_arg = 2;
my_param + my_arg
}
i have this wat
...
(func $wasm_debug_symbols::add_two::h8849f07edd700d60 (type $t3) (param $p0 i32) (result i32)
...
there's only auto generated names for params/vars like $p0, $p1, $l1, $l2, etc.
but this is strange because I've configured rust project to include DWARF debug symbols to wasm
[package.metadata.wasm-pack.profile.dev.wasm-bindgen]
dwarf-debug-info = true
i can even see those my_param and my_arg strings in target wasm file
$ hexdump -C wasm_debug_symbols_bg.wasm | grep -A 1 -B 1 my
001174a0 73 63 72 69 62 65 5f 61 64 64 5f 74 77 6f 00 6d |scribe_add_two.m|
001174b0 79 5f 70 61 72 61 6d 00 6d 79 5f 61 72 67 00 61 |y_param.my_arg.a|
001174c0 72 67 30 00 5f 72 65 74 00 63 6c 61 6e 67 20 4c |rg0._ret.clang L|
apparently original names for params/vars are included in wasm, but wasm2wat cannot find them.
also i've checked that wasm file in dev tools of chrome and firefox, and i don't see original params/vars there either (i assume those browsers have their own wasm to wat converters)
also i've tried to write simple function in wat, feed it to wat2wasm, and then feed resulting wasm to wasm2wat back again. and i see that custom names for params are preserved. it means wasm2wat can extract param names from wasm ok.
simple function in wat
(module
(type $t0 (func (param i32 i32) (result i32)))
(func $addTwo (export "add_two") (type $t0) (param $my_param i32) (param $p1 i32) (result i32)
(i32.add
(local.get $my_param)
(local.get $my_param))))
so i assume that problem is
- either in
wasm-pack, which generates invalid debug symbols, sowasm2watcannot extract them - or in
wasm2wat, which cannot read valid debug symbols from wasm
any thoughts?
i've created minimum rust project for testing.
wasm_debug_symbols_bg.wasm (from wasm-pack)
wasm_debug_symbols_bg.wat (from wasm2wat)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked wasm_debug_symbols_bg.wasm and wasm_debug_symbols_bg.wat, then compare wasm2wat output with the wat2wasm round trip. Check how wasm2wat handles DWARF names versus ordinary local names and use the wasm-pack configuration as context. Done means the missing-name behavior is explained and the appropriate tool's handling is fixed or the issue is redirected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust, wasm
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100