gdb: Frame Apply
8.5 Applying a Command to Several Frames.
=========================================
'frame apply [all | COUNT | -COUNT | level LEVEL...] [FLAG]... COMMAND'
The 'frame apply' command allows you to apply the named COMMAND to
one or more frames.
'all'
Specify 'all' to apply COMMAND to all frames.
'COUNT'
Use COUNT to apply COMMAND to the innermost COUNT frames,
where COUNT is a positive number.
'-COUNT'
Use -COUNT to apply COMMAND to the outermost COUNT frames,
where COUNT is a positive number.
'level'
Use 'level' to apply COMMAND to the set of frames identified
by the LEVEL list. LEVEL is a frame level or a range of frame
levels as LEVEL1-LEVEL2. The frame level is the number shown
in the first field of the 'backtrace' command output. E.g.,
'2-4 6-8 3' indicates to apply COMMAND for the frames at
levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
Note that the frames on which 'frame apply' applies a command are
also influenced by the 'set backtrace' settings such as 'set backtrace
past-main' and 'set backtrace limit N'. See Backtraces
Backtrace.
The FLAG arguments control what output to produce and how to handle
errors raised when applying COMMAND to a frame. FLAG must start with a
'-' directly followed by one letter in 'qcs'. If several flags are
provided, they must be given individually, such as '-c -q'.
By default, GDB displays some frame information before the output
produced by COMMAND, and an error raised during the execution of a
COMMAND will abort 'frame apply'. The following flags can be used to
fine-tune this behavior:
'-c'
The flag '-c', which stands for 'continue', causes any errors in
COMMAND to be displayed, and the execution of 'frame apply' then
continues.
'-s'
The flag '-s', which stands for 'silent', causes any errors or
empty output produced by a COMMAND to be silently ignored. That
is, the execution continues, but the frame information and errors
are not printed.
'-q'
The flag '-q' ('quiet') disables printing the frame information.
The following example shows how the flags '-c' and '-s' are working
when applying the command 'p j' to all frames, where variable 'j' can
only be successfully printed in the outermost '#1 main' frame.
(gdb) frame apply all p j
#0 some_function (i=5) at fun.c:4
No symbol "j" in current context.
(gdb) frame apply all -c p j
#0 some_function (i=5) at fun.c:4
No symbol "j" in current context.
#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
$1 = 5
(gdb) frame apply all -s p j
#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
$2 = 5
(gdb)
By default, 'frame apply', prints the frame location information
before the command output:
(gdb) frame apply all p $sp
#0 some_function (i=5) at fun.c:4
$4 = (void *) 0xffffd1e0
#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
$5 = (void *) 0xffffd1f0
(gdb)
If flag '-q' is given, no frame information is printed:
(gdb) frame apply all -q p $sp
$12 = (void *) 0xffffd1e0
$13 = (void *) 0xffffd1f0
(gdb)
'faas COMMAND'
Shortcut for 'frame apply all -s COMMAND'. Applies COMMAND on all
frames, ignoring errors and empty output.
It can for example be used to print a local variable or a function
argument without knowing the frame where this variable or argument
is, using:
(gdb) faas p some_local_var_i_do_not_remember_where_it_is
Note that the command 'tfaas COMMAND' applies COMMAND on all frames
of all threads. See Threads Threads.