Debugging with GDB (September 2007)

Chapter 18: Canned Sequences of Commands 253
If you try to define a hook which does not m atch any known command, GDB issues a
warning from the define command.
18.3 Command files
A command file for GDB is a file of lines that are GDB commands. Comments (lines
starting with #) may also be included. An empty line in a command file does nothing; it
does not mean to repeat the last command, as it would from the terminal.
When you start GDB, it executes commands from its init files. These are files named
.gdbinit on Unix and gdb.ini on DOS/Windows. During startup, GDB does the
following:
1. Reads the init file (if any) in your home directory
1
.
2. Processes command line options and operands.
3. Reads the init file (if any) in the current working directory.
4. Reads command files specified by the -x option.
The init file in your home directory can set options (such as set complaints’) that affect
subsequent processing of command line options and operands. Init files are not executed if
you use the -nx option (see Section 2.1.2 [Choos ing modes], page 13).
It can be useful to create a .gdbinit file in the directory where you are debugging an
application. This file will set the actions that apply for this application.
For example, one might add lines like:
dir /usr/src/path/to/source/files
to add source directories or:
break fatal
to set breakpoints on fatal error routines or diagnostic routines.
On some configurations of GDB, the init file is known by a different name (these are typ-
ically environments where a specialized form of GDB may need to coexist with other forms,
hence a different name for the specialized version’s init file). These are the environments
with special init file names:
VxWorks (Wind River Systems real-time OS): .vxgdbinit
OS68K (Enea Data Systems real-time OS): .os68gdbinit
ES-1800 (Ericsson Telecom AB M68000 emulator): .esgdbinit
You can also request the execution of a command file with the source command:
source filename
Execute the command file filename.
The lines in a command file are executed sequentially. They are not printed as they are
executed. An error in any command terminates execution of the command file.
Commands that would ask for confirmation if used interactively proceed without asking
when used in a command file. Many GDB commands that normally print messages to say
what they are doing omit the messages when called from command files.
1
On DO S/Windows systems, the home directory is the one pointed to by the HOME environment variable.