Files
2024-02-19 00:21:47 -05:00

363 lines
15 KiB
HTML

<HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created on November, 11 2002 by texi2html 1.64 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HEAD>
<TITLE>Debugging with GDB: Symbols</TITLE>
<META NAME="description" CONTENT="Debugging with GDB: Symbols">
<META NAME="keywords" CONTENT="Debugging with GDB: Symbols">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">
</HEAD>
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
<A NAME="SEC119"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_13.html#SEC118"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<H1> 13. Examining the Symbol Table </H1>
<!--docid::SEC119::-->
<P>
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 <A HREF="gdb_3.html#SEC8">Choosing files</A>), or by one of the
file-management commands (see section <A HREF="gdb_16.html#SEC128">Commands to specify files</A>).
</P><P>
<A NAME="IDX516"></A>
<A NAME="IDX517"></A>
<A NAME="IDX518"></A>
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 <A HREF="gdb_9.html#SEC55">Program variables</A>). File names
are recorded in object files as debugging symbols, but GDB would
ordinarily parse a typical file name, like <TT>`foo.c'</TT>, as the three words
<SAMP>`foo'</SAMP> <SAMP>`.'</SAMP> <SAMP>`c'</SAMP>. To allow GDB to recognize
<SAMP>`foo.c'</SAMP> as a single symbol, enclose it in single quotes; for example,
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>p 'foo.c'::x
</FONT></pre></td></tr></table></P><P>
looks up the value of <CODE>x</CODE> in the scope of the file <TT>`foo.c'</TT>.
</P><P>
<DL COMPACT>
<A NAME="IDX519"></A>
<A NAME="IDX520"></A>
<DT><CODE>info address <VAR>symbol</VAR></CODE>
<DD>Describe where the data for <VAR>symbol</VAR> 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.
<P>
Note the contrast with <SAMP>`print &#38;<VAR>symbol</VAR>'</SAMP>, 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.
</P><P>
<A NAME="IDX521"></A>
<A NAME="IDX522"></A>
<DT><CODE>info symbol <VAR>addr</VAR></CODE>
<DD>Print the name of a symbol which is stored at the address <VAR>addr</VAR>.
If no symbol is stored exactly at <VAR>addr</VAR>, GDB prints the
nearest symbol and an offset from it:
<P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>(gdb) info symbol 0x54320
_initialize_vx + 396 in section .text
</FONT></pre></td></tr></table></P><P>
This is the opposite of the <CODE>info address</CODE> command. You can use
it to find out the name of a variable or a function given its address.
</P><P>
<A NAME="IDX523"></A>
<DT><CODE>whatis <VAR>expr</VAR></CODE>
<DD>Print the data type of expression <VAR>expr</VAR>. <VAR>expr</VAR> is not
actually evaluated, and any side-effecting operations (such as
assignments or function calls) inside it do not take place.
See section <A HREF="gdb_9.html#SEC54">Expressions</A>.
<P>
<DT><CODE>whatis</CODE>
<DD>Print the data type of <CODE>$</CODE>, the last value in the value history.
<P>
<A NAME="IDX524"></A>
<DT><CODE>ptype <VAR>typename</VAR></CODE>
<DD>Print a description of data type <VAR>typename</VAR>. <VAR>typename</VAR> may be
the name of a type, or for C code it may have the form <SAMP>`class
<VAR>class-name</VAR>'</SAMP>, <SAMP>`struct <VAR>struct-tag</VAR>'</SAMP>, <SAMP>`union
<VAR>union-tag</VAR>'</SAMP> or <SAMP>`enum <VAR>enum-tag</VAR>'</SAMP>.
<P>
<DT><CODE>ptype <VAR>expr</VAR></CODE>
<DD><DT><CODE>ptype</CODE>
<DD>Print a description of the type of expression <VAR>expr</VAR>. <CODE>ptype</CODE>
differs from <CODE>whatis</CODE> by printing a detailed description, instead
of just the name of the type.
<P>
For example, for this variable declaration:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>struct complex {double real; double imag;} v;
</FONT></pre></td></tr></table></P><P>
the two commands give this output:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>(gdb) whatis v
type = struct complex
(gdb) ptype v
type = struct complex {
double real;
double imag;
}
</FONT></pre></td></tr></table></P><P>
As with <CODE>whatis</CODE>, using <CODE>ptype</CODE> without an argument refers to
the type of <CODE>$</CODE>, the last value in the value history.
</P><P>
<A NAME="IDX525"></A>
<DT><CODE>info types <VAR>regexp</VAR></CODE>
<DD><DT><CODE>info types</CODE>
<DD>Print a brief description of all types whose names match <VAR>regexp</VAR>
(or all types in your program, if you supply no argument). Each
complete typename is matched as though it were a complete line; thus,
<SAMP>`i type value'</SAMP> gives information on all types in your program whose
names include the string <CODE>value</CODE>, but <SAMP>`i type ^value$'</SAMP> gives
information only on types whose complete name is <CODE>value</CODE>.
<P>
This command differs from <CODE>ptype</CODE> in two ways: first, like
<CODE>whatis</CODE>, it does not print a detailed description; second, it
lists all source files where a type is defined.
</P><P>
<A NAME="IDX526"></A>
<A NAME="IDX527"></A>
<DT><CODE>info scope <VAR>addr</VAR></CODE>
<DD>List all the variables local to a particular scope. This command
accepts a location--a function name, a source line, or an address
preceded by a <SAMP>`*'</SAMP>, and prints all the variables local to the
scope defined by that location. For example:
<P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>(gdb) <B>info scope command_line_handler</B>
Scope for command_line_handler:
Symbol rl is an argument at stack/frame offset 8, length 4.
Symbol linebuffer is in static storage at address 0x150a18, length 4.
Symbol linelength is in static storage at address 0x150a1c, length 4.
Symbol p is a local variable in register $esi, length 4.
Symbol p1 is a local variable in register $ebx, length 4.
Symbol nline is a local variable in register $edx, length 4.
Symbol repeat is a local variable at frame offset -8, length 4.
</FONT></pre></td></tr></table></P><P>
This command is especially useful for determining what data to collect
during a <EM>trace experiment</EM>, see <A HREF="gdb_11.html#SEC79">collect</A>.
</P><P>
<A NAME="IDX528"></A>
<DT><CODE>info source</CODE>
<DD>Show information about the current source file--that is, the source file for
the function containing the current point of execution:
<UL>
<LI>
the name of the source file, and the directory containing it,
<LI>
the directory it was compiled in,
<LI>
its length, in lines,
<LI>
which programming language it is written in,
<LI>
whether the executable includes debugging information for that file, and
if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
<LI>
whether the debugging information includes information about
preprocessor macros.
</UL>
<P>
<A NAME="IDX529"></A>
<DT><CODE>info sources</CODE>
<DD>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 will be read when needed.
<P>
<A NAME="IDX530"></A>
<DT><CODE>info functions</CODE>
<DD>Print the names and data types of all defined functions.
<P>
<DT><CODE>info functions <VAR>regexp</VAR></CODE>
<DD>Print the names and data types of all defined functions
whose names contain a match for regular expression <VAR>regexp</VAR>.
Thus, <SAMP>`info fun step'</SAMP> finds all functions whose names
include <CODE>step</CODE>; <SAMP>`info fun ^step'</SAMP> finds those whose names
start with <CODE>step</CODE>. If a function name contains characters
that conflict with the regular expression language (eg.
<SAMP>`operator*()'</SAMP>), they may be quoted with a backslash.
<P>
<A NAME="IDX531"></A>
<DT><CODE>info variables</CODE>
<DD>Print the names and data types of all variables that are declared
outside of functions (i.e. excluding local variables).
<P>
<DT><CODE>info variables <VAR>regexp</VAR></CODE>
<DD>Print the names and data types of all variables (except for local
variables) whose names contain a match for regular expression
<VAR>regexp</VAR>.
<P>
<A NAME="IDX532"></A>
Some systems allow individual object files that make up your program to
be replaced without stopping and restarting your program. For example,
in VxWorks you can simply recompile a defective object file and keep on
running. If you are running on one of these systems, you can allow
GDB to reload the symbols for automatically relinked modules:
</P><P>
<DL COMPACT>
<A NAME="IDX533"></A>
<DT><CODE>set symbol-reloading on</CODE>
<DD>Replace symbol definitions for the corresponding source file when an
object file with a particular name is seen again.
<P>
<DT><CODE>set symbol-reloading off</CODE>
<DD>Do not replace symbol definitions when encountering object files of the
same name more than once. This is the default state; if you are not
running on a system that permits automatic relinking of modules, you
should leave <CODE>symbol-reloading</CODE> 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.
<P>
<A NAME="IDX534"></A>
<DT><CODE>show symbol-reloading</CODE>
<DD>Show the current <CODE>on</CODE> or <CODE>off</CODE> setting.
</DL>
<P>
<A NAME="IDX535"></A>
<DT><CODE>set opaque-type-resolution on</CODE>
<DD>Tell GDB to resolve opaque types. An opaque type is a type
declared as a pointer to a <CODE>struct</CODE>, <CODE>class</CODE>, or
<CODE>union</CODE>---for example, <CODE>struct MyType *</CODE>---that is used in one
source file although the full declaration of <CODE>struct MyType</CODE> is in
another source file. The default is on.
<P>
A change in the setting of this subcommand will not take effect until
the next time symbols for a file are loaded.
</P><P>
<DT><CODE>set opaque-type-resolution off</CODE>
<DD>Tell GDB not to resolve opaque types. In this case, the type
is printed as follows:
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>{&#60;no data fields&#62;}
</FONT></pre></td></tr></table><P>
<A NAME="IDX536"></A>
<DT><CODE>show opaque-type-resolution</CODE>
<DD>Show whether opaque types are resolved or not.
<P>
<A NAME="IDX537"></A>
<A NAME="IDX538"></A>
<A NAME="IDX539"></A>
<A NAME="IDX540"></A>
<DT><CODE>maint print symbols <VAR>filename</VAR></CODE>
<DD><DT><CODE>maint print psymbols <VAR>filename</VAR></CODE>
<DD><DT><CODE>maint print msymbols <VAR>filename</VAR></CODE>
<DD>Write a dump of debugging symbol data into the file <VAR>filename</VAR>.
These commands are used to debug the GDB symbol-reading code. Only
symbols with debugging data are included. If you use <SAMP>`maint print
symbols'</SAMP>, GDB includes all the symbols for which it has already
collected full details: that is, <VAR>filename</VAR> reflects symbols for
only those files whose symbols GDB has read. You can use the
command <CODE>info sources</CODE> to find out which files these are. If you
use <SAMP>`maint print psymbols'</SAMP> 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,
<SAMP>`maint print msymbols'</SAMP> dumps just the minimal symbol information
required for each object file from which GDB has read some symbols.
See section <A HREF="gdb_16.html#SEC128">Commands to specify files</A>, for a discussion of how
GDB reads symbols (in the description of <CODE>symbol-file</CODE>).
</DL>
<P>
<A NAME="Altering"></A>
<HR SIZE="6">
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_35.html#SEC643">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>
<FONT SIZE="-1">
<address>
<p>Please send FSF &amp; GNU inquiries &amp; questions to <a
href="mailto:gnu@gnu.org">gnu@gnu.org</a>. There are also <a
href="http://www.gnu.org/home.html#ContactInfo">other ways to
contact</a> the FSF.</p>
<p>These pages are maintained by <a
href="http://www.gnu.org/software/gdb/">the GDB developers</a>.</p>
<p>Copyright Free Software Foundation, Inc., 59 Temple Place - Suite
330, Boston, MA 02111, USA.</p>
<p>Verbatim copying and distribution of this entire article is
permitted in any medium, provided this notice is preserved.</p>
</address>
This document was generated
by <I>GDB Administrator</I> on <I>November, 11 2002</I>
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>