-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc/manual: Add 'Debugging Nix' section #11637
base: master
Are you sure you want to change the base?
Conversation
This commit adds a new 'Debugging Nix' section to the Nix manual. It provides instructions on how to build Nix with debug symbols and how to debug the Nix binary using debuggers like `lldb`. Fixes NixOS#11502
`debug` before configuring the build: | ||
|
||
```console | ||
[nix-shell]$ export mesonBuildType=debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is needed for the Meson build, but our regular build has debug symbols by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by a regular build? I followed this guide:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edolstra is talking about the old autotools buildsystem that we are migrating away from. Do we want debugoptimized instead of debug here?
[nix-shell]$ export mesonBuildType=debug | |
[nix-shell]$ export mesonBuildType=debugoptimized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimized makes sense to me if the debugger is this able to nicely link back into the source code.
To debug the Nix binary you just built: | ||
|
||
```console | ||
[nix-shell]$ lldb -- ./subprojects/nix/nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I use gdb
, and if you're in a nix develop
shell, you can just do
gdb --args nix ...
i.e. no need to give a full path to the nix
binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So meson actually installs it to /home/joerg/git/nix/out/bin which is not in PATH. But in that case we would also need to run ninjaInstallPhase
. I think it makes sense that both build system choose different locations for our own sanity while we still have two and not put both in PATH. I actually prefer being explicit about the executable location, because it's less error prone for users following the tutorial. Let's say one person has exited the devshell to get a debugger and no longer has the PATH from it set, in that case they might run the debugger against the global installed nix, which is not good.
|
||
```console | ||
[nix-shell]$ mesonConfigurePhase | ||
[nix-shell]$ ninjaBuildPhase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get a proper nix installation, we might want to install it instead? The extra overhead is negligible.
[nix-shell]$ ninjaBuildPhase | |
[nix-shell]$ ninjaInstallPhase |
### Installing a Debugger | ||
|
||
Install your preferred debugger within the development shell. For example, to | ||
install `lldb`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we want to suggest gdb on Linux still by default? At least for me it used to be more stable. But I am happily convinced if this has changed. And on macOS I believe we should not suggest to install lldb with nix-shell because it's not code-signed, meaning it won't be able to use the debugger api without disabling apples security protection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Linux I can see why we would want to recommend gdb
, it's just the case that I am on Mac an that's the only thing I was familiar with.
I haven't experienced needing to disable security protection on macOS to work with lldb in nix-shell.
I haven't figured out how to both debug the We could use the Is there a way to point nix to a different socket in terms of the daemon? |
if you run as root than nix won't use the nix-daemon but will have similar privileges. This might be helpful for debugging. Otherwise, you would need to run two debugger sessions. |
Then the problem becomes that you can't reproduce the IPC interactions between the two. |
Usually you won't to need a debugger on both processes at the same time. You can just have the debugger on one process and than maybe verbose logging or strace on the other instance. |
I recently had the problem that the nix-daemon wasn't able to access an ssh key needed to access a remote builder. This was do to the fact that the key was password protected and the subprocess was not piped back to the nix client. |
This PR adds a new 'Debugging Nix' section to the Nix manual. It provides instructions on how to build Nix with debug symbols and how to debug the Nix binary using debuggers like
lldb
.Motivation
Currently, it's hard to get started with launching a debuggable instance of Nix. Building Nix with debug symbols requires knowledge of internal environment variables like mesonBuildType, which are not well-documented.
Context
Please see #11502.
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.