Selection.html 9.7 KB

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