Symbols.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  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-2019 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.2, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Symbols</title>
  16. <meta name="description" content="Debugging with GDB: Symbols">
  17. <meta name="keywords" content="Debugging with GDB: Symbols">
  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="index.html#Top" rel="up" title="Top">
  26. <link href="Altering.html#Altering" rel="next" title="Altering">
  27. <link href="Unsupported-Languages.html#Unsupported-Languages" rel="prev" title="Unsupported Languages">
  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="Symbols"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Altering.html#Altering" accesskey="n" rel="next">Altering</a>, Previous: <a href="Languages.html#Languages" accesskey="p" rel="prev">Languages</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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="Examining-the-Symbol-Table"></a>
  65. <h2 class="chapter">16 Examining the Symbol Table</h2>
  66. <p>The commands described in this chapter allow you to inquire about the
  67. symbols (names of variables, functions and types) defined in your
  68. program. This information is inherent in the text of your program and
  69. does not change as your program executes. <small>GDB</small> finds it in your
  70. program&rsquo;s symbol table, in the file indicated when you started <small>GDB</small>
  71. (see <a href="File-Options.html#File-Options">Choosing Files</a>), or by one of the
  72. file-management commands (see <a href="Files.html#Files">Commands to Specify Files</a>).
  73. </p>
  74. <a name="index-symbol-names"></a>
  75. <a name="index-names-of-symbols"></a>
  76. <a name="index-quoting-names"></a>
  77. <a name="quoting-names"></a><p>Occasionally, you may need to refer to symbols that contain unusual
  78. characters, which <small>GDB</small> ordinarily treats as word delimiters. The
  79. most frequent case is in referring to static variables in other
  80. source files (see <a href="Variables.html#Variables">Program Variables</a>). File names
  81. are recorded in object files as debugging symbols, but <small>GDB</small> would
  82. ordinarily parse a typical file name, like <samp>foo.c</samp>, as the three words
  83. &lsquo;<samp>foo</samp>&rsquo; &lsquo;<samp>.</samp>&rsquo; &lsquo;<samp>c</samp>&rsquo;. To allow <small>GDB</small> to recognize
  84. &lsquo;<samp>foo.c</samp>&rsquo; as a single symbol, enclose it in single quotes; for example,
  85. </p>
  86. <div class="smallexample">
  87. <pre class="smallexample">p 'foo.c'::x
  88. </pre></div>
  89. <p>looks up the value of <code>x</code> in the scope of the file <samp>foo.c</samp>.
  90. </p>
  91. <dl compact="compact">
  92. <dd><a name="index-case_002dinsensitive-symbol-names"></a>
  93. <a name="index-case-sensitivity-in-symbol-names"></a>
  94. <a name="index-set-case_002dsensitive"></a>
  95. </dd>
  96. <dt><code>set case-sensitive on</code></dt>
  97. <dt><code>set case-sensitive off</code></dt>
  98. <dt><code>set case-sensitive auto</code></dt>
  99. <dd><p>Normally, when <small>GDB</small> looks up symbols, it matches their names
  100. with case sensitivity determined by the current source language.
  101. Occasionally, you may wish to control that. The command <code>set
  102. case-sensitive</code> lets you do that by specifying <code>on</code> for
  103. case-sensitive matches or <code>off</code> for case-insensitive ones. If
  104. you specify <code>auto</code>, case sensitivity is reset to the default
  105. suitable for the source language. The default is case-sensitive
  106. matches for all languages except for Fortran, for which the default is
  107. case-insensitive matches.
  108. </p>
  109. <a name="index-show-case_002dsensitive"></a>
  110. </dd>
  111. <dt><code>show case-sensitive</code></dt>
  112. <dd><p>This command shows the current setting of case sensitivity for symbols
  113. lookups.
  114. </p>
  115. <a name="index-set-print-type-methods"></a>
  116. </dd>
  117. <dt><code>set print type methods</code></dt>
  118. <dt><code>set print type methods on</code></dt>
  119. <dt><code>set print type methods off</code></dt>
  120. <dd><p>Normally, when <small>GDB</small> prints a class, it displays any methods
  121. declared in that class. You can control this behavior either by
  122. passing the appropriate flag to <code>ptype</code>, or using <code>set
  123. print type methods</code>. Specifying <code>on</code> will cause <small>GDB</small> to
  124. display the methods; this is the default. Specifying <code>off</code> will
  125. cause <small>GDB</small> to omit the methods.
  126. </p>
  127. <a name="index-show-print-type-methods"></a>
  128. </dd>
  129. <dt><code>show print type methods</code></dt>
  130. <dd><p>This command shows the current setting of method display when printing
  131. classes.
  132. </p>
  133. <a name="index-set-print-type-nested_002dtype_002dlimit"></a>
  134. </dd>
  135. <dt><code>set print type nested-type-limit <var>limit</var></code></dt>
  136. <dt><code>set print type nested-type-limit unlimited</code></dt>
  137. <dd><p>Set the limit of displayed nested types that the type printer will
  138. show. A <var>limit</var> of <code>unlimited</code> or <code>-1</code> will show all
  139. nested definitions. By default, the type printer will not show any nested
  140. types defined in classes.
  141. </p>
  142. <a name="index-show-print-type-nested_002dtype_002dlimit"></a>
  143. </dd>
  144. <dt><code>show print type nested-type-limit</code></dt>
  145. <dd><p>This command shows the current display limit of nested types when
  146. printing classes.
  147. </p>
  148. <a name="index-set-print-type-typedefs"></a>
  149. </dd>
  150. <dt><code>set print type typedefs</code></dt>
  151. <dt><code>set print type typedefs on</code></dt>
  152. <dt><code>set print type typedefs off</code></dt>
  153. <dd>
  154. <p>Normally, when <small>GDB</small> prints a class, it displays any typedefs
  155. defined in that class. You can control this behavior either by
  156. passing the appropriate flag to <code>ptype</code>, or using <code>set
  157. print type typedefs</code>. Specifying <code>on</code> will cause <small>GDB</small> to
  158. display the typedef definitions; this is the default. Specifying
  159. <code>off</code> will cause <small>GDB</small> to omit the typedef definitions.
  160. Note that this controls whether the typedef definition itself is
  161. printed, not whether typedef names are substituted when printing other
  162. types.
  163. </p>
  164. <a name="index-show-print-type-typedefs"></a>
  165. </dd>
  166. <dt><code>show print type typedefs</code></dt>
  167. <dd><p>This command shows the current setting of typedef display when
  168. printing classes.
  169. </p>
  170. <a name="index-info-address"></a>
  171. <a name="index-address-of-a-symbol"></a>
  172. </dd>
  173. <dt><code>info address <var>symbol</var></code></dt>
  174. <dd><p>Describe where the data for <var>symbol</var> is stored. For a register
  175. variable, this says which register it is kept in. For a non-register
  176. local variable, this prints the stack-frame offset at which the variable
  177. is always stored.
  178. </p>
  179. <p>Note the contrast with &lsquo;<samp>print &amp;<var>symbol</var></samp>&rsquo;, which does not work
  180. at all for a register variable, and for a stack local variable prints
  181. the exact address of the current instantiation of the variable.
  182. </p>
  183. <a name="index-info-symbol"></a>
  184. <a name="index-symbol-from-address"></a>
  185. <a name="index-closest-symbol-and-offset-for-an-address"></a>
  186. </dd>
  187. <dt><code>info symbol <var>addr</var></code></dt>
  188. <dd><p>Print the name of a symbol which is stored at the address <var>addr</var>.
  189. If no symbol is stored exactly at <var>addr</var>, <small>GDB</small> prints the
  190. nearest symbol and an offset from it:
  191. </p>
  192. <div class="smallexample">
  193. <pre class="smallexample">(gdb) info symbol 0x54320
  194. _initialize_vx + 396 in section .text
  195. </pre></div>
  196. <p>This is the opposite of the <code>info address</code> command. You can use
  197. it to find out the name of a variable or a function given its address.
  198. </p>
  199. <p>For dynamically linked executables, the name of executable or shared
  200. library containing the symbol is also printed:
  201. </p>
  202. <div class="smallexample">
  203. <pre class="smallexample">(gdb) info symbol 0x400225
  204. _start + 5 in section .text of /tmp/a.out
  205. (gdb) info symbol 0x2aaaac2811cf
  206. __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
  207. </pre></div>
  208. <a name="index-demangle-1"></a>
  209. <a name="index-demangle"></a>
  210. </dd>
  211. <dt><code>demangle <span class="roman">[</span>-l <var>language</var><span class="roman">]</span> <span class="roman">[</span><var>--</var><span class="roman">]</span> <var>name</var></code></dt>
  212. <dd><p>Demangle <var>name</var>.
  213. If <var>language</var> is provided it is the name of the language to demangle
  214. <var>name</var> in. Otherwise <var>name</var> is demangled in the current language.
  215. </p>
  216. <p>The &lsquo;<samp>--</samp>&rsquo; option specifies the end of options,
  217. and is useful when <var>name</var> begins with a dash.
  218. </p>
  219. <p>The parameter <code>demangle-style</code> specifies how to interpret the kind
  220. of mangling used. See <a href="Print-Settings.html#Print-Settings">Print Settings</a>.
  221. </p>
  222. <a name="index-whatis"></a>
  223. </dd>
  224. <dt><code>whatis[/<var>flags</var>] [<var>arg</var>]</code></dt>
  225. <dd><p>Print the data type of <var>arg</var>, which can be either an expression
  226. or a name of a data type. With no argument, print the data type of
  227. <code>$</code>, the last value in the value history.
  228. </p>
  229. <p>If <var>arg</var> is an expression (see <a href="Expressions.html#Expressions">Expressions</a>), it
  230. is not actually evaluated, and any side-effecting operations (such as
  231. assignments or function calls) inside it do not take place.
  232. </p>
  233. <p>If <var>arg</var> is a variable or an expression, <code>whatis</code> prints its
  234. literal type as it is used in the source code. If the type was
  235. defined using a <code>typedef</code>, <code>whatis</code> will <em>not</em> print
  236. the data type underlying the <code>typedef</code>. If the type of the
  237. variable or the expression is a compound data type, such as
  238. <code>struct</code> or <code>class</code>, <code>whatis</code> never prints their
  239. fields or methods. It just prints the <code>struct</code>/<code>class</code>
  240. name (a.k.a. its <em>tag</em>). If you want to see the members of
  241. such a compound data type, use <code>ptype</code>.
  242. </p>
  243. <p>If <var>arg</var> is a type name that was defined using <code>typedef</code>,
  244. <code>whatis</code> <em>unrolls</em> only one level of that <code>typedef</code>.
  245. Unrolling means that <code>whatis</code> will show the underlying type used
  246. in the <code>typedef</code> declaration of <var>arg</var>. However, if that
  247. underlying type is also a <code>typedef</code>, <code>whatis</code> will not
  248. unroll it.
  249. </p>
  250. <p>For C code, the type names may also have the form &lsquo;<samp>class
  251. <var>class-name</var></samp>&rsquo;, &lsquo;<samp>struct <var>struct-tag</var></samp>&rsquo;, &lsquo;<samp>union
  252. <var>union-tag</var></samp>&rsquo; or &lsquo;<samp>enum <var>enum-tag</var></samp>&rsquo;.
  253. </p>
  254. <p><var>flags</var> can be used to modify how the type is displayed.
  255. Available flags are:
  256. </p>
  257. <dl compact="compact">
  258. <dt><code>r</code></dt>
  259. <dd><p>Display in &ldquo;raw&rdquo; form. Normally, <small>GDB</small> substitutes template
  260. parameters and typedefs defined in a class when printing the class&rsquo;
  261. members. The <code>/r</code> flag disables this.
  262. </p>
  263. </dd>
  264. <dt><code>m</code></dt>
  265. <dd><p>Do not print methods defined in the class.
  266. </p>
  267. </dd>
  268. <dt><code>M</code></dt>
  269. <dd><p>Print methods defined in the class. This is the default, but the flag
  270. exists in case you change the default with <code>set print type methods</code>.
  271. </p>
  272. </dd>
  273. <dt><code>t</code></dt>
  274. <dd><p>Do not print typedefs defined in the class. Note that this controls
  275. whether the typedef definition itself is printed, not whether typedef
  276. names are substituted when printing other types.
  277. </p>
  278. </dd>
  279. <dt><code>T</code></dt>
  280. <dd><p>Print typedefs defined in the class. This is the default, but the flag
  281. exists in case you change the default with <code>set print type typedefs</code>.
  282. </p>
  283. </dd>
  284. <dt><code>o</code></dt>
  285. <dd><p>Print the offsets and sizes of fields in a struct, similar to what the
  286. <code>pahole</code> tool does. This option implies the <code>/tm</code> flags.
  287. </p>
  288. <p>For example, given the following declarations:
  289. </p>
  290. <div class="smallexample">
  291. <pre class="smallexample">struct tuv
  292. {
  293. int a1;
  294. char *a2;
  295. int a3;
  296. };
  297. struct xyz
  298. {
  299. int f1;
  300. char f2;
  301. void *f3;
  302. struct tuv f4;
  303. };
  304. union qwe
  305. {
  306. struct tuv fff1;
  307. struct xyz fff2;
  308. };
  309. struct tyu
  310. {
  311. int a1 : 1;
  312. int a2 : 3;
  313. int a3 : 23;
  314. char a4 : 2;
  315. int64_t a5;
  316. int a6 : 5;
  317. int64_t a7 : 3;
  318. };
  319. </pre></div>
  320. <p>Issuing a <kbd>ptype /o struct tuv</kbd> command would print:
  321. </p>
  322. <div class="smallexample">
  323. <pre class="smallexample">(gdb) ptype /o struct tuv
  324. /* offset | size */ type = struct tuv {
  325. /* 0 | 4 */ int a1;
  326. /* XXX 4-byte hole */
  327. /* 8 | 8 */ char *a2;
  328. /* 16 | 4 */ int a3;
  329. /* total size (bytes): 24 */
  330. }
  331. </pre></div>
  332. <p>Notice the format of the first column of comments. There, you can
  333. find two parts separated by the &lsquo;<samp>|</samp>&rsquo; character: the <em>offset</em>,
  334. which indicates where the field is located inside the struct, in
  335. bytes, and the <em>size</em> of the field. Another interesting line is
  336. the marker of a <em>hole</em> in the struct, indicating that it may be
  337. possible to pack the struct and make it use less space by reorganizing
  338. its fields.
  339. </p>
  340. <p>It is also possible to print offsets inside an union:
  341. </p>
  342. <div class="smallexample">
  343. <pre class="smallexample">(gdb) ptype /o union qwe
  344. /* offset | size */ type = union qwe {
  345. /* 24 */ struct tuv {
  346. /* 0 | 4 */ int a1;
  347. /* XXX 4-byte hole */
  348. /* 8 | 8 */ char *a2;
  349. /* 16 | 4 */ int a3;
  350. /* total size (bytes): 24 */
  351. } fff1;
  352. /* 40 */ struct xyz {
  353. /* 0 | 4 */ int f1;
  354. /* 4 | 1 */ char f2;
  355. /* XXX 3-byte hole */
  356. /* 8 | 8 */ void *f3;
  357. /* 16 | 24 */ struct tuv {
  358. /* 16 | 4 */ int a1;
  359. /* XXX 4-byte hole */
  360. /* 24 | 8 */ char *a2;
  361. /* 32 | 4 */ int a3;
  362. /* total size (bytes): 24 */
  363. } f4;
  364. /* total size (bytes): 40 */
  365. } fff2;
  366. /* total size (bytes): 40 */
  367. }
  368. </pre></div>
  369. <p>In this case, since <code>struct tuv</code> and <code>struct xyz</code> occupy the
  370. same space (because we are dealing with an union), the offset is not
  371. printed for them. However, you can still examine the offset of each
  372. of these structures&rsquo; fields.
  373. </p>
  374. <p>Another useful scenario is printing the offsets of a struct containing
  375. bitfields:
  376. </p>
  377. <div class="smallexample">
  378. <pre class="smallexample">(gdb) ptype /o struct tyu
  379. /* offset | size */ type = struct tyu {
  380. /* 0:31 | 4 */ int a1 : 1;
  381. /* 0:28 | 4 */ int a2 : 3;
  382. /* 0: 5 | 4 */ int a3 : 23;
  383. /* 3: 3 | 1 */ signed char a4 : 2;
  384. /* XXX 3-bit hole */
  385. /* XXX 4-byte hole */
  386. /* 8 | 8 */ int64_t a5;
  387. /* 16:27 | 4 */ int a6 : 5;
  388. /* 16:56 | 8 */ int64_t a7 : 3;
  389. /* total size (bytes): 24 */
  390. }
  391. </pre></div>
  392. <p>Note how the offset information is now extended to also include how
  393. many bits are left to be used in each bitfield.
  394. </p></dd>
  395. </dl>
  396. <a name="index-ptype"></a>
  397. </dd>
  398. <dt><code>ptype[/<var>flags</var>] [<var>arg</var>]</code></dt>
  399. <dd><p><code>ptype</code> accepts the same arguments as <code>whatis</code>, but prints a
  400. detailed description of the type, instead of just the name of the type.
  401. See <a href="Expressions.html#Expressions">Expressions</a>.
  402. </p>
  403. <p>Contrary to <code>whatis</code>, <code>ptype</code> always unrolls any
  404. <code>typedef</code>s in its argument declaration, whether the argument is
  405. a variable, expression, or a data type. This means that <code>ptype</code>
  406. of a variable or an expression will not print literally its type as
  407. present in the source code&mdash;use <code>whatis</code> for that. <code>typedef</code>s at
  408. the pointer or reference targets are also unrolled. Only <code>typedef</code>s of
  409. fields, methods and inner <code>class typedef</code>s of <code>struct</code>s,
  410. <code>class</code>es and <code>union</code>s are not unrolled even with <code>ptype</code>.
  411. </p>
  412. <p>For example, for this variable declaration:
  413. </p>
  414. <div class="smallexample">
  415. <pre class="smallexample">typedef double real_t;
  416. struct complex { real_t real; double imag; };
  417. typedef struct complex complex_t;
  418. complex_t var;
  419. real_t *real_pointer_var;
  420. </pre></div>
  421. <p>the two commands give this output:
  422. </p>
  423. <div class="smallexample">
  424. <pre class="smallexample">(gdb) whatis var
  425. type = complex_t
  426. (gdb) ptype var
  427. type = struct complex {
  428. real_t real;
  429. double imag;
  430. }
  431. (gdb) whatis complex_t
  432. type = struct complex
  433. (gdb) whatis struct complex
  434. type = struct complex
  435. (gdb) ptype struct complex
  436. type = struct complex {
  437. real_t real;
  438. double imag;
  439. }
  440. (gdb) whatis real_pointer_var
  441. type = real_t *
  442. (gdb) ptype real_pointer_var
  443. type = double *
  444. </pre></div>
  445. <p>As with <code>whatis</code>, using <code>ptype</code> without an argument refers to
  446. the type of <code>$</code>, the last value in the value history.
  447. </p>
  448. <a name="index-incomplete-type"></a>
  449. <p>Sometimes, programs use opaque data types or incomplete specifications
  450. of complex data structure. If the debug information included in the
  451. program does not allow <small>GDB</small> to display a full declaration of
  452. the data type, it will say &lsquo;<samp>&lt;incomplete type&gt;</samp>&rsquo;. For example,
  453. given these declarations:
  454. </p>
  455. <div class="smallexample">
  456. <pre class="smallexample"> struct foo;
  457. struct foo *fooptr;
  458. </pre></div>
  459. <p>but no definition for <code>struct foo</code> itself, <small>GDB</small> will say:
  460. </p>
  461. <div class="smallexample">
  462. <pre class="smallexample"> (gdb) ptype foo
  463. $1 = &lt;incomplete type&gt;
  464. </pre></div>
  465. <p>&ldquo;Incomplete type&rdquo; is C terminology for data types that are not
  466. completely specified.
  467. </p>
  468. <a name="index-unknown-type"></a>
  469. <p>Othertimes, information about a variable&rsquo;s type is completely absent
  470. from the debug information included in the program. This most often
  471. happens when the program or library where the variable is defined
  472. includes no debug information at all. <small>GDB</small> knows the variable
  473. exists from inspecting the linker/loader symbol table (e.g., the ELF
  474. dynamic symbol table), but such symbols do not contain type
  475. information. Inspecting the type of a (global) variable for which
  476. <small>GDB</small> has no type information shows:
  477. </p>
  478. <div class="smallexample">
  479. <pre class="smallexample"> (gdb) ptype var
  480. type = &lt;data variable, no debug info&gt;
  481. </pre></div>
  482. <p>See <a href="Variables.html#Variables">no debug info variables</a>, for how to print the values
  483. of such variables.
  484. </p>
  485. <a name="index-info-types"></a>
  486. </dd>
  487. <dt><code>info types <var>regexp</var></code></dt>
  488. <dt><code>info types</code></dt>
  489. <dd><p>Print a brief description of all types whose names match the regular
  490. expression <var>regexp</var> (or all types in your program, if you supply
  491. no argument). Each complete typename is matched as though it were a
  492. complete line; thus, &lsquo;<samp>i type value</samp>&rsquo; gives information on all
  493. types in your program whose names include the string <code>value</code>, but
  494. &lsquo;<samp>i type ^value$</samp>&rsquo; gives information only on types whose complete
  495. name is <code>value</code>.
  496. </p>
  497. <p>In programs using different languages, <small>GDB</small> chooses the syntax
  498. to print the type description according to the
  499. &lsquo;<samp>set language</samp>&rsquo; value: using &lsquo;<samp>set language auto</samp>&rsquo;
  500. (see <a href="Automatically.html#Automatically">Set Language Automatically</a>) means to use the
  501. language of the type, other values mean to use
  502. the manually specified language (see <a href="Manually.html#Manually">Set Language Manually</a>).
  503. </p>
  504. <p>This command differs from <code>ptype</code> in two ways: first, like
  505. <code>whatis</code>, it does not print a detailed description; second, it
  506. lists all source files and line numbers where a type is defined.
  507. </p>
  508. <a name="index-info-type_002dprinters"></a>
  509. </dd>
  510. <dt><code>info type-printers</code></dt>
  511. <dd><p>Versions of <small>GDB</small> that ship with Python scripting enabled may
  512. have &ldquo;type printers&rdquo; available. When using <code>ptype</code> or
  513. <code>whatis</code>, these printers are consulted when the name of a type
  514. is needed. See <a href="Type-Printing-API.html#Type-Printing-API">Type Printing API</a>, for more information on writing
  515. type printers.
  516. </p>
  517. <p><code>info type-printers</code> displays all the available type printers.
  518. </p>
  519. <a name="index-enable-type_002dprinter"></a>
  520. <a name="index-disable-type_002dprinter"></a>
  521. </dd>
  522. <dt><code>enable type-printer <var>name</var>&hellip;</code></dt>
  523. <dt><code>disable type-printer <var>name</var>&hellip;</code></dt>
  524. <dd><p>These commands can be used to enable or disable type printers.
  525. </p>
  526. <a name="index-info-scope"></a>
  527. <a name="index-local-variables"></a>
  528. </dd>
  529. <dt><code>info scope <var>location</var></code></dt>
  530. <dd><p>List all the variables local to a particular scope. This command
  531. accepts a <var>location</var> argument&mdash;a function name, a source line, or
  532. an address preceded by a &lsquo;<samp>*</samp>&rsquo;, and prints all the variables local
  533. to the scope defined by that location. (See <a href="Specify-Location.html#Specify-Location">Specify Location</a>, for
  534. details about supported forms of <var>location</var>.) For example:
  535. </p>
  536. <div class="smallexample">
  537. <pre class="smallexample">(gdb) <b>info scope command_line_handler</b>
  538. Scope for command_line_handler:
  539. Symbol rl is an argument at stack/frame offset 8, length 4.
  540. Symbol linebuffer is in static storage at address 0x150a18, length 4.
  541. Symbol linelength is in static storage at address 0x150a1c, length 4.
  542. Symbol p is a local variable in register $esi, length 4.
  543. Symbol p1 is a local variable in register $ebx, length 4.
  544. Symbol nline is a local variable in register $edx, length 4.
  545. Symbol repeat is a local variable at frame offset -8, length 4.
  546. </pre></div>
  547. <p>This command is especially useful for determining what data to collect
  548. during a <em>trace experiment</em>, see <a href="Tracepoint-Actions.html#Tracepoint-Actions">collect</a>.
  549. </p>
  550. <a name="index-info-source"></a>
  551. </dd>
  552. <dt><code>info source</code></dt>
  553. <dd><p>Show information about the current source file&mdash;that is, the source file for
  554. the function containing the current point of execution:
  555. </p><ul>
  556. <li> the name of the source file, and the directory containing it,
  557. </li><li> the directory it was compiled in,
  558. </li><li> its length, in lines,
  559. </li><li> which programming language it is written in,
  560. </li><li> if the debug information provides it, the program that compiled the file
  561. (which may include, e.g., the compiler version and command line arguments),
  562. </li><li> whether the executable includes debugging information for that file, and
  563. if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
  564. </li><li> whether the debugging information includes information about
  565. preprocessor macros.
  566. </li></ul>
  567. <a name="index-info-sources"></a>
  568. </dd>
  569. <dt><code>info sources</code></dt>
  570. <dd><p>Print the names of all source files in your program for which there is
  571. debugging information, organized into two lists: files whose symbols
  572. have already been read, and files whose symbols will be read when needed.
  573. </p>
  574. <a name="index-info-functions"></a>
  575. </dd>
  576. <dt><code>info functions [-q]</code></dt>
  577. <dd><p>Print the names and data types of all defined functions.
  578. Similarly to &lsquo;<samp>info types</samp>&rsquo;, this command groups its output by source
  579. files and annotates each function definition with its source line
  580. number.
  581. </p>
  582. <p>In programs using different languages, <small>GDB</small> chooses the syntax
  583. to print the function name and type according to the
  584. &lsquo;<samp>set language</samp>&rsquo; value: using &lsquo;<samp>set language auto</samp>&rsquo;
  585. (see <a href="Automatically.html#Automatically">Set Language Automatically</a>) means to use the
  586. language of the function, other values mean to use
  587. the manually specified language (see <a href="Manually.html#Manually">Set Language Manually</a>).
  588. </p>
  589. <p>The optional flag &lsquo;<samp>-q</samp>&rsquo;, which stands for &lsquo;<samp>quiet</samp>&rsquo;, disables
  590. printing header information and messages explaining why no functions
  591. have been printed.
  592. </p>
  593. </dd>
  594. <dt><code>info functions [-q] [-t <var>type_regexp</var>] [<var>regexp</var>]</code></dt>
  595. <dd><p>Like &lsquo;<samp>info functions</samp>&rsquo;, but only print the names and data types
  596. of the functions selected with the provided regexp(s).
  597. </p>
  598. <p>If <var>regexp</var> is provided, print only the functions whose names
  599. match the regular expression <var>regexp</var>.
  600. Thus, &lsquo;<samp>info fun step</samp>&rsquo; finds all functions whose
  601. names include <code>step</code>; &lsquo;<samp>info fun ^step</samp>&rsquo; finds those whose names
  602. start with <code>step</code>. If a function name contains characters that
  603. conflict with the regular expression language (e.g.
  604. &lsquo;<samp>operator*()</samp>&rsquo;), they may be quoted with a backslash.
  605. </p>
  606. <p>If <var>type_regexp</var> is provided, print only the functions whose
  607. types, as printed by the <code>whatis</code> command, match
  608. the regular expression <var>type_regexp</var>.
  609. If <var>type_regexp</var> contains space(s), it should be enclosed in
  610. quote characters. If needed, use backslash to escape the meaning
  611. of special characters or quotes.
  612. Thus, &lsquo;<samp>info fun -t '^int ('</samp>&rsquo; finds the functions that return
  613. an integer; &lsquo;<samp>info fun -t '(.*int.*'</samp>&rsquo; finds the functions that
  614. have an argument type containing int; &lsquo;<samp>info fun -t '^int (' ^step</samp>&rsquo;
  615. finds the functions whose names start with <code>step</code> and that return
  616. int.
  617. </p>
  618. <p>If both <var>regexp</var> and <var>type_regexp</var> are provided, a function
  619. is printed only if its name matches <var>regexp</var> and its type matches
  620. <var>type_regexp</var>.
  621. </p>
  622. <a name="index-info-variables"></a>
  623. </dd>
  624. <dt><code>info variables [-q]</code></dt>
  625. <dd><p>Print the names and data types of all variables that are defined
  626. outside of functions (i.e. excluding local variables).
  627. The printed variables are grouped by source files and annotated with
  628. their respective source line numbers.
  629. </p>
  630. <p>In programs using different languages, <small>GDB</small> chooses the syntax
  631. to print the variable name and type according to the
  632. &lsquo;<samp>set language</samp>&rsquo; value: using &lsquo;<samp>set language auto</samp>&rsquo;
  633. (see <a href="Automatically.html#Automatically">Set Language Automatically</a>) means to use the
  634. language of the variable, other values mean to use
  635. the manually specified language (see <a href="Manually.html#Manually">Set Language Manually</a>).
  636. </p>
  637. <p>The optional flag &lsquo;<samp>-q</samp>&rsquo;, which stands for &lsquo;<samp>quiet</samp>&rsquo;, disables
  638. printing header information and messages explaining why no variables
  639. have been printed.
  640. </p>
  641. </dd>
  642. <dt><code>info variables [-q] [-t <var>type_regexp</var>] [<var>regexp</var>]</code></dt>
  643. <dd><p>Like <kbd>info variables</kbd>, but only print the variables selected
  644. with the provided regexp(s).
  645. </p>
  646. <p>If <var>regexp</var> is provided, print only the variables whose names
  647. match the regular expression <var>regexp</var>.
  648. </p>
  649. <p>If <var>type_regexp</var> is provided, print only the variables whose
  650. types, as printed by the <code>whatis</code> command, match
  651. the regular expression <var>type_regexp</var>.
  652. If <var>type_regexp</var> contains space(s), it should be enclosed in
  653. quote characters. If needed, use backslash to escape the meaning
  654. of special characters or quotes.
  655. </p>
  656. <p>If both <var>regexp</var> and <var>type_regexp</var> are provided, an argument
  657. is printed only if its name matches <var>regexp</var> and its type matches
  658. <var>type_regexp</var>.
  659. </p>
  660. <a name="index-info-classes"></a>
  661. <a name="index-Objective_002dC_002c-classes-and-selectors"></a>
  662. </dd>
  663. <dt><code>info classes</code></dt>
  664. <dt><code>info classes <var>regexp</var></code></dt>
  665. <dd><p>Display all Objective-C classes in your program, or
  666. (with the <var>regexp</var> argument) all those matching a particular regular
  667. expression.
  668. </p>
  669. <a name="index-info-selectors"></a>
  670. </dd>
  671. <dt><code>info selectors</code></dt>
  672. <dt><code>info selectors <var>regexp</var></code></dt>
  673. <dd><p>Display all Objective-C selectors in your program, or
  674. (with the <var>regexp</var> argument) all those matching a particular regular
  675. expression.
  676. </p>
  677. <a name="index-opaque-data-types"></a>
  678. <a name="index-set-opaque_002dtype_002dresolution"></a>
  679. </dd>
  680. <dt><code>set opaque-type-resolution on</code></dt>
  681. <dd><p>Tell <small>GDB</small> to resolve opaque types. An opaque type is a type
  682. declared as a pointer to a <code>struct</code>, <code>class</code>, or
  683. <code>union</code>&mdash;for example, <code>struct MyType *</code>&mdash;that is used in one
  684. source file although the full declaration of <code>struct MyType</code> is in
  685. another source file. The default is on.
  686. </p>
  687. <p>A change in the setting of this subcommand will not take effect until
  688. the next time symbols for a file are loaded.
  689. </p>
  690. </dd>
  691. <dt><code>set opaque-type-resolution off</code></dt>
  692. <dd><p>Tell <small>GDB</small> not to resolve opaque types. In this case, the type
  693. is printed as follows:
  694. </p><div class="smallexample">
  695. <pre class="smallexample">{&lt;no data fields&gt;}
  696. </pre></div>
  697. <a name="index-show-opaque_002dtype_002dresolution"></a>
  698. </dd>
  699. <dt><code>show opaque-type-resolution</code></dt>
  700. <dd><p>Show whether opaque types are resolved or not.
  701. </p>
  702. <a name="index-set-print-symbol_002dloading"></a>
  703. <a name="index-print-messages-when-symbols-are-loaded"></a>
  704. </dd>
  705. <dt><code>set print symbol-loading</code></dt>
  706. <dt><code>set print symbol-loading full</code></dt>
  707. <dt><code>set print symbol-loading brief</code></dt>
  708. <dt><code>set print symbol-loading off</code></dt>
  709. <dd><p>The <code>set print symbol-loading</code> command allows you to control the
  710. printing of messages when <small>GDB</small> loads symbol information.
  711. By default a message is printed for the executable and one for each
  712. shared library, and normally this is what you want. However, when
  713. debugging apps with large numbers of shared libraries these messages
  714. can be annoying.
  715. When set to <code>brief</code> a message is printed for each executable,
  716. and when <small>GDB</small> loads a collection of shared libraries at once
  717. it will only print one message regardless of the number of shared
  718. libraries. When set to <code>off</code> no messages are printed.
  719. </p>
  720. <a name="index-show-print-symbol_002dloading"></a>
  721. </dd>
  722. <dt><code>show print symbol-loading</code></dt>
  723. <dd><p>Show whether messages will be printed when a <small>GDB</small> command
  724. entered from the keyboard causes symbol information to be loaded.
  725. </p>
  726. <a name="index-maint-print-symbols"></a>
  727. <a name="index-symbol-dump"></a>
  728. <a name="index-maint-print-psymbols"></a>
  729. <a name="index-partial-symbol-dump"></a>
  730. <a name="index-maint-print-msymbols"></a>
  731. <a name="index-minimal-symbol-dump"></a>
  732. </dd>
  733. <dt><code>maint print symbols <span class="roman">[</span>-pc <var>address</var><span class="roman">]</span> <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
  734. <dt><code>maint print symbols <span class="roman">[</span>-objfile <var>objfile</var><span class="roman">]</span> <span class="roman">[</span>-source <var>source</var><span class="roman">]</span> <span class="roman">[</span>--<span class="roman">]</span> <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
  735. <dt><code>maint print psymbols <span class="roman">[</span>-objfile <var>objfile</var><span class="roman">]</span> <span class="roman">[</span>-pc <var>address</var><span class="roman">]</span> <span class="roman">[</span>--<span class="roman">]</span> <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
  736. <dt><code>maint print psymbols <span class="roman">[</span>-objfile <var>objfile</var><span class="roman">]</span> <span class="roman">[</span>-source <var>source</var><span class="roman">]</span> <span class="roman">[</span>--<span class="roman">]</span> <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
  737. <dt><code>maint print msymbols <span class="roman">[</span>-objfile <var>objfile</var><span class="roman">]</span> <span class="roman">[</span>--<span class="roman">]</span> <span class="roman">[</span><var>filename</var><span class="roman">]</span></code></dt>
  738. <dd><p>Write a dump of debugging symbol data into the file <var>filename</var> or
  739. the terminal if <var>filename</var> is unspecified.
  740. If <code>-objfile <var>objfile</var></code> is specified, only dump symbols for
  741. that objfile.
  742. If <code>-pc <var>address</var></code> is specified, only dump symbols for the file
  743. with code at that address. Note that <var>address</var> may be a symbol like
  744. <code>main</code>.
  745. If <code>-source <var>source</var></code> is specified, only dump symbols for that
  746. source file.
  747. </p>
  748. <p>These commands are used to debug the <small>GDB</small> symbol-reading code.
  749. These commands do not modify internal <small>GDB</small> state, therefore
  750. &lsquo;<samp>maint print symbols</samp>&rsquo; will only print symbols for already expanded symbol
  751. tables.
  752. You can use the command <code>info sources</code> to find out which files these are.
  753. If you use &lsquo;<samp>maint print psymbols</samp>&rsquo; instead, the dump shows information
  754. about symbols that <small>GDB</small> only knows partially&mdash;that is, symbols
  755. defined in files that <small>GDB</small> has skimmed, but not yet read completely.
  756. Finally, &lsquo;<samp>maint print msymbols</samp>&rsquo; just dumps &ldquo;minimal symbols&rdquo;, e.g.,
  757. &ldquo;ELF symbols&rdquo;.
  758. </p>
  759. <p>See <a href="Files.html#Files">Commands to Specify Files</a>, for a discussion of how
  760. <small>GDB</small> reads symbols (in the description of <code>symbol-file</code>).
  761. </p>
  762. <a name="index-maint-info-symtabs"></a>
  763. <a name="index-maint-info-psymtabs"></a>
  764. <a name="index-listing-GDB_0027s-internal-symbol-tables"></a>
  765. <a name="index-symbol-tables_002c-listing-GDB_0027s-internal"></a>
  766. <a name="index-full-symbol-tables_002c-listing-GDB_0027s-internal"></a>
  767. <a name="index-partial-symbol-tables_002c-listing-GDB_0027s-internal"></a>
  768. </dd>
  769. <dt><code>maint info symtabs <span class="roman">[</span> <var>regexp</var> <span class="roman">]</span></code></dt>
  770. <dt><code>maint info psymtabs <span class="roman">[</span> <var>regexp</var> <span class="roman">]</span></code></dt>
  771. <dd>
  772. <p>List the <code>struct symtab</code> or <code>struct partial_symtab</code>
  773. structures whose names match <var>regexp</var>. If <var>regexp</var> is not
  774. given, list them all. The output includes expressions which you can
  775. copy into a <small>GDB</small> debugging this one to examine a particular
  776. structure in more detail. For example:
  777. </p>
  778. <div class="smallexample">
  779. <pre class="smallexample">(gdb) maint info psymtabs dwarf2read
  780. { objfile /home/gnu/build/gdb/gdb
  781. ((struct objfile *) 0x82e69d0)
  782. { psymtab /home/gnu/src/gdb/dwarf2read.c
  783. ((struct partial_symtab *) 0x8474b10)
  784. readin no
  785. fullname (null)
  786. text addresses 0x814d3c8 -- 0x8158074
  787. globals (* (struct partial_symbol **) 0x8507a08 @ 9)
  788. statics (* (struct partial_symbol **) 0x40e95b78 @ 2882)
  789. dependencies (none)
  790. }
  791. }
  792. (gdb) maint info symtabs
  793. (gdb)
  794. </pre></div>
  795. <p>We see that there is one partial symbol table whose filename contains
  796. the string &lsquo;<samp>dwarf2read</samp>&rsquo;, belonging to the &lsquo;<samp>gdb</samp>&rsquo; executable;
  797. and we see that <small>GDB</small> has not read in any symtabs yet at all.
  798. If we set a breakpoint on a function, that will cause <small>GDB</small> to
  799. read the symtab for the compilation unit containing that function:
  800. </p>
  801. <div class="smallexample">
  802. <pre class="smallexample">(gdb) break dwarf2_psymtab_to_symtab
  803. Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
  804. line 1574.
  805. (gdb) maint info symtabs
  806. { objfile /home/gnu/build/gdb/gdb
  807. ((struct objfile *) 0x82e69d0)
  808. { symtab /home/gnu/src/gdb/dwarf2read.c
  809. ((struct symtab *) 0x86c1f38)
  810. dirname (null)
  811. fullname (null)
  812. blockvector ((struct blockvector *) 0x86c1bd0) (primary)
  813. linetable ((struct linetable *) 0x8370fa0)
  814. debugformat DWARF 2
  815. }
  816. }
  817. (gdb)
  818. </pre></div>
  819. <a name="index-maint-info-line_002dtable"></a>
  820. <a name="index-listing-GDB_0027s-internal-line-tables"></a>
  821. <a name="index-line-tables_002c-listing-GDB_0027s-internal"></a>
  822. </dd>
  823. <dt><code>maint info line-table <span class="roman">[</span> <var>regexp</var> <span class="roman">]</span></code></dt>
  824. <dd>
  825. <p>List the <code>struct linetable</code> from all <code>struct symtab</code>
  826. instances whose name matches <var>regexp</var>. If <var>regexp</var> is not
  827. given, list the <code>struct linetable</code> from all <code>struct symtab</code>.
  828. </p>
  829. <a name="index-maint-set-symbol_002dcache_002dsize"></a>
  830. <a name="index-symbol-cache-size"></a>
  831. </dd>
  832. <dt><code>maint set symbol-cache-size <var>size</var></code></dt>
  833. <dd><p>Set the size of the symbol cache to <var>size</var>.
  834. The default size is intended to be good enough for debugging
  835. most applications. This option exists to allow for experimenting
  836. with different sizes.
  837. </p>
  838. <a name="index-maint-show-symbol_002dcache_002dsize"></a>
  839. </dd>
  840. <dt><code>maint show symbol-cache-size</code></dt>
  841. <dd><p>Show the size of the symbol cache.
  842. </p>
  843. <a name="index-maint-print-symbol_002dcache"></a>
  844. <a name="index-symbol-cache_002c-printing-its-contents"></a>
  845. </dd>
  846. <dt><code>maint print symbol-cache</code></dt>
  847. <dd><p>Print the contents of the symbol cache.
  848. This is useful when debugging symbol cache issues.
  849. </p>
  850. <a name="index-maint-print-symbol_002dcache_002dstatistics"></a>
  851. <a name="index-symbol-cache_002c-printing-usage-statistics"></a>
  852. </dd>
  853. <dt><code>maint print symbol-cache-statistics</code></dt>
  854. <dd><p>Print symbol cache usage statistics.
  855. This helps determine how well the cache is being utilized.
  856. </p>
  857. <a name="index-maint-flush_002dsymbol_002dcache"></a>
  858. <a name="index-symbol-cache_002c-flushing"></a>
  859. </dd>
  860. <dt><code>maint flush-symbol-cache</code></dt>
  861. <dd><p>Flush the contents of the symbol cache, all entries are removed.
  862. This command is useful when debugging the symbol cache.
  863. It is also useful when collecting performance data.
  864. </p>
  865. </dd>
  866. </dl>
  867. <hr>
  868. <div class="header">
  869. <p>
  870. Next: <a href="Altering.html#Altering" accesskey="n" rel="next">Altering</a>, Previous: <a href="Languages.html#Languages" accesskey="p" rel="prev">Languages</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</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>
  871. </div>
  872. </body>
  873. </html>