GDB/MI Stack Manipulation (Debugging with GDB)
Next: GDB/MI Variable Objects, Previous: GDB/MI Program Execution, Up: GDB/MI [Contents][Index]
27.14 GDB/MI Stack Manipulation Commands
The -enable-frame-filters Command
-enable-frame-filters
GDB allows Python-based frame filters to affect the output of the MI commands relating to stack traces. As there is no way to implement this in a fully backward-compatible way, a front end must request that this functionality be enabled.
Once enabled, this feature cannot be disabled.
Note that if Python support has not been compiled into GDB, this command will still succeed (and do nothing).
The -stack-info-frame Command
Synopsis
-stack-info-frame
Get info on the selected frame.
GDB Command
The corresponding GDB command is ‘info frame
’ or ‘frame
’ (without arguments).
Example
(gdb) -stack-info-frame ^done,frame={level="1",addr="0x0001076c",func="callee3", file="../../../devo/gdb/testsuite/gdb.mi/basics.c", fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17", arch="i386:x86_64"} (gdb)
The -stack-info-depth Command
Synopsis
-stack-info-depth [ max-depth ]
Return the depth of the stack. If the integer argument max-depth
is specified, do not count beyond max-depth
frames.
GDB Command
There’s no equivalent GDB command.
Example
For a stack with frame levels 0 through 11:
(gdb) -stack-info-depth ^done,depth="12" (gdb) -stack-info-depth 4 ^done,depth="4" (gdb) -stack-info-depth 12 ^done,depth="12" (gdb) -stack-info-depth 11 ^done,depth="11" (gdb) -stack-info-depth 13 ^done,depth="12" (gdb)
The -stack-list-arguments Command
Synopsis
-stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] print-values [ low-frame high-frame ]
Display a list of the arguments for the frames between low-frame
and high-frame
(inclusive). If low-frame
and high-frame
are not provided, list the arguments for the whole call stack. If the two arguments are equal, show the single frame at the corresponding level. It is an error if low-frame
is larger than the actual number of frames. On the other hand, high-frame
may be larger than the actual number of frames, in which case only existing frames will be returned.
If print-values
is 0 or --no-values
, print only the names of the variables; if it is 1 or --all-values
, print also their values; and if it is 2 or --simple-values
, print the name, type and value for simple data types, and the name and type for arrays, structures and unions. If the option --no-frame-filters
is supplied, then Python frame filters will not be executed.
If the --skip-unavailable
option is specified, arguments that are not available are not listed. Partially available arguments are still displayed, however.
Use of this command to obtain arguments in a single frame is deprecated in favor of the ‘-stack-list-variables
’ command.
GDB Command
GDB does not have an equivalent command. gdbtk
has a ‘gdb_get_args
’ command which partially overlaps with the functionality of ‘-stack-list-arguments
’.
Example
(gdb) -stack-list-frames ^done, stack=[ frame={level="0",addr="0x00010734",func="callee4", file="../../../devo/gdb/testsuite/gdb.mi/basics.c", fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8", arch="i386:x86_64"}, frame={level="1",addr="0x0001076c",func="callee3", file="../../../devo/gdb/testsuite/gdb.mi/basics.c", fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17", arch="i386:x86_64"}, frame={level="2",addr="0x0001078c",func="callee2", file="../../../devo/gdb/testsuite/gdb.mi/basics.c", fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22", arch="i386:x86_64"}, frame={level="3",addr="0x000107b4",func="callee1", file="../../../devo/gdb/testsuite/gdb.mi/basics.c", fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27", arch="i386:x86_64"}, frame={level="4",addr="0x000107e0",func="main", file="../../../devo/gdb/testsuite/gdb.mi/basics.c", fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32", arch="i386:x86_64"}] (gdb) -stack-list-arguments 0 ^done, stack-args=[ frame={level="0",args=[]}, frame={level="1",args=[name="strarg"]}, frame={level="2",args=[name="intarg",name="strarg"]}, frame={level="3",args=[name="intarg",name="strarg",name="fltarg"]}, frame={level="4",args=[]}] (gdb) -stack-list-arguments 1 ^done, stack-args=[ frame={level="0",args=[]}, frame={level="1", args=[{name="strarg",value="0x11940 \"A string argument.\""}]}, frame={level="2",args=[ {name="intarg",value="2"}, {name="strarg",value="0x11940 \"A string argument.\""}]}, {frame={level="3",args=[ {name="intarg",value="2"}, {name="strarg",value="0x11940 \"A string argument.\""}, {name="fltarg",value="3.5"}]}, frame={level="4",args=[]}] (gdb) -stack-list-arguments 0 2 2 ^done,stack-args=[frame={level="2",args=[name="intarg",name="strarg"]}] (gdb) -stack-list-arguments 1 2 2 ^done,stack-args=[frame={level="2", args=[{name="intarg",value="2"}, {name="strarg",value="0x11940 \"A string argument.\""}]}] (gdb)
The -stack-list-frames Command
Synopsis
-stack-list-frames [ --no-frame-filters low-frame high-frame ]
List the frames currently on the stack. For each frame it displays the following info:
- ‘
level
’ - The frame number, 0 being the topmost frame, i.e., the innermost function.
- ‘
addr
’ - The
$pc
value for that frame. - ‘
func
’ - Function name.
- ‘
file
’ - File name of the source file where the function lives.
- ‘
fullname
’ - The full file name of the source file where the function lives.
- ‘
line
’ - Line number corresponding to the
$pc
. - ‘
from
’ - The shared library where this function is defined. This is only given if the frame’s function is not known.
- ‘
arch
’ - Frame’s architecture.
If invoked without arguments, this command prints a backtrace for the whole stack. If given two integer arguments, it shows the frames whose levels are between the two arguments (inclusive). If the two arguments are equal, it shows the single frame at the corresponding level. It is an error if low-frame
is larger than the actual number of frames. On the other hand, high-frame
may be larger than the actual number of frames, in which case only existing frames will be returned. If the option --no-frame-filters
is supplied, then Python frame filters will not be executed.
GDB Command
The corresponding GDB commands are ‘backtrace
’ and ‘where
’.
Example
Full stack backtrace:
(gdb) -stack-list-frames ^done,stack= [frame={level="0",addr="0x0001076c",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11", arch="i386:x86_64"}, frame={level="1",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="2",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="3",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="4",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="5",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="6",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="7",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="8",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="9",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="10",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="11",addr="0x00010738",func="main", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4", arch="i386:x86_64"}] (gdb)
Show frames between low_frame
and high_frame
:
(gdb) -stack-list-frames 3 5 ^done,stack= [frame={level="3",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="4",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}, frame={level="5",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}] (gdb)
Show a single frame:
(gdb) -stack-list-frames 3 3 ^done,stack= [frame={level="3",addr="0x000107a4",func="foo", file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14", arch="i386:x86_64"}] (gdb)
The -stack-list-locals Command
Synopsis
-stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] print-values
Display the local variable names for the selected frame. If print-values
is 0 or --no-values
, print only the names of the variables; if it is 1 or --all-values
, print also their values; and if it is 2 or --simple-values
, print the name, type and value for simple data types, and the name and type for arrays, structures and unions. In this last case, a frontend can immediately display the value of simple data types and create variable objects for other data types when the user wishes to explore their values in more detail. If the option --no-frame-filters
is supplied, then Python frame filters will not be executed.
If the --skip-unavailable
option is specified, local variables that are not available are not listed. Partially available local variables are still displayed, however.
This command is deprecated in favor of the ‘-stack-list-variables
’ command.
GDB Command
‘info locals
’ in GDB, ‘gdb_get_locals
’ in gdbtk
.
Example
(gdb) -stack-list-locals 0 ^done,locals=[name="A",name="B",name="C"] (gdb) -stack-list-locals --all-values ^done,locals=[{name="A",value="1"},{name="B",value="2"}, {name="C",value="{1, 2, 3}"}] -stack-list-locals --simple-values ^done,locals=[{name="A",type="int",value="1"}, {name="B",type="int",value="2"},{name="C",type="int [3]"}] (gdb)
The -stack-list-variables Command
Synopsis
-stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] print-values
Display the names of local variables and function arguments for the selected frame. If print-values
is 0 or --no-values
, print only the names of the variables; if it is 1 or --all-values
, print also their values; and if it is 2 or --simple-values
, print the name, type and value for simple data types, and the name and type for arrays, structures and unions. If the option --no-frame-filters
is supplied, then Python frame filters will not be executed.
If the --skip-unavailable
option is specified, local variables and arguments that are not available are not listed. Partially available arguments and local variables are still displayed, however.
Example
(gdb) -stack-list-variables --thread 1 --frame 0 --all-values ^done,variables=[{name="x",value="11"},{name="s",value="{a = 1, b = 2}"}] (gdb)
The -stack-select-frame Command
Synopsis
-stack-select-frame framenum
Change the selected frame. Select a different frame framenum
on the stack.
This command in deprecated in favor of passing the ‘--frame
’ option to every command.
GDB Command
The corresponding GDB commands are ‘frame
’, ‘up
’, ‘down
’, ‘select-frame
’, ‘up-silent
’, and ‘down-silent
’.
Example
(gdb) -stack-select-frame 2 ^done (gdb)
Next: GDB/MI Variable Objects, Previous: GDB/MI Program Execution, Up: GDB/MI [Contents][Index]