ziglang/zig
Debugging
Tools that help when the compiler itself misbehaves.
Crash reports
src/crash_report.zig registers a custom panic handler. When the self-hosted compiler crashes, you get a Zig stack trace plus the source location of the unanalyzed declaration that triggered the failure (when available). src/main.zig wires it up:
pub const panic = crash_report.panic;
pub const debug = crash_report.debug;If you are debugging a comptime infinite loop or a Sema panic, this is what dumps the cycle.
Pretty-printers
The tools/ directory has GDB and LLDB pretty-printers for the compiler's internal types and the standard library:
| File | What it prints |
|---|---|
tools/lldb_pretty_printers.py (~58 KB) |
LLDB summaries for Sema, AIR, ZIR, InternPool, Type, Value, etc. |
tools/stage1_gdb_pretty_printers.py |
Stage1-era types (still useful when debugging the bootstrap path). |
tools/stage2_gdb_pretty_printers.py |
Stage2 compiler types. |
tools/zig_gdb_pretty_printers.py |
Generic Zig builtins (slices, optionals, errors). |
tools/std_gdb_pretty_printers.py |
std.ArrayList, std.HashMap, std.Target, etc. |
Source them from your .gdbinit/.lldbinit.
Verbose flags
zig build-exe ... -fverbose-{ir,llvm-ir,c,...} dumps the IR at each pipeline stage. The exact set of flags is in src/main.zig's argument parser. Useful pairs:
-femit-asm=...and the LLVM-side-fllvm-ir.-femit-zir/-femit-air(when enabled by build options).-fno-llvmto force the self-hosted backend, or-fllvmto force LLVM.
Tracy
src/tracy.zig integrates Tracy zones around the major pipeline stages. Pass -Dtracy=<path> (when the option is exposed by your build configuration) to link Tracy and emit a profile.
Logging the build itself
zig build --verbose, --verbose-cc, --verbose-link, and --verbose-llvm-ir (where supported) make the build runner print exactly what commands it would invoke. The build runner lives in lib/compiler/build_runner.zig.
Incremental compilation debugging
When something only fails under --watch:
- Reproduce with
tools/incr-check.zig— the harness exposes the same edit/recompile loop deterministically. - Inspect what the watcher told the compiler to invalidate.
lib/std/Build/Watch.zigandsrc/IncrementalDebugServer.zigare the relevant files. - The
Zcukeeps a dependency graph; seesrc/Zcu.zigfor the data structures used to invalidate decls.
Reducing a crash
zig reduce (lib/compiler/reduce.zig) is the in-tree minimizer. Given a Zig file and a script that classifies a build as "still buggy" vs "no longer buggy", it produces the smallest reproducer.
Common stumbling blocks
- OOM during analysis.
Semacan build a deep dependency chain; check that you aren't accidentally creating an unboundedcomptimerecursion. - LLVM mismatch. The CMake build pins a specific LLVM version (see
CMakeLists.txt'sfind_package(LLVM ...)lines). Build errors that mention symbol mismatches insrc/zig_llvm*.cppusually mean an LLVM version skew. - Stale cache.
zig buildis cache-aggressive.rm -rf zig-out zig-cache .zig-cacheresolves most "I changed something but it didn't take effect" reports.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.