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: Backtrace</title>
18
19<meta name="description" content="Debugging with GDB: Backtrace">
20<meta name="keywords" content="Debugging with GDB: Backtrace">
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="Selection.html#Selection" rel="next" title="Selection">
30<link href="Frames.html#Frames" rel="previous" title="Frames">
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="Backtrace"></a>
65<div class="header">
66<p>
67Next: <a href="Selection.html#Selection" accesskey="n" rel="next">Selection</a>, Previous: <a href="Frames.html#Frames" accesskey="p" rel="previous">Frames</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="Backtraces"></a>
71<h3 class="section">8.2 Backtraces</h3>
72
73<a name="index-traceback"></a>
74<a name="index-call-stack-traces"></a>
75<p>A backtrace is a summary of how your program got where it is.  It shows one
76line per frame, for many frames, starting with the currently executing
77frame (frame zero), followed by its caller (frame one), and on up the
78stack.
79</p>
80<a name="backtrace_002dcommand"></a><a name="index-backtrace"></a>
81<a name="index-bt-_0028backtrace_0029"></a>
82<p>To print a backtrace of the entire stack, use the <code>backtrace</code>
83command, or its alias <code>bt</code>.  This command will print one line per
84frame for frames in the stack.  By default, all stack frames are
85printed.  You can stop the backtrace at any time by typing the system
86interrupt character, normally <kbd>Ctrl-c</kbd>.
87</p>
88<dl compact="compact">
89<dt><code>backtrace [<var>option</var>]&hellip; [<var>qualifier</var>]&hellip; [<var>count</var>]</code></dt>
90<dt><code>bt [<var>option</var>]&hellip; [<var>qualifier</var>]&hellip; [<var>count</var>]</code></dt>
91<dd><p>Print the backtrace of the entire stack.
92</p>
93<p>The optional <var>count</var> can be one of the following:
94</p>
95<dl compact="compact">
96<dt><code><var>n</var></code></dt>
97<dt><code><var>n</var></code></dt>
98<dd><p>Print only the innermost <var>n</var> frames, where <var>n</var> is a positive
99number.
100</p>
101</dd>
102<dt><code>-<var>n</var></code></dt>
103<dt><code>-<var>n</var></code></dt>
104<dd><p>Print only the outermost <var>n</var> frames, where <var>n</var> is a positive
105number.
106</p></dd>
107</dl>
108
109<p>Options:
110</p>
111<dl compact="compact">
112<dt><code>-full</code></dt>
113<dd><p>Print the values of the local variables also.  This can be combined
114with the optional <var>count</var> to limit the number of frames shown.
115</p>
116</dd>
117<dt><code>-no-filters</code></dt>
118<dd><p>Do not run Python frame filters on this backtrace.  See <a href="Frame-Filter-API.html#Frame-Filter-API">Frame Filter API</a>, for more information.  Additionally use <a href="Frame-Filter-Management.html#disable-frame_002dfilter-all">disable frame-filter all</a> to turn off all frame filters.  This is only
119relevant when <small>GDB</small> has been configured with <code>Python</code>
120support.
121</p>
122</dd>
123<dt><code>-hide</code></dt>
124<dd><p>A Python frame filter might decide to &ldquo;elide&rdquo; some frames.  Normally
125such elided frames are still printed, but they are indented relative
126to the filtered frames that cause them to be elided.  The <code>-hide</code>
127option causes elided frames to not be printed at all.
128</p></dd>
129</dl>
130
131<p>The <code>backtrace</code> command also supports a number of options that
132allow overriding relevant global print settings as set by <code>set
133backtrace</code> and <code>set print</code> subcommands:
134</p>
135<dl compact="compact">
136<dt><code>-past-main [<code>on</code>|<code>off</code>]</code></dt>
137<dd><p>Set whether backtraces should continue past <code>main</code>.  Related setting:
138<a href="#set-backtrace-past_002dmain">set backtrace past-main</a>.
139</p>
140</dd>
141<dt><code>-past-entry [<code>on</code>|<code>off</code>]</code></dt>
142<dd><p>Set whether backtraces should continue past the entry point of a program.
143Related setting: <a href="#set-backtrace-past_002dentry">set backtrace past-entry</a>.
144</p>
145</dd>
146<dt><code>-entry-values <code>no</code>|<code>only</code>|<code>preferred</code>|<code>if-needed</code>|<code>both</code>|<code>compact</code>|<code>default</code></code></dt>
147<dd><p>Set printing of function arguments at function entry.
148Related setting: <a href="Print-Settings.html#set-print-entry_002dvalues">set print entry-values</a>.
149</p>
150</dd>
151<dt><code>-frame-arguments <code>all</code>|<code>scalars</code>|<code>none</code></code></dt>
152<dd><p>Set printing of non-scalar frame arguments.
153Related setting: <a href="Print-Settings.html#set-print-frame_002darguments">set print frame-arguments</a>.
154</p>
155</dd>
156<dt><code>-raw-frame-arguments [<code>on</code>|<code>off</code>]</code></dt>
157<dd><p>Set whether to print frame arguments in raw form.
158Related setting: <a href="Print-Settings.html#set-print-raw_002dframe_002darguments">set print raw-frame-arguments</a>.
159</p>
160</dd>
161<dt><code>-frame-info <code>auto</code>|<code>source-line</code>|<code>location</code>|<code>source-and-location</code>|<code>location-and-address</code>|<code>short-location</code></code></dt>
162<dd><p>Set printing of frame information.
163Related setting: <a href="Print-Settings.html#set-print-frame_002dinfo">set print frame-info</a>.
164</p></dd>
165</dl>
166
167<p>The optional <var>qualifier</var> is maintained for backward compatibility.
168It can be one of the following:
169</p>
170<dl compact="compact">
171<dt><code>full</code></dt>
172<dd><p>Equivalent to the <code>-full</code> option.
173</p>
174</dd>
175<dt><code>no-filters</code></dt>
176<dd><p>Equivalent to the <code>-no-filters</code> option.
177</p>
178</dd>
179<dt><code>hide</code></dt>
180<dd><p>Equivalent to the <code>-hide</code> option.
181</p></dd>
182</dl>
183
184</dd>
185</dl>
186
187<a name="index-where"></a>
188<a name="index-info-stack"></a>
189<p>The names <code>where</code> and <code>info stack</code> (abbreviated <code>info s</code>)
190are additional aliases for <code>backtrace</code>.
191</p>
192<a name="index-multiple-threads_002c-backtrace"></a>
193<p>In a multi-threaded program, <small>GDB</small> by default shows the
194backtrace only for the current thread.  To display the backtrace for
195several or all of the threads, use the command <code>thread apply</code>
196(see <a href="Threads.html#Threads">thread apply</a>).  For example, if you type <kbd>thread
197apply all backtrace</kbd>, <small>GDB</small> will display the backtrace for all
198the threads; this is handy when you debug a core dump of a
199multi-threaded program.
200</p>
201<p>Each line in the backtrace shows the frame number and the function name.
202The program counter value is also shown&mdash;unless you use <code>set
203print address off</code>.  The backtrace also shows the source file name and
204line number, as well as the arguments to the function.  The program
205counter value is omitted if it is at the beginning of the code for that
206line number.
207</p>
208<p>Here is an example of a backtrace.  It was made with the command
209&lsquo;<samp>bt 3</samp>&rsquo;, so it shows the innermost three frames.
210</p>
211<div class="smallexample">
212<pre class="smallexample">#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
213    at builtin.c:993
214#1  0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
215#2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
216    at macro.c:71
217(More stack frames follow...)
218</pre></div>
219
220<p>The display for frame zero does not begin with a program counter
221value, indicating that your program has stopped at the beginning of the
222code for line <code>993</code> of <code>builtin.c</code>.
223</p>
224<p>The value of parameter <code>data</code> in frame 1 has been replaced by
225<code>&hellip;</code>.  By default, <small>GDB</small> prints the value of a parameter
226only if it is a scalar (integer, pointer, enumeration, etc).  See command
227<kbd>set print frame-arguments</kbd> in <a href="Print-Settings.html#Print-Settings">Print Settings</a> for more details
228on how to configure the way function parameter values are printed.
229The command <kbd>set print frame-info</kbd> (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>) controls
230what frame information is printed.
231</p>
232<a name="index-optimized-out_002c-in-backtrace"></a>
233<a name="index-function-call-arguments_002c-optimized-out"></a>
234<p>If your program was compiled with optimizations, some compilers will
235optimize away arguments passed to functions if those arguments are
236never used after the call.  Such optimizations generate code that
237passes arguments through registers, but doesn&rsquo;t store those arguments
238in the stack frame.  <small>GDB</small> has no way of displaying such
239arguments in stack frames other than the innermost one.  Here&rsquo;s what
240such a backtrace might look like:
241</p>
242<div class="smallexample">
243<pre class="smallexample">#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
244    at builtin.c:993
245#1  0x6e38 in expand_macro (sym=&lt;optimized out&gt;) at macro.c:242
246#2  0x6840 in expand_token (obs=0x0, t=&lt;optimized out&gt;, td=0xf7fffb08)
247    at macro.c:71
248(More stack frames follow...)
249</pre></div>
250
251<p>The values of arguments that were not saved in their stack frames are
252shown as &lsquo;<samp>&lt;optimized out&gt;</samp>&rsquo;.
253</p>
254<p>If you need to display the values of such optimized-out arguments,
255either deduce that from other variables whose values depend on the one
256you are interested in, or recompile without optimizations.
257</p>
258<a name="index-backtrace-beyond-main-function"></a>
259<a name="index-program-entry-point"></a>
260<a name="index-startup-code_002c-and-backtrace"></a>
261<p>Most programs have a standard user entry point&mdash;a place where system
262libraries and startup code transition into user code.  For C this is
263<code>main</code><a name="DOCF9" href="#FOOT9"><sup>9</sup></a>.
264When <small>GDB</small> finds the entry function in a backtrace
265it will terminate the backtrace, to avoid tracing into highly
266system-specific (and generally uninteresting) code.
267</p>
268<p>If you need to examine the startup code, or limit the number of levels
269in a backtrace, you can change this behavior:
270</p>
271<dl compact="compact">
272<dt><code>set backtrace past-main</code></dt>
273<dt><code>set backtrace past-main on</code></dt>
274<dd><a name="set-backtrace-past_002dmain"></a><a name="index-set-backtrace"></a>
275<p>Backtraces will continue past the user entry point.
276</p>
277</dd>
278<dt><code>set backtrace past-main off</code></dt>
279<dd><p>Backtraces will stop when they encounter the user entry point.  This is the
280default.
281</p>
282</dd>
283<dt><code>show backtrace past-main</code></dt>
284<dd><a name="index-show-backtrace"></a>
285<p>Display the current user entry point backtrace policy.
286</p>
287</dd>
288<dt><code>set backtrace past-entry</code></dt>
289<dt><code>set backtrace past-entry on</code></dt>
290<dd><a name="set-backtrace-past_002dentry"></a><p>Backtraces will continue past the internal entry point of an application.
291This entry point is encoded by the linker when the application is built,
292and is likely before the user entry point <code>main</code> (or equivalent) is called.
293</p>
294</dd>
295<dt><code>set backtrace past-entry off</code></dt>
296<dd><p>Backtraces will stop when they encounter the internal entry point of an
297application.  This is the default.
298</p>
299</dd>
300<dt><code>show backtrace past-entry</code></dt>
301<dd><p>Display the current internal entry point backtrace policy.
302</p>
303</dd>
304<dt><code>set backtrace limit <var>n</var></code></dt>
305<dt><code>set backtrace limit 0</code></dt>
306<dt><code>set backtrace limit unlimited</code></dt>
307<dd><a name="set-backtrace-limit"></a><a name="index-backtrace-limit"></a>
308<p>Limit the backtrace to <var>n</var> levels.  A value of <code>unlimited</code>
309or zero means unlimited levels.
310</p>
311</dd>
312<dt><code>show backtrace limit</code></dt>
313<dd><p>Display the current limit on backtrace levels.
314</p></dd>
315</dl>
316
317<p>You can control how file names are displayed.
318</p>
319<dl compact="compact">
320<dt><code>set filename-display</code></dt>
321<dt><code>set filename-display relative</code></dt>
322<dd><a name="index-filename_002ddisplay"></a>
323<p>Display file names relative to the compilation directory.  This is the default.
324</p>
325</dd>
326<dt><code>set filename-display basename</code></dt>
327<dd><p>Display only basename of a filename.
328</p>
329</dd>
330<dt><code>set filename-display absolute</code></dt>
331<dd><p>Display an absolute filename.
332</p>
333</dd>
334<dt><code>show filename-display</code></dt>
335<dd><p>Show the current way to display filenames.
336</p></dd>
337</dl>
338
339<div class="footnote">
340<hr>
341<h4 class="footnotes-heading">Footnotes</h4>
342
343<h3><a name="FOOT9" href="#DOCF9">(9)</a></h3>
344<p>Note that embedded programs (the so-called &ldquo;free-standing&rdquo;
345environment) are not required to have a <code>main</code> function as the
346entry point.  They could even have multiple entry points.</p>
347</div>
348<hr>
349<div class="header">
350<p>
351Next: <a href="Selection.html#Selection" accesskey="n" rel="next">Selection</a>, Previous: <a href="Frames.html#Frames" accesskey="p" rel="previous">Frames</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>
352</div>
353
354
355
356</body>
357</html>
358