1<html lang="en"> 2<head> 3<title>Symbols - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="prev" href="Languages.html#Languages" title="Languages"> 9<link rel="next" href="Altering.html#Altering" title="Altering"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 1988-2013 Free Software Foundation, Inc. 13 14Permission is granted to copy, distribute and/or modify this document 15under the terms of the GNU Free Documentation License, Version 1.3 or 16any later version published by the Free Software Foundation; with the 17Invariant Sections being ``Free Software'' and ``Free Software Needs 18Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 19and with the Back-Cover Texts as in (a) below. 20 21(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 22this GNU Manual. Buying copies from GNU Press supports the FSF in 23developing GNU and promoting software freedom.'' 24--> 25<meta http-equiv="Content-Style-Type" content="text/css"> 26<style type="text/css"><!-- 27 pre.display { font-family:inherit } 28 pre.format { font-family:inherit } 29 pre.smalldisplay { font-family:inherit; font-size:smaller } 30 pre.smallformat { font-family:inherit; font-size:smaller } 31 pre.smallexample { font-size:smaller } 32 pre.smalllisp { font-size:smaller } 33 span.sc { font-variant:small-caps } 34 span.roman { font-family:serif; font-weight:normal; } 35 span.sansserif { font-family:sans-serif; font-weight:normal; } 36--></style> 37<link rel="stylesheet" type="text/css" href="../cs.css"> 38</head> 39<body> 40<div class="node"> 41<a name="Symbols"></a> 42<p> 43Next: <a rel="next" accesskey="n" href="Altering.html#Altering">Altering</a>, 44Previous: <a rel="previous" accesskey="p" href="Languages.html#Languages">Languages</a>, 45Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 46<hr> 47</div> 48 49<h2 class="chapter">16 Examining the Symbol Table</h2> 50 51<p>The commands described in this chapter allow you to inquire about the 52symbols (names of variables, functions and types) defined in your 53program. This information is inherent in the text of your program and 54does not change as your program executes. <span class="sc">gdb</span> finds it in your 55program's symbol table, in the file indicated when you started <span class="sc">gdb</span> 56(see <a href="File-Options.html#File-Options">Choosing Files</a>), or by one of the 57file-management commands (see <a href="Files.html#Files">Commands to Specify Files</a>). 58 59 <p><a name="index-symbol-names-984"></a><a name="index-names-of-symbols-985"></a><a name="index-quoting-names-986"></a>Occasionally, you may need to refer to symbols that contain unusual 60characters, which <span class="sc">gdb</span> ordinarily treats as word delimiters. The 61most frequent case is in referring to static variables in other 62source files (see <a href="Variables.html#Variables">Program Variables</a>). File names 63are recorded in object files as debugging symbols, but <span class="sc">gdb</span> would 64ordinarily parse a typical file name, like <samp><span class="file">foo.c</span></samp>, as the three words 65‘<samp><span class="samp">foo</span></samp>’ ‘<samp><span class="samp">.</span></samp>’ ‘<samp><span class="samp">c</span></samp>’. To allow <span class="sc">gdb</span> to recognize 66‘<samp><span class="samp">foo.c</span></samp>’ as a single symbol, enclose it in single quotes; for example, 67 68<pre class="smallexample"> p 'foo.c'::x 69</pre> 70 <p class="noindent">looks up the value of <code>x</code> in the scope of the file <samp><span class="file">foo.c</span></samp>. 71 72 73<a name="index-case_002dinsensitive-symbol-names-987"></a> 74<a name="index-case-sensitivity-in-symbol-names-988"></a> 75<a name="index-set-case_002dsensitive-989"></a> 76<dl><dt><code>set case-sensitive on</code><dt><code>set case-sensitive off</code><dt><code>set case-sensitive auto</code><dd>Normally, when <span class="sc">gdb</span> looks up symbols, it matches their names 77with case sensitivity determined by the current source language. 78Occasionally, you may wish to control that. The command <code>set 79case-sensitive</code> lets you do that by specifying <code>on</code> for 80case-sensitive matches or <code>off</code> for case-insensitive ones. If 81you specify <code>auto</code>, case sensitivity is reset to the default 82suitable for the source language. The default is case-sensitive 83matches for all languages except for Fortran, for which the default is 84case-insensitive matches. 85 86 <p><a name="index-show-case_002dsensitive-990"></a><br><dt><code>show case-sensitive</code><dd>This command shows the current setting of case sensitivity for symbols 87lookups. 88 89 <p><a name="index-set-print-type-methods-991"></a><br><dt><code>set print type methods</code><dt><code>set print type methods on</code><dt><code>set print type methods off</code><dd>Normally, when <span class="sc">gdb</span> prints a class, it displays any methods 90declared in that class. You can control this behavior either by 91passing the appropriate flag to <code>ptype</code>, or using <samp><span class="command">set 92print type methods</span></samp>. Specifying <code>on</code> will cause <span class="sc">gdb</span> to 93display the methods; this is the default. Specifying <code>off</code> will 94cause <span class="sc">gdb</span> to omit the methods. 95 96 <p><a name="index-show-print-type-methods-992"></a><br><dt><code>show print type methods</code><dd>This command shows the current setting of method display when printing 97classes. 98 99 <p><a name="index-set-print-type-typedefs-993"></a><br><dt><code>set print type typedefs</code><dt><code>set print type typedefs on</code><dt><code>set print type typedefs off</code><dd> 100Normally, when <span class="sc">gdb</span> prints a class, it displays any typedefs 101defined in that class. You can control this behavior either by 102passing the appropriate flag to <code>ptype</code>, or using <samp><span class="command">set 103print type typedefs</span></samp>. Specifying <code>on</code> will cause <span class="sc">gdb</span> to 104display the typedef definitions; this is the default. Specifying 105<code>off</code> will cause <span class="sc">gdb</span> to omit the typedef definitions. 106Note that this controls whether the typedef definition itself is 107printed, not whether typedef names are substituted when printing other 108types. 109 110 <p><a name="index-show-print-type-typedefs-994"></a><br><dt><code>show print type typedefs</code><dd>This command shows the current setting of typedef display when 111printing classes. 112 113 <p><a name="index-info-address-995"></a><a name="index-address-of-a-symbol-996"></a><br><dt><code>info address </code><var>symbol</var><dd>Describe where the data for <var>symbol</var> is stored. For a register 114variable, this says which register it is kept in. For a non-register 115local variable, this prints the stack-frame offset at which the variable 116is always stored. 117 118 <p>Note the contrast with ‘<samp><span class="samp">print &</span><var>symbol</var></samp>’, which does not work 119at all for a register variable, and for a stack local variable prints 120the exact address of the current instantiation of the variable. 121 122 <p><a name="index-info-symbol-997"></a><a name="index-symbol-from-address-998"></a><a name="index-closest-symbol-and-offset-for-an-address-999"></a><br><dt><code>info symbol </code><var>addr</var><dd>Print the name of a symbol which is stored at the address <var>addr</var>. 123If no symbol is stored exactly at <var>addr</var>, <span class="sc">gdb</span> prints the 124nearest symbol and an offset from it: 125 126 <pre class="smallexample"> (gdb) info symbol 0x54320 127 _initialize_vx + 396 in section .text 128</pre> 129 <p class="noindent">This is the opposite of the <code>info address</code> command. You can use 130it to find out the name of a variable or a function given its address. 131 132 <p>For dynamically linked executables, the name of executable or shared 133library containing the symbol is also printed: 134 135 <pre class="smallexample"> (gdb) info symbol 0x400225 136 _start + 5 in section .text of /tmp/a.out 137 (gdb) info symbol 0x2aaaac2811cf 138 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6 139</pre> 140 <p><a name="index-whatis-1000"></a><br><dt><code>whatis[/</code><var>flags</var><code>] [</code><var>arg</var><code>]</code><dd>Print the data type of <var>arg</var>, which can be either an expression 141or a name of a data type. With no argument, print the data type of 142<code>$</code>, the last value in the value history. 143 144 <p>If <var>arg</var> is an expression (see <a href="Expressions.html#Expressions">Expressions</a>), it 145is not actually evaluated, and any side-effecting operations (such as 146assignments or function calls) inside it do not take place. 147 148 <p>If <var>arg</var> is a variable or an expression, <code>whatis</code> prints its 149literal type as it is used in the source code. If the type was 150defined using a <code>typedef</code>, <code>whatis</code> will <em>not</em> print 151the data type underlying the <code>typedef</code>. If the type of the 152variable or the expression is a compound data type, such as 153<code>struct</code> or <code>class</code>, <code>whatis</code> never prints their 154fields or methods. It just prints the <code>struct</code>/<code>class</code> 155name (a.k.a. its <dfn>tag</dfn>). If you want to see the members of 156such a compound data type, use <code>ptype</code>. 157 158 <p>If <var>arg</var> is a type name that was defined using <code>typedef</code>, 159<code>whatis</code> <dfn>unrolls</dfn> only one level of that <code>typedef</code>. 160Unrolling means that <code>whatis</code> will show the underlying type used 161in the <code>typedef</code> declaration of <var>arg</var>. However, if that 162underlying type is also a <code>typedef</code>, <code>whatis</code> will not 163unroll it. 164 165 <p>For C code, the type names may also have the form ‘<samp><span class="samp">class 166</span><var>class-name</var></samp>’, ‘<samp><span class="samp">struct </span><var>struct-tag</var></samp>’, ‘<samp><span class="samp">union 167</span><var>union-tag</var></samp>’ or ‘<samp><span class="samp">enum </span><var>enum-tag</var></samp>’. 168 169 <p><var>flags</var> can be used to modify how the type is displayed. 170Available flags are: 171 172 <dl> 173<dt><code>r</code><dd>Display in “raw” form. Normally, <span class="sc">gdb</span> substitutes template 174parameters and typedefs defined in a class when printing the class' 175members. The <code>/r</code> flag disables this. 176 177 <br><dt><code>m</code><dd>Do not print methods defined in the class. 178 179 <br><dt><code>M</code><dd>Print methods defined in the class. This is the default, but the flag 180exists in case you change the default with <samp><span class="command">set print type methods</span></samp>. 181 182 <br><dt><code>t</code><dd>Do not print typedefs defined in the class. Note that this controls 183whether the typedef definition itself is printed, not whether typedef 184names are substituted when printing other types. 185 186 <br><dt><code>T</code><dd>Print typedefs defined in the class. This is the default, but the flag 187exists in case you change the default with <samp><span class="command">set print type typedefs</span></samp>. 188</dl> 189 190 <p><a name="index-ptype-1001"></a><br><dt><code>ptype[/</code><var>flags</var><code>] [</code><var>arg</var><code>]</code><dd><code>ptype</code> accepts the same arguments as <code>whatis</code>, but prints a 191detailed description of the type, instead of just the name of the type. 192See <a href="Expressions.html#Expressions">Expressions</a>. 193 194 <p>Contrary to <code>whatis</code>, <code>ptype</code> always unrolls any 195<code>typedef</code>s in its argument declaration, whether the argument is 196a variable, expression, or a data type. This means that <code>ptype</code> 197of a variable or an expression will not print literally its type as 198present in the source code—use <code>whatis</code> for that. <code>typedef</code>s at 199the pointer or reference targets are also unrolled. Only <code>typedef</code>s of 200fields, methods and inner <code>class typedef</code>s of <code>struct</code>s, 201<code>class</code>es and <code>union</code>s are not unrolled even with <code>ptype</code>. 202 203 <p>For example, for this variable declaration: 204 205 <pre class="smallexample"> typedef double real_t; 206 struct complex { real_t real; double imag; }; 207 typedef struct complex complex_t; 208 complex_t var; 209 real_t *real_pointer_var; 210</pre> 211 <p class="noindent">the two commands give this output: 212 213 <pre class="smallexample"> (gdb) whatis var 214 type = complex_t 215 (gdb) ptype var 216 type = struct complex { 217 real_t real; 218 double imag; 219 } 220 (gdb) whatis complex_t 221 type = struct complex 222 (gdb) whatis struct complex 223 type = struct complex 224 (gdb) ptype struct complex 225 type = struct complex { 226 real_t real; 227 double imag; 228 } 229 (gdb) whatis real_pointer_var 230 type = real_t * 231 (gdb) ptype real_pointer_var 232 type = double * 233</pre> 234 <p class="noindent">As with <code>whatis</code>, using <code>ptype</code> without an argument refers to 235the type of <code>$</code>, the last value in the value history. 236 237 <p><a name="index-incomplete-type-1002"></a>Sometimes, programs use opaque data types or incomplete specifications 238of complex data structure. If the debug information included in the 239program does not allow <span class="sc">gdb</span> to display a full declaration of 240the data type, it will say ‘<samp><span class="samp"><incomplete type></span></samp>’. For example, 241given these declarations: 242 243 <pre class="smallexample"> struct foo; 244 struct foo *fooptr; 245</pre> 246 <p class="noindent">but no definition for <code>struct foo</code> itself, <span class="sc">gdb</span> will say: 247 248 <pre class="smallexample"> (gdb) ptype foo 249 $1 = <incomplete type> 250</pre> 251 <p class="noindent">“Incomplete type” is C terminology for data types that are not 252completely specified. 253 254 <p><a name="index-info-types-1003"></a><br><dt><code>info types </code><var>regexp</var><dt><code>info types</code><dd>Print a brief description of all types whose names match the regular 255expression <var>regexp</var> (or all types in your program, if you supply 256no argument). Each complete typename is matched as though it were a 257complete line; thus, ‘<samp><span class="samp">i type value</span></samp>’ gives information on all 258types in your program whose names include the string <code>value</code>, but 259‘<samp><span class="samp">i type ^value$</span></samp>’ gives information only on types whose complete 260name is <code>value</code>. 261 262 <p>This command differs from <code>ptype</code> in two ways: first, like 263<code>whatis</code>, it does not print a detailed description; second, it 264lists all source files where a type is defined. 265 266 <p><a name="index-info-type_002dprinters-1004"></a><br><dt><code>info type-printers</code><dd>Versions of <span class="sc">gdb</span> that ship with Python scripting enabled may 267have “type printers” available. When using <samp><span class="command">ptype</span></samp> or 268<samp><span class="command">whatis</span></samp>, these printers are consulted when the name of a type 269is needed. See <a href="Type-Printing-API.html#Type-Printing-API">Type Printing API</a>, for more information on writing 270type printers. 271 272 <p><code>info type-printers</code> displays all the available type printers. 273 274 <p><a name="index-enable-type_002dprinter-1005"></a><a name="index-disable-type_002dprinter-1006"></a><br><dt><code>enable type-printer </code><var>name</var><code>...</code><br><dt><code>disable type-printer </code><var>name</var><code>...</code><dd>These commands can be used to enable or disable type printers. 275 276 <p><a name="index-info-scope-1007"></a><a name="index-local-variables-1008"></a><br><dt><code>info scope </code><var>location</var><dd>List all the variables local to a particular scope. This command 277accepts a <var>location</var> argument—a function name, a source line, or 278an address preceded by a ‘<samp><span class="samp">*</span></samp>’, and prints all the variables local 279to the scope defined by that location. (See <a href="Specify-Location.html#Specify-Location">Specify Location</a>, for 280details about supported forms of <var>location</var>.) For example: 281 282 <pre class="smallexample"> (gdb) <b>info scope command_line_handler</b> 283 Scope for command_line_handler: 284 Symbol rl is an argument at stack/frame offset 8, length 4. 285 Symbol linebuffer is in static storage at address 0x150a18, length 4. 286 Symbol linelength is in static storage at address 0x150a1c, length 4. 287 Symbol p is a local variable in register $esi, length 4. 288 Symbol p1 is a local variable in register $ebx, length 4. 289 Symbol nline is a local variable in register $edx, length 4. 290 Symbol repeat is a local variable at frame offset -8, length 4. 291</pre> 292 <p class="noindent">This command is especially useful for determining what data to collect 293during a <dfn>trace experiment</dfn>, see <a href="Tracepoint-Actions.html#Tracepoint-Actions">collect</a>. 294 295 <p><a name="index-info-source-1009"></a><br><dt><code>info source</code><dd>Show information about the current source file—that is, the source file for 296the function containing the current point of execution: 297 <ul> 298<li>the name of the source file, and the directory containing it, 299<li>the directory it was compiled in, 300<li>its length, in lines, 301<li>which programming language it is written in, 302<li>whether the executable includes debugging information for that file, and 303if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and 304<li>whether the debugging information includes information about 305preprocessor macros. 306</ul> 307 308 <p><a name="index-info-sources-1010"></a><br><dt><code>info sources</code><dd>Print the names of all source files in your program for which there is 309debugging information, organized into two lists: files whose symbols 310have already been read, and files whose symbols will be read when needed. 311 312 <p><a name="index-info-functions-1011"></a><br><dt><code>info functions</code><dd>Print the names and data types of all defined functions. 313 314 <br><dt><code>info functions </code><var>regexp</var><dd>Print the names and data types of all defined functions 315whose names contain a match for regular expression <var>regexp</var>. 316Thus, ‘<samp><span class="samp">info fun step</span></samp>’ finds all functions whose names 317include <code>step</code>; ‘<samp><span class="samp">info fun ^step</span></samp>’ finds those whose names 318start with <code>step</code>. If a function name contains characters 319that conflict with the regular expression language (e.g. 320‘<samp><span class="samp">operator*()</span></samp>’), they may be quoted with a backslash. 321 322 <p><a name="index-info-variables-1012"></a><br><dt><code>info variables</code><dd>Print the names and data types of all variables that are defined 323outside of functions (i.e. excluding local variables). 324 325 <br><dt><code>info variables </code><var>regexp</var><dd>Print the names and data types of all variables (except for local 326variables) whose names contain a match for regular expression 327<var>regexp</var>. 328 329 <p><a name="index-info-classes-1013"></a><a name="index-Objective_002dC_002c-classes-and-selectors-1014"></a><br><dt><code>info classes</code><dt><code>info classes </code><var>regexp</var><dd>Display all Objective-C classes in your program, or 330(with the <var>regexp</var> argument) all those matching a particular regular 331expression. 332 333 <p><a name="index-info-selectors-1015"></a><br><dt><code>info selectors</code><dt><code>info selectors </code><var>regexp</var><dd>Display all Objective-C selectors in your program, or 334(with the <var>regexp</var> argument) all those matching a particular regular 335expression. 336 337 <p><a name="index-opaque-data-types-1016"></a><a name="index-set-opaque_002dtype_002dresolution-1017"></a><br><dt><code>set opaque-type-resolution on</code><dd>Tell <span class="sc">gdb</span> to resolve opaque types. An opaque type is a type 338declared as a pointer to a <code>struct</code>, <code>class</code>, or 339<code>union</code>—for example, <code>struct MyType *</code>—that is used in one 340source file although the full declaration of <code>struct MyType</code> is in 341another source file. The default is on. 342 343 <p>A change in the setting of this subcommand will not take effect until 344the next time symbols for a file are loaded. 345 346 <br><dt><code>set opaque-type-resolution off</code><dd>Tell <span class="sc">gdb</span> not to resolve opaque types. In this case, the type 347is printed as follows: 348 <pre class="smallexample"> {<no data fields>} 349</pre> 350 <p><a name="index-show-opaque_002dtype_002dresolution-1018"></a><br><dt><code>show opaque-type-resolution</code><dd>Show whether opaque types are resolved or not. 351 352 <p><a name="index-maint-print-symbols-1019"></a><a name="index-symbol-dump-1020"></a><a name="index-maint-print-psymbols-1021"></a><a name="index-partial-symbol-dump-1022"></a><a name="index-maint-print-msymbols-1023"></a><a name="index-minimal-symbol-dump-1024"></a><br><dt><code>maint print symbols </code><var>filename</var><dt><code>maint print psymbols </code><var>filename</var><dt><code>maint print msymbols </code><var>filename</var><dd>Write a dump of debugging symbol data into the file <var>filename</var>. 353These commands are used to debug the <span class="sc">gdb</span> symbol-reading code. Only 354symbols with debugging data are included. If you use ‘<samp><span class="samp">maint print 355symbols</span></samp>’, <span class="sc">gdb</span> includes all the symbols for which it has already 356collected full details: that is, <var>filename</var> reflects symbols for 357only those files whose symbols <span class="sc">gdb</span> has read. You can use the 358command <code>info sources</code> to find out which files these are. If you 359use ‘<samp><span class="samp">maint print psymbols</span></samp>’ instead, the dump shows information about 360symbols that <span class="sc">gdb</span> only knows partially—that is, symbols defined in 361files that <span class="sc">gdb</span> has skimmed, but not yet read completely. Finally, 362‘<samp><span class="samp">maint print msymbols</span></samp>’ dumps just the minimal symbol information 363required for each object file from which <span class="sc">gdb</span> has read some symbols. 364See <a href="Files.html#Files">Commands to Specify Files</a>, for a discussion of how 365<span class="sc">gdb</span> reads symbols (in the description of <code>symbol-file</code>). 366 367 <p><a name="index-maint-info-symtabs-1025"></a><a name="index-maint-info-psymtabs-1026"></a><a name="index-listing-_0040value_007bGDBN_007d_0027s-internal-symbol-tables-1027"></a><a name="index-symbol-tables_002c-listing-_0040value_007bGDBN_007d_0027s-internal-1028"></a><a name="index-full-symbol-tables_002c-listing-_0040value_007bGDBN_007d_0027s-internal-1029"></a><a name="index-partial-symbol-tables_002c-listing-_0040value_007bGDBN_007d_0027s-internal-1030"></a><br><dt><code>maint info symtabs </code><span class="roman">[</span> <var>regexp</var> <span class="roman">]</span><dt><code>maint info psymtabs </code><span class="roman">[</span> <var>regexp</var> <span class="roman">]</span><dd> 368List the <code>struct symtab</code> or <code>struct partial_symtab</code> 369structures whose names match <var>regexp</var>. If <var>regexp</var> is not 370given, list them all. The output includes expressions which you can 371copy into a <span class="sc">gdb</span> debugging this one to examine a particular 372structure in more detail. For example: 373 374 <pre class="smallexample"> (gdb) maint info psymtabs dwarf2read 375 { objfile /home/gnu/build/gdb/gdb 376 ((struct objfile *) 0x82e69d0) 377 { psymtab /home/gnu/src/gdb/dwarf2read.c 378 ((struct partial_symtab *) 0x8474b10) 379 readin no 380 fullname (null) 381 text addresses 0x814d3c8 -- 0x8158074 382 globals (* (struct partial_symbol **) 0x8507a08 @ 9) 383 statics (* (struct partial_symbol **) 0x40e95b78 @ 2882) 384 dependencies (none) 385 } 386 } 387 (gdb) maint info symtabs 388 (gdb) 389</pre> 390 <p class="noindent">We see that there is one partial symbol table whose filename contains 391the string ‘<samp><span class="samp">dwarf2read</span></samp>’, belonging to the ‘<samp><span class="samp">gdb</span></samp>’ executable; 392and we see that <span class="sc">gdb</span> has not read in any symtabs yet at all. 393If we set a breakpoint on a function, that will cause <span class="sc">gdb</span> to 394read the symtab for the compilation unit containing that function: 395 396 <pre class="smallexample"> (gdb) break dwarf2_psymtab_to_symtab 397 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c, 398 line 1574. 399 (gdb) maint info symtabs 400 { objfile /home/gnu/build/gdb/gdb 401 ((struct objfile *) 0x82e69d0) 402 { symtab /home/gnu/src/gdb/dwarf2read.c 403 ((struct symtab *) 0x86c1f38) 404 dirname (null) 405 fullname (null) 406 blockvector ((struct blockvector *) 0x86c1bd0) (primary) 407 linetable ((struct linetable *) 0x8370fa0) 408 debugformat DWARF 2 409 } 410 } 411 (gdb) 412</pre> 413 </dl> 414 415 </body></html> 416 417