You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Selection.html 9.6KB

3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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>Selection (Debugging with GDB)</title>
  17. <meta name="description" content="Selection (Debugging with GDB)">
  18. <meta name="keywords" content="Selection (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="Stack.html#Stack" rel="up" title="Stack">
  26. <link href="Frame-Info.html#Frame-Info" rel="next" title="Frame Info">
  27. <link href="Backtrace.html#Backtrace" rel="prev" title="Backtrace">
  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="Selection"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Frame-Info.html#Frame-Info" accesskey="n" rel="next">Frame Info</a>, Previous: <a href="Backtrace.html#Backtrace" accesskey="p" rel="prev">Backtrace</a>, Up: <a href="Stack.html#Stack" accesskey="u" rel="up">Stack</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="Selecting-a-Frame"></a>
  64. <h3 class="section">8.3 Selecting a Frame</h3>
  65. <p>Most commands for examining the stack and other data in your program work on
  66. whichever stack frame is selected at the moment. Here are the commands for
  67. selecting a stack frame; all of them finish by printing a brief description
  68. of the stack frame just selected.
  69. </p>
  70. <dl compact="compact">
  71. <dd><a name="index-frame_002c-selecting"></a>
  72. <a name="index-f-_0028frame_0029"></a>
  73. </dd>
  74. <dt><code>frame <span class="roman">[</span> <var>frame-selection-spec</var> <span class="roman">]</span></code></dt>
  75. <dt><code>f <span class="roman">[</span> <var>frame-selection-spec</var> <span class="roman">]</span></code></dt>
  76. <dd><p>The <code>frame</code> command allows different stack frames to be
  77. selected. The <var>frame-selection-spec</var> can be any of the following:
  78. </p>
  79. <dl compact="compact">
  80. <dd><a name="index-frame-level-1"></a>
  81. </dd>
  82. <dt><code><var>num</var></code></dt>
  83. <dt><code>level <var>num</var></code></dt>
  84. <dd><p>Select frame level <var>num</var>. Recall that frame zero is the innermost
  85. (currently executing) frame, frame one is the frame that called the
  86. innermost one, and so on. The highest level frame is usually the one
  87. for <code>main</code>.
  88. </p>
  89. <p>As this is the most common method of navigating the frame stack, the
  90. string <code>level</code> can be omitted. For example, the following two
  91. commands are equivalent:
  92. </p>
  93. <div class="smallexample">
  94. <pre class="smallexample">(gdb) frame 3
  95. (gdb) frame level 3
  96. </pre></div>
  97. <a name="index-frame-address"></a>
  98. </dd>
  99. <dt><code>address <var>stack-address</var></code></dt>
  100. <dd><p>Select the frame with stack address <var>stack-address</var>. The
  101. <var>stack-address</var> for a frame can be seen in the output of
  102. <code>info frame</code>, for example:
  103. </p>
  104. <div class="smallexample">
  105. <pre class="smallexample">(gdb) info frame
  106. Stack level 1, frame at 0x7fffffffda30:
  107. rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
  108. tail call frame, caller of frame at 0x7fffffffda30
  109. source language c++.
  110. Arglist at unknown address.
  111. Locals at unknown address, Previous frame's sp is 0x7fffffffda30
  112. </pre></div>
  113. <p>The <var>stack-address</var> for this frame is <code>0x7fffffffda30</code> as
  114. indicated by the line:
  115. </p>
  116. <div class="smallexample">
  117. <pre class="smallexample">Stack level 1, frame at 0x7fffffffda30:
  118. </pre></div>
  119. <a name="index-frame-function"></a>
  120. </dd>
  121. <dt><code>function <var>function-name</var></code></dt>
  122. <dd><p>Select the stack frame for function <var>function-name</var>. If there are
  123. multiple stack frames for function <var>function-name</var> then the inner
  124. most stack frame is selected.
  125. </p>
  126. <a name="index-frame-view"></a>
  127. </dd>
  128. <dt><code>view <var>stack-address</var> <span class="roman">[</span> <var>pc-addr</var> <span class="roman">]</span></code></dt>
  129. <dd><p>View a frame that is not part of <small>GDB</small>&rsquo;s backtrace. The frame
  130. viewed has stack address <var>stack-addr</var>, and optionally, a program
  131. counter address of <var>pc-addr</var>.
  132. </p>
  133. <p>This is useful mainly if the chaining of stack frames has been
  134. damaged by a bug, making it impossible for <small>GDB</small> to assign
  135. numbers properly to all frames. In addition, this can be useful
  136. when your program has multiple stacks and switches between them.
  137. </p>
  138. <p>When viewing a frame outside the current backtrace using
  139. <code>frame view</code> then you can always return to the original
  140. stack using one of the previous stack frame selection instructions,
  141. for example <code>frame level 0</code>.
  142. </p>
  143. </dd>
  144. </dl>
  145. <a name="index-up"></a>
  146. </dd>
  147. <dt><code>up <var>n</var></code></dt>
  148. <dd><p>Move <var>n</var> frames up the stack; <var>n</var> defaults to 1. For positive
  149. numbers <var>n</var>, this advances toward the outermost frame, to higher
  150. frame numbers, to frames that have existed longer.
  151. </p>
  152. <a name="index-down"></a>
  153. <a name="index-do-_0028down_0029"></a>
  154. </dd>
  155. <dt><code>down <var>n</var></code></dt>
  156. <dd><p>Move <var>n</var> frames down the stack; <var>n</var> defaults to 1. For
  157. positive numbers <var>n</var>, this advances toward the innermost frame, to
  158. lower frame numbers, to frames that were created more recently.
  159. You may abbreviate <code>down</code> as <code>do</code>.
  160. </p></dd>
  161. </dl>
  162. <p>All of these commands end by printing two lines of output describing the
  163. frame. The first line shows the frame number, the function name, the
  164. arguments, and the source file and line number of execution in that
  165. frame. The second line shows the text of that source line.
  166. </p>
  167. <p>For example:
  168. </p>
  169. <div class="smallexample">
  170. <pre class="smallexample">(gdb) up
  171. #1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
  172. at env.c:10
  173. 10 read_input_file (argv[i]);
  174. </pre></div>
  175. <p>After such a printout, the <code>list</code> command with no arguments
  176. prints ten lines centered on the point of execution in the frame.
  177. You can also edit the program at the point of execution with your favorite
  178. editing program by typing <code>edit</code>.
  179. See <a href="List.html#List">Printing Source Lines</a>,
  180. for details.
  181. </p>
  182. <dl compact="compact">
  183. <dd><a name="index-select_002dframe"></a>
  184. </dd>
  185. <dt><code>select-frame <span class="roman">[</span> <var>frame-selection-spec</var> <span class="roman">]</span></code></dt>
  186. <dd><p>The <code>select-frame</code> command is a variant of <code>frame</code> that does
  187. not display the new frame after selecting it. This command is
  188. intended primarily for use in <small>GDB</small> command scripts, where the
  189. output might be unnecessary and distracting. The
  190. <var>frame-selection-spec</var> is as for the <code>frame</code> command
  191. described in <a href="#Selection">Selecting a Frame</a>.
  192. </p>
  193. <a name="index-down_002dsilently"></a>
  194. <a name="index-up_002dsilently"></a>
  195. </dd>
  196. <dt><code>up-silently <var>n</var></code></dt>
  197. <dt><code>down-silently <var>n</var></code></dt>
  198. <dd><p>These two commands are variants of <code>up</code> and <code>down</code>,
  199. respectively; they differ in that they do their work silently, without
  200. causing display of the new frame. They are intended primarily for use
  201. in <small>GDB</small> command scripts, where the output might be unnecessary and
  202. distracting.
  203. </p></dd>
  204. </dl>
  205. <hr>
  206. <div class="header">
  207. <p>
  208. Next: <a href="Frame-Info.html#Frame-Info" accesskey="n" rel="next">Frame Info</a>, Previous: <a href="Backtrace.html#Backtrace" accesskey="p" rel="prev">Backtrace</a>, Up: <a href="Stack.html#Stack" accesskey="u" rel="up">Stack</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>
  209. </div>
  210. </body>
  211. </html>