279 lines
16 KiB
HTML
279 lines
16 KiB
HTML
<html lang="en">
|
|
<head>
|
|
<title>Continuing and Stepping - Debugging with GDB</title>
|
|
<meta http-equiv="Content-Type" content="text/html">
|
|
<meta name="description" content="Debugging with GDB">
|
|
<meta name="generator" content="makeinfo 4.13">
|
|
<link title="Top" rel="start" href="index.html#Top">
|
|
<link rel="up" href="Stopping.html#Stopping" title="Stopping">
|
|
<link rel="prev" href="Breakpoints.html#Breakpoints" title="Breakpoints">
|
|
<link rel="next" href="Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-Files" title="Skipping Over Functions and Files">
|
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
|
<!--
|
|
Copyright (C) 1988-2019 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
|
any later version published by the Free Software Foundation; with the
|
|
Invariant Sections being ``Free Software'' and ``Free Software Needs
|
|
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
|
|
and with the Back-Cover Texts as in (a) below.
|
|
|
|
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
|
|
this GNU Manual. Buying copies from GNU Press supports the FSF in
|
|
developing GNU and promoting software freedom.''
|
|
-->
|
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
|
<style type="text/css"><!--
|
|
pre.display { font-family:inherit }
|
|
pre.format { font-family:inherit }
|
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
|
pre.smallexample { font-size:smaller }
|
|
pre.smalllisp { font-size:smaller }
|
|
span.sc { font-variant:small-caps }
|
|
span.roman { font-family:serif; font-weight:normal; }
|
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
<div class="node">
|
|
<a name="Continuing-and-Stepping"></a>
|
|
<p>
|
|
Next: <a rel="next" accesskey="n" href="Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-Files">Skipping Over Functions and Files</a>,
|
|
Previous: <a rel="previous" accesskey="p" href="Breakpoints.html#Breakpoints">Breakpoints</a>,
|
|
Up: <a rel="up" accesskey="u" href="Stopping.html#Stopping">Stopping</a>
|
|
<hr>
|
|
</div>
|
|
|
|
<h3 class="section">5.2 Continuing and Stepping</h3>
|
|
|
|
<p><a name="index-stepping-349"></a><a name="index-continuing-350"></a><a name="index-resuming-execution-351"></a><dfn>Continuing</dfn> means resuming program execution until your program
|
|
completes normally. In contrast, <dfn>stepping</dfn> means executing just
|
|
one more “step” of your program, where “step” may mean either one
|
|
line of source code, or one machine instruction (depending on what
|
|
particular command you use). Either when continuing or when stepping,
|
|
your program may stop even sooner, due to a breakpoint or a signal. (If
|
|
it stops due to a signal, you may want to use <code>handle</code>, or use
|
|
‘<samp><span class="samp">signal 0</span></samp>’ to resume execution (see <a href="Signals.html#Signals">Signals</a>),
|
|
or you may step into the signal's handler (see <a href="stepping-and-signal-handlers.html#stepping-and-signal-handlers">stepping and signal handlers</a>).)
|
|
|
|
|
|
<a name="index-continue-352"></a>
|
|
<a name="index-c-_0040r_007b_0028_0040code_007bcontinue_007d_0029_007d-353"></a>
|
|
<a name="index-fg-_0040r_007b_0028resume-foreground-execution_0029_007d-354"></a>
|
|
<dl><dt><code>continue </code><span class="roman">[</span><var>ignore-count</var><span class="roman">]</span><dt><code>c </code><span class="roman">[</span><var>ignore-count</var><span class="roman">]</span><dt><code>fg </code><span class="roman">[</span><var>ignore-count</var><span class="roman">]</span><dd>Resume program execution, at the address where your program last stopped;
|
|
any breakpoints set at that address are bypassed. The optional argument
|
|
<var>ignore-count</var> allows you to specify a further number of times to
|
|
ignore a breakpoint at this location; its effect is like that of
|
|
<code>ignore</code> (see <a href="Conditions.html#Conditions">Break Conditions</a>).
|
|
|
|
<p>The argument <var>ignore-count</var> is meaningful only when your program
|
|
stopped due to a breakpoint. At other times, the argument to
|
|
<code>continue</code> is ignored.
|
|
|
|
<p>The synonyms <code>c</code> and <code>fg</code> (for <dfn>foreground</dfn>, as the
|
|
debugged program is deemed to be the foreground program) are provided
|
|
purely for convenience, and have exactly the same behavior as
|
|
<code>continue</code>.
|
|
</dl>
|
|
|
|
<p>To resume execution at a different place, you can use <code>return</code>
|
|
(see <a href="Returning.html#Returning">Returning from a Function</a>) to go back to the
|
|
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.
|
|
|
|
<p>A typical technique for using stepping is to set a breakpoint
|
|
(see <a href="Breakpoints.html#Breakpoints">Breakpoints; Watchpoints; and Catchpoints</a>) at the
|
|
beginning of the function or the section of your program where a problem
|
|
is believed to lie, run your program until it stops at that breakpoint,
|
|
and then step through the suspect area, examining the variables that are
|
|
interesting, until you see the problem happen.
|
|
|
|
|
|
<a name="index-step-355"></a>
|
|
<a name="index-s-_0040r_007b_0028_0040code_007bstep_007d_0029_007d-356"></a>
|
|
<dl><dt><code>step</code><dd>Continue running your program until control reaches a different source
|
|
line, then stop it and return control to <span class="sc">gdb</span>. This command is
|
|
abbreviated <code>s</code>.
|
|
|
|
<blockquote>
|
|
<!-- "without debugging information" is imprecise; actually "without line -->
|
|
<!-- numbers in the debugging information". (gcc -g1 has debugging info but -->
|
|
<!-- not line numbers). But it seems complex to try to make that -->
|
|
<!-- distinction here. -->
|
|
<em>Warning:</em> If you use the <code>step</code> command while control is
|
|
within a function that was compiled without debugging information,
|
|
execution proceeds until control reaches a function that does have
|
|
debugging information. Likewise, it will not step into a function which
|
|
is compiled without debugging information. To step through functions
|
|
without debugging information, use the <code>stepi</code> command, described
|
|
below.
|
|
</blockquote>
|
|
|
|
<p>The <code>step</code> command only stops at the first instruction of a source
|
|
line. This prevents the multiple stops that could otherwise occur in
|
|
<code>switch</code> statements, <code>for</code> loops, etc. <code>step</code> continues
|
|
to stop if a function that has debugging information is called within
|
|
the line. In other words, <code>step</code> <em>steps inside</em> any functions
|
|
called within the line.
|
|
|
|
<p>Also, the <code>step</code> command only enters a function if there is line
|
|
number information for the function. Otherwise it acts like the
|
|
<code>next</code> command. This avoids problems when using <code>cc -gl</code>
|
|
on <acronym>MIPS</acronym> machines. Previously, <code>step</code> entered subroutines if there
|
|
was any debugging information about the routine.
|
|
|
|
<br><dt><code>step </code><var>count</var><dd>Continue running as in <code>step</code>, but do so <var>count</var> times. If a
|
|
breakpoint is reached, or a signal not related to stepping occurs before
|
|
<var>count</var> steps, stepping stops right away.
|
|
|
|
<p><a name="index-next-357"></a><a name="index-n-_0040r_007b_0028_0040code_007bnext_007d_0029_007d-358"></a><br><dt><code>next </code><span class="roman">[</span><var>count</var><span class="roman">]</span><dd>Continue to the next source line in the current (innermost) stack frame.
|
|
This is similar to <code>step</code>, but function calls that appear within
|
|
the line of code are executed without stopping. Execution stops when
|
|
control reaches a different line of code at the original stack level
|
|
that was executing when you gave the <code>next</code> command. This command
|
|
is abbreviated <code>n</code>.
|
|
|
|
<p>An argument <var>count</var> is a repeat count, as for <code>step</code>.
|
|
|
|
<!-- FIX ME!! Do we delete this, or is there a way it fits in with -->
|
|
<!-- the following paragraph? - Vctoria -->
|
|
<!-- @code{next} within a function that lacks debugging information acts like -->
|
|
<!-- @code{step}, but any function calls appearing within the code of the -->
|
|
<!-- function are executed without stopping. -->
|
|
<p>The <code>next</code> command only stops at the first instruction of a
|
|
source line. This prevents multiple stops that could otherwise occur in
|
|
<code>switch</code> statements, <code>for</code> loops, etc.
|
|
|
|
<p><a name="index-set-step_002dmode-359"></a><br><dt><code>set step-mode</code><dd><a name="index-functions-without-line-info_002c-and-stepping-360"></a><a name="index-stepping-into-functions-with-no-line-info-361"></a><dt><code>set step-mode on</code><dd>The <code>set step-mode on</code> command causes the <code>step</code> command to
|
|
stop at the first instruction of a function which contains no debug line
|
|
information rather than stepping over it.
|
|
|
|
<p>This is useful in cases where you may be interested in inspecting the
|
|
machine instructions of a function which has no symbolic info and do not
|
|
want <span class="sc">gdb</span> to automatically skip over this function.
|
|
|
|
<br><dt><code>set step-mode off</code><dd>Causes the <code>step</code> command to step over any functions which contains no
|
|
debug information. This is the default.
|
|
|
|
<br><dt><code>show step-mode</code><dd>Show whether <span class="sc">gdb</span> will stop in or step over functions without
|
|
source line debug information.
|
|
|
|
<p><a name="index-finish-362"></a><a name="index-fin-_0040r_007b_0028_0040code_007bfinish_007d_0029_007d-363"></a><br><dt><code>finish</code><dd>Continue running until just after function in the selected stack frame
|
|
returns. Print the returned value (if any). This command can be
|
|
abbreviated as <code>fin</code>.
|
|
|
|
<p>Contrast this with the <code>return</code> command (see <a href="Returning.html#Returning">Returning from a Function</a>).
|
|
|
|
<p><a name="index-until-364"></a><a name="index-u-_0040r_007b_0028_0040code_007buntil_007d_0029_007d-365"></a><a name="index-run-until-specified-location-366"></a><br><dt><code>until</code><dt><code>u</code><dd>Continue running until a source line past the current line, in the
|
|
current stack frame, is reached. This command is used to avoid single
|
|
stepping through a loop more than once. It is like the <code>next</code>
|
|
command, except that when <code>until</code> encounters a jump, it
|
|
automatically continues execution until the program counter is greater
|
|
than the address of the jump.
|
|
|
|
<p>This means that when you reach the end of a loop after single stepping
|
|
though it, <code>until</code> makes your program continue execution until it
|
|
exits the loop. In contrast, a <code>next</code> command at the end of a loop
|
|
simply steps back to the beginning of the loop, which forces you to step
|
|
through the next iteration.
|
|
|
|
<p><code>until</code> always stops your program if it attempts to exit the current
|
|
stack frame.
|
|
|
|
<p><code>until</code> may produce somewhat counterintuitive results if the order
|
|
of machine code does not match the order of the source lines. For
|
|
example, in the following excerpt from a debugging session, the <code>f</code>
|
|
(<code>frame</code>) command shows that execution is stopped at line
|
|
<code>206</code>; yet when we use <code>until</code>, we get to line <code>195</code>:
|
|
|
|
<pre class="smallexample"> (gdb) f
|
|
#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
|
|
206 expand_input();
|
|
(gdb) until
|
|
195 for ( ; argc > 0; NEXTARG) {
|
|
</pre>
|
|
<p>This happened because, for execution efficiency, the compiler had
|
|
generated code for the loop closure test at the end, rather than the
|
|
start, of the loop—even though the test in a C <code>for</code>-loop is
|
|
written before the body of the loop. The <code>until</code> command appeared
|
|
to step back to the beginning of the loop when it advanced to this
|
|
expression; however, it has not really gone to an earlier
|
|
statement—not in terms of the actual machine code.
|
|
|
|
<p><code>until</code> with no argument works by means of single
|
|
instruction stepping, and hence is slower than <code>until</code> with an
|
|
argument.
|
|
|
|
<br><dt><code>until </code><var>location</var><dt><code>u </code><var>location</var><dd>Continue running your program until either the specified <var>location</var> is
|
|
reached, or the current stack frame returns. The location is any of
|
|
the forms described in <a href="Specify-Location.html#Specify-Location">Specify Location</a>.
|
|
This form of the command uses temporary breakpoints, and
|
|
hence is quicker than <code>until</code> without an argument. The specified
|
|
location is actually reached only if it is in the current frame. This
|
|
implies that <code>until</code> can be used to skip over recursive function
|
|
invocations. For instance in the code below, if the current location is
|
|
line <code>96</code>, issuing <code>until 99</code> will execute the program up to
|
|
line <code>99</code> in the same invocation of factorial, i.e., after the inner
|
|
invocations have returned.
|
|
|
|
<pre class="smallexample"> 94 int factorial (int value)
|
|
95 {
|
|
96 if (value > 1) {
|
|
97 value *= factorial (value - 1);
|
|
98 }
|
|
99 return (value);
|
|
100 }
|
|
</pre>
|
|
<p><a name="index-advance-_0040var_007blocation_007d-367"></a><br><dt><code>advance </code><var>location</var><dd>Continue running the program up to the given <var>location</var>. An argument is
|
|
required, which should be of one of the forms described in
|
|
<a href="Specify-Location.html#Specify-Location">Specify Location</a>.
|
|
Execution will also stop upon exit from the current stack
|
|
frame. This command is similar to <code>until</code>, but <code>advance</code> will
|
|
not skip over recursive function calls, and the target location doesn't
|
|
have to be in the same frame as the current one.
|
|
|
|
<p><a name="index-stepi-368"></a><a name="index-si-_0040r_007b_0028_0040code_007bstepi_007d_0029_007d-369"></a><br><dt><code>stepi</code><dt><code>stepi </code><var>arg</var><dt><code>si</code><dd>Execute one machine instruction, then stop and return to the debugger.
|
|
|
|
<p>It is often useful to do ‘<samp><span class="samp">display/i $pc</span></samp>’ when stepping by machine
|
|
instructions. This makes <span class="sc">gdb</span> automatically display the next
|
|
instruction to be executed, each time your program stops. See <a href="Auto-Display.html#Auto-Display">Automatic Display</a>.
|
|
|
|
<p>An argument is a repeat count, as in <code>step</code>.
|
|
|
|
<p><a name="index-nexti-370"></a><a name="index-ni-_0040r_007b_0028_0040code_007bnexti_007d_0029_007d-371"></a><br><dt><code>nexti</code><dt><code>nexti </code><var>arg</var><dt><code>ni</code><dd>Execute one machine instruction, but if it is a function call,
|
|
proceed until the function returns.
|
|
|
|
<p>An argument is a repeat count, as in <code>next</code>.
|
|
|
|
</dl>
|
|
|
|
<p><a name="range-stepping"></a><a name="index-range-stepping-372"></a><a name="index-target_002dassisted-range-stepping-373"></a>By default, and if available, <span class="sc">gdb</span> makes use of
|
|
target-assisted <dfn>range stepping</dfn>. In other words, whenever you
|
|
use a stepping command (e.g., <code>step</code>, <code>next</code>), <span class="sc">gdb</span>
|
|
tells the target to step the corresponding range of instruction
|
|
addresses instead of issuing multiple single-steps. This speeds up
|
|
line stepping, particularly for remote targets. Ideally, there should
|
|
be no reason you would want to turn range stepping off. However, it's
|
|
possible that a bug in the debug info, a bug in the remote stub (for
|
|
remote targets), or even a bug in <span class="sc">gdb</span> could make line
|
|
stepping behave incorrectly when target-assisted range stepping is
|
|
enabled. You can use the following command to turn off range stepping
|
|
if necessary:
|
|
|
|
|
|
<a name="index-set-range_002dstepping-374"></a>
|
|
<a name="index-show-range_002dstepping-375"></a>
|
|
<dl><dt><code>set range-stepping</code><dt><code>show range-stepping</code><dd>Control whether range stepping is enabled.
|
|
|
|
<p>If <code>on</code>, and the target supports it, <span class="sc">gdb</span> tells the
|
|
target to step a range of addresses itself, instead of issuing
|
|
multiple single-steps. If <code>off</code>, <span class="sc">gdb</span> always issues
|
|
single-steps, even if range stepping is supported by the target. The
|
|
default is <code>on</code>.
|
|
|
|
</dl>
|
|
|
|
</body></html>
|
|
|