203 lines
11 KiB
HTML
203 lines
11 KiB
HTML
<html lang="en">
|
|
<head>
|
|
<title>Backtrace - Debugging with GDB</title>
|
|
<meta http-equiv="Content-Type" content="text/html">
|
|
<meta name="description" content="Debugging with GDB">
|
|
<meta name="generator" content="makeinfo 4.13">
|
|
<link title="Top" rel="start" href="index.html#Top">
|
|
<link rel="up" href="Stack.html#Stack" title="Stack">
|
|
<link rel="prev" href="Frames.html#Frames" title="Frames">
|
|
<link rel="next" href="Selection.html#Selection" title="Selection">
|
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
|
<!--
|
|
Copyright (C) 1988-2019 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
|
any later version published by the Free Software Foundation; with the
|
|
Invariant Sections being ``Free Software'' and ``Free Software Needs
|
|
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
|
|
and with the Back-Cover Texts as in (a) below.
|
|
|
|
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
|
|
this GNU Manual. Buying copies from GNU Press supports the FSF in
|
|
developing GNU and promoting software freedom.''
|
|
-->
|
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
|
<style type="text/css"><!--
|
|
pre.display { font-family:inherit }
|
|
pre.format { font-family:inherit }
|
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
|
pre.smallexample { font-size:smaller }
|
|
pre.smalllisp { font-size:smaller }
|
|
span.sc { font-variant:small-caps }
|
|
span.roman { font-family:serif; font-weight:normal; }
|
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
<div class="node">
|
|
<a name="Backtrace"></a>
|
|
<p>
|
|
Next: <a rel="next" accesskey="n" href="Selection.html#Selection">Selection</a>,
|
|
Previous: <a rel="previous" accesskey="p" href="Frames.html#Frames">Frames</a>,
|
|
Up: <a rel="up" accesskey="u" href="Stack.html#Stack">Stack</a>
|
|
<hr>
|
|
</div>
|
|
|
|
<h3 class="section">8.2 Backtraces</h3>
|
|
|
|
<p><a name="index-traceback-513"></a><a name="index-call-stack-traces-514"></a>A backtrace is a summary of how your program got where it is. It shows one
|
|
line per frame, for many frames, starting with the currently executing
|
|
frame (frame zero), followed by its caller (frame one), and on up the
|
|
stack.
|
|
|
|
<p><a name="backtrace_002dcommand"></a><a name="index-backtrace-515"></a><a name="index-bt-_0040r_007b_0028_0040code_007bbacktrace_007d_0029_007d-516"></a>To print a backtrace of the entire stack, use the <code>backtrace</code>
|
|
command, or its alias <code>bt</code>. This command will print one line per
|
|
frame for frames in the stack. By default, all stack frames are
|
|
printed. You can stop the backtrace at any time by typing the system
|
|
interrupt character, normally <kbd>Ctrl-c</kbd>.
|
|
|
|
<dl>
|
|
<dt><code>backtrace [</code><var>args</var><code>...]</code><dt><code>bt [</code><var>args</var><code>...]</code><dd>Print the backtrace of the entire stack. The optional <var>args</var> can
|
|
be one of the following:
|
|
|
|
<dl>
|
|
<dt><var>n</var><dt><var>n</var><dd>Print only the innermost <var>n</var> frames, where <var>n</var> is a positive
|
|
number.
|
|
|
|
<br><dt><code>-</code><var>n</var><dt><code>-</code><var>n</var><dd>Print only the outermost <var>n</var> frames, where <var>n</var> is a positive
|
|
number.
|
|
|
|
<br><dt><code>full</code><dd>Print the values of the local variables also. This can be combined
|
|
with a number to limit the number of frames shown.
|
|
|
|
<br><dt><code>no-filters</code><dd>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="disable-frame_002dfilter-all.html#disable-frame_002dfilter-all">disable frame-filter all</a> to turn off all frame filters. This is only
|
|
relevant when <span class="sc">gdb</span> has been configured with <code>Python</code>
|
|
support.
|
|
|
|
<br><dt><code>hide</code><dd>A Python frame filter might decide to “elide” some frames. Normally
|
|
such elided frames are still printed, but they are indented relative
|
|
to the filtered frames that cause them to be elided. The <code>hide</code>
|
|
option causes elided frames to not be printed at all.
|
|
</dl>
|
|
</dl>
|
|
|
|
<p><a name="index-where-517"></a><a name="index-info-stack-518"></a>The names <code>where</code> and <code>info stack</code> (abbreviated <code>info s</code>)
|
|
are additional aliases for <code>backtrace</code>.
|
|
|
|
<p><a name="index-multiple-threads_002c-backtrace-519"></a>In a multi-threaded program, <span class="sc">gdb</span> by default shows the
|
|
backtrace only for the current thread. To display the backtrace for
|
|
several or all of the threads, use the command <code>thread apply</code>
|
|
(see <a href="Threads.html#Threads">thread apply</a>). For example, if you type <kbd>thread
|
|
apply all backtrace</kbd>, <span class="sc">gdb</span> will display the backtrace for all
|
|
the threads; this is handy when you debug a core dump of a
|
|
multi-threaded program.
|
|
|
|
<p>Each line in the backtrace shows the frame number and the function name.
|
|
The program counter value is also shown—unless you use <code>set
|
|
print address off</code>. The backtrace also shows the source file name and
|
|
line number, as well as the arguments to the function. The program
|
|
counter value is omitted if it is at the beginning of the code for that
|
|
line number.
|
|
|
|
<p>Here is an example of a backtrace. It was made with the command
|
|
‘<samp><span class="samp">bt 3</span></samp>’, so it shows the innermost three frames.
|
|
|
|
<pre class="smallexample"> #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
|
|
at builtin.c:993
|
|
#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
|
|
#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
|
|
at macro.c:71
|
|
(More stack frames follow...)
|
|
</pre>
|
|
<p class="noindent">The display for frame zero does not begin with a program counter
|
|
value, indicating that your program has stopped at the beginning of the
|
|
code for line <code>993</code> of <code>builtin.c</code>.
|
|
|
|
<p class="noindent">The value of parameter <code>data</code> in frame 1 has been replaced by
|
|
<code>...</code>. By default, <span class="sc">gdb</span> prints the value of a parameter
|
|
only if it is a scalar (integer, pointer, enumeration, etc). See command
|
|
<kbd>set print frame-arguments</kbd> in <a href="Print-Settings.html#Print-Settings">Print Settings</a> for more details
|
|
on how to configure the way function parameter values are printed.
|
|
|
|
<p><a name="index-optimized-out_002c-in-backtrace-520"></a><a name="index-function-call-arguments_002c-optimized-out-521"></a>If your program was compiled with optimizations, some compilers will
|
|
optimize away arguments passed to functions if those arguments are
|
|
never used after the call. Such optimizations generate code that
|
|
passes arguments through registers, but doesn't store those arguments
|
|
in the stack frame. <span class="sc">gdb</span> has no way of displaying such
|
|
arguments in stack frames other than the innermost one. Here's what
|
|
such a backtrace might look like:
|
|
|
|
<pre class="smallexample"> #0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
|
|
at builtin.c:993
|
|
#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
|
|
#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
|
|
at macro.c:71
|
|
(More stack frames follow...)
|
|
</pre>
|
|
<p class="noindent">The values of arguments that were not saved in their stack frames are
|
|
shown as ‘<samp><span class="samp"><optimized out></span></samp>’.
|
|
|
|
<p>If you need to display the values of such optimized-out arguments,
|
|
either deduce that from other variables whose values depend on the one
|
|
you are interested in, or recompile without optimizations.
|
|
|
|
<p><a name="index-backtrace-beyond-_0040code_007bmain_007d-function-522"></a><a name="index-program-entry-point-523"></a><a name="index-startup-code_002c-and-backtrace-524"></a>Most programs have a standard user entry point—a place where system
|
|
libraries and startup code transition into user code. For C this is
|
|
<code>main</code><a rel="footnote" href="#fn-1" name="fnd-1"><sup>1</sup></a>.
|
|
When <span class="sc">gdb</span> finds the entry function in a backtrace
|
|
it will terminate the backtrace, to avoid tracing into highly
|
|
system-specific (and generally uninteresting) code.
|
|
|
|
<p>If you need to examine the startup code, or limit the number of levels
|
|
in a backtrace, you can change this behavior:
|
|
|
|
<dl>
|
|
<dt><code>set backtrace past-main</code><dt><code>set backtrace past-main on</code><dd><a name="index-set-backtrace-525"></a>Backtraces will continue past the user entry point.
|
|
|
|
<br><dt><code>set backtrace past-main off</code><dd>Backtraces will stop when they encounter the user entry point. This is the
|
|
default.
|
|
|
|
<br><dt><code>show backtrace past-main</code><dd><a name="index-show-backtrace-526"></a>Display the current user entry point backtrace policy.
|
|
|
|
<br><dt><code>set backtrace past-entry</code><dt><code>set backtrace past-entry on</code><dd>Backtraces will continue past the internal entry point of an application.
|
|
This entry point is encoded by the linker when the application is built,
|
|
and is likely before the user entry point <code>main</code> (or equivalent) is called.
|
|
|
|
<br><dt><code>set backtrace past-entry off</code><dd>Backtraces will stop when they encounter the internal entry point of an
|
|
application. This is the default.
|
|
|
|
<br><dt><code>show backtrace past-entry</code><dd>Display the current internal entry point backtrace policy.
|
|
|
|
<br><dt><code>set backtrace limit </code><var>n</var><dt><code>set backtrace limit 0</code><dt><code>set backtrace limit unlimited</code><dd><a name="index-backtrace-limit-527"></a>Limit the backtrace to <var>n</var> levels. A value of <code>unlimited</code>
|
|
or zero means unlimited levels.
|
|
|
|
<br><dt><code>show backtrace limit</code><dd>Display the current limit on backtrace levels.
|
|
</dl>
|
|
|
|
<p>You can control how file names are displayed.
|
|
|
|
<dl>
|
|
<dt><code>set filename-display</code><dt><code>set filename-display relative</code><dd><a name="index-filename_002ddisplay-528"></a>Display file names relative to the compilation directory. This is the default.
|
|
|
|
<br><dt><code>set filename-display basename</code><dd>Display only basename of a filename.
|
|
|
|
<br><dt><code>set filename-display absolute</code><dd>Display an absolute filename.
|
|
|
|
<br><dt><code>show filename-display</code><dd>Show the current way to display filenames.
|
|
</dl>
|
|
|
|
<div class="footnote">
|
|
<hr>
|
|
<h4>Footnotes</h4><p class="footnote"><small>[<a name="fn-1" href="#fnd-1">1</a>]</small>
|
|
Note that embedded programs (the so-called “free-standing”
|
|
environment) are not required to have a <code>main</code> function as the
|
|
entry point. They could even have multiple entry points.</p>
|
|
|
|
<hr></div>
|
|
|
|
</body></html>
|
|
|