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, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 131998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 14Free Software Foundation, Inc. 15 16Permission is granted to copy, distribute and/or modify this document 17under the terms of the GNU Free Documentation License, Version 1.3 or 18any later version published by the Free Software Foundation; with the 19Invariant Sections being ``Free Software'' and ``Free Software Needs 20Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 21and with the Back-Cover Texts as in (a) below. 22 23(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 24this GNU Manual. Buying copies from GNU Press supports the FSF in 25developing GNU and promoting software freedom.''--> 26<meta http-equiv="Content-Style-Type" content="text/css"> 27<style type="text/css"><!-- 28 pre.display { font-family:inherit } 29 pre.format { font-family:inherit } 30 pre.smalldisplay { font-family:inherit; font-size:smaller } 31 pre.smallformat { font-family:inherit; font-size:smaller } 32 pre.smallexample { font-size:smaller } 33 pre.smalllisp { font-size:smaller } 34 span.sc { font-variant:small-caps } 35 span.roman { font-family:serif; font-weight:normal; } 36 span.sansserif { font-family:sans-serif; font-weight:normal; } 37--></style> 38<link rel="stylesheet" type="text/css" href="../cs.css"> 39</head> 40<body> 41<div class="node"> 42<a name="Symbols"></a> 43<p> 44Next: <a rel="next" accesskey="n" href="Altering.html#Altering">Altering</a>, 45Previous: <a rel="previous" accesskey="p" href="Languages.html#Languages">Languages</a>, 46Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 47<hr> 48</div> 49 50<h2 class="chapter">16 Examining the Symbol Table</h2> 51 52<p>The commands described in this chapter allow you to inquire about the 53symbols (names of variables, functions and types) defined in your 54program. This information is inherent in the text of your program and 55does not change as your program executes. <span class="sc">gdb</span> finds it in your 56program's symbol table, in the file indicated when you started <span class="sc">gdb</span> 57(see <a href="File-Options.html#File-Options">Choosing Files</a>), or by one of the 58file-management commands (see <a href="Files.html#Files">Commands to Specify Files</a>). 59 60 <p><a name="index-symbol-names-883"></a><a name="index-names-of-symbols-884"></a><a name="index-quoting-names-885"></a>Occasionally, you may need to refer to symbols that contain unusual 61characters, which <span class="sc">gdb</span> ordinarily treats as word delimiters. The 62most frequent case is in referring to static variables in other 63source files (see <a href="Variables.html#Variables">Program Variables</a>). File names 64are recorded in object files as debugging symbols, but <span class="sc">gdb</span> would 65ordinarily parse a typical file name, like <samp><span class="file">foo.c</span></samp>, as the three words 66‘<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 67‘<samp><span class="samp">foo.c</span></samp>’ as a single symbol, enclose it in single quotes; for example, 68 69<pre class="smallexample"> p 'foo.c'::x 70</pre> 71 <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>. 72 73 74<a name="index-case_002dinsensitive-symbol-names-886"></a> 75<a name="index-case-sensitivity-in-symbol-names-887"></a> 76<a name="index-set-case_002dsensitive-888"></a> 77<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 78with case sensitivity determined by the current source language. 79Occasionally, you may wish to control that. The command <code>set 80case-sensitive</code> lets you do that by specifying <code>on</code> for 81case-sensitive matches or <code>off</code> for case-insensitive ones. If 82you specify <code>auto</code>, case sensitivity is reset to the default 83suitable for the source language. The default is case-sensitive 84matches for all languages except for Fortran, for which the default is 85case-insensitive matches. 86 87 <p><a name="index-show-case_002dsensitive-889"></a><br><dt><code>show case-sensitive</code><dd>This command shows the current setting of case sensitivity for symbols 88lookups. 89 90 <p><a name="index-info-address-890"></a><a name="index-address-of-a-symbol-891"></a><br><dt><code>info address </code><var>symbol</var><dd>Describe where the data for <var>symbol</var> is stored. For a register 91variable, this says which register it is kept in. For a non-register 92local variable, this prints the stack-frame offset at which the variable 93is always stored. 94 95 <p>Note the contrast with ‘<samp><span class="samp">print &</span><var>symbol</var></samp>’, which does not work 96at all for a register variable, and for a stack local variable prints 97the exact address of the current instantiation of the variable. 98 99 <p><a name="index-info-symbol-892"></a><a name="index-symbol-from-address-893"></a><a name="index-closest-symbol-and-offset-for-an-address-894"></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>. 100If no symbol is stored exactly at <var>addr</var>, <span class="sc">gdb</span> prints the 101nearest symbol and an offset from it: 102 103 <pre class="smallexample"> (gdb) info symbol 0x54320 104 _initialize_vx + 396 in section .text 105</pre> 106 <p class="noindent">This is the opposite of the <code>info address</code> command. You can use 107it to find out the name of a variable or a function given its address. 108 109 <p>For dynamically linked executables, the name of executable or shared 110library containing the symbol is also printed: 111 112 <pre class="smallexample"> (gdb) info symbol 0x400225 113 _start + 5 in section .text of /tmp/a.out 114 (gdb) info symbol 0x2aaaac2811cf 115 __read_nocancel + 6 in section .text of /usr/lib64/libc.so.6 116</pre> 117 <p><a name="index-whatis-895"></a><br><dt><code>whatis [</code><var>arg</var><code>]</code><dd>Print the data type of <var>arg</var>, which can be either an expression or 118a data type. With no argument, print the data type of <code>$</code>, the 119last value in the value history. If <var>arg</var> is an expression, it is 120not actually evaluated, and any side-effecting operations (such as 121assignments or function calls) inside it do not take place. If 122<var>arg</var> is a type name, it may be the name of a type or typedef, or 123for C code it may have the form ‘<samp><span class="samp">class </span><var>class-name</var></samp>’, 124‘<samp><span class="samp">struct </span><var>struct-tag</var></samp>’, ‘<samp><span class="samp">union </span><var>union-tag</var></samp>’ or 125‘<samp><span class="samp">enum </span><var>enum-tag</var></samp>’. 126See <a href="Expressions.html#Expressions">Expressions</a>. 127 128 <p><a name="index-ptype-896"></a><br><dt><code>ptype [</code><var>arg</var><code>]</code><dd><code>ptype</code> accepts the same arguments as <code>whatis</code>, but prints a 129detailed description of the type, instead of just the name of the type. 130See <a href="Expressions.html#Expressions">Expressions</a>. 131 132 <p>For example, for this variable declaration: 133 134 <pre class="smallexample"> struct complex {double real; double imag;} v; 135</pre> 136 <p class="noindent">the two commands give this output: 137 138 <pre class="smallexample"> (gdb) whatis v 139 type = struct complex 140 (gdb) ptype v 141 type = struct complex { 142 double real; 143 double imag; 144 } 145</pre> 146 <p class="noindent">As with <code>whatis</code>, using <code>ptype</code> without an argument refers to 147the type of <code>$</code>, the last value in the value history. 148 149 <p><a name="index-incomplete-type-897"></a>Sometimes, programs use opaque data types or incomplete specifications 150of complex data structure. If the debug information included in the 151program does not allow <span class="sc">gdb</span> to display a full declaration of 152the data type, it will say ‘<samp><span class="samp"><incomplete type></span></samp>’. For example, 153given these declarations: 154 155 <pre class="smallexample"> struct foo; 156 struct foo *fooptr; 157</pre> 158 <p class="noindent">but no definition for <code>struct foo</code> itself, <span class="sc">gdb</span> will say: 159 160 <pre class="smallexample"> (gdb) ptype foo 161 $1 = <incomplete type> 162</pre> 163 <p class="noindent">“Incomplete type” is C terminology for data types that are not 164completely specified. 165 166 <p><a name="index-info-types-898"></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 167expression <var>regexp</var> (or all types in your program, if you supply 168no argument). Each complete typename is matched as though it were a 169complete line; thus, ‘<samp><span class="samp">i type value</span></samp>’ gives information on all 170types in your program whose names include the string <code>value</code>, but 171‘<samp><span class="samp">i type ^value$</span></samp>’ gives information only on types whose complete 172name is <code>value</code>. 173 174 <p>This command differs from <code>ptype</code> in two ways: first, like 175<code>whatis</code>, it does not print a detailed description; second, it 176lists all source files where a type is defined. 177 178 <p><a name="index-info-scope-899"></a><a name="index-local-variables-900"></a><br><dt><code>info scope </code><var>location</var><dd>List all the variables local to a particular scope. This command 179accepts a <var>location</var> argument—a function name, a source line, or 180an address preceded by a ‘<samp><span class="samp">*</span></samp>’, and prints all the variables local 181to the scope defined by that location. (See <a href="Specify-Location.html#Specify-Location">Specify Location</a>, for 182details about supported forms of <var>location</var>.) For example: 183 184 <pre class="smallexample"> (gdb) <b>info scope command_line_handler</b> 185 Scope for command_line_handler: 186 Symbol rl is an argument at stack/frame offset 8, length 4. 187 Symbol linebuffer is in static storage at address 0x150a18, length 4. 188 Symbol linelength is in static storage at address 0x150a1c, length 4. 189 Symbol p is a local variable in register $esi, length 4. 190 Symbol p1 is a local variable in register $ebx, length 4. 191 Symbol nline is a local variable in register $edx, length 4. 192 Symbol repeat is a local variable at frame offset -8, length 4. 193</pre> 194 <p class="noindent">This command is especially useful for determining what data to collect 195during a <dfn>trace experiment</dfn>, see <a href="Tracepoint-Actions.html#Tracepoint-Actions">collect</a>. 196 197 <p><a name="index-info-source-901"></a><br><dt><code>info source</code><dd>Show information about the current source file—that is, the source file for 198the function containing the current point of execution: 199 <ul> 200<li>the name of the source file, and the directory containing it, 201<li>the directory it was compiled in, 202<li>its length, in lines, 203<li>which programming language it is written in, 204<li>whether the executable includes debugging information for that file, and 205if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and 206<li>whether the debugging information includes information about 207preprocessor macros. 208</ul> 209 210 <p><a name="index-info-sources-902"></a><br><dt><code>info sources</code><dd>Print the names of all source files in your program for which there is 211debugging information, organized into two lists: files whose symbols 212have already been read, and files whose symbols will be read when needed. 213 214 <p><a name="index-info-functions-903"></a><br><dt><code>info functions</code><dd>Print the names and data types of all defined functions. 215 216 <br><dt><code>info functions </code><var>regexp</var><dd>Print the names and data types of all defined functions 217whose names contain a match for regular expression <var>regexp</var>. 218Thus, ‘<samp><span class="samp">info fun step</span></samp>’ finds all functions whose names 219include <code>step</code>; ‘<samp><span class="samp">info fun ^step</span></samp>’ finds those whose names 220start with <code>step</code>. If a function name contains characters 221that conflict with the regular expression language (e.g. 222‘<samp><span class="samp">operator*()</span></samp>’), they may be quoted with a backslash. 223 224 <p><a name="index-info-variables-904"></a><br><dt><code>info variables</code><dd>Print the names and data types of all variables that are defined 225outside of functions (i.e. excluding local variables). 226 227 <br><dt><code>info variables </code><var>regexp</var><dd>Print the names and data types of all variables (except for local 228variables) whose names contain a match for regular expression 229<var>regexp</var>. 230 231 <p><a name="index-info-classes-905"></a><a name="index-Objective_002dC_002c-classes-and-selectors-906"></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 232(with the <var>regexp</var> argument) all those matching a particular regular 233expression. 234 235 <p><a name="index-info-selectors-907"></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 236(with the <var>regexp</var> argument) all those matching a particular regular 237expression. 238 239 <p><a name="index-reloading-symbols-908"></a>Some systems allow individual object files that make up your program to 240be replaced without stopping and restarting your program. For example, 241in VxWorks you can simply recompile a defective object file and keep on 242running. If you are running on one of these systems, you can allow 243<span class="sc">gdb</span> to reload the symbols for automatically relinked modules: 244 245 246<a name="index-set-symbol_002dreloading-909"></a> 247<dl><dt><code>set symbol-reloading on</code><dd>Replace symbol definitions for the corresponding source file when an 248object file with a particular name is seen again. 249 250 <br><dt><code>set symbol-reloading off</code><dd>Do not replace symbol definitions when encountering object files of the 251same name more than once. This is the default state; if you are not 252running on a system that permits automatic relinking of modules, you 253should leave <code>symbol-reloading</code> off, since otherwise <span class="sc">gdb</span> 254may discard symbols when linking large programs, that may contain 255several modules (from different directories or libraries) with the same 256name. 257 258 <p><a name="index-show-symbol_002dreloading-910"></a><br><dt><code>show symbol-reloading</code><dd>Show the current <code>on</code> or <code>off</code> setting. 259</dl> 260 261 <p><a name="index-opaque-data-types-911"></a><a name="index-set-opaque_002dtype_002dresolution-912"></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 262declared as a pointer to a <code>struct</code>, <code>class</code>, or 263<code>union</code>—for example, <code>struct MyType *</code>—that is used in one 264source file although the full declaration of <code>struct MyType</code> is in 265another source file. The default is on. 266 267 <p>A change in the setting of this subcommand will not take effect until 268the next time symbols for a file are loaded. 269 270 <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 271is printed as follows: 272 <pre class="smallexample"> {<no data fields>} 273</pre> 274 <p><a name="index-show-opaque_002dtype_002dresolution-913"></a><br><dt><code>show opaque-type-resolution</code><dd>Show whether opaque types are resolved or not. 275 276 <p><a name="index-maint-print-symbols-914"></a><a name="index-symbol-dump-915"></a><a name="index-maint-print-psymbols-916"></a><a name="index-partial-symbol-dump-917"></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>. 277These commands are used to debug the <span class="sc">gdb</span> symbol-reading code. Only 278symbols with debugging data are included. If you use ‘<samp><span class="samp">maint print 279symbols</span></samp>’, <span class="sc">gdb</span> includes all the symbols for which it has already 280collected full details: that is, <var>filename</var> reflects symbols for 281only those files whose symbols <span class="sc">gdb</span> has read. You can use the 282command <code>info sources</code> to find out which files these are. If you 283use ‘<samp><span class="samp">maint print psymbols</span></samp>’ instead, the dump shows information about 284symbols that <span class="sc">gdb</span> only knows partially—that is, symbols defined in 285files that <span class="sc">gdb</span> has skimmed, but not yet read completely. Finally, 286‘<samp><span class="samp">maint print msymbols</span></samp>’ dumps just the minimal symbol information 287required for each object file from which <span class="sc">gdb</span> has read some symbols. 288See <a href="Files.html#Files">Commands to Specify Files</a>, for a discussion of how 289<span class="sc">gdb</span> reads symbols (in the description of <code>symbol-file</code>). 290 291 <p><a name="index-maint-info-symtabs-918"></a><a name="index-maint-info-psymtabs-919"></a><a name="index-listing-_0040value_007bGDBN_007d_0027s-internal-symbol-tables-920"></a><a name="index-symbol-tables_002c-listing-_0040value_007bGDBN_007d_0027s-internal-921"></a><a name="index-full-symbol-tables_002c-listing-_0040value_007bGDBN_007d_0027s-internal-922"></a><a name="index-partial-symbol-tables_002c-listing-_0040value_007bGDBN_007d_0027s-internal-923"></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> 292List the <code>struct symtab</code> or <code>struct partial_symtab</code> 293structures whose names match <var>regexp</var>. If <var>regexp</var> is not 294given, list them all. The output includes expressions which you can 295copy into a <span class="sc">gdb</span> debugging this one to examine a particular 296structure in more detail. For example: 297 298 <pre class="smallexample"> (gdb) maint info psymtabs dwarf2read 299 { objfile /home/gnu/build/gdb/gdb 300 ((struct objfile *) 0x82e69d0) 301 { psymtab /home/gnu/src/gdb/dwarf2read.c 302 ((struct partial_symtab *) 0x8474b10) 303 readin no 304 fullname (null) 305 text addresses 0x814d3c8 -- 0x8158074 306 globals (* (struct partial_symbol **) 0x8507a08 @ 9) 307 statics (* (struct partial_symbol **) 0x40e95b78 @ 2882) 308 dependencies (none) 309 } 310 } 311 (gdb) maint info symtabs 312 (gdb) 313</pre> 314 <p class="noindent">We see that there is one partial symbol table whose filename contains 315the string ‘<samp><span class="samp">dwarf2read</span></samp>’, belonging to the ‘<samp><span class="samp">gdb</span></samp>’ executable; 316and we see that <span class="sc">gdb</span> has not read in any symtabs yet at all. 317If we set a breakpoint on a function, that will cause <span class="sc">gdb</span> to 318read the symtab for the compilation unit containing that function: 319 320 <pre class="smallexample"> (gdb) break dwarf2_psymtab_to_symtab 321 Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c, 322 line 1574. 323 (gdb) maint info symtabs 324 { objfile /home/gnu/build/gdb/gdb 325 ((struct objfile *) 0x82e69d0) 326 { symtab /home/gnu/src/gdb/dwarf2read.c 327 ((struct symtab *) 0x86c1f38) 328 dirname (null) 329 fullname (null) 330 blockvector ((struct blockvector *) 0x86c1bd0) (primary) 331 linetable ((struct linetable *) 0x8370fa0) 332 debugformat DWARF 2 333 } 334 } 335 (gdb) 336</pre> 337 </dl> 338 339 </body></html> 340 341