3 <title>Debugging with GDB
</title>
4 <meta http-equiv=
"Content-Type" content=
"text/html">
5 <meta name=
"description" content=
"Debugging with GDB">
6 <meta name=
"generator" content=
"makeinfo 4.3">
7 <link href=
"http://www.gnu.org/software/texinfo/" rel=
"generator-home">
12 Node:
<a name=
"GDB%2fMI%20Stack%20Manipulation">GDB/MI Stack Manipulation
</a>,
13 Next:
<a rel=
"next" accesskey=
"n" href=
"GDB-MI-Symbol-Query.html#GDB%2fMI%20Symbol%20Query">GDB/MI Symbol Query
</a>,
14 Previous:
<a rel=
"previous" accesskey=
"p" href=
"GDB-MI-Miscellaneous-Commands.html#GDB%2fMI%20Miscellaneous%20Commands">GDB/MI Miscellaneous Commands
</a>,
15 Up:
<a rel=
"up" accesskey=
"u" href=
"GDB-MI.html#GDB%2fMI">GDB/MI
</a>
19 <h3 class=
"section"><small>GDB/MI
</small> Stack Manipulation Commands
</h3>
21 <h4 class=
"subheading">The
<code>-stack-info-frame
</code> Command
</h4>
23 <h5 class=
"subsubheading">Synopsis
</h5>
25 <pre class=
"example"> -stack-info-frame
28 <p>Get info on the current frame.
30 <h5 class=
"subsubheading">GDB Command
</h5>
32 <p>The corresponding GDB command is
<code>info frame
</code> or
<code>frame
</code>
35 <h5 class=
"subsubheading">Example
</h5>
39 <h4 class=
"subheading">The
<code>-stack-info-depth
</code> Command
</h4>
41 <h5 class=
"subsubheading">Synopsis
</h5>
43 <pre class=
"example"> -stack-info-depth [
<var>max-depth
</var> ]
46 <p>Return the depth of the stack. If the integer argument
<var>max-depth
</var>
47 is specified, do not count beyond
<var>max-depth
</var> frames.
49 <h5 class=
"subsubheading">GDB Command
</h5>
51 <p>There's no equivalent GDB command.
53 <h5 class=
"subsubheading">Example
</h5>
55 <p>For a stack with frame levels
0 through
11:
57 <pre class=
"smallexample"> (gdb)
75 <h4 class=
"subheading">The
<code>-stack-list-arguments
</code> Command
</h4>
77 <h5 class=
"subsubheading">Synopsis
</h5>
79 <pre class=
"example"> -stack-list-arguments
<var>show-values
</var>
80 [
<var>low-frame
</var> <var>high-frame
</var> ]
83 <p>Display a list of the arguments for the frames between
<var>low-frame
</var>
84 and
<var>high-frame
</var> (inclusive). If
<var>low-frame
</var> and
85 <var>high-frame
</var> are not provided, list the arguments for the whole call
88 <p>The
<var>show-values
</var> argument must have a value of
0 or
1. A value of
89 0 means that only the names of the arguments are listed, a value of
1
90 means that both names and values of the arguments are printed.
92 <h5 class=
"subsubheading">GDB Command
</h5>
94 GDB does not have an equivalent command.
<code>gdbtk
</code> has a
95 <code>gdb_get_args
</code> command which partially overlaps with the
96 functionality of
<code>-stack-list-arguments
</code>.
98 <h5 class=
"subsubheading">Example
</h5>
100 <pre class=
"smallexample"> (gdb)
104 frame={
level=
"0 ",
addr=
"0x00010734",
func=
"callee4",
105 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"8"},
106 frame={
level=
"1 ",
addr=
"0x0001076c",
func=
"callee3",
107 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"17"},
108 frame={
level=
"2 ",
addr=
"0x0001078c",
func=
"callee2",
109 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"22"},
110 frame={
level=
"3 ",
addr=
"0x000107b4",
func=
"callee1",
111 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"27"},
112 frame={
level=
"4 ",
addr=
"0x000107e0",
func=
"main",
113 file=
"../../../devo/gdb/testsuite/gdb.mi/basics.c",
line=
"32"}]
115 -stack-list-arguments
0
118 frame={
level=
"0",args=[]},
119 frame={
level=
"1",args=[
name=
"strarg"]},
120 frame={
level=
"2",args=[
name=
"intarg",
name=
"strarg"]},
121 frame={
level=
"3",args=[
name=
"intarg",
name=
"strarg",
name=
"fltarg"]},
122 frame={
level=
"4",args=[]}]
124 -stack-list-arguments
1
127 frame={
level=
"0",args=[]},
129 args=[{
name=
"strarg",
value=
"0x11940 \"A string argument.\
""}]},
130 frame={
level=
"2",args=[
131 {
name=
"intarg",
value=
"2"},
132 {
name=
"strarg",
value=
"0x11940 \"A string argument.\
""}]},
133 {frame={
level=
"3",args=[
134 {
name=
"intarg",
value=
"2"},
135 {
name=
"strarg",
value=
"0x11940 \"A string argument.\
""},
136 {
name=
"fltarg",
value=
"3.5"}]},
137 frame={
level=
"4",args=[]}]
139 -stack-list-arguments
0 2 2
140 ^done,stack-args=[frame={
level=
"2",args=[
name=
"intarg",
name=
"strarg"]}]
142 -stack-list-arguments
1 2 2
143 ^done,stack-args=[frame={
level=
"2",
144 args=[{
name=
"intarg",
value=
"2"},
145 {
name=
"strarg",
value=
"0x11940 \"A string argument.\
""}]}]
149 <h4 class=
"subheading">The
<code>-stack-list-frames
</code> Command
</h4>
151 <h5 class=
"subsubheading">Synopsis
</h5>
153 <pre class=
"example"> -stack-list-frames [
<var>low-frame
</var> <var>high-frame
</var> ]
156 <p>List the frames currently on the stack. For each frame it displays the
160 <dt><code></code><var>level
</var><code></code>
161 <dd>The frame number,
0 being the topmost frame, i.e. the innermost function.
162 <br><dt><code></code><var>addr
</var><code></code>
163 <dd>The
<code>$pc
</code> value for that frame.
164 <br><dt><code></code><var>func
</var><code></code>
166 <br><dt><code></code><var>file
</var><code></code>
167 <dd>File name of the source file where the function lives.
168 <br><dt><code></code><var>line
</var><code></code>
169 <dd>Line number corresponding to the
<code>$pc
</code>.
172 <p>If invoked without arguments, this command prints a backtrace for the
173 whole stack. If given two integer arguments, it shows the frames whose
174 levels are between the two arguments (inclusive). If the two arguments
175 are equal, it shows the single frame at the corresponding level.
177 <h5 class=
"subsubheading">GDB Command
</h5>
179 <p>The corresponding GDB commands are
<code>backtrace
</code> and
<code>where
</code>.
181 <h5 class=
"subsubheading">Example
</h5>
183 <p>Full stack backtrace:
185 <pre class=
"smallexample"> (gdb)
188 [frame={
level=
"0 ",
addr=
"0x0001076c",
func=
"foo",
189 file=
"recursive2.c",
line=
"11"},
190 frame={
level=
"1 ",
addr=
"0x000107a4",
func=
"foo",
191 file=
"recursive2.c",
line=
"14"},
192 frame={
level=
"2 ",
addr=
"0x000107a4",
func=
"foo",
193 file=
"recursive2.c",
line=
"14"},
194 frame={
level=
"3 ",
addr=
"0x000107a4",
func=
"foo",
195 file=
"recursive2.c",
line=
"14"},
196 frame={
level=
"4 ",
addr=
"0x000107a4",
func=
"foo",
197 file=
"recursive2.c",
line=
"14"},
198 frame={
level=
"5 ",
addr=
"0x000107a4",
func=
"foo",
199 file=
"recursive2.c",
line=
"14"},
200 frame={
level=
"6 ",
addr=
"0x000107a4",
func=
"foo",
201 file=
"recursive2.c",
line=
"14"},
202 frame={
level=
"7 ",
addr=
"0x000107a4",
func=
"foo",
203 file=
"recursive2.c",
line=
"14"},
204 frame={
level=
"8 ",
addr=
"0x000107a4",
func=
"foo",
205 file=
"recursive2.c",
line=
"14"},
206 frame={
level=
"9 ",
addr=
"0x000107a4",
func=
"foo",
207 file=
"recursive2.c",
line=
"14"},
208 frame={
level=
"10",
addr=
"0x000107a4",
func=
"foo",
209 file=
"recursive2.c",
line=
"14"},
210 frame={
level=
"11",
addr=
"0x00010738",
func=
"main",
211 file=
"recursive2.c",
line=
"4"}]
215 <p>Show frames between
<var>low_frame
</var> and
<var>high_frame
</var>:
217 <pre class=
"smallexample"> (gdb)
218 -stack-list-frames
3 5
220 [frame={
level=
"3 ",
addr=
"0x000107a4",
func=
"foo",
221 file=
"recursive2.c",
line=
"14"},
222 frame={
level=
"4 ",
addr=
"0x000107a4",
func=
"foo",
223 file=
"recursive2.c",
line=
"14"},
224 frame={
level=
"5 ",
addr=
"0x000107a4",
func=
"foo",
225 file=
"recursive2.c",
line=
"14"}]
229 <p>Show a single frame:
231 <pre class=
"smallexample"> (gdb)
232 -stack-list-frames
3 3
234 [frame={
level=
"3 ",
addr=
"0x000107a4",
func=
"foo",
235 file=
"recursive2.c",
line=
"14"}]
239 <h4 class=
"subheading">The
<code>-stack-list-locals
</code> Command
</h4>
241 <h5 class=
"subsubheading">Synopsis
</h5>
243 <pre class=
"example"> -stack-list-locals
<var>print-values
</var>
246 <p>Display the local variable names for the current frame. With an
247 argument of
0 prints only the names of the variables, with argument of
1
248 prints also their values.
250 <h5 class=
"subsubheading">GDB Command
</h5>
252 <p><code>info locals
</code> in GDB,
<code>gdb_get_locals
</code> in
<code>gdbtk
</code>.
254 <h5 class=
"subsubheading">Example
</h5>
256 <pre class=
"smallexample"> (gdb)
258 ^done,locals=[
name=
"A",
name=
"B",
name=
"C"]
261 ^done,locals=[{
name=
"A",
value=
"1"},{
name=
"B",
value=
"2"},
262 {
name=
"C",
value=
"3"}]
266 <h4 class=
"subheading">The
<code>-stack-select-frame
</code> Command
</h4>
268 <h5 class=
"subsubheading">Synopsis
</h5>
270 <pre class=
"example"> -stack-select-frame
<var>framenum
</var>
273 <p>Change the current frame. Select a different frame
<var>framenum
</var> on
276 <h5 class=
"subsubheading">GDB Command
</h5>
278 <p>The corresponding GDB commands are
<code>frame
</code>,
<code>up
</code>,
279 <code>down
</code>,
<code>select-frame
</code>,
<code>up-silent
</code>, and
<code>down-silent
</code>.
281 <h5 class=
"subsubheading">Example
</h5>
283 <pre class=
"smallexample"> (gdb)
284 -stack-select-frame
2