Add DWARF5 debug info for wx compile --debug - #14
Draft
MellKam wants to merge 1 commit into
Draft
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a
--debugcompile mode alongside today's Release path:mir::schedulerlowers 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.mir::Local.name) and into a newwasm::Function.locals_debug, alongside per-function(low_pc, high_pc)captured during codegen.dwarf::mod.rshand-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_arangeswasm custom sections — no sidecar file, self-contained in the.wasmoutput.gimliis a dev-dependency only, used to round-trip our own encoder's output in tests.DW_OP_WASM_location+DW_OP_stack_value+DW_OP_pieceper flattened field. TheDW_OP_stack_valuemarker 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 adwarf-playground/scratch area with a writeup of three wasmtime DWARF-transform issues found during this work(
wasmtime-dwarf-transform-bug.md).