Debugging Nix
This section shows how to build and debug Nix with debug symbols enabled.
Building Nix with Debug Symbols
In the development shell, set the mesonBuildType
environment variable to debug
before configuring the build:
[nix-shell]$ export mesonBuildType=debugoptimized
Then, proceed to build Nix as described in Building Nix. This will build Nix with debug symbols, which are essential for effective debugging.
Debugging the Nix Binary
Obtain your preferred debugger within the development shell:
[nix-shell]$ nix-shell -p gdb
On macOS, use lldb
:
[nix-shell]$ nix-shell -p lldb
Launching the Debugger
To debug the Nix binary, run:
[nix-shell]$ gdb --args ../outputs/out/bin/nix
On macOS, use lldb
:
[nix-shell]$ lldb -- ../outputs/out/bin/nix
Using the Debugger
Inside the debugger, you can set breakpoints, run the program, and inspect variables.
(gdb) break main
(gdb) run <arguments>
Refer to the GDB Documentation for comprehensive usage instructions.
On macOS, use lldb
:
(lldb) breakpoint set --name main
(lldb) process launch -- <arguments>
Refer to the LLDB Tutorial for comprehensive usage instructions.