Backtrace.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Backtrace</title>
  16. <meta name="description" content="Debugging with GDB: Backtrace">
  17. <meta name="keywords" content="Debugging with GDB: Backtrace">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Stack.html#Stack" rel="up" title="Stack">
  26. <link href="Selection.html#Selection" rel="next" title="Selection">
  27. <link href="Frames.html#Frames" rel="previous" title="Frames">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Backtrace"></a>
  59. <div class="header">
  60. <p>
  61. Next: <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>
  62. </div>
  63. <hr>
  64. <a name="Backtraces"></a>
  65. <h3 class="section">8.2 Backtraces</h3>
  66. <a name="index-traceback"></a>
  67. <a name="index-call-stack-traces"></a>
  68. <p>A backtrace is a summary of how your program got where it is. It shows one
  69. line per frame, for many frames, starting with the currently executing
  70. frame (frame zero), followed by its caller (frame one), and on up the
  71. stack.
  72. </p>
  73. <a name="backtrace_002dcommand"></a><a name="index-backtrace"></a>
  74. <a name="index-bt-_0028backtrace_0029"></a>
  75. <p>To print a backtrace of the entire stack, use the <code>backtrace</code>
  76. command, or its alias <code>bt</code>. This command will print one line per
  77. frame for frames in the stack. By default, all stack frames are
  78. printed. You can stop the backtrace at any time by typing the system
  79. interrupt character, normally <kbd>Ctrl-c</kbd>.
  80. </p>
  81. <dl compact="compact">
  82. <dt><code>backtrace [<var>option</var>]&hellip; [<var>qualifier</var>]&hellip; [<var>count</var>]</code></dt>
  83. <dt><code>bt [<var>option</var>]&hellip; [<var>qualifier</var>]&hellip; [<var>count</var>]</code></dt>
  84. <dd><p>Print the backtrace of the entire stack.
  85. </p>
  86. <p>The optional <var>count</var> can be one of the following:
  87. </p>
  88. <dl compact="compact">
  89. <dt><code><var>n</var></code></dt>
  90. <dt><code><var>n</var></code></dt>
  91. <dd><p>Print only the innermost <var>n</var> frames, where <var>n</var> is a positive
  92. number.
  93. </p>
  94. </dd>
  95. <dt><code>-<var>n</var></code></dt>
  96. <dt><code>-<var>n</var></code></dt>
  97. <dd><p>Print only the outermost <var>n</var> frames, where <var>n</var> is a positive
  98. number.
  99. </p></dd>
  100. </dl>
  101. <p>Options:
  102. </p>
  103. <dl compact="compact">
  104. <dt><code>-full</code></dt>
  105. <dd><p>Print the values of the local variables also. This can be combined
  106. with the optional <var>count</var> to limit the number of frames shown.
  107. </p>
  108. </dd>
  109. <dt><code>-no-filters</code></dt>
  110. <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
  111. relevant when <small>GDB</small> has been configured with <code>Python</code>
  112. support.
  113. </p>
  114. </dd>
  115. <dt><code>-hide</code></dt>
  116. <dd><p>A Python frame filter might decide to &ldquo;elide&rdquo; some frames. Normally
  117. such elided frames are still printed, but they are indented relative
  118. to the filtered frames that cause them to be elided. The <code>-hide</code>
  119. option causes elided frames to not be printed at all.
  120. </p></dd>
  121. </dl>
  122. <p>The <code>backtrace</code> command also supports a number of options that
  123. allow overriding relevant global print settings as set by <code>set
  124. backtrace</code> and <code>set print</code> subcommands:
  125. </p>
  126. <dl compact="compact">
  127. <dt><code>-past-main [<code>on</code>|<code>off</code>]</code></dt>
  128. <dd><p>Set whether backtraces should continue past <code>main</code>. Related setting:
  129. <a href="#set-backtrace-past_002dmain">set backtrace past-main</a>.
  130. </p>
  131. </dd>
  132. <dt><code>-past-entry [<code>on</code>|<code>off</code>]</code></dt>
  133. <dd><p>Set whether backtraces should continue past the entry point of a program.
  134. Related setting: <a href="#set-backtrace-past_002dentry">set backtrace past-entry</a>.
  135. </p>
  136. </dd>
  137. <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>
  138. <dd><p>Set printing of function arguments at function entry.
  139. Related setting: <a href="Print-Settings.html#set-print-entry_002dvalues">set print entry-values</a>.
  140. </p>
  141. </dd>
  142. <dt><code>-frame-arguments <code>all</code>|<code>scalars</code>|<code>none</code></code></dt>
  143. <dd><p>Set printing of non-scalar frame arguments.
  144. Related setting: <a href="Print-Settings.html#set-print-frame_002darguments">set print frame-arguments</a>.
  145. </p>
  146. </dd>
  147. <dt><code>-raw-frame-arguments [<code>on</code>|<code>off</code>]</code></dt>
  148. <dd><p>Set whether to print frame arguments in raw form.
  149. Related setting: <a href="Print-Settings.html#set-print-raw_002dframe_002darguments">set print raw-frame-arguments</a>.
  150. </p>
  151. </dd>
  152. <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>
  153. <dd><p>Set printing of frame information.
  154. Related setting: <a href="Print-Settings.html#set-print-frame_002dinfo">set print frame-info</a>.
  155. </p></dd>
  156. </dl>
  157. <p>The optional <var>qualifier</var> is maintained for backward compatibility.
  158. It can be one of the following:
  159. </p>
  160. <dl compact="compact">
  161. <dt><code>full</code></dt>
  162. <dd><p>Equivalent to the <code>-full</code> option.
  163. </p>
  164. </dd>
  165. <dt><code>no-filters</code></dt>
  166. <dd><p>Equivalent to the <code>-no-filters</code> option.
  167. </p>
  168. </dd>
  169. <dt><code>hide</code></dt>
  170. <dd><p>Equivalent to the <code>-hide</code> option.
  171. </p></dd>
  172. </dl>
  173. </dd>
  174. </dl>
  175. <a name="index-where"></a>
  176. <a name="index-info-stack"></a>
  177. <p>The names <code>where</code> and <code>info stack</code> (abbreviated <code>info s</code>)
  178. are additional aliases for <code>backtrace</code>.
  179. </p>
  180. <a name="index-multiple-threads_002c-backtrace"></a>
  181. <p>In a multi-threaded program, <small>GDB</small> by default shows the
  182. backtrace only for the current thread. To display the backtrace for
  183. several or all of the threads, use the command <code>thread apply</code>
  184. (see <a href="Threads.html#Threads">thread apply</a>). For example, if you type <kbd>thread
  185. apply all backtrace</kbd>, <small>GDB</small> will display the backtrace for all
  186. the threads; this is handy when you debug a core dump of a
  187. multi-threaded program.
  188. </p>
  189. <p>Each line in the backtrace shows the frame number and the function name.
  190. The program counter value is also shown&mdash;unless you use <code>set
  191. print address off</code>. The backtrace also shows the source file name and
  192. line number, as well as the arguments to the function. The program
  193. counter value is omitted if it is at the beginning of the code for that
  194. line number.
  195. </p>
  196. <p>Here is an example of a backtrace. It was made with the command
  197. &lsquo;<samp>bt 3</samp>&rsquo;, so it shows the innermost three frames.
  198. </p>
  199. <div class="smallexample">
  200. <pre class="smallexample">#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
  201. at builtin.c:993
  202. #1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
  203. #2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
  204. at macro.c:71
  205. (More stack frames follow...)
  206. </pre></div>
  207. <p>The display for frame zero does not begin with a program counter
  208. value, indicating that your program has stopped at the beginning of the
  209. code for line <code>993</code> of <code>builtin.c</code>.
  210. </p>
  211. <p>The value of parameter <code>data</code> in frame 1 has been replaced by
  212. <code>&hellip;</code>. By default, <small>GDB</small> prints the value of a parameter
  213. only if it is a scalar (integer, pointer, enumeration, etc). See command
  214. <kbd>set print frame-arguments</kbd> in <a href="Print-Settings.html#Print-Settings">Print Settings</a> for more details
  215. on how to configure the way function parameter values are printed.
  216. The command <kbd>set print frame-info</kbd> (see <a href="Print-Settings.html#Print-Settings">Print Settings</a>) controls
  217. what frame information is printed.
  218. </p>
  219. <a name="index-optimized-out_002c-in-backtrace"></a>
  220. <a name="index-function-call-arguments_002c-optimized-out"></a>
  221. <p>If your program was compiled with optimizations, some compilers will
  222. optimize away arguments passed to functions if those arguments are
  223. never used after the call. Such optimizations generate code that
  224. passes arguments through registers, but doesn&rsquo;t store those arguments
  225. in the stack frame. <small>GDB</small> has no way of displaying such
  226. arguments in stack frames other than the innermost one. Here&rsquo;s what
  227. such a backtrace might look like:
  228. </p>
  229. <div class="smallexample">
  230. <pre class="smallexample">#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
  231. at builtin.c:993
  232. #1 0x6e38 in expand_macro (sym=&lt;optimized out&gt;) at macro.c:242
  233. #2 0x6840 in expand_token (obs=0x0, t=&lt;optimized out&gt;, td=0xf7fffb08)
  234. at macro.c:71
  235. (More stack frames follow...)
  236. </pre></div>
  237. <p>The values of arguments that were not saved in their stack frames are
  238. shown as &lsquo;<samp>&lt;optimized out&gt;</samp>&rsquo;.
  239. </p>
  240. <p>If you need to display the values of such optimized-out arguments,
  241. either deduce that from other variables whose values depend on the one
  242. you are interested in, or recompile without optimizations.
  243. </p>
  244. <a name="index-backtrace-beyond-main-function"></a>
  245. <a name="index-program-entry-point"></a>
  246. <a name="index-startup-code_002c-and-backtrace"></a>
  247. <p>Most programs have a standard user entry point&mdash;a place where system
  248. libraries and startup code transition into user code. For C this is
  249. <code>main</code><a name="DOCF9" href="#FOOT9"><sup>9</sup></a>.
  250. When <small>GDB</small> finds the entry function in a backtrace
  251. it will terminate the backtrace, to avoid tracing into highly
  252. system-specific (and generally uninteresting) code.
  253. </p>
  254. <p>If you need to examine the startup code, or limit the number of levels
  255. in a backtrace, you can change this behavior:
  256. </p>
  257. <dl compact="compact">
  258. <dt><code>set backtrace past-main</code></dt>
  259. <dt><code>set backtrace past-main on</code></dt>
  260. <dd><a name="set-backtrace-past_002dmain"></a><a name="index-set-backtrace"></a>
  261. <p>Backtraces will continue past the user entry point.
  262. </p>
  263. </dd>
  264. <dt><code>set backtrace past-main off</code></dt>
  265. <dd><p>Backtraces will stop when they encounter the user entry point. This is the
  266. default.
  267. </p>
  268. </dd>
  269. <dt><code>show backtrace past-main</code></dt>
  270. <dd><a name="index-show-backtrace"></a>
  271. <p>Display the current user entry point backtrace policy.
  272. </p>
  273. </dd>
  274. <dt><code>set backtrace past-entry</code></dt>
  275. <dt><code>set backtrace past-entry on</code></dt>
  276. <dd><a name="set-backtrace-past_002dentry"></a><p>Backtraces will continue past the internal entry point of an application.
  277. This entry point is encoded by the linker when the application is built,
  278. and is likely before the user entry point <code>main</code> (or equivalent) is called.
  279. </p>
  280. </dd>
  281. <dt><code>set backtrace past-entry off</code></dt>
  282. <dd><p>Backtraces will stop when they encounter the internal entry point of an
  283. application. This is the default.
  284. </p>
  285. </dd>
  286. <dt><code>show backtrace past-entry</code></dt>
  287. <dd><p>Display the current internal entry point backtrace policy.
  288. </p>
  289. </dd>
  290. <dt><code>set backtrace limit <var>n</var></code></dt>
  291. <dt><code>set backtrace limit 0</code></dt>
  292. <dt><code>set backtrace limit unlimited</code></dt>
  293. <dd><a name="set-backtrace-limit"></a><a name="index-backtrace-limit"></a>
  294. <p>Limit the backtrace to <var>n</var> levels. A value of <code>unlimited</code>
  295. or zero means unlimited levels.
  296. </p>
  297. </dd>
  298. <dt><code>show backtrace limit</code></dt>
  299. <dd><p>Display the current limit on backtrace levels.
  300. </p></dd>
  301. </dl>
  302. <p>You can control how file names are displayed.
  303. </p>
  304. <dl compact="compact">
  305. <dt><code>set filename-display</code></dt>
  306. <dt><code>set filename-display relative</code></dt>
  307. <dd><a name="index-filename_002ddisplay"></a>
  308. <p>Display file names relative to the compilation directory. This is the default.
  309. </p>
  310. </dd>
  311. <dt><code>set filename-display basename</code></dt>
  312. <dd><p>Display only basename of a filename.
  313. </p>
  314. </dd>
  315. <dt><code>set filename-display absolute</code></dt>
  316. <dd><p>Display an absolute filename.
  317. </p>
  318. </dd>
  319. <dt><code>show filename-display</code></dt>
  320. <dd><p>Show the current way to display filenames.
  321. </p></dd>
  322. </dl>
  323. <div class="footnote">
  324. <hr>
  325. <h4 class="footnotes-heading">Footnotes</h4>
  326. <h3><a name="FOOT9" href="#DOCF9">(9)</a></h3>
  327. <p>Note that embedded programs (the so-called &ldquo;free-standing&rdquo;
  328. environment) are not required to have a <code>main</code> function as the
  329. entry point. They could even have multiple entry points.</p>
  330. </div>
  331. <hr>
  332. <div class="header">
  333. <p>
  334. Next: <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>
  335. </div>
  336. </body>
  337. </html>