Debugging with GDB (February 2008)

Table Of Contents
34 Debugging with GDB
see Section 8.9 [Convenience variables], page 75, 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 Section 5.1.7 [Breakpoint menus], page 42,
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 selected stack frame. (See Section 6.1
[Frames], page 51, for a description of stack frames.)
break linenum
Set a breakpoint at line linenum in the current source file. The current source
file is the last file whose source text was printed. The breakpoint will stop your
program just before it executes any of the code on that line.
break filename :linenum
Set a breakpoint at line linenum in source file filename.
break filename :function
Set a breakpoint at entry to function function found in file filename. Specifying
a file name as well as a function name is superfluous except when multiple files
contain similarly named functions.
break *address
Set a breakpoint at address address. You can use this to set breakpoints in
parts of your program which do not have debugging information or source files.
break When called without any arguments, break sets a breakpoint at the next in-
struction to be executed in the selected stack frame (see Chapter 6 [Examining
the Stack], page 51). In any selected frame but the innermost, this makes your
program stop as soon as control returns to that frame. This is similar to the
effect of a finish command in the frame inside the selected frame—except that
finish does not leave an active breakpoint. If you use break without an argu-
ment in the innermost frame, GDB stops the next time it reaches the current
location; this may be useful inside loops.
GDB normally ignores breakpoints when it resumes execution, until at least one
instruction has been executed. If it did not do this, you would be unable to pro-
ceed past a breakpoint without first disabling the breakpoint. This rule applies
whether or not the breakpoint already existed when your program stopped.
break ... if cond
Set a breakpoint with condition cond; evaluate the expression cond each time
the breakpoint is reached, and stop only if the value is nonzero—that is, if cond
evaluates as true. ... stands for one of the possible arguments described
above (or no argument) specifying where to break. See Section 5.1.5 [Break
conditions], page 40, for more information on breakpoint conditions.