Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

206 lines
8.9KB

  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>Checkpoint/Restart (Debugging with GDB)</title>
  17. <meta name="description" content="Checkpoint/Restart (Debugging with GDB)">
  18. <meta name="keywords" content="Checkpoint/Restart (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="Running.html#Running" rel="up" title="Running">
  26. <link href="Stopping.html#Stopping" rel="next" title="Stopping">
  27. <link href="Forks.html#Forks" rel="prev" title="Forks">
  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="Checkpoint_002fRestart"></a>
  58. <div class="header">
  59. <p>
  60. Previous: <a href="Forks.html#Forks" accesskey="p" rel="prev">Forks</a>, Up: <a href="Running.html#Running" accesskey="u" rel="up">Running</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="Setting-a-Bookmark-to-Return-to-Later"></a>
  64. <h3 class="section">4.12 Setting a <em>Bookmark</em> to Return to Later</h3>
  65. <a name="index-checkpoint"></a>
  66. <a name="index-restart"></a>
  67. <a name="index-bookmark"></a>
  68. <a name="index-snapshot-of-a-process"></a>
  69. <a name="index-rewind-program-state"></a>
  70. <p>On certain operating systems<a name="DOCF4" href="#FOOT4"><sup>4</sup></a>, <small>GDB</small> is able to save a <em>snapshot</em> of a
  71. program&rsquo;s state, called a <em>checkpoint</em>, and come back to it
  72. later.
  73. </p>
  74. <p>Returning to a checkpoint effectively undoes everything that has
  75. happened in the program since the <code>checkpoint</code> was saved. This
  76. includes changes in memory, registers, and even (within some limits)
  77. system state. Effectively, it is like going back in time to the
  78. moment when the checkpoint was saved.
  79. </p>
  80. <p>Thus, if you&rsquo;re stepping thru a program and you think you&rsquo;re
  81. getting close to the point where things go wrong, you can save
  82. a checkpoint. Then, if you accidentally go too far and miss
  83. the critical statement, instead of having to restart your program
  84. from the beginning, you can just go back to the checkpoint and
  85. start again from there.
  86. </p>
  87. <p>This can be especially useful if it takes a lot of time or
  88. steps to reach the point where you think the bug occurs.
  89. </p>
  90. <p>To use the <code>checkpoint</code>/<code>restart</code> method of debugging:
  91. </p>
  92. <dl compact="compact">
  93. <dd><a name="index-checkpoint-1"></a>
  94. </dd>
  95. <dt><code>checkpoint</code></dt>
  96. <dd><p>Save a snapshot of the debugged program&rsquo;s current execution state.
  97. The <code>checkpoint</code> command takes no arguments, but each checkpoint
  98. is assigned a small integer id, similar to a breakpoint id.
  99. </p>
  100. <a name="index-info-checkpoints"></a>
  101. </dd>
  102. <dt><code>info checkpoints</code></dt>
  103. <dd><p>List the checkpoints that have been saved in the current debugging
  104. session. For each checkpoint, the following information will be
  105. listed:
  106. </p>
  107. <dl compact="compact">
  108. <dt><code>Checkpoint ID</code></dt>
  109. <dt><code>Process ID</code></dt>
  110. <dt><code>Code Address</code></dt>
  111. <dt><code>Source line, or label</code></dt>
  112. </dl>
  113. <a name="index-restart-checkpoint_002did"></a>
  114. </dd>
  115. <dt><code>restart <var>checkpoint-id</var></code></dt>
  116. <dd><p>Restore the program state that was saved as checkpoint number
  117. <var>checkpoint-id</var>. All program variables, registers, stack frames
  118. etc. will be returned to the values that they had when the checkpoint
  119. was saved. In essence, gdb will &ldquo;wind back the clock&rdquo; to the point
  120. in time when the checkpoint was saved.
  121. </p>
  122. <p>Note that breakpoints, <small>GDB</small> variables, command history etc.
  123. are not affected by restoring a checkpoint. In general, a checkpoint
  124. only restores things that reside in the program being debugged, not in
  125. the debugger.
  126. </p>
  127. <a name="index-delete-checkpoint-checkpoint_002did"></a>
  128. </dd>
  129. <dt><code>delete checkpoint <var>checkpoint-id</var></code></dt>
  130. <dd><p>Delete the previously-saved checkpoint identified by <var>checkpoint-id</var>.
  131. </p>
  132. </dd>
  133. </dl>
  134. <p>Returning to a previously saved checkpoint will restore the user state
  135. of the program being debugged, plus a significant subset of the system
  136. (OS) state, including file pointers. It won&rsquo;t &ldquo;un-write&rdquo; data from
  137. a file, but it will rewind the file pointer to the previous location,
  138. so that the previously written data can be overwritten. For files
  139. opened in read mode, the pointer will also be restored so that the
  140. previously read data can be read again.
  141. </p>
  142. <p>Of course, characters that have been sent to a printer (or other
  143. external device) cannot be &ldquo;snatched back&rdquo;, and characters received
  144. from eg. a serial device can be removed from internal program buffers,
  145. but they cannot be &ldquo;pushed back&rdquo; into the serial pipeline, ready to
  146. be received again. Similarly, the actual contents of files that have
  147. been changed cannot be restored (at this time).
  148. </p>
  149. <p>However, within those constraints, you actually can &ldquo;rewind&rdquo; your
  150. program to a previously saved point in time, and begin debugging it
  151. again &mdash; and you can change the course of events so as to debug a
  152. different execution path this time.
  153. </p>
  154. <a name="index-checkpoints-and-process-id"></a>
  155. <p>Finally, there is one bit of internal program state that will be
  156. different when you return to a checkpoint &mdash; the program&rsquo;s process
  157. id. Each checkpoint will have a unique process id (or <var>pid</var>),
  158. and each will be different from the program&rsquo;s original <var>pid</var>.
  159. If your program has saved a local copy of its process id, this could
  160. potentially pose a problem.
  161. </p>
  162. <a name="A-Non_002dobvious-Benefit-of-Using-Checkpoints"></a>
  163. <h4 class="subsection">4.12.1 A Non-obvious Benefit of Using Checkpoints</h4>
  164. <p>On some systems such as <small>GNU</small>/Linux, address space randomization
  165. is performed on new processes for security reasons. This makes it
  166. difficult or impossible to set a breakpoint, or watchpoint, on an
  167. absolute address if you have to restart the program, since the
  168. absolute location of a symbol will change from one execution to the
  169. next.
  170. </p>
  171. <p>A checkpoint, however, is an <em>identical</em> copy of a process.
  172. Therefore if you create a checkpoint at (eg.) the start of main,
  173. and simply return to that checkpoint instead of restarting the
  174. process, you can avoid the effects of address randomization and
  175. your symbols will all stay in the same place.
  176. </p>
  177. <div class="footnote">
  178. <hr>
  179. <h4 class="footnotes-heading">Footnotes</h4>
  180. <h3><a name="FOOT4" href="#DOCF4">(4)</a></h3>
  181. <p>Currently, only
  182. <small>GNU</small>/Linux.</p>
  183. </div>
  184. <hr>
  185. <div class="header">
  186. <p>
  187. Previous: <a href="Forks.html#Forks" accesskey="p" rel="prev">Forks</a>, Up: <a href="Running.html#Running" accesskey="u" rel="up">Running</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>
  188. </div>
  189. </body>
  190. </html>