Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)

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 “Choosing files” (page 19)), or by one of
the file-management commands (see “Commands to specify files” (page 88)).
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 “Program variables” (page 58)). 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 register variable, and for a stack local
variable prints the exact address of the current instantiation
of the variable. This command is available only for
applications running on 11i v3 or later.
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 “Expressions” (page 58).
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:
((gdb)) whatis v
type = struct complex
((gdb)) ptype v
type = struct complex {
double real;
double imag;
}
As with whatis, using ptype without an argument refers
to the type of $, the last value in the value history.
81