GDB contains a large repertoire of commands. See Debugging with GDB,
for extensive documentation on the use
of these commands, together with examples of their use. Furthermore,
the command help invoked from within GDB activates a simple help
facility which summarizes the available commands and their options.
In this section we summarize a few of the most commonly
used commands to give an idea of what
GDB is about. You should create
a simple program with debugging information and experiment with the use of
GDB commands on the program as you read through the
set argscommand is not needed if the program does not require arguments.
runcommand causes execution of the program to start from the beginning. If the program is already running, that is to say if you are currently positioned at a breakpoint, then a prompt will ask for confirmation that you want to abandon the current execution and restart.
GDBwill await further commands. location is either a line number within a file, given in the format
file:linenumber, or it is the name of a subprogram. If you request that a breakpoint be set on a subprogram that is overloaded, a prompt will ask you to specify on which of those subprograms you want to breakpoint. You can also specify that all of them should be breakpointed. If the program is run and execution encounters the breakpoint, then the program stops and
GDBsignals that the breakpoint was encountered by printing the line of code before which the program is halted.
GDB, so the expression can contain function calls, variables, operators, and attribute references.
GDBcan display the values of variables local to the current frame. The command
upcan be used to examine the contents of other active frames, by moving the focus up the stack, that is to say from callee to caller, one frame at a time.
GDBdown from the frame currently being examined to the frame of its callee (the reverse of the previous command),
The above list is a very short introduction to the commands that
GDB provides. Important additional capabilities, including conditional
breakpoints, the ability to execute command sequences on a breakpoint,
the ability to debug at the machine instruction level and many other
features are described in detail in Debugging with GDB. Note that most commands can be abbreviated
(for example, c for continue, bt for backtrace).