Fetch Debug Symbols Automatically in GDB With debuginfod
Point GDB at a debuginfod server with DEBUGINFOD_URLS and it downloads matching debug symbols and source for any shared library on demand, keyed by build ID.

Step into printf in GDB and you land in a wall of assembly, with the message __vfprintf_internal (...) at vfprintf-internal.c:1244, then 1244 vfprintf-internal.c: No such file or directory. The C library on your machine was built with debug information, and the distribution stripped it into a separate package that you did not install. The traditional fix was to find that package, match its version to your running library and install it. debuginfod removes the matching problem: it is an HTTP service that serves debug files and source by build ID, and GDB can query it by itself. You set one environment variable, accept one prompt, and the symbols arrive. This post covers how it works, how to turn it on, what the prompts and cache look like, and where it does not help. The examples use GDB 16.3 on Fedora-style and Debian-style distributions with glibc 2.40.
Why symbols are separate
A shipped binary or library is usually stripped. The -g information is useful to the person debugging and dead weight for the person running, so build systems split it off into a separate file. Each ELF file carries a build ID, a hash in the .note.gnu.build-id section that uniquely names that exact build. The debug file made from the same build carries the same ID. GDB has always been able to look up /usr/lib/debug/.build-id/ab/cdef....debug using that ID when the debug package is installed. debuginfod makes the same lookup over HTTP.
You can read a library's build ID yourself.
readelf -n /lib/x86_64-linux-gnu/libc.so.6 | grep 'Build ID' Build ID: 6f1b8c0e9a2d4b7c5e3f1a8d0c9b2e7f4a6d3c15The value on your system will differ. Because it names the exact bytes, a debuginfod server cannot hand you a debug file for a different build by mistake.
Turn it on
Set DEBUGINFOD_URLS to one or more server addresses, separated by spaces. Many distributions set it for you. Fedora, Debian 12 and later and Ubuntu 22.04 and later ship a config that points it at the distribution's server when GDB is built against libdebuginfod. Check first.
echo "$DEBUGINFOD_URLS"https://debuginfod.elfutils.org/Your distribution may print its own address, and an empty line means nothing is set. The project's public federated server at debuginfod.elfutils.org proxies to many distribution servers, so it is a sensible default. To set it yourself for one shell:
export DEBUGINFOD_URLS="https://debuginfod.elfutils.org/"Put it in your shell profile to keep it. For a server on a corporate network, list its URL, and several URLs are queried in turn.
The first run: the prompt
Start GDB on a program that uses glibc and stop somewhere.
gdb -q ./sum_gReading symbols from ./sum_g...
This GDB supports auto-downloading debuginfo from the following URLs:
<https://debuginfod.elfutils.org/>
Enable debuginfod for this session? (y or [n])GDB asks once per session because a download sends the build IDs of your libraries to a remote server. For a proprietary program, those IDs are information about what you are debugging, so the default answer is no. If the server is your own, say yes. To skip the prompt next time, set the policy in ~/.gdbinit.
set debuginfod enabled onThe accepted values are on, off and ask. set debuginfod enabled on downloads without asking, and off never does. GDB 12 introduced these settings, and the prompt appeared in that release.
What a download looks like
With debuginfod enabled, run the program to a breakpoint and step into the library.
(gdb) break main
Breakpoint 1 at 0x1155: file sum.c, line 13.
(gdb) run
Starting program: /home/dev/sum_g
Downloading separate debug info for /lib/x86_64-linux-gnu/libc.so.6
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main () at sum.c:13
13 int data[] = {4, 8, 15, 16, 23, 42};
(gdb) break printf
Breakpoint 2 at 0x7ffff7e5c770: file ./stdio-common/printf.c, line 28.
(gdb) continue
Continuing.
Breakpoint 2, __printf (format=0x555555556004 "sum = %d\n") at ./stdio-common/printf.c:28
28 ./stdio-common/printf.c: No such file or directory.The line Downloading separate debug info for ... is the debuginfod client at work: GDB took the build ID of libc.so.6, asked the server for the debug file, and received it. Breakpoint 2 now says file ./stdio-common/printf.c, line 28, so the symbols loaded. But the source file is still missing, and the next section covers that. The download is cached in ~/.cache/debuginfod_client/, so the second session does not repeat it.
Source files too
debuginfod serves source as well as symbols, but only the files the debug info names, and only when the server has the source package. When it does, GDB downloads each on first use.
(gdb) list
Downloading source file /usr/src/debug/glibc-2.40/stdio-common/printf.c
23 #include <libioP.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #undef printf
28
29 /* Write formatted output to stdout from the format string FORMAT. */
30 /* VARARGS1 */
31 int
32 __printf (const char *format, ...)
33 {The exact lines depend on the glibc version and the distribution's patches; this is typical of a glibc 2.40 source tree. Whether your distribution's server provides source is up to it, and the message No such file or directory after a successful symbol download means it does not, or the source path in the debug info is something that has not been served. set substitute-path can redirect GDB to a local copy of the source if you have one.
Cache, timeouts and control
Four environment variables matter, documented in the debuginfod-client-config(7) man page of elfutils.
| Variable | Effect |
|---|---|
DEBUGINFOD_URLS | space-separated server URLs |
DEBUGINFOD_CACHE_PATH | cache directory, default ~/.cache/debuginfod_client |
DEBUGINFOD_TIMEOUT | seconds of no progress before giving up, default 90 |
DEBUGINFOD_PROGRESS | set to any value for a progress line on the terminal |
A download of a large library's debug info can be tens of megabytes, so the first stop in a new library can pause for a while. Press Ctrl-C to cancel it; GDB carries on without symbols. The cache is bounded by a cleaning interval and limit configured in files under the cache directory, such as cache_clean_interval_set and max_unused_age_s, and the default removes files unused for about a week.
To see what GDB did, ask it.
(gdb) show debuginfod urls
The current set of debuginfod URLs is: "https://debuginfod.elfutils.org/".
(gdb) show debuginfod enabled
Debuginfod functionality is currently set to "on".set debuginfod urls changes the list for the session, which lets you point at a company server inside GDB without touching the environment.
When it does not help
debuginfod finds files by build ID, so it only helps with a binary that has a build ID and a server that has seen that build. A program you compiled yourself without -g is nobody's debug info but yours; rebuild it. A proprietary vendor library that is not on any server stays opaque. Private builds in your company need your own server: the debuginfod daemon from elfutils indexes a directory of RPMs, DEBs or ELF files, and serves them over HTTP, started with a command such as debuginfod -F /srv/builds. Air-gapped hosts cannot reach a public server at all, so copy the debug packages in by hand.
There is a privacy cost. Each lookup sends a build ID, and the server learns what you are running. For open-source distribution builds that is harmless; for code under NDA, use a server inside your network and keep DEBUGINFOD_URLS unset elsewhere.
Finally, debuginfod fixes missing symbols, not optimised code. A fully symbolised printf frame in an -O2 glibc still shows <optimized out> for some variables.


