Skip to content

Add DWARF5 debug info for wx compile --debug - #14

Draft
MellKam wants to merge 1 commit into
developfrom
dwarf-debugging
Draft

Add DWARF5 debug info for wx compile --debug#14
MellKam wants to merge 1 commit into
developfrom
dwarf-debugging

Conversation

@MellKam

@MellKam MellKam commented Aug 14, 2026

Copy link
Copy Markdown
Member

Introduces a --debug compile mode alongside today's Release path:

  • mir::scheduler lowers the MIR expression tree directly to wasm (no inlining, no CSE, no scheduling) so every source local keeps a fixed wasm slot and instructions stay in source order — legible for a debugger even though it forgoes Release's opt::builder/scheduler optimizations.
  • Local/parameter names are threaded from TIR through MIR (mir::Local.name) and into a new wasm::Function.locals_debug, alongside per-function (low_pc, high_pc) captured during codegen.
  • dwarf::mod.rs hand-rolls a DWARF5 encoder (compile unit, subprogram/parameter/variable DIEs, a line-number program, and a type-DIE table) emitted as .debug_info/.debug_line/.debug_str/ .debug_line_str/.debug_abbrev/.debug_aranges wasm custom sections — no sidecar file, self-contained in the .wasm output. gimli is a dev-dependency only, used to round-trip our own encoder's output in tests.
  • Struct locals (split across consecutive wasm locals) use chained DW_OP_WASM_location+DW_OP_stack_value+DW_OP_piece per flattened field. The DW_OP_stack_value marker is required per general DWARF semantics (marks the local as a value, not an address to dereference) — its absence crashes wasmtime's own DWARF→native transform on any module with no declared linear memory; a regression test pins this.

Also adds a working wasmtime + CodeLLDB VS Code debugging setup (.vscode/launch.json) for JIT'd wasm modules, and a dwarf-playground/ scratch area with a writeup of three wasmtime DWARF-transform issues found during this work
(wasmtime-dwarf-transform-bug.md).

Introduces a `--debug` compile mode alongside today's Release path:

- `mir::scheduler` lowers the MIR expression tree directly to wasm
  (no inlining, no CSE, no scheduling) so every source local keeps a
  fixed wasm slot and instructions stay in source order — legible for
  a debugger even though it forgoes Release's opt::builder/scheduler
  optimizations.
- Local/parameter names are threaded from TIR through MIR
  (`mir::Local.name`) and into a new `wasm::Function.locals_debug`,
  alongside per-function `(low_pc, high_pc)` captured during codegen.
- `dwarf::mod.rs` hand-rolls a DWARF5 encoder (compile unit,
  subprogram/parameter/variable DIEs, a line-number program, and a
  type-DIE table) emitted as `.debug_info`/`.debug_line`/`.debug_str`/
  `.debug_line_str`/`.debug_abbrev`/`.debug_aranges` wasm custom
  sections — no sidecar file, self-contained in the `.wasm` output.
  `gimli` is a dev-dependency only, used to round-trip our own
  encoder's output in tests.
- Struct locals (split across consecutive wasm locals) use chained
  `DW_OP_WASM_location`+`DW_OP_stack_value`+`DW_OP_piece` per
  flattened field. The `DW_OP_stack_value` marker is required per
  general DWARF semantics (marks the local as a value, not an address
  to dereference) — its absence crashes wasmtime's own DWARF→native
  transform on any module with no declared linear memory; a
  regression test pins this.

Also adds a working wasmtime + CodeLLDB VS Code debugging setup
(`.vscode/launch.json`) for JIT'd wasm modules, and a
`dwarf-playground/` scratch area with a writeup of three wasmtime
DWARF-transform issues found during this work
(`wasmtime-dwarf-transform-bug.md`).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

1 participant