Debug Symbols: Difference between revisions

imported>Symphorien
explain how to get debug info in gdb. maybe slightly too verbose.
 
Pigs (talk | contribs)
m Add category nixpkgs
 
(5 intermediate revisions by 3 users not shown)
Line 7: Line 7:
Two types of packages can provide debug symbols:
Two types of packages can provide debug symbols:
==== Unstripped packages ====
==== Unstripped packages ====
To prevent stripping of a derivation, use the option <code>dontStrip = true;</code>. This still compiles with optimisation;
to compile with <code>-Og -ggdb</code> in addition to disabling stripping, you can use the function <code>enableDebugging</code>.
Let's take the example of <code>socat</code>.
Let's take the example of <code>socat</code>.
If you install socat, then run  
If you install socat, then run  
{{Commands|
{{Commands|
Line 30: Line 31:
you see that you have debugging symbols for neither socat itself nor for dependent libraries.
you see that you have debugging symbols for neither socat itself nor for dependent libraries.


Now, to build an unstripped socat:
Now, build an unstripped socat:
{{Commands|
{{Commands|
$ nix-build -E 'with import <nixpkgs> {}; enableDebugging socat'
$ nix-build -E 'with import <nixpkgs> {}; enableDebugging socat'
Line 125: Line 126:


==== NixOS ====
==== NixOS ====
By toggling <code>environment.enableDebugInfo</code> to 'true' in <code>/etc/nixos/configuration.nix</code>, all
By toggling <code>environment.enableDebugInfo</code> to 'true' in <code>/etc/nixos/configuration.nix</code>, all separate debug info derivations in your <code>systemPackages</code> will have their debug output linked in <code>/run/current-system/sw/lib/debug/</code> and will be automatically available to gdb. Though note that this will not pick up debug symbols of dependencies – you will need to add the dependencies you want to debug to <code>environment.systemPackages</code> explicitly. If a derivation you are interested in does not have separate debug info enabled, you still have to override it with an overlay for example.
separate debug info derivations in your <code>systemPackages</code> will have their debug output linked in <code>/run/current-system/sw/lib/debug/</code> and
 
will be automatically available to gdb. If a derivation you are interested in does not have separate debug info enabled, you
==== dwarffs ====
still have to override it with an overlay for example.
To avoid the need to explicitly list every dependency in <code>environment.systemPackages</code> to have its debug output available, you can use [https://github.com/edolstra/dwarffs dwarffs]. It will create a virtual file system where gdb will be able to look for separate debug symbols for packages on-demand. The downside is that it might increase gdb start up time significantly.
 
==== nixseparatedebuginfo ====
[https://github.com/symphorien/nixseparatedebuginfod nixseparatedebuginfod] is a debuginfod server that can download the relevant debug outputs and source files as needed by debuginfod-capable tools. Compared to dwarffs, it does not require root access, and handles debug outputs of derivations not built by hydra (eg locally or on a custom binary cache) and source files. Gdb is built with support for debuginfod, and valgrind has support if you additionally install the bin output of elfutils.
 
[[Category:Nixpkgs]]