skills/zig/zig-debugging/SKILL.md
Zig debugging skill. Use when debugging Zig programs with GDB or LLDB, interpreting Zig runtime panics, using std.debug.print for tracing, configuring debug builds, or debugging Zig programs in VS Code. Activates on queries about debugging Zig, Zig panics, zig gdb, zig lldb, std.debug.print, Zig stack traces, or Zig error return traces.
npx skillsauth add mohitmishra786/low-level-dev-skills zig-debuggingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide agents through debugging Zig programs: GDB/LLDB sessions, interpreting Zig panics and error return traces, std.debug.print logging, debug build configuration, and IDE integration.
# Debug build (default) — full debug info, safety checks
zig build-exe src/main.zig -O Debug
# With build system
zig build # uses Debug by default
zig build -Doptimize=Debug
# Run directly with debug output
zig run src/main.zig
Zig emits standard DWARF debug information compatible with GDB:
# Build with debug info
zig build-exe src/main.zig -O Debug -femit-bin=myapp
# Launch GDB
gdb ./myapp
# GDB session
(gdb) break main
(gdb) run arg1 arg2
(gdb) next # step over
(gdb) step # step into
(gdb) continue
(gdb) print my_var
(gdb) info locals
(gdb) bt # backtrace
Break on Zig panics:
(gdb) break __zig_panic_start
(gdb) break std.builtin.default_panic
lldb ./myapp
(lldb) b main
(lldb) r arg1 arg2
(lldb) n # next
(lldb) s # step into
(lldb) p my_var # print
(lldb) frame variable
(lldb) bt # backtrace
(lldb) c # continue
# Break on panic
(lldb) b __zig_panic
Zig panics include the source location and reason:
thread 'main' panic: index out of bounds: index 5, len 3
/home/user/src/main.zig:15:14
/home/user/src/main.zig:42:9
???:?:?: (name not available)
Common panic messages:
| Panic | Cause |
|-------|-------|
| index out of bounds: index N, len M | Slice/array OOB access |
| integer overflow | Arithmetic overflow in Debug/ReleaseSafe |
| attempt to unwrap null | Optional access .? on null |
| reached unreachable code | unreachable executed |
| casting... | Invalid enum tag or union access |
| integer cast truncated bits | @intCast with value out of range |
| out of memory | Allocator failed |
Zig tracks where errors propagate with error return traces:
error: FileNotFound
/home/user/src/main.zig:30:20: 0x10a3b in openConfig (main)
const f = try std.fs.openFileAbsolute(path, .{});
^
/home/user/src/main.zig:15:25: 0x10b12 in run (main)
const cfg = try openConfig("/etc/myapp.conf");
^
/home/user/src/main.zig:8:20: 0x10c44 in main (main)
try run();
^
The trace shows the exact try chain where the error propagated. Read bottom-up: main → run → openConfig.
Enable in release builds:
// build.zig
const exe = b.addExecutable(.{
.name = "myapp",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.error_tracing = true, // enable even in ReleaseFast
});
const std = @import("std");
pub fn main() !void {
const x: u32 = 42;
const name = "world";
// Basic print (always to stderr)
std.debug.print("x = {d}, name = {s}\n", .{ x, name });
// Print any value (useful for structs)
const point = Point{ .x = 1, .y = 2 };
std.debug.print("point = {any}\n", .{point});
// Formatted output
std.debug.print("hex: {x}, binary: {b}\n", .{ x, x });
// Log levels (respects compile-time log level)
const log = std.log.scoped(.my_module);
log.debug("debug info: {d}", .{x});
log.info("started processing", .{});
log.warn("unusual condition", .{});
log.err("failed: {s}", .{"reason"});
}
// Override default log level at root
pub const std_options = std.Options{
.log_level = .debug, // .debug | .info | .warn | .err
};
// Custom log handler
pub fn logFn(
comptime level: std.log.Level,
comptime scope: @TypeOf(.enum_literal),
comptime format: []const u8,
args: anytype,
) void {
const prefix = "[" ++ @tagName(level) ++ "] (" ++ @tagName(scope) ++ "): ";
std.debug.print(prefix ++ format ++ "\n", args);
}
pub const std_options = std.Options{
.logFn = logFn,
};
Install the zig.vscode-zig extension and CodeLLDB.
.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug Zig",
"program": "${workspaceFolder}/zig-out/bin/myapp",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "zig build"
}
]
}
.vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "zig build",
"type": "shell",
"command": "zig build",
"group": { "kind": "build", "isDefault": true },
"problemMatcher": ["$zig"]
}
]
}
skills/zig/zig-compiler for build modes and debug info flagsskills/debuggers/gdb for GDB fundamentalsskills/debuggers/lldb for LLDB fundamentalsskills/zig/zig-cinterop when debugging mixed Zig/C codedevelopment
Zig testing skill for writing and running tests. Use when using zig build test, writing comptime tests, using test filters, working with test allocators to detect leaks, or using Zig's built-in fuzz testing (0.14+). Activates on queries about Zig tests, zig test, zig build test, comptime testing, test allocators, Zig fuzz testing, or detecting memory leaks in Zig tests.
tools
Zig cross-compilation skill. Use when cross-compiling Zig programs to different targets, using Zig's built-in cross-compilation for embedded, WASM, Windows, ARM, or using zig cc to cross-compile C code without a system cross-toolchain. Activates on queries about Zig cross-compilation, zig target triples, zig cc cross-compile, Zig embedded targets, or Zig WASM.
development
Zig comptime skill for compile-time evaluation and metaprogramming. Use when using comptime parameters, comptime types, generics via anytype, comptime reflection with @typeInfo, or metaprogramming patterns that replace C++ templates. Activates on queries about Zig comptime, compile-time evaluation, Zig generics, anytype, @typeInfo, comptime types, or Zig metaprogramming.
development
Zig compiler skill for systems programming. Use when compiling Zig programs, selecting optimization modes, using zig cc as a C compiler, reading Zig error messages, or understanding Zig's compilation model. Activates on queries about zig build-exe, zig build-lib, optimize modes, ReleaseSafe, ReleaseFast, ReleaseSmall, zig cc, zig ast-check, or Zig compilation errors.