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: Frame Apply</title>
18
19<meta name="description" content="Debugging with GDB: Frame Apply">
20<meta name="keywords" content="Debugging with GDB: Frame Apply">
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-Filter-Management.html#Frame-Filter-Management" rel="next" title="Frame Filter Management">
30<link href="Frame-Info.html#Frame-Info" rel="previous" title="Frame Info">
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="Frame-Apply"></a>
65<div class="header">
66<p>
67Next: <a href="Frame-Filter-Management.html#Frame-Filter-Management" accesskey="n" rel="next">Frame Filter Management</a>, Previous: <a href="Frame-Info.html#Frame-Info" accesskey="p" rel="previous">Frame Info</a>, Up: <a href="Stack.html#Stack" accesskey="u" rel="up">Stack</a> &nbsp; [<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="Applying-a-Command-to-Several-Frames"></a>
71<h3 class="section">8.5 Applying a Command to Several Frames</h3>
72<a name="index-frame-apply"></a>
73<a name="index-apply-command-to-several-frames"></a>
74<dl compact="compact">
75<dt><code>frame apply [all | <var>count</var> | <var>-count</var> | level <var>level</var>&hellip;] [<var>option</var>]&hellip; <var>command</var></code></dt>
76<dd><p>The <code>frame apply</code> command allows you to apply the named
77<var>command</var> to one or more frames.
78</p>
79<dl compact="compact">
80<dt><code><code>all</code></code></dt>
81<dd><p>Specify <code>all</code> to apply <var>command</var> to all frames.
82</p>
83</dd>
84<dt><code><var>count</var></code></dt>
85<dd><p>Use <var>count</var> to apply <var>command</var> to the innermost <var>count</var>
86frames, where <var>count</var> is a positive number.
87</p>
88</dd>
89<dt><code><var>-count</var></code></dt>
90<dd><p>Use <var>-count</var> to apply <var>command</var> to the outermost <var>count</var>
91frames, where <var>count</var> is a positive number.
92</p>
93</dd>
94<dt><code><code>level</code></code></dt>
95<dd><p>Use <code>level</code> to apply <var>command</var> to the set of frames identified
96by the <var>level</var> list.  <var>level</var> is a frame level or a range of frame
97levels as <var>level1</var>-<var>level2</var>.  The frame level is the number shown
98in the first field of the &lsquo;<samp>backtrace</samp>&rsquo; command output.
99E.g., &lsquo;<samp>2-4 6-8 3</samp>&rsquo; indicates to apply <var>command</var> for the frames
100at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
101</p>
102</dd>
103</dl>
104
105<p>Note that the frames on which <code>frame apply</code> applies a command are
106also influenced by the <code>set backtrace</code> settings such as <code>set
107backtrace past-main</code> and <code>set backtrace limit N</code>.
108See <a href="Backtrace.html#Backtrace">Backtraces</a>.
109</p>
110<p>The <code>frame apply</code> command also supports a number of options that
111allow overriding relevant <code>set backtrace</code> settings:
112</p>
113<dl compact="compact">
114<dt><code>-past-main [<code>on</code>|<code>off</code>]</code></dt>
115<dd><p>Whether backtraces should continue past <code>main</code>.
116Related setting: <a href="Backtrace.html#set-backtrace-past_002dmain">set backtrace past-main</a>.
117</p>
118</dd>
119<dt><code>-past-entry [<code>on</code>|<code>off</code>]</code></dt>
120<dd><p>Whether backtraces should continue past the entry point of a program.
121Related setting: <a href="Backtrace.html#set-backtrace-past_002dentry">set backtrace past-entry</a>.
122</p></dd>
123</dl>
124
125<p>By default, <small>GDB</small> displays some frame information before the
126output produced by <var>command</var>, and an error raised during the
127execution of a <var>command</var> will abort <code>frame apply</code>.  The
128following options can be used to fine-tune these behaviors:
129</p>
130<dl compact="compact">
131<dt><code>-c</code></dt>
132<dd><p>The flag <code>-c</code>, which stands for &lsquo;<samp>continue</samp>&rsquo;, causes any
133errors in <var>command</var> to be displayed, and the execution of
134<code>frame apply</code> then continues.
135</p></dd>
136<dt><code>-s</code></dt>
137<dd><p>The flag <code>-s</code>, which stands for &lsquo;<samp>silent</samp>&rsquo;, causes any errors
138or empty output produced by a <var>command</var> to be silently ignored.
139That is, the execution continues, but the frame information and errors
140are not printed.
141</p></dd>
142<dt><code>-q</code></dt>
143<dd><p>The flag <code>-q</code> (&lsquo;<samp>quiet</samp>&rsquo;) disables printing the frame
144information.
145</p></dd>
146</dl>
147
148<p>The following example shows how the flags <code>-c</code> and <code>-s</code> are
149working when applying the command <code>p j</code> to all frames, where
150variable <code>j</code> can only be successfully printed in the outermost
151<code>#1 main</code> frame.
152</p>
153<div class="smallexample">
154<pre class="smallexample">(gdb) frame apply all p j
155#0  some_function (i=5) at fun.c:4
156No symbol &quot;j&quot; in current context.
157(gdb) frame apply all -c p j
158#0  some_function (i=5) at fun.c:4
159No symbol &quot;j&quot; in current context.
160#1  0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
161$1 = 5
162(gdb) frame apply all -s p j
163#1  0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
164$2 = 5
165(gdb)
166</pre></div>
167
168<p>By default, &lsquo;<samp>frame apply</samp>&rsquo;, prints the frame location
169information before the command output:
170</p>
171<div class="smallexample">
172<pre class="smallexample">(gdb) frame apply all p $sp
173#0  some_function (i=5) at fun.c:4
174$4 = (void *) 0xffffd1e0
175#1  0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
176$5 = (void *) 0xffffd1f0
177(gdb)
178</pre></div>
179
180<p>If the flag <code>-q</code> is given, no frame information is printed:
181</p><div class="smallexample">
182<pre class="smallexample">(gdb) frame apply all -q p $sp
183$12 = (void *) 0xffffd1e0
184$13 = (void *) 0xffffd1f0
185(gdb)
186</pre></div>
187
188</dd>
189</dl>
190
191<dl compact="compact">
192<dd>
193<a name="index-faas"></a>
194<a name="index-apply-a-command-to-all-frames-_0028ignoring-errors-and-empty-output_0029"></a>
195</dd>
196<dt><code>faas <var>command</var></code></dt>
197<dd><p>Shortcut for <code>frame apply all -s <var>command</var></code>.
198Applies <var>command</var> on all frames, ignoring errors and empty output.
199</p>
200<p>It can for example be used to print a local variable or a function
201argument without knowing the frame where this variable or argument
202is, using:
203</p><div class="smallexample">
204<pre class="smallexample">(gdb) faas p some_local_var_i_do_not_remember_where_it_is
205</pre></div>
206
207<p>The <code>faas</code> command accepts the same options as the <code>frame
208apply</code> command.  See <a href="#Frame-Apply">frame apply</a>.
209</p>
210<p>Note that the command <code>tfaas <var>command</var></code> applies <var>command</var>
211on all frames of all threads.  See See <a href="Threads.html#Threads">Threads</a>.
212</p></dd>
213</dl>
214
215
216<hr>
217<div class="header">
218<p>
219Next: <a href="Frame-Filter-Management.html#Frame-Filter-Management" accesskey="n" rel="next">Frame Filter Management</a>, Previous: <a href="Frame-Info.html#Frame-Info" accesskey="p" rel="previous">Frame Info</a>, Up: <a href="Stack.html#Stack" accesskey="u" rel="up">Stack</a> &nbsp; [<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>
220</div>
221
222
223
224</body>
225</html>
226