Debugging with GDB (February 2008)

Table Of Contents
Chapter 10: Examining the Symbol Table 93
10 Examining the Symbol Table
The commands described in this chapter allow you to inquire about the symbols (names
of variables, functions and types) defined in your program. This information is inherent in
the text of your program and does not change as your program executes. GDB finds it in
your program’s symbol table, in the file indicated when you started GDB (see Section 2.1.1
[Choosing files], page 12), or by one of the file-management commands (see Section 12.1
[Commands to specify files], page 103).
Occasionally, you may need to refer to symbols that contain unusual characters, which
GDB ordinarily treats as word delimiters. The most frequent case is in referring to static
variables in other source files (see Section 8.2 [Program variables], page 64). File names are
recorded in object files as debugging symbols, but GDB would ordinarily parse a typical
file name, like foo.c’, as the three words foo . c’. To allow GDB to recognize foo.c
as a single symbol, enclose it in single quotes; for example,
p ’foo.c’::x
looks up the value of x in the scope of the file foo.c’.
info address symbol
Describe where the data for symbol is stored. For a register variable, this says
which register it is kept in. For a non-register local variable, this prints the
stack-frame offset at which the variable is always stored.
Note the contrast with print &symbol’, which does not work at all for a regis-
ter variable, and for a stack local variable prints the exact address of the current
instantiation of the variable.
whatis expr
Print the data type of expression expr. expr is not actually evaluated, and any
side-effecting operations (such as assignments or function calls) inside it do not
take place. See Section 8.1 [Expressions], page 63.
whatis Print the data type of $, the last value in the value history.
ptype typename
Print a description of data type typename. typename may be the name of a
type, or for C code it may have the form ‘class class-name ’, ‘struct struct-
tag ’, union union-tag or enum enum-tag’.
ptype expr
ptype Print a description of the type of expression expr. ptype differs from whatis
by printing a detailed description, instead of just the name of the type.
For example, for this variable declaration:
struct complex {double real; double imag;} v;
the two commands give this output: