Inspecting GDB Symbol Tables on Linux via Compiler and CLI Utilities
When source code is compiled, human-readable identifiers such as function and variable names are transformed into memory addresses. A symbol table is a data structure produced during compilation that retains the mapping between these identifiers and their corresponding addresses, along with type information, source locations, and scoping details. Debuggers like GDB rely on this table to allow you to refer to symbols by name and to navigate the program’s structure during a debugging session.
To embed symbol information into an ELF binary, include debug data at compile time. With GCC, use the -g flag:
gcc -g -o example example.c
This command generates an executable example that includes DWARF debugging information, which contains the symbol table. Keep in mind that the resulting binary will be larger; production deployments often strip these sections for size and performance reasons.
Several command-line tools let you inspect the symbol table without launching GDB. The nm utility lists symbols from object files:
nm example
By default, nm output is sorted alphabetically and shows symbol names alongside their types and values. You can also use objdump with the -t option for a more detailed table:
objdump -t example
For even richer output, readelf -s displays symbol information directly from ELF sections:
readelf -s example
Inside a GDB session, the debugger itself can query the symbol table. Use info functions to list all defined functions and their load addresses, or info variables to view global and static variables. Additional commands like info types and info scope help you explore the full debugging information available.
Understanding how to generate and read symbol tables equips you to diagnose issues more efficiently and gives you deeper insight into compiled programs.