6.7.9. Best practices for debug packages
A debug package is a package that contains additional information that can be used by gdb
. Since Debian binaries are stripped by default, debugging information, including function names and line numbers, is otherwise not available when running gdb
on Debian binaries. Debug packages allow users who need this additional debugging information to install it without bloating a regular system with the information.
The debug packages contain separated debugging symbols that gdb
can find and load on the fly when debugging a program or library. The convention in Debian is to keep these symbols in /usr/lib/debug/
path, where path is the path to the executable or library. For example, debugging symbols for /usr/bin/foo
go in /usr/lib/debug/usr/bin/foo
, and debugging symbols for /usr/lib/libfoo.so.1
go in /usr/lib/debug/usr/lib/libfoo.so.1
.
6.7.9.1. Automatically generated debug packages
Debug symbol packages can be generated automatically for any binary package that contains executable binaries, and except for corner cases, it should not be necessary to use the old manually generated ones anymore. The package name for a automatic generated debug symbol package ends in -dbgsym
.
The dbgsym
packages are not installed into the regular archives, but in dedicated archives. That means, if you need the debug symbols for debugging, you need to add this archives to your apt configuration and then install the dbgsym
package you are interested in. Please read https://wiki.debian.org/HowToGetABacktrace on how to do that.
6.7.9.2. Manual -dbg packages
Before the advent of the automatic dbgsym
packages, debug packages needed to be manually generated. The name of a manual debug packages ends in -dbg
. It is recommended to migrate such old legacy packages to the new dbgsym
packages whenever possible. The procedure to convert your package is described in https://wiki.debian.org/AutomaticDebugPackages but the gist is to use the --dbgsym-migration='pkgname-dbg (<< currentversion~)'
switch of the dh_strip
command.
However, sometimes it is not possible to convert to the new dbgsym
packages, or you will encounter the old manual -dbg packages in the archives, so you might need to deal with them. It is not recommended to create manual -dbg packages for new packages, except if the automatic ones won’t work for some reason.
One reason could be that debug packages contains an entire special debugging build of a library or other binary. However, usually separating debugging information from the already built binaries is sufficient and will also save space and build time.
This is the case, for example, for debugging symbols of Python extensions. For now the right way to package Python extension debug symbols is to use -dbg
packages as described in https://wiki.debian.org/Python/DbgBuilds.
To create -dbg
packages, the package maintainer has to explicitly specify them in debian/control
.
The debugging symbols can be extracted from an object file using objcopy --only-keep-debug
. Then the object file can be stripped, and objcopy --add-gnu-debuglink
used to specify the path to the debugging symbol file. objcopy 1 explains in detail how this works.
Note that the debug package should depend on the package that it provides debugging symbols for, and this dependency should be versioned. For example:
Depends: libfoo (= ${binary:Version})
The dh_strip
command in debhelper
supports creating debug packages, and can take care of using objcopy
to separate out the debugging symbols for you. If your package uses debhelper/9.20151219
or newer, you don’t need to do anything. debhelper
will generate debug symbol packages (as package
-dbgsym) for you with no additional changes to your source package.