3 <title>Debugging with GDB
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Debugging with GDB">
6 <meta name=
"generator" content=
"makeinfo 4.3">
7 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home">
12 Node:
<a name=
"Break%20Commands">Break Commands
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Breakpoint-Menus.html#Breakpoint%20Menus">Breakpoint Menus
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Conditions.html#Conditions">Conditions
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Breakpoints.html#Breakpoints">Breakpoints
</a>
19 <h4 class=
"subsection">Breakpoint command lists
</h4>
21 <p>You can give any breakpoint (or watchpoint or catchpoint) a series of
22 commands to execute when your program stops due to that breakpoint. For
23 example, you might want to print the values of certain expressions, or
24 enable other breakpoints.
27 <dt><code>commands
</code>[
<code></code><var>bnum
</var><code></code>]
<code></code>
28 <dd><dt><code>...
</code><var>command-list
</var><code> ...
</code>
29 <dd><dt><code>end
</code>
30 <dd>Specify a list of commands for breakpoint number
<var>bnum
</var>. The commands
31 themselves appear on the following lines. Type a line containing just
32 <code>end
</code> to terminate the commands.
34 <p>To remove all commands from a breakpoint, type
<code>commands
</code> and
35 follow it immediately with
<code>end
</code>; that is, give no commands.
37 <p>With no
<var>bnum
</var> argument,
<code>commands
</code> refers to the last
38 breakpoint, watchpoint, or catchpoint set (not to the breakpoint most
39 recently encountered).
42 <p>Pressing
<RET
> as a means of repeating the last GDB command is
43 disabled within a
<var>command-list
</var>.
45 <p>You can use breakpoint commands to start your program up again. Simply
46 use the
<code>continue
</code> command, or
<code>step
</code>, or any other command
47 that resumes execution.
49 <p>Any other commands in the command list, after a command that resumes
50 execution, are ignored. This is because any time you resume execution
51 (even with a simple
<code>next
</code> or
<code>step
</code>), you may encounter
52 another breakpoint--which could have its own command list, leading to
53 ambiguities about which list to execute.
55 <p>If the first command you specify in a command list is
<code>silent
</code>, the
56 usual message about stopping at a breakpoint is not printed. This may
57 be desirable for breakpoints that are to print a specific message and
58 then continue. If none of the remaining commands print anything, you
59 see no sign that the breakpoint was reached.
<code>silent
</code> is
60 meaningful only at the beginning of a breakpoint command list.
62 <p>The commands
<code>echo
</code>,
<code>output
</code>, and
<code>printf
</code> allow you to
63 print precisely controlled output, and are often useful in silent
64 breakpoints. See
<a href=
"Output.html#Output">Commands for controlled output
</a>.
66 <p>For example, here is how you could use breakpoint commands to print the
67 value of
<code>x
</code> at entry to
<code>foo
</code> whenever
<code>x
</code> is positive.
69 <pre class=
"example"> break foo if x
>0
77 <p>One application for breakpoint commands is to compensate for one bug so
78 you can test for another. Put a breakpoint just after the erroneous line
79 of code, give it a condition to detect the case in which something
80 erroneous has been done, and give it commands to assign correct values
81 to any variables that need them. End with the
<code>continue
</code> command
82 so that your program does not stop, and start with the
<code>silent
</code>
83 command so that no output is produced. Here is an example:
85 <pre class=
"example"> break
403