Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)

2 Getting In and Out of GDB
This chapter discusses how to start GDB, and exit out of it. The essentials are:
type '(gdb)' to start GDB.
type quit or C-d to exit.
Invoking GDB
Invoke GDB by running the program (gdb). Once started, GDB reads commands from the terminal
until you tell it to exit.
You can also run (gdb) with a variety of arguments and options, to specify more of your debugging
environment at the outset.
The command-line options described here are designed to cover a variety of situations; in some
environments, some of these options may effectively be unavailable.
The most usual way to start GDB is with one argument, specifying an executable program:
(gdb) program
You can also start with both an executable program and a core file specified:
(gdb) program core
You can, instead, specify a process ID as a second argument, if you want to debug a running
process:
(gdb) program 1234
would attach GDB to process 1234 (unless you also have a file named '1234'; GDB does check
for a core file first).
Taking advantage of the second command-line argument requires a fairly complete operating
system; when you use GDB as a remote debugger attached to a bare board, there may not be
any notion of “process, and there is often no way to get a core dump. GDB will warn you if it is
unable to attach or to read core dumps.
You can run (gdb) without printing the front material, which describes GDB's non-warranty, by
specifying -silent:
gdb -silent
You can further control how GDB starts up by using command-line options. GDB itself can remind
you of the options available.
Type
(gdb) -help
to display all available options and briefly describe their use ('(gdb)-h' is a shorter equivalent).
All options and command-line arguments you give are processed in sequential order. The order
makes a difference when the `-x' option is used.
Choosing files
When GDB starts, it reads any arguments other than options as specifying an executable file and
core file (or process ID). This is the same as if the arguments were specified by the '-se' and '-c'
options respectively. (GDB reads the first argument that does not have an associated option flag
as equivalent to the '-se' option followed by that argument; and the second argument that does
not have an associated option flag, if any, as equivalent to the '-c' option followed by that
argument.)
If GDB has not been configured to included core file support, such as for most embedded targets,
then it will complain about a second argument and ignore it.
Invoking GDB 19