Frame Apply (Debugging with GDB)
Next: Frame Filter Management, Previous: Frame Info, Up: Stack [Contents][Index]
8.5 Applying a Command to Several Frames.
frame apply [all | count | -count | level level…] [option]… commandThe
frame applycommand allows you to apply the namedcommandto one or more frames.allSpecify
allto applycommandto all frames.countUse
countto applycommandto the innermostcountframes, wherecountis a positive number.-countUse
-countto applycommandto the outermostcountframes, wherecountis a positive number.levelUse
levelto applycommandto the set of frames identified by thelevellist.levelis a frame level or a range of frame levels aslevel1-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 applycommandfor 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 applyapplies a command are also influenced by theset backtracesettings such asset backtrace past-mainandset backtrace limit N. See Backtraces.The
frame applycommand also supports a number of options that allow overriding relevantset backtracesettings:-past-main [on|off]Whether backtraces should continue past
main. Related setting: set backtrace past-main.-past-entry [on|off]Whether backtraces should continue past the entry point of a program. Related setting: set backtrace past-entry.
By default, GDB displays some frame information before the output produced by
command, and an error raised during the execution of acommandwill abortframe apply. The following options can be used to fine-tune these behaviors:-cThe flag
-c, which stands for ‘continue’, causes any errors incommandto be displayed, and the execution offrame applythen continues.-sThe flag
-s, which stands for ‘silent’, causes any errors or empty output produced by acommandto be silently ignored. That is, the execution continues, but the frame information and errors are not printed.-qThe flag
-q(‘quiet’) disables printing the frame information.
The following example shows how the flags
-cand-sare working when applying the commandp jto all frames, where variablejcan only be successfully printed in the outermost#1 mainframe.(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 the flag
-qis 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
The faas command accepts the same options as the frame apply command. See frame apply.
Note that the command tfaas command applies command on all frames of all threads. See See Threads.
Next: Frame Filter Management, Previous: Frame Info, Up: Stack [Contents][Index]