bytecodealliance / bytecodealliance/wasmtime
Support of DWARF transformation for static/global variables
- Dominant language
- Rust
- Stars
- 18.6k
- Forks
- 1.8k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 121
Description
C global variables (such as `double s = 0;`) are compiled to WebAssembly as locations in the memory. The produced DWARF describes them as DIEs with `DW_AT_location` attribute that points to that memory address, e.g.:
```
0x00000072: DW_TAG_variable
DW_AT_name ("s")
DW_AT_type (0x00000083 "double")
DW_AT_external (true)
DW_AT_decl_file ("/Users/yury/Work/wasmtime/t.c")
DW_AT_decl_line (11)
DW_AT_location (DW_OP_addr 0x410)
```
The wasmtime does not attempt to transform such locations since it needs "vmctx". In https://github.com/bytecodealliance/wasmtime/pull/1482 , we used some global state, accessible to debugger, to resolve pointers. It is possible to do the same for `DW_OP_addr` in static variables expression: user sets current vmctx in some global memory and a debugger gets it in DWARF expressions (in crates/debug/transform/expression.rs). Though we need to able to [relocate the data in the DWARF expression written by gimli](https://github.com/gimli-rs/gimli/issues/474) to make this work.
The similar approach can be used for transformation of `DW_OP_Wasm_location wasm-global` operation.
Contributor guide
Assessment
This issue has not been assessed yet.