Debug symbols for nix-shell and nix-build

I’m working on a package for the nixpkgs master branch that segfaults inside libstdc++. I have a hard time to figure out how to get all the debug symbols I need to run gdb.

If I understand it correctly environment.enableDebugInfo = true only applies to packages installed in context of the NixOS system derivation.

How do I get the debug symbols for dependencies of packages build with nix-build and - if possible - configure the environment so that gdb can find them automatically?

There is a enableDebugging function that can be used to enable debugging symbols:

$ nix-build -E 'with import <nixpkgs> {}; enableDebugging hello'
$ file result/bin/hello
result/bin/hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/fg4yq8i8wd08xg3fy58l6q73cjy8hjr2-glibc-2.27/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, with debug_info, not stripped
2 Likes

There are so many hidden and useful functions in nixpkgs, I hope there can be at least a simple list for it.

If you create an article List of useful nixpkgs function in the wiki I might add also some I know.

I think this only enables debug symbols for the package in question, but I need the debug symbols of its dependencies (esp. libstdc++ from the gcc package in this case).

If I understand it correctly environment.enableDebugInfo = true in the NixOS config installs the debug symbols for all packages that use separateDebugInfo and sets up the environment so that gdb can find them.

My problem is, that my NixOS system channel is different from the channel I develop against (due to the bug in question only happening when compiling on the master branch). The libstdc++ is therefore different for the package I want to debug.

Therefore neither are the debug symbols installed, nor would the environment variables be set to include them. I guess I could fetch the debug symbols manually and call gdb with them myself, but is there a better, automatic way to do this?

You can probably write a nix derivation that pulls also libstdc++ with debug symbols.

I’m not sure if I understand the problem correctly but using GitHub - edolstra/dwarffs: A FUSE filesystem that allows tools like gdb to look up debug info files via HTTP might help if the gcc pkg you’re using is already built in hydra.nixos.org.

I’m not sure what I did wrong previously, but enableDebugging now is enough, without needing dwarffs to have debug symbols in gdb.