1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Continuing and Stepping</title> 18 19<meta name="description" content="Debugging with GDB: Continuing and Stepping"> 20<meta name="keywords" content="Debugging with GDB: Continuing and Stepping"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Stopping.html#Stopping" rel="up" title="Stopping"> 29<link href="Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-Files" rel="next" title="Skipping Over Functions and Files"> 30<link href="Breakpoint_002drelated-Warnings.html#Breakpoint_002drelated-Warnings" rel="previous" title="Breakpoint-related Warnings"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Continuing-and-Stepping"></a> 65<div class="header"> 66<p> 67Next: <a href="Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-Files" accesskey="n" rel="next">Skipping Over Functions and Files</a>, Previous: <a href="Breakpoints.html#Breakpoints" accesskey="p" rel="previous">Breakpoints</a>, Up: <a href="Stopping.html#Stopping" accesskey="u" rel="up">Stopping</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 68</div> 69<hr> 70<a name="Continuing-and-Stepping-1"></a> 71<h3 class="section">5.2 Continuing and Stepping</h3> 72 73<a name="index-stepping"></a> 74<a name="index-continuing"></a> 75<a name="index-resuming-execution"></a> 76<p><em>Continuing</em> means resuming program execution until your program 77completes normally. In contrast, <em>stepping</em> means executing just 78one more “step” of your program, where “step” may mean either one 79line of source code, or one machine instruction (depending on what 80particular command you use). Either when continuing or when stepping, 81your program may stop even sooner, due to a breakpoint or a signal. (If 82it stops due to a signal, you may want to use <code>handle</code>, or use 83‘<samp>signal 0</samp>’ to resume execution (see <a href="Signals.html#Signals">Signals</a>), 84or you may step into the signal’s handler (see <a href="Signals.html#stepping-and-signal-handlers">stepping and signal handlers</a>).) 85</p> 86<dl compact="compact"> 87<dd><a name="index-continue"></a> 88<a name="index-c-_0028continue_0029"></a> 89<a name="index-fg-_0028resume-foreground-execution_0029"></a> 90</dd> 91<dt><code>continue <span class="roman">[</span><var>ignore-count</var><span class="roman">]</span></code></dt> 92<dt><code>c <span class="roman">[</span><var>ignore-count</var><span class="roman">]</span></code></dt> 93<dt><code>fg <span class="roman">[</span><var>ignore-count</var><span class="roman">]</span></code></dt> 94<dd><p>Resume program execution, at the address where your program last stopped; 95any breakpoints set at that address are bypassed. The optional argument 96<var>ignore-count</var> allows you to specify a further number of times to 97ignore a breakpoint at this location; its effect is like that of 98<code>ignore</code> (see <a href="Conditions.html#Conditions">Break Conditions</a>). 99</p> 100<p>The argument <var>ignore-count</var> is meaningful only when your program 101stopped due to a breakpoint. At other times, the argument to 102<code>continue</code> is ignored. 103</p> 104<p>The synonyms <code>c</code> and <code>fg</code> (for <em>foreground</em>, as the 105debugged program is deemed to be the foreground program) are provided 106purely for convenience, and have exactly the same behavior as 107<code>continue</code>. 108</p></dd> 109</dl> 110 111<p>To resume execution at a different place, you can use <code>return</code> 112(see <a href="Returning.html#Returning">Returning from a Function</a>) to go back to the 113calling function; or <code>jump</code> (see <a href="Jumping.html#Jumping">Continuing at a 114Different Address</a>) to go to an arbitrary location in your program. 115</p> 116<p>A typical technique for using stepping is to set a breakpoint 117(see <a href="Breakpoints.html#Breakpoints">Breakpoints; Watchpoints; and Catchpoints</a>) at the 118beginning of the function or the section of your program where a problem 119is believed to lie, run your program until it stops at that breakpoint, 120and then step through the suspect area, examining the variables that are 121interesting, until you see the problem happen. 122</p> 123<dl compact="compact"> 124<dd><a name="index-step"></a> 125<a name="index-s-_0028step_0029"></a> 126</dd> 127<dt><code>step</code></dt> 128<dd><p>Continue running your program until control reaches a different source 129line, then stop it and return control to <small>GDB</small>. This command is 130abbreviated <code>s</code>. 131</p> 132<blockquote> 133<p><em>Warning:</em> If you use the <code>step</code> command while control is 134within a function that was compiled without debugging information, 135execution proceeds until control reaches a function that does have 136debugging information. Likewise, it will not step into a function which 137is compiled without debugging information. To step through functions 138without debugging information, use the <code>stepi</code> command, described 139below. 140</p></blockquote> 141 142<p>The <code>step</code> command only stops at the first instruction of a source 143line. This prevents the multiple stops that could otherwise occur in 144<code>switch</code> statements, <code>for</code> loops, etc. <code>step</code> continues 145to stop if a function that has debugging information is called within 146the line. In other words, <code>step</code> <em>steps inside</em> any functions 147called within the line. 148</p> 149<p>Also, the <code>step</code> command only enters a function if there is line 150number information for the function. Otherwise it acts like the 151<code>next</code> command. This avoids problems when using <code>cc -gl</code> 152on <acronym>MIPS</acronym> machines. Previously, <code>step</code> entered subroutines if there 153was any debugging information about the routine. 154</p> 155</dd> 156<dt><code>step <var>count</var></code></dt> 157<dd><p>Continue running as in <code>step</code>, but do so <var>count</var> times. If a 158breakpoint is reached, or a signal not related to stepping occurs before 159<var>count</var> steps, stepping stops right away. 160</p> 161<a name="index-next"></a> 162<a name="index-n-_0028next_0029"></a> 163</dd> 164<dt><code>next <span class="roman">[</span><var>count</var><span class="roman">]</span></code></dt> 165<dd><p>Continue to the next source line in the current (innermost) stack frame. 166This is similar to <code>step</code>, but function calls that appear within 167the line of code are executed without stopping. Execution stops when 168control reaches a different line of code at the original stack level 169that was executing when you gave the <code>next</code> command. This command 170is abbreviated <code>n</code>. 171</p> 172<p>An argument <var>count</var> is a repeat count, as for <code>step</code>. 173</p> 174 175 176<p>The <code>next</code> command only stops at the first instruction of a 177source line. This prevents multiple stops that could otherwise occur in 178<code>switch</code> statements, <code>for</code> loops, etc. 179</p> 180<a name="index-set-step_002dmode"></a> 181</dd> 182<dt><code>set step-mode</code></dt> 183<dd><a name="index-functions-without-line-info_002c-and-stepping"></a> 184<a name="index-stepping-into-functions-with-no-line-info"></a> 185</dd> 186<dt><code>set step-mode on</code></dt> 187<dd><p>The <code>set step-mode on</code> command causes the <code>step</code> command to 188stop at the first instruction of a function which contains no debug line 189information rather than stepping over it. 190</p> 191<p>This is useful in cases where you may be interested in inspecting the 192machine instructions of a function which has no symbolic info and do not 193want <small>GDB</small> to automatically skip over this function. 194</p> 195</dd> 196<dt><code>set step-mode off</code></dt> 197<dd><p>Causes the <code>step</code> command to step over any functions which contains no 198debug information. This is the default. 199</p> 200</dd> 201<dt><code>show step-mode</code></dt> 202<dd><p>Show whether <small>GDB</small> will stop in or step over functions without 203source line debug information. 204</p> 205<a name="index-finish"></a> 206<a name="index-fin-_0028finish_0029"></a> 207</dd> 208<dt><code>finish</code></dt> 209<dd><p>Continue running until just after function in the selected stack frame 210returns. Print the returned value (if any). This command can be 211abbreviated as <code>fin</code>. 212</p> 213<p>Contrast this with the <code>return</code> command (see <a href="Returning.html#Returning">Returning from a Function</a>). 214</p> 215<a name="index-set-print-finish"></a> 216<a name="index-show-print-finish"></a> 217</dd> 218<dt><code>set print finish <span class="roman">[</span>on|off<span class="roman">]</span></code></dt> 219<dt><code>show print finish</code></dt> 220<dd><p>By default the <code>finish</code> command will show the value that is 221returned by the function. This can be disabled using <code>set print 222finish off</code>. When disabled, the value is still entered into the value 223history (see <a href="Value-History.html#Value-History">Value History</a>), but not displayed. 224</p> 225<a name="index-until"></a> 226<a name="index-u-_0028until_0029"></a> 227<a name="index-run-until-specified-location"></a> 228</dd> 229<dt><code>until</code></dt> 230<dt><code>u</code></dt> 231<dd><p>Continue running until a source line past the current line, in the 232current stack frame, is reached. This command is used to avoid single 233stepping through a loop more than once. It is like the <code>next</code> 234command, except that when <code>until</code> encounters a jump, it 235automatically continues execution until the program counter is greater 236than the address of the jump. 237</p> 238<p>This means that when you reach the end of a loop after single stepping 239though it, <code>until</code> makes your program continue execution until it 240exits the loop. In contrast, a <code>next</code> command at the end of a loop 241simply steps back to the beginning of the loop, which forces you to step 242through the next iteration. 243</p> 244<p><code>until</code> always stops your program if it attempts to exit the current 245stack frame. 246</p> 247<p><code>until</code> may produce somewhat counterintuitive results if the order 248of machine code does not match the order of the source lines. For 249example, in the following excerpt from a debugging session, the <code>f</code> 250(<code>frame</code>) command shows that execution is stopped at line 251<code>206</code>; yet when we use <code>until</code>, we get to line <code>195</code>: 252</p> 253<div class="smallexample"> 254<pre class="smallexample">(gdb) f 255#0 main (argc=4, argv=0xf7fffae8) at m4.c:206 256206 expand_input(); 257(gdb) until 258195 for ( ; argc > 0; NEXTARG) { 259</pre></div> 260 261<p>This happened because, for execution efficiency, the compiler had 262generated code for the loop closure test at the end, rather than the 263start, of the loop—even though the test in a C <code>for</code>-loop is 264written before the body of the loop. The <code>until</code> command appeared 265to step back to the beginning of the loop when it advanced to this 266expression; however, it has not really gone to an earlier 267statement—not in terms of the actual machine code. 268</p> 269<p><code>until</code> with no argument works by means of single 270instruction stepping, and hence is slower than <code>until</code> with an 271argument. 272</p> 273</dd> 274<dt><code>until <var>location</var></code></dt> 275<dt><code>u <var>location</var></code></dt> 276<dd><p>Continue running your program until either the specified <var>location</var> is 277reached, or the current stack frame returns. The location is any of 278the forms described in <a href="Specify-Location.html#Specify-Location">Specify Location</a>. 279This form of the command uses temporary breakpoints, and 280hence is quicker than <code>until</code> without an argument. The specified 281location is actually reached only if it is in the current frame. This 282implies that <code>until</code> can be used to skip over recursive function 283invocations. For instance in the code below, if the current location is 284line <code>96</code>, issuing <code>until 99</code> will execute the program up to 285line <code>99</code> in the same invocation of factorial, i.e., after the inner 286invocations have returned. 287</p> 288<div class="smallexample"> 289<pre class="smallexample">94 int factorial (int value) 29095 { 29196 if (value > 1) { 29297 value *= factorial (value - 1); 29398 } 29499 return (value); 295100 } 296</pre></div> 297 298 299<a name="index-advance-location"></a> 300</dd> 301<dt><code>advance <var>location</var></code></dt> 302<dd><p>Continue running the program up to the given <var>location</var>. An argument is 303required, which should be of one of the forms described in 304<a href="Specify-Location.html#Specify-Location">Specify Location</a>. 305Execution will also stop upon exit from the current stack 306frame. This command is similar to <code>until</code>, but <code>advance</code> will 307not skip over recursive function calls, and the target location doesn’t 308have to be in the same frame as the current one. 309</p> 310 311<a name="index-stepi"></a> 312<a name="index-si-_0028stepi_0029"></a> 313</dd> 314<dt><code>stepi</code></dt> 315<dt><code>stepi <var>arg</var></code></dt> 316<dt><code>si</code></dt> 317<dd><p>Execute one machine instruction, then stop and return to the debugger. 318</p> 319<p>It is often useful to do ‘<samp>display/i $pc</samp>’ when stepping by machine 320instructions. This makes <small>GDB</small> automatically display the next 321instruction to be executed, each time your program stops. See <a href="Auto-Display.html#Auto-Display">Automatic Display</a>. 322</p> 323<p>An argument is a repeat count, as in <code>step</code>. 324</p> 325<a name="index-nexti"></a> 326<a name="index-ni-_0028nexti_0029"></a> 327</dd> 328<dt><code>nexti</code></dt> 329<dt><code>nexti <var>arg</var></code></dt> 330<dt><code>ni</code></dt> 331<dd><p>Execute one machine instruction, but if it is a function call, 332proceed until the function returns. 333</p> 334<p>An argument is a repeat count, as in <code>next</code>. 335</p> 336</dd> 337</dl> 338 339<a name="range-stepping"></a><a name="index-range-stepping"></a> 340<a name="index-target_002dassisted-range-stepping"></a> 341<p>By default, and if available, <small>GDB</small> makes use of 342target-assisted <em>range stepping</em>. In other words, whenever you 343use a stepping command (e.g., <code>step</code>, <code>next</code>), <small>GDB</small> 344tells the target to step the corresponding range of instruction 345addresses instead of issuing multiple single-steps. This speeds up 346line stepping, particularly for remote targets. Ideally, there should 347be no reason you would want to turn range stepping off. However, it’s 348possible that a bug in the debug info, a bug in the remote stub (for 349remote targets), or even a bug in <small>GDB</small> could make line 350stepping behave incorrectly when target-assisted range stepping is 351enabled. You can use the following command to turn off range stepping 352if necessary: 353</p> 354<dl compact="compact"> 355<dd><a name="index-set-range_002dstepping"></a> 356<a name="index-show-range_002dstepping"></a> 357</dd> 358<dt><code>set range-stepping</code></dt> 359<dt><code>show range-stepping</code></dt> 360<dd><p>Control whether range stepping is enabled. 361</p> 362<p>If <code>on</code>, and the target supports it, <small>GDB</small> tells the 363target to step a range of addresses itself, instead of issuing 364multiple single-steps. If <code>off</code>, <small>GDB</small> always issues 365single-steps, even if range stepping is supported by the target. The 366default is <code>on</code>. 367</p> 368</dd> 369</dl> 370 371<hr> 372<div class="header"> 373<p> 374Next: <a href="Skipping-Over-Functions-and-Files.html#Skipping-Over-Functions-and-Files" accesskey="n" rel="next">Skipping Over Functions and Files</a>, Previous: <a href="Breakpoints.html#Breakpoints" accesskey="p" rel="previous">Breakpoints</a>, Up: <a href="Stopping.html#Stopping" accesskey="u" rel="up">Stopping</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 375</div> 376 377 378 379</body> 380</html> 381