Continuing-and-Stepping.html 18 KB

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