The commands described in this section 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
doesn't change as your program executes. GDB finds it in your
program's symbol table, in the file indicated when you started GDB
(see the description of the gdb
utility).
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").
Filenames are recorded in object files as debugging symbols, but GDB
ordinarily parses a typical filename, like foo.c,
as the three words
foo, ., and 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's kept in. For a nonregister
local variable, this prints the stack-frame offset at which the variable is always stored.
Note the contrast with print & symbol, which doesn't work
at all for a register variable, and for a stack local variable prints
the exact address of the current instantiation of the variable.
- whatis exp
-
Print the data type of expression exp. The
exp expression isn't
actually evaluated, and any side-effecting operations (such as
assignments or function calls) inside it don't take place.
See "Expressions."
- whatis
- Print the data type of $, the last value in the value history.
- ptype typename
-
Print a description of data type typename, which 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
- enum enum-tag
- ptype exp or ptype
- Print a description of the type of expression exp.
The ptype command
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.
- info types regexp or info types
-
Print a brief description of all types whose name matches regexp
(or all types in your program, if you supply no argument). Each
complete typename is matched as though it were a complete line; thus,
i type value gives information on all types in your program whose
name includes the string value, but i type ^value$ gives
information only on types whose complete name is value.
This command differs from ptype in two ways: first, like
whatis, it doesn't print a detailed description; second, it
lists all source files where a type is defined.
- info source
-
Show the name of the current source file—that is, the source file for
the function containing the current point of execution—and the language it was written in.
- info sources
-
Print the names of all source files in your program for which there is
debugging information, organized into two lists: files whose symbols
have already been read, and files whose symbols are read when needed.
- info functions
-
Print the names and data types of all defined functions.
- info functions regexp
- Print the names and data types of all defined functions
whose names contain a match for regular expression regexp.
Thus, info fun step finds all functions whose names
include step; info fun ^step finds those whose names
start with step.
- info variables
-
Print the names and data types of all variables that are declared
outside of functions (i.e., excluding local variables).
- info variables regexp
- Print the names and data types of all variables (except for local
variables) whose names contain a match for regular expression regexp.
Some systems allow individual object files that make up your program to
be replaced without stopping and restarting your program.
If you're running on one of these systems, you can allow GDB to
reload the symbols for automatically relinked modules:
- set symbol-reloading on — replace symbol definitions
for the corresponding source file when an object file with a particular name is seen again.
- set symbol-reloading off — don't replace symbol
definitions when reencountering object files of the same name.
This is the default state; if you aren't running on a
system that permits automatically relinking modules, you should leave
symbol-reloading off, since otherwise GDB may discard symbols
when linking large programs, that may contain several modules (from
different directories or libraries) with the same name.
- show symbol-reloading — show the current
on or off setting.
- maint print symbols filename or
maint print psymbols filename or
maint print msymbols filename
-
Write a dump of debugging symbol data into the file filename.
These commands are used to debug the GDB symbol-reading code.
Only symbols with debugging data are included.
- If you use maint print symbols,
GDB includes all the symbols for which it has already
collected full details: that is, filename reflects symbols for
only those files whose symbols GDB has read. You can use the
command info sources to find out which files these are.
- If you use maint print psymbols instead, the dump shows information about
symbols that GDB only knows partially—that is, symbols defined in
files that GDB has skimmed, but not yet read completely.
- Finally, maint print msymbols dumps just the minimal symbol information
required for each object file from which GDB has read some symbols.