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-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Selection</title> 18 19<meta name="description" content="Debugging with GDB: Selection"> 20<meta name="keywords" content="Debugging with GDB: Selection"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Stack.html#Stack" rel="up" title="Stack"> 29<link href="Frame-Info.html#Frame-Info" rel="next" title="Frame Info"> 30<link href="Backtrace.html#Backtrace" rel="previous" title="Backtrace"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Selection"></a> 65<div class="header"> 66<p> 67Next: <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> [<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> 68</div> 69<hr> 70<a name="Selecting-a-Frame"></a> 71<h3 class="section">8.3 Selecting a Frame</h3> 72 73<p>Most commands for examining the stack and other data in your program work on 74whichever stack frame is selected at the moment. Here are the commands for 75selecting a stack frame; all of them finish by printing a brief description 76of the stack frame just selected. 77</p> 78<dl compact="compact"> 79<dd><a name="index-frame_002c-selecting"></a> 80<a name="index-f-_0028frame_0029"></a> 81</dd> 82<dt><code>frame <span class="roman">[</span> <var>frame-selection-spec</var> <span class="roman">]</span></code></dt> 83<dt><code>f <span class="roman">[</span> <var>frame-selection-spec</var> <span class="roman">]</span></code></dt> 84<dd><p>The <code>frame</code> command allows different stack frames to be 85selected. The <var>frame-selection-spec</var> can be any of the following: 86</p> 87<dl compact="compact"> 88<dd><a name="index-frame-level-1"></a> 89</dd> 90<dt><code><var>num</var></code></dt> 91<dt><code>level <var>num</var></code></dt> 92<dd><p>Select frame level <var>num</var>. Recall that frame zero is the innermost 93(currently executing) frame, frame one is the frame that called the 94innermost one, and so on. The highest level frame is usually the one 95for <code>main</code>. 96</p> 97<p>As this is the most common method of navigating the frame stack, the 98string <code>level</code> can be omitted. For example, the following two 99commands are equivalent: 100</p> 101<div class="smallexample"> 102<pre class="smallexample">(gdb) frame 3 103(gdb) frame level 3 104</pre></div> 105 106<a name="index-frame-address"></a> 107</dd> 108<dt><code>address <var>stack-address</var></code></dt> 109<dd><p>Select the frame with stack address <var>stack-address</var>. The 110<var>stack-address</var> for a frame can be seen in the output of 111<code>info frame</code>, for example: 112</p> 113<div class="smallexample"> 114<pre class="smallexample">(gdb) info frame 115Stack level 1, frame at 0x7fffffffda30: 116 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5 117 tail call frame, caller of frame at 0x7fffffffda30 118 source language c++. 119 Arglist at unknown address. 120 Locals at unknown address, Previous frame's sp is 0x7fffffffda30 121</pre></div> 122 123<p>The <var>stack-address</var> for this frame is <code>0x7fffffffda30</code> as 124indicated by the line: 125</p> 126<div class="smallexample"> 127<pre class="smallexample">Stack level 1, frame at 0x7fffffffda30: 128</pre></div> 129 130<a name="index-frame-function"></a> 131</dd> 132<dt><code>function <var>function-name</var></code></dt> 133<dd><p>Select the stack frame for function <var>function-name</var>. If there are 134multiple stack frames for function <var>function-name</var> then the inner 135most stack frame is selected. 136</p> 137<a name="index-frame-view"></a> 138</dd> 139<dt><code>view <var>stack-address</var> <span class="roman">[</span> <var>pc-addr</var> <span class="roman">]</span></code></dt> 140<dd><p>View a frame that is not part of <small>GDB</small>’s backtrace. The frame 141viewed has stack address <var>stack-addr</var>, and optionally, a program 142counter address of <var>pc-addr</var>. 143</p> 144<p>This is useful mainly if the chaining of stack frames has been 145damaged by a bug, making it impossible for <small>GDB</small> to assign 146numbers properly to all frames. In addition, this can be useful 147when your program has multiple stacks and switches between them. 148</p> 149<p>When viewing a frame outside the current backtrace using 150<code>frame view</code> then you can always return to the original 151stack using one of the previous stack frame selection instructions, 152for example <code>frame level 0</code>. 153</p> 154</dd> 155</dl> 156 157<a name="index-up"></a> 158</dd> 159<dt><code>up <var>n</var></code></dt> 160<dd><p>Move <var>n</var> frames up the stack; <var>n</var> defaults to 1. For positive 161numbers <var>n</var>, this advances toward the outermost frame, to higher 162frame numbers, to frames that have existed longer. 163</p> 164<a name="index-down"></a> 165<a name="index-do-_0028down_0029"></a> 166</dd> 167<dt><code>down <var>n</var></code></dt> 168<dd><p>Move <var>n</var> frames down the stack; <var>n</var> defaults to 1. For 169positive numbers <var>n</var>, this advances toward the innermost frame, to 170lower frame numbers, to frames that were created more recently. 171You may abbreviate <code>down</code> as <code>do</code>. 172</p></dd> 173</dl> 174 175<p>All of these commands end by printing two lines of output describing the 176frame. The first line shows the frame number, the function name, the 177arguments, and the source file and line number of execution in that 178frame. The second line shows the text of that source line. 179</p> 180<p>For example: 181</p> 182<div class="smallexample"> 183<pre class="smallexample">(gdb) up 184#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc) 185 at env.c:10 18610 read_input_file (argv[i]); 187</pre></div> 188 189<p>After such a printout, the <code>list</code> command with no arguments 190prints ten lines centered on the point of execution in the frame. 191You can also edit the program at the point of execution with your favorite 192editing program by typing <code>edit</code>. 193See <a href="List.html#List">Printing Source Lines</a>, 194for details. 195</p> 196<dl compact="compact"> 197<dd><a name="index-select_002dframe"></a> 198</dd> 199<dt><code>select-frame <span class="roman">[</span> <var>frame-selection-spec</var> <span class="roman">]</span></code></dt> 200<dd><p>The <code>select-frame</code> command is a variant of <code>frame</code> that does 201not display the new frame after selecting it. This command is 202intended primarily for use in <small>GDB</small> command scripts, where the 203output might be unnecessary and distracting. The 204<var>frame-selection-spec</var> is as for the <code>frame</code> command 205described in <a href="#Selection">Selecting a Frame</a>. 206</p> 207<a name="index-down_002dsilently"></a> 208<a name="index-up_002dsilently"></a> 209</dd> 210<dt><code>up-silently <var>n</var></code></dt> 211<dt><code>down-silently <var>n</var></code></dt> 212<dd><p>These two commands are variants of <code>up</code> and <code>down</code>, 213respectively; they differ in that they do their work silently, without 214causing display of the new frame. They are intended primarily for use 215in <small>GDB</small> command scripts, where the output might be unnecessary and 216distracting. 217</p></dd> 218</dl> 219 220<hr> 221<div class="header"> 222<p> 223Next: <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> [<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> 224</div> 225 226 227 228</body> 229</html> 230