neingeist
/
arduinisten
Archived
1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

481 lines
19 KiB
HTML

<HTML>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created on March, 27 2008 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="SEC146"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_13.html#SEC145"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> &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#SEC147"> &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_38.html#SEC764">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::SEC146::-->
<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#SEC155">Commands to Specify Files</A>).
</P><P>
<A NAME="IDX640"></A>
<A NAME="IDX641"></A>
<A NAME="IDX642"></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#SEC61">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="IDX643"></A>
<A NAME="IDX644"></A>
<A NAME="IDX645"></A>
<DT><CODE>set case-sensitive on</CODE>
<DD><DT><CODE>set case-sensitive off</CODE>
<DD><DT><CODE>set case-sensitive auto</CODE>
<DD>Normally, when GDB looks up symbols, it matches their names
with case sensitivity determined by the current source language.
Occasionally, you may wish to control that. The command <CODE>set
case-sensitive</CODE> lets you do that by specifying <CODE>on</CODE> for
case-sensitive matches or <CODE>off</CODE> for case-insensitive ones. If
you specify <CODE>auto</CODE>, case sensitivity is reset to the default
suitable for the source language. The default is case-sensitive
matches for all languages except for Fortran, for which the default is
case-insensitive matches.
<P>
<A NAME="IDX646"></A>
<DT><CODE>show case-sensitive</CODE>
<DD>This command shows the current setting of case sensitivity for symbols
lookups.
<P>
<A NAME="IDX647"></A>
<A NAME="IDX648"></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="IDX649"></A>
<A NAME="IDX650"></A>
<A NAME="IDX651"></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="IDX652"></A>
<DT><CODE>whatis [<VAR>arg</VAR>]</CODE>
<DD>Print the data type of <VAR>arg</VAR>, which can be either an expression or
a data type. With no argument, print the data type of <CODE>$</CODE>, the
last value in the value history. If <VAR>arg</VAR> is an expression, it is
not actually evaluated, and any side-effecting operations (such as
assignments or function calls) inside it do not take place. If
<VAR>arg</VAR> is a type name, it may be the name of a type or typedef, 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>.
See section <A HREF="gdb_9.html#SEC60">Expressions</A>.
<P>
<A NAME="IDX653"></A>
<DT><CODE>ptype [<VAR>arg</VAR>]</CODE>
<DD><CODE>ptype</CODE> accepts the same arguments as <CODE>whatis</CODE>, but prints a
detailed description of the type, instead of just the name of the type.
See section <A HREF="gdb_9.html#SEC60">Expressions</A>.
<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="IDX654"></A>
Sometimes, programs use opaque data types or incomplete specifications
of complex data structure. If the debug information included in the
program does not allow GDB to display a full declaration of
the data type, it will say <SAMP>`&#60;incomplete type&#62;'</SAMP>. For example,
given these declarations:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre> struct foo;
struct foo *fooptr;
</FONT></pre></td></tr></table></P><P>
but no definition for <CODE>struct foo</CODE> itself, GDB will say:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre> (gdb) ptype foo
$1 = &#60;incomplete type&#62;
</FONT></pre></td></tr></table></P><P>
"Incomplete type" is C terminology for data types that are not
completely specified.
</P><P>
<A NAME="IDX655"></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 the regular
expression <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="IDX656"></A>
<A NAME="IDX657"></A>
<DT><CODE>info scope <VAR>location</VAR></CODE>
<DD>List all the variables local to a particular scope. This command
accepts a <VAR>location</VAR> argument--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. (See section <A HREF="gdb_8.html#SEC53">7.2 Specifying a Location</A>, for
details about supported forms of <VAR>location</VAR>.) 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#SEC89">collect</A>.
</P><P>
<A NAME="IDX658"></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="IDX659"></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="IDX660"></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 (e.g.
<SAMP>`operator*()'</SAMP>), they may be quoted with a backslash.
<P>
<A NAME="IDX661"></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="IDX662"></A>
<A NAME="IDX663"></A>
<DT><CODE>info classes</CODE>
<DD><DT><CODE>info classes <VAR>regexp</VAR></CODE>
<DD>Display all Objective-C classes in your program, or
(with the <VAR>regexp</VAR> argument) all those matching a particular regular
expression.
<P>
<A NAME="IDX664"></A>
<DT><CODE>info selectors</CODE>
<DD><DT><CODE>info selectors <VAR>regexp</VAR></CODE>
<DD>Display all Objective-C selectors in your program, or
(with the <VAR>regexp</VAR> argument) all those matching a particular regular
expression.
<P>
<A NAME="IDX665"></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="IDX666"></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="IDX667"></A>
<DT><CODE>show symbol-reloading</CODE>
<DD>Show the current <CODE>on</CODE> or <CODE>off</CODE> setting.
</DL>
<P>
<A NAME="IDX668"></A>
<A NAME="IDX669"></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="IDX670"></A>
<DT><CODE>show opaque-type-resolution</CODE>
<DD>Show whether opaque types are resolved or not.
<P>
<A NAME="IDX671"></A>
<A NAME="IDX672"></A>
<A NAME="IDX673"></A>
<A NAME="IDX674"></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#SEC155">Commands to Specify Files</A>, for a discussion of how
GDB reads symbols (in the description of <CODE>symbol-file</CODE>).
<P>
<A NAME="IDX675"></A>
<A NAME="IDX676"></A>
<A NAME="IDX677"></A>
<A NAME="IDX678"></A>
<A NAME="IDX679"></A>
<A NAME="IDX680"></A>
<DT><CODE>maint info symtabs [ <VAR>regexp</VAR> ]</CODE>
<DD><DT><CODE>maint info psymtabs [ <VAR>regexp</VAR> ]</CODE>
<DD><P>
List the <CODE>struct symtab</CODE> or <CODE>struct partial_symtab</CODE>
structures whose names match <VAR>regexp</VAR>. If <VAR>regexp</VAR> is not
given, list them all. The output includes expressions which you can
copy into a GDB debugging this one to examine a particular
structure in more detail. For example:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>(gdb) maint info psymtabs dwarf2read
{ objfile /home/gnu/build/gdb/gdb
((struct objfile *) 0x82e69d0)
{ psymtab /home/gnu/src/gdb/dwarf2read.c
((struct partial_symtab *) 0x8474b10)
readin no
fullname (null)
text addresses 0x814d3c8 -- 0x8158074
globals (* (struct partial_symbol **) 0x8507a08 @ 9)
statics (* (struct partial_symbol **) 0x40e95b78 @ 2882)
dependencies (none)
}
}
(gdb) maint info symtabs
(gdb)
</FONT></pre></td></tr></table>We see that there is one partial symbol table whose filename contains
the string <SAMP>`dwarf2read'</SAMP>, belonging to the <SAMP>`gdb'</SAMP> executable;
and we see that GDB has not read in any symtabs yet at all.
If we set a breakpoint on a function, that will cause GDB to
read the symtab for the compilation unit containing that function:
</P><P>
<TABLE><tr><td>&nbsp;</td><td class=smallexample><FONT SIZE=-1><pre>(gdb) break dwarf2_psymtab_to_symtab
Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
line 1574.
(gdb) maint info symtabs
{ objfile /home/gnu/build/gdb/gdb
((struct objfile *) 0x82e69d0)
{ symtab /home/gnu/src/gdb/dwarf2read.c
((struct symtab *) 0x86c1f38)
dirname (null)
fullname (null)
blockvector ((struct blockvector *) 0x86c1bd0) (primary)
linetable ((struct linetable *) 0x8370fa0)
debugformat DWARF 2
}
}
(gdb)
</FONT></pre></td></tr></table></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#SEC147"> &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_38.html#SEC764">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>March, 27 2008</I>
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>
</BODY>
</HTML>