Both Fedora and Ubuntu follow the convention described in Debugging Information in Separate Files.
Gdb first retrieves the filename present in the executable's .gnu_debuglink
section. .gnu_debuglink
doesn't include any directory names. Gdb then looks for a file named (if I may use shell syntax) $(dirname $executable)/$debuglink
, then /usr/lib/debug/$(dirname $executable)/$debuglink
, for the debugging information. (It actually looks in a couple alternative locations; the documentation linked to above has more info.)
The debugging information for a distro-supplied executable can be found in, for example,
/usr/lib/debug/usr/sbin/apache2
on Ubuntu or /usr/lib/debug/usr/sbin/httpd.debug
on Fedora. (Fedora adds a .debug
extension, making it easy to place the file with the debugging information in the same directory as the executable, if you wish.)
The directory /usr/lib/debug
is compiled into gdb at build time, but the gdb user can change it using the set debug-file-directory dirpath1:dirpath2:...
command.
If you're also interested in making the source code available to gdb:
Gdb looks for the source code in the compilation directory (which it retrieves from the debugging information's DW_AT_comp_dir
attributes) or the current working directory. The user can use a variety of gdb commands described in Specifying Source Directories to adjust this.
Fedora's *-debuginfo
packages include both the debugging information and the source code. The source code gets installed under /usr/src/debug
, and the debugging information in the file under /usr/lib/debug
includes a DW_AT_comp_dir
attribute with the directory pathname, such as /usr/src/debug/httpd-2.4.10
. There can be multiple DW_AT_comp_dir
attributes if the executable was built from multiple compilation units.
Ubuntu's *-dbg
packages don't include the source code, in my experience, but users can download the source into the current working directory with the command apt-get source ...
. The debugging information's DW_AT_comp_dir
attribute is something like /build/buildd/apache2-2.4.7
.