ERR/E3.0 (slice 2): emit DWARF line-info

Attach LLVM debug metadata so a captured return-address PC resolves to
file:line:col (the runtime half E3.3 needs) and sx binaries become
debuggable in lldb/gdb.

- llvm_api.zig: bind llvm-c/DebugInfo.h (DIBuilder C API was unbound).
- emit_llvm.zig: DIBuilder + one DICompileUnit/DIFile on the main file,
  a DISubprogram per function (LLVMSetSubprogram), and a DILocation per
  instruction from Inst.span (errors.SourceLoc.compute, scoped to the
  subprogram). Plus the "Debug Info Version"/"Dwarf Version" module
  flags and LLVMDIBuilderFinalize.
- Gated on opt none/less + a wired source map (setDebugContext from
  core.zig), mirroring lower.zig's tracesEnabled; release strips it.

Verified: sx ir/sx asm --opt none show correct DILocations + .loc
directives; the 290-example JIT suite (-O0 -> debug on) verifies and
runs unchanged. +2 DWARF unit tests.
This commit is contained in:
agra
2026-06-01 13:14:00 +03:00
parent b44a5d05ef
commit c32d694d57
4 changed files with 273 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
pub const c = @cImport({
@cInclude("llvm-c/Core.h");
@cInclude("llvm-c/Analysis.h");
@cInclude("llvm-c/DebugInfo.h");
@cInclude("llvm-c/Target.h");
@cInclude("llvm-c/TargetMachine.h");