Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

380 lines
18KB

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