Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)

5 Stopping and Continuing
The principal purpose of a debugger is to let you stop your program before it terminates abnormally
or runs into trouble, so that you can investigate and determine the reason.
Inside GDB, your program can stop for several reasons, such as a signal, a breakpoint, or reaching
a new line after a GDB command such as step. You can then examine and change variables,
set new breakpoints or remove old ones, and then continue execution. Usually, the messages shown
by GDB provide information on the status of your program―but you can also explicitly request
this information at any time.
info program Display information about the status of your program: whether it is running or
not, what process it is, and why it stopped.
5.1 Breakpoints
A breakpoint makes your program stop whenever a certain point in the program is reached. For
each breakpoint, you can add conditions to control in finer detail whether your program stops.
You can set breakpoints with the break command and its variants. (see “Setting breakpoints
(page 39)) You can stop your program by line number, function name or an address in the program.
You can arrange to have values from your program displayed automatically whenever GDB stops
at a breakpoint. See Automatic display” (page 67).
In HP-UX, SunOS 4.x, SVR4, and Alpha OSF/1 configurations, you can set breakpoints in shared
libraries before the executable is run. See “Debugging support for shared libraries” (page 166).
A catchpoint is another special breakpoint that stops your program when a certain kind of event
occurs, such as the throwing of a C++ exception or the loading of a library. As with watchpoints,
you use a different command to set a catchpoint (see “Setting catchpoints” (page 42)), but apart
from that, you can manage a catchpoint like any other breakpoint. (To stop when your program
receives a signal, use the handle command; see “Signals” (page 50).)
GDB assigns a number to each breakpoint, watchpoint, or catchpoint when you create it; these
numbers are successive integers starting with one. In many of the commands for controlling various
features of breakpoints you use the breakpoint number to say which breakpoint you want to change.
Each breakpoint may be enabled or disabled; if disabled, it has no effect on your program
until you enable it again.
Some GDB commands accept a range of breakpoints on which to operate. A breakpoint range
is either a single breakpoint number, like '5', or two such numbers, in increasing order, separated
by a hyphen, like '5-7'. When a breakpoint range is given to a command, all breakpoint in that
range are operated on.
5.1.1 Setting breakpoints
Breakpoints are set with the break command (abbreviated b). The debugger convenience variable
'$bpnum' records the number of the breakpoint you have set most recently; see “Convenience
variables” (page 73), for a discussion of what you can do with convenience variables.
You have several ways to say where the breakpoint should go.
break function Set a breakpoint at entry to function function. When using
source languages that permit overloading of symbols, such
as C++, function may refer to more than one possible place
to break. See “Breakpoint menus (page 47), for a discussion
of that situation.
break +offset, break
-offset
Set a breakpoint some number of lines forward or back from
the position at which execution stopped in the currently
5.1 Breakpoints 39