You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

357 line
15KB

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