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=
"Continuing%20and%20Stepping">Continuing and Stepping
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"Signals.html#Signals">Signals
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"Breakpoints.html#Breakpoints">Breakpoints
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"Stopping.html#Stopping">Stopping
</a>
19 <h3 class=
"section">Continuing and stepping
</h3>
21 <p><dfn>Continuing
</dfn> means resuming program execution until your program
22 completes normally. In contrast,
<dfn>stepping
</dfn> means executing just
23 one more
"step" of your program, where
"step" may mean either one
24 line of source code, or one machine instruction (depending on what
25 particular command you use). Either when continuing or when stepping,
26 your program may stop even sooner, due to a breakpoint or a signal. (If
27 it stops due to a signal, you may want to use
<code>handle
</code>, or use
28 <code>signal
0</code> to resume execution. See
<a href=
"Signals.html#Signals">Signals
</a>.)
31 <dt><code>continue
</code>[
<code></code><var>ignore-count
</var><code></code>]
<code></code>
32 <dd><dt><code>c
</code>[
<code></code><var>ignore-count
</var><code></code>]
<code></code>
33 <dd><dt><code>fg
</code>[
<code></code><var>ignore-count
</var><code></code>]
<code></code>
34 <dd>Resume program execution, at the address where your program last stopped;
35 any breakpoints set at that address are bypassed. The optional argument
36 <var>ignore-count
</var> allows you to specify a further number of times to
37 ignore a breakpoint at this location; its effect is like that of
38 <code>ignore
</code> (see
<a href=
"Conditions.html#Conditions">Break conditions
</a>).
40 <p>The argument
<var>ignore-count
</var> is meaningful only when your program
41 stopped due to a breakpoint. At other times, the argument to
42 <code>continue
</code> is ignored.
44 <p>The synonyms
<code>c
</code> and
<code>fg
</code> (for
<dfn>foreground
</dfn>, as the
45 debugged program is deemed to be the foreground program) are provided
46 purely for convenience, and have exactly the same behavior as
47 <code>continue
</code>.
50 <p>To resume execution at a different place, you can use
<code>return
</code>
51 (see
<a href=
"Returning.html#Returning">Returning from a function
</a>) to go back to the
52 calling function; or
<code>jump
</code> (see
<a href=
"Jumping.html#Jumping">Continuing at a different address
</a>) to go to an arbitrary location in your program.
54 <p>A typical technique for using stepping is to set a breakpoint
55 (see
<a href=
"Breakpoints.html#Breakpoints">Breakpoints; watchpoints; and catchpoints
</a>) at the
56 beginning of the function or the section of your program where a problem
57 is believed to lie, run your program until it stops at that breakpoint,
58 and then step through the suspect area, examining the variables that are
59 interesting, until you see the problem happen.
63 <dd>Continue running your program until control reaches a different source
64 line, then stop it and return control to GDB. This command is
65 abbreviated
<code>s
</code>.
68 <em>Warning:
</em> If you use the
<code>step
</code> command while control is
69 within a function that was compiled without debugging information,
70 execution proceeds until control reaches a function that does have
71 debugging information. Likewise, it will not step into a function which
72 is compiled without debugging information. To step through functions
73 without debugging information, use the
<code>stepi
</code> command, described
77 <p>The
<code>step
</code> command only stops at the first instruction of a source
78 line. This prevents the multiple stops that could otherwise occur in
79 <code>switch
</code> statements,
<code>for
</code> loops, etc.
<code>step
</code> continues
80 to stop if a function that has debugging information is called within
81 the line. In other words,
<code>step
</code> <em>steps inside
</em> any functions
82 called within the line.
84 <p>Also, the
<code>step
</code> command only enters a function if there is line
85 number information for the function. Otherwise it acts like the
86 <code>next
</code> command. This avoids problems when using
<code>cc -gl
</code>
87 on MIPS machines. Previously,
<code>step
</code> entered subroutines if there
88 was any debugging information about the routine.
90 <br><dt><code>step
</code><var>count
</var><code></code>
91 <dd>Continue running as in
<code>step
</code>, but do so
<var>count
</var> times. If a
92 breakpoint is reached, or a signal not related to stepping occurs before
93 <var>count
</var> steps, stepping stops right away.
95 <br><dt><code>next
</code>[
<code></code><var>count
</var><code></code>]
<code></code>
96 <dd>Continue to the next source line in the current (innermost) stack frame.
97 This is similar to
<code>step
</code>, but function calls that appear within
98 the line of code are executed without stopping. Execution stops when
99 control reaches a different line of code at the original stack level
100 that was executing when you gave the
<code>next
</code> command. This command
101 is abbreviated
<code>n
</code>.
103 <p>An argument
<var>count
</var> is a repeat count, as for
<code>step
</code>.
105 <p>The
<code>next
</code> command only stops at the first instruction of a
106 source line. This prevents multiple stops that could otherwise occur in
107 <code>switch
</code> statements,
<code>for
</code> loops, etc.
109 <br><dt><code>set step-mode
</code>
110 <dd><dt><code>set step-mode on
</code>
111 <dd>The
<code>set step-mode on
</code> command causes the
<code>step
</code> command to
112 stop at the first instruction of a function which contains no debug line
113 information rather than stepping over it.
115 <p>This is useful in cases where you may be interested in inspecting the
116 machine instructions of a function which has no symbolic info and do not
117 want GDB to automatically skip over this function.
119 <br><dt><code>set step-mode off
</code>
120 <dd>Causes the
<code>step
</code> command to step over any functions which contains no
121 debug information. This is the default.
123 <br><dt><code>finish
</code>
124 <dd>Continue running until just after function in the selected stack frame
125 returns. Print the returned value (if any).
127 <p>Contrast this with the
<code>return
</code> command (see
<a href=
"Returning.html#Returning">Returning from a function
</a>).
129 <br><dt><code>until
</code>
130 <dd><dt><code>u
</code>
131 <dd>Continue running until a source line past the current line, in the
132 current stack frame, is reached. This command is used to avoid single
133 stepping through a loop more than once. It is like the
<code>next
</code>
134 command, except that when
<code>until
</code> encounters a jump, it
135 automatically continues execution until the program counter is greater
136 than the address of the jump.
138 <p>This means that when you reach the end of a loop after single stepping
139 though it,
<code>until
</code> makes your program continue execution until it
140 exits the loop. In contrast, a
<code>next
</code> command at the end of a loop
141 simply steps back to the beginning of the loop, which forces you to step
142 through the next iteration.
144 <p><code>until
</code> always stops your program if it attempts to exit the current
147 <p><code>until
</code> may produce somewhat counterintuitive results if the order
148 of machine code does not match the order of the source lines. For
149 example, in the following excerpt from a debugging session, the
<code>f
</code>
150 (
<code>frame
</code>) command shows that execution is stopped at line
151 <code>206</code>; yet when we use
<code>until
</code>, we get to line
<code>195</code>:
153 <pre class=
"example"> (gdb) f
154 #
0 main (argc=
4, argv=
0xf7fffae8) at m4.c:
206
157 195 for ( ; argc
> 0; NEXTARG) {
160 <p>This happened because, for execution efficiency, the compiler had
161 generated code for the loop closure test at the end, rather than the
162 start, of the loop--even though the test in a C
<code>for
</code>-loop is
163 written before the body of the loop. The
<code>until
</code> command appeared
164 to step back to the beginning of the loop when it advanced to this
165 expression; however, it has not really gone to an earlier
166 statement--not in terms of the actual machine code.
168 <p><code>until
</code> with no argument works by means of single
169 instruction stepping, and hence is slower than
<code>until
</code> with an
172 <br><dt><code>until
</code><var>location
</var><code></code>
173 <dd><dt><code>u
</code><var>location
</var><code></code>
174 <dd>Continue running your program until either the specified location is
175 reached, or the current stack frame returns.
<var>location
</var> is any of
176 the forms of argument acceptable to
<code>break
</code> (see
<a href=
"Set-Breaks.html#Set%20Breaks">Setting breakpoints
</a>). This form of the command uses breakpoints,
177 and hence is quicker than
<code>until
</code> without an argument.
179 <br><dt><code>stepi
</code>
180 <dd><dt><code>stepi
</code><var>arg
</var><code></code>
181 <dd><dt><code>si
</code>
182 <dd>Execute one machine instruction, then stop and return to the debugger.
184 <p>It is often useful to do
<code>display/i $pc
</code> when stepping by machine
185 instructions. This makes GDB automatically display the next
186 instruction to be executed, each time your program stops. See
<a href=
"Auto-Display.html#Auto%20Display">Automatic display
</a>.
188 <p>An argument is a repeat count, as in
<code>step
</code>.
190 <br><dt><code>nexti
</code>
191 <dd><dt><code>nexti
</code><var>arg
</var><code></code>
192 <dd><dt><code>ni
</code>
193 <dd>Execute one machine instruction, but if it is a function call,
194 proceed until the function returns.
196 <p>An argument is a repeat count, as in
<code>next
</code>.