0%

s15 — Debug Info

Goal

Native-compiled binaries are debuggable: DWARF line tables, frame/variable info, and type descriptions emitted for BIR programs; gdb/lldb scripted smoke proves breakpoints, backtraces, and variable inspection; CodeView lands as the Windows work item.

Implementation Sketch

  • Line tables: span provenance (carried through BIR->MIR per s06) drives .debug_line emission; every MIR instruction maps to a source span or the function-entry span (ARC-inserted ops carry their causing expression’s span per impl-hygiene span-provenance rules).
  • Frames/variables: .debug_info DIEs for functions, params, locals; location lists from regalloc output (register/stack-slot per range); DW_AT_frame_base consistent with the s13 CFI.
  • Types: DWARF type DIEs derived from ReprPlan (layouts/field offsets/discriminants — niche-encoded enums get best-effort encodings; decision record for the encoding scheme).
  • DebugLevel plumbing: reuse BuildOptions.debug_level; parity of behavior with the LLVM path’s DebugContext (None for dev-tier runs if so decided at s22).
  • CodeView: scoped work item for Windows (after DWARF stabilizes; .debug$S/.debug$T via the object crate).
  • Debugger smoke harness: scripted gdb/lldb sessions (batch mode) asserting breakpoint-hit, backtrace shape, and variable read on a fixture corpus.

Test Strategy

  • Matrix: {breakpoint at line, step over call, backtrace through 3 frames, inspect int/str/struct/Option local} x {x86-64 native, aarch64-qemu} (qemu gdbstub) — scripted assertions.
  • Semantic pin: line-table pin for one fixture (addr->line mapping snapshot via ori_test_harness bless).
  • Negative pin: a span-less MIR instruction (test-only mutation) fails the line-table completeness check.

Work Items

  • .debug_line emission from span provenance + completeness check (no span-less instructions).
  • .debug_info function/param/local DIEs with regalloc-driven location lists + CFI-consistent frame base.
  • DWARF type DIEs from ReprPlan incl. niche-enum encoding decision record.
  • gdb/lldb scripted smoke harness green on the debug matrix; line-table bless pin + span-completeness negative pin.
  • CodeView work item executed for Windows (.debug$S/$T) or explicitly ratcheted with its own follow-on anchor inside this plan.