Debugging with GDB (September 2007)

Chapter 12: GDB Files 103
12 GDB Files
GDB needs to know the file name of the program to be debugged, both in order to read
its symbol table and in order to start your program. To debug a core dump of a previous
run, you must also tell GDB the name of the core dump file.
12.1 Commands to specify files
You can specify executable and core dump file names as arguments to the GDB start-up
command. (see Chapter 2 [Getting In and Out of GDB], page 11).
Occasionally it is necessary to change to a different file during a GDB session. In these
situations the GDB commands to specify new files are useful.
file filename
Use filename as the program to be debugged. It is read for its symbols and for
the contents of pure memory. It is also the program e xecuted when you use the
run command. If you do not specify a directory and the file is not found in the
GDB working directory, GDB uses the environment variable PATH as a list of
directories to search, just as the shell does when looking for a program to run.
You can change the value of this variable, for both GDB and your program,
using the path command.
On systems with memory-mapped files, an auxiliary file named
filename.syms may hold symbol table information for filename. If so,
GDB maps in the symbol table from filename.syms’, starting up more
quickly. See the descriptions of the file options -mapped and -readnow
(available on the command line, and with the commands file, symbol-file,
or add-symbol-file, described below) for more information.
file file with no argument makes GDB discard any information it has on both
executable file and the symbol table.
exec-file [ filename ]
Specify that the program to be run (but not the symbol table) is found in file-
name. GDB s earches the environment variable PATH if necessary to locate your
program. Omitting filename means to discard information on the executable
file.
symbol-file [ filename ]
Read symbol table information from file filename. PATH is searched when nec-
essary. Use the file command to get both symbol table and program to run
from the same file.
symbol-file with no argument clears out GDB information on the symbol
table of your program.
The symbol-file command causes GDB to forget the contents of its conve-
nience variables, the value history, and all breakpoints and auto-display expres-
sions. This is because they may contain pointers to the internal data recording
symbols and data types, which are part of the old symbol table data being
discarded inside GDB.