Skip to Content
marmot

Status: research, 2026-11-18. Next: a review, then an opt-in build behind MARMOT_DWARF=1.

Goal: gdb and lldb break at file:line and step. Perf (and pprof) show file:line. Line tables only, no variables or types.

What exists today

  • Frontend: every op and llvm.func carries loc("/abs/file.go":line:col), no columns by default (codegen/locs.go).
  • LLVM path (-O 2, -release, and dev functions tier0 cannot take): the backend's -g 1 default runs MLIR's DIScopeForLLVMFuncOp with LineTablesOnly (Pipeline.cpp). Every object has .debug_line, .debug_info (one DISubprogram per function), .debug_ranges, .debug_frame, .debug_str, .debug_abbrev. Ops without a frontend location get "<autogenerated>":1 (Pipeline.cpp, for tracebacks as gc names wrapper code).
  • Driver (Linux): first link keeps the DWARF, marmot-pcln reads it (or the per-object fragments) into .marmot_pcln, then llvm-objcopy --strip-all removes DWARF and the symbol table. MacOS: dsymutil or fragments, then -Wl,-S.
  • tier0 (dev) writes no DWARF on any path (MIR, EmitX64/EmitArm64). Its rows go only into the pc table fragments: one row per op, deduplicated by (line, file), no columns, no is_stmt or prologue_end. The first row (fn loc, offset 0) covers the prologue. Inlined frontend code gets the callee's line with no inline record. Panic blocks sit at the function end (rows monotonic in offset, not line). (tier0, 2026-11-18.)
  • Final binaries have no symbol table (llvm-nm: 0 symbols), so perf shows no function names today.
program, modefinal binary.debug_lineall .debug_*of which .debug_frame + .debug_ranges
hello dev217 KB000
sketch dev14.7 MB5.3 KB6.7 KB1.1 KB
hello -O 2179 KB76 KB250 KB99 KB
mapstr -O 2196 KB77 KB249 KB99 KB
sketch -O 28.49 MB1.57 MB4.02 MB1.48 MB
hello -release172 KB16 KB52 KB19 KB
mapstr -release205 KB25 KB79 KB28 KB

(Sketch -release hit the 30 min backend limit in this run under load, tuios not measured.)

  • dev has no line tables at all: tier0 emits none (sketch dev's 5 KB is the LLVM fallback).
  • LLVM's set costs 30 to 140% of the binary. .debug_line alone is 9% (hello -release) to 43% (hello -O 2, where std is not pruned) and 18% for sketch -O 2.
  • .debug_frame duplicates .eh_frame for unwinding, and .debug_ranges exists because function sections give each CU many ranges. Neither is needed for line tables.

gdb 17 on nbody -O 2 (first link): "break main.go:30" resolves, and run stops in main.energy. bt shows main.main at main.go:90, next steps lines 33 and 34, and info line is right. Two defects:

  1. The stop shows "main[energy] () at <autogenerated>:1": the prologue rows carry the <autogenerated> location, so the first stop is on a row without a source line.
  2. DW_LANG_C (MLIR hard-codes it): gdb prints "main[energy]" and cannot parse "break main.energy" as a Go name.

nbody dev: "No symbol table is loaded".

Design options

A. Keep LLVM's DWARF (LLVM modes only). Driver change: with MARMOT_DWARF=1, strip only .debug_frame. Replace .debug_ranges by DWARF 5 rnglists or drop it, because CU ranges are optional for line lookups. Keep .debug_line, .debug_info, .debug_abbrev, .debug_str and .symtab. Backend: own copy of the DI scope pass (about 200 lines) with DW_LANG_Go, producer "marmot", and the function's own line for prologue ops instead of <autogenerated>. Does not cover dev.

B. One writer in marmot-pcln for every mode (recommended). marmot-pcln already holds every row of the final binary with addresses, files, function ranges and inline records (fragments or DWARF). With -dwarf it writes .debug_line (DWARF 5, one CU), .debug_abbrev, .debug_str and .debug_line_str. It also writes a minimal .debug_info: the CU plus one DW_TAG_subprogram per function (name, low_pc, high_pc). The driver adds them with objcopy like .marmot_pcln. Then:

  • dev works without changes to the tier0 emitters (rows exist already),
  • the rows match tracebacks exactly,
  • DW_LANG_Go and Go names (main.energy) come for free,
  • nothing changes in objects or cache keys (link step only, behind the switch),
  • size is about one byte per row with special opcodes, plus about 17 bytes per function in .debug_info, plus names. The pc table's line data is the proxy: measure it against LLVM's .debug_line before building. Costs: is_stmt is set on every row. prologue_end is missing unless tier0 records the prologue end offset (tier0 says it knows it) and LLVM's rows keep a flag in the fragments. Inline records (N rows) can become DW_TAG_inlined_subroutine later. Columns: none (as now).

C. tier0 writes .debug_line per object. Rejected: two writers, cached objects change, and the link must merge and relocate them.

Recommendation: B for all modes. A's backend part (DW_LANG_Go, no <autogenerated> prologue rows) only if B's rows need LLVM's prologue_end.

Driver and flags

  • MARMOT_DWARF=1 (later -g): keep .symtab (function symbols: perf needs them), add the B sections. Default builds, -release included, are unchanged.
  • -s still removes everything.
  • macOS: lldb reads DWARF from the executable's __DWARF segment. B adds it with the same placeholder method as __marmot_pcln, so no dSYM is needed. Check with lldb on the Mac pool (mac-heavy.sh).

Compatibility

  • gdb: file:line breaks and stepping need only .debug_line plus subprograms. With DW_LANG_Go, gdb's Go mode parses pkg.Func names. No runtime-gdb.py (goroutines): out of scope.
  • lldb: same, no Go plugin needed for lines.
  • perf: function names from .symtab, file:line from .debug_line (perf report --sort srcline, perf annotate).
  • pprof: marmot's runtime symbolizes through the pc table already. Check that profiles carry file:line. DWARF does not change that path.
  • Delve: not a goal. It needs gc's runtime layout (g, buildinfo, type DIEs) to work.

Open questions for the critic

  1. B gives up LLVM's prologue_end and column data. Is is_stmt on every row good enough for gdb's "break func" prologue skip? (gdb uses the second row of the function.)
  2. Prologue rows in LLVM modes: use the function's own line, as gc does, or line 0? This changes the pc table (an output change), so it needs its own gate.
  3. Size budget: what share of the binary may MARMOT_DWARF cost? It is opt-in, so the SPEC 0.8x rule does not apply to it. Proposed: report it in marmot size as its own kind.

Next steps

  1. Measure pc table line bytes against LLVM .debug_line on sketch -O 2 and tuios -O 2 (light job).
  2. Prototype B: marmot-pcln -dwarf, driver objcopy, MARMOT_DWARF=1. Test: gdb and lldb break, step and bt on nbody in dev, -O 2 and -release. Perf report shows main.energy with lines. Size table as above.
  3. Then the points of the review, then approval to land (opt-in, default output unchanged).

On this page

Was this page helpful?

Report an issueOpen issues