611 lines
26 KiB
HTML
611 lines
26 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: Source</TITLE>
|
|
|
|
<META NAME="description" CONTENT="Debugging with GDB: Source">
|
|
<META NAME="keywords" CONTENT="Debugging with GDB: Source">
|
|
<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="SEC46"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_7.html#SEC45"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC47"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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> 7. Examining Source Files </H1>
|
|
<!--docid::SEC46::-->
|
|
<P>
|
|
|
|
GDB can print parts of your program's source, since the debugging
|
|
information recorded in the program tells GDB what source files were
|
|
used to build it. When your program stops, GDB spontaneously prints
|
|
the line where it stopped. Likewise, when you select a stack frame
|
|
(see section <A HREF="gdb_7.html#SEC44">Selecting a frame</A>), GDB prints the line where
|
|
execution in that frame has stopped. You can print other portions of
|
|
source files by explicit command.
|
|
</P><P>
|
|
|
|
If you use GDB through its GNU Emacs interface, you may
|
|
prefer to use Emacs facilities to view source; see <A HREF="gdb_23.html#SEC203">Using GDB under GNU Emacs</A>.
|
|
</P><P>
|
|
|
|
<BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_8.html#SEC47">7.1 Printing source lines</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_8.html#SEC48">7.2 Editing source files</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_8.html#SEC50">7.3 Searching source files</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_8.html#SEC51">7.4 Specifying source directories</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_8.html#SEC52">7.5 Source and machine code</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
</TABLE></BLOCKQUOTE>
|
|
<P>
|
|
|
|
<A NAME="List"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC47"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC48"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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>
|
|
<H2> 7.1 Printing source lines </H2>
|
|
<!--docid::SEC47::-->
|
|
<P>
|
|
|
|
<A NAME="IDX257"></A>
|
|
<A NAME="IDX258"></A>
|
|
To print lines from a source file, use the <CODE>list</CODE> command
|
|
(abbreviated <CODE>l</CODE>). By default, ten lines are printed.
|
|
There are several ways to specify what part of the file you want to print.
|
|
</P><P>
|
|
|
|
Here are the forms of the <CODE>list</CODE> command most commonly used:
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><CODE>list <VAR>linenum</VAR></CODE>
|
|
<DD>Print lines centered around line number <VAR>linenum</VAR> in the
|
|
current source file.
|
|
<P>
|
|
|
|
<DT><CODE>list <VAR>function</VAR></CODE>
|
|
<DD>Print lines centered around the beginning of function
|
|
<VAR>function</VAR>.
|
|
<P>
|
|
|
|
<DT><CODE>list</CODE>
|
|
<DD>Print more lines. If the last lines printed were printed with a
|
|
<CODE>list</CODE> command, this prints lines following the last lines
|
|
printed; however, if the last line printed was a solitary line printed
|
|
as part of displaying a stack frame (see section <A HREF="gdb_7.html#SEC41">Examining the Stack</A>), this prints lines centered around that line.
|
|
<P>
|
|
|
|
<DT><CODE>list -</CODE>
|
|
<DD>Print lines just before the lines last printed.
|
|
</DL>
|
|
<P>
|
|
|
|
By default, GDB prints ten source lines with any of these forms of
|
|
the <CODE>list</CODE> command. You can change this using <CODE>set listsize</CODE>:
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX259"></A>
|
|
<DT><CODE>set listsize <VAR>count</VAR></CODE>
|
|
<DD>Make the <CODE>list</CODE> command display <VAR>count</VAR> source lines (unless
|
|
the <CODE>list</CODE> argument explicitly specifies some other number).
|
|
<P>
|
|
|
|
<A NAME="IDX260"></A>
|
|
<DT><CODE>show listsize</CODE>
|
|
<DD>Display the number of lines that <CODE>list</CODE> prints.
|
|
</DL>
|
|
<P>
|
|
|
|
Repeating a <CODE>list</CODE> command with <KBD>RET</KBD> discards the argument,
|
|
so it is equivalent to typing just <CODE>list</CODE>. This is more useful
|
|
than listing the same lines again. An exception is made for an
|
|
argument of <SAMP>`-'</SAMP>; that argument is preserved in repetition so that
|
|
each repetition moves up in the source file.
|
|
</P><P>
|
|
|
|
<A NAME="IDX261"></A>
|
|
In general, the <CODE>list</CODE> command expects you to supply zero, one or two
|
|
<EM>linespecs</EM>. Linespecs specify source lines; there are several ways
|
|
of writing them, but the effect is always to specify some source line.
|
|
Here is a complete description of the possible arguments for <CODE>list</CODE>:
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><CODE>list <VAR>linespec</VAR></CODE>
|
|
<DD>Print lines centered around the line specified by <VAR>linespec</VAR>.
|
|
<P>
|
|
|
|
<DT><CODE>list <VAR>first</VAR>,<VAR>last</VAR></CODE>
|
|
<DD>Print lines from <VAR>first</VAR> to <VAR>last</VAR>. Both arguments are
|
|
linespecs.
|
|
<P>
|
|
|
|
<DT><CODE>list ,<VAR>last</VAR></CODE>
|
|
<DD>Print lines ending with <VAR>last</VAR>.
|
|
<P>
|
|
|
|
<DT><CODE>list <VAR>first</VAR>,</CODE>
|
|
<DD>Print lines starting with <VAR>first</VAR>.
|
|
<P>
|
|
|
|
<DT><CODE>list +</CODE>
|
|
<DD>Print lines just after the lines last printed.
|
|
<P>
|
|
|
|
<DT><CODE>list -</CODE>
|
|
<DD>Print lines just before the lines last printed.
|
|
<P>
|
|
|
|
<DT><CODE>list</CODE>
|
|
<DD>As described in the preceding table.
|
|
</DL>
|
|
<P>
|
|
|
|
Here are the ways of specifying a single source line--all the
|
|
kinds of linespec.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><CODE><VAR>number</VAR></CODE>
|
|
<DD>Specifies line <VAR>number</VAR> of the current source file.
|
|
When a <CODE>list</CODE> command has two linespecs, this refers to
|
|
the same source file as the first linespec.
|
|
<P>
|
|
|
|
<DT><CODE>+<VAR>offset</VAR></CODE>
|
|
<DD>Specifies the line <VAR>offset</VAR> lines after the last line printed.
|
|
When used as the second linespec in a <CODE>list</CODE> command that has
|
|
two, this specifies the line <VAR>offset</VAR> lines down from the
|
|
first linespec.
|
|
<P>
|
|
|
|
<DT><CODE>-<VAR>offset</VAR></CODE>
|
|
<DD>Specifies the line <VAR>offset</VAR> lines before the last line printed.
|
|
<P>
|
|
|
|
<DT><CODE><VAR>filename</VAR>:<VAR>number</VAR></CODE>
|
|
<DD>Specifies line <VAR>number</VAR> in the source file <VAR>filename</VAR>.
|
|
<P>
|
|
|
|
<DT><CODE><VAR>function</VAR></CODE>
|
|
<DD>Specifies the line that begins the body of the function <VAR>function</VAR>.
|
|
For example: in C, this is the line with the open brace.
|
|
<P>
|
|
|
|
<DT><CODE><VAR>filename</VAR>:<VAR>function</VAR></CODE>
|
|
<DD>Specifies the line of the open-brace that begins the body of the
|
|
function <VAR>function</VAR> in the file <VAR>filename</VAR>. You only need the
|
|
file name with a function name to avoid ambiguity when there are
|
|
identically named functions in different source files.
|
|
<P>
|
|
|
|
<DT><CODE>*<VAR>address</VAR></CODE>
|
|
<DD>Specifies the line containing the program address <VAR>address</VAR>.
|
|
<VAR>address</VAR> may be any expression.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="Edit"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC48"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC47"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC49"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC50"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC50"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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>
|
|
<H2> 7.2 Editing source files </H2>
|
|
<!--docid::SEC48::-->
|
|
<P>
|
|
|
|
<A NAME="IDX262"></A>
|
|
<A NAME="IDX263"></A>
|
|
To edit the lines in a source file, use the <CODE>edit</CODE> command.
|
|
The editing program of your choice
|
|
is invoked with the current line set to
|
|
the active line in the program.
|
|
Alternatively, there are several ways to specify what part of the file you
|
|
want to print if you want to see other parts of the program.
|
|
</P><P>
|
|
|
|
Here are the forms of the <CODE>edit</CODE> command most commonly used:
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><CODE>edit</CODE>
|
|
<DD>Edit the current source file at the active line number in the program.
|
|
<P>
|
|
|
|
<DT><CODE>edit <VAR>number</VAR></CODE>
|
|
<DD>Edit the current source file with <VAR>number</VAR> as the active line number.
|
|
<P>
|
|
|
|
<DT><CODE>edit <VAR>function</VAR></CODE>
|
|
<DD>Edit the file containing <VAR>function</VAR> at the beginning of its definition.
|
|
<P>
|
|
|
|
<DT><CODE>edit <VAR>filename</VAR>:<VAR>number</VAR></CODE>
|
|
<DD>Specifies line <VAR>number</VAR> in the source file <VAR>filename</VAR>.
|
|
<P>
|
|
|
|
<DT><CODE>edit <VAR>filename</VAR>:<VAR>function</VAR></CODE>
|
|
<DD>Specifies the line that begins the body of the
|
|
function <VAR>function</VAR> in the file <VAR>filename</VAR>. You only need the
|
|
file name with a function name to avoid ambiguity when there are
|
|
identically named functions in different source files.
|
|
<P>
|
|
|
|
<DT><CODE>edit *<VAR>address</VAR></CODE>
|
|
<DD>Specifies the line containing the program address <VAR>address</VAR>.
|
|
<VAR>address</VAR> may be any expression.
|
|
</DL>
|
|
<P>
|
|
|
|
<HR SIZE="6">
|
|
<A NAME="SEC49"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC48"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC50"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC50"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC48"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC50"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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>
|
|
<H3> 7.2.1 Choosing your editor </H3>
|
|
<!--docid::SEC49::-->
|
|
You can customize GDB to use any editor you want
|
|
<A NAME="DOCF2" HREF="gdb_fot.html#FOOT2">(2)</A>. By default, it is /bin/ex, but you can change this
|
|
by setting the environment variable <CODE>EDITOR</CODE> before using
|
|
GDB. For example, to configure GDB to use the
|
|
<CODE>vi</CODE> editor, you could use these commands with the <CODE>sh</CODE> shell:
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>EDITOR=/usr/bin/vi
|
|
export EDITOR
|
|
gdb ...
|
|
</FONT></pre></td></tr></table>or in the <CODE>csh</CODE> shell,
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>setenv EDITOR /usr/bin/vi
|
|
gdb ...
|
|
</FONT></pre></td></tr></table><P>
|
|
|
|
<A NAME="Search"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC50"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC49"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC51"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC51"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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>
|
|
<H2> 7.3 Searching source files </H2>
|
|
<!--docid::SEC50::-->
|
|
<P>
|
|
|
|
There are two commands for searching through the current source file for a
|
|
regular expression.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX264"></A>
|
|
<A NAME="IDX265"></A>
|
|
<DT><CODE>forward-search <VAR>regexp</VAR></CODE>
|
|
<DD><DT><CODE>search <VAR>regexp</VAR></CODE>
|
|
<DD>The command <SAMP>`forward-search <VAR>regexp</VAR>'</SAMP> checks each line,
|
|
starting with the one following the last line listed, for a match for
|
|
<VAR>regexp</VAR>. It lists the line that is found. You can use the
|
|
synonym <SAMP>`search <VAR>regexp</VAR>'</SAMP> or abbreviate the command name as
|
|
<CODE>fo</CODE>.
|
|
<P>
|
|
|
|
<DT><CODE>reverse-search <VAR>regexp</VAR></CODE>
|
|
<DD>The command <SAMP>`reverse-search <VAR>regexp</VAR>'</SAMP> checks each line, starting
|
|
with the one before the last line listed and going backward, for a match
|
|
for <VAR>regexp</VAR>. It lists the line that is found. You can abbreviate
|
|
this command as <CODE>rev</CODE>.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="Source Path"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC51"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC50"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC52"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC52"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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>
|
|
<H2> 7.4 Specifying source directories </H2>
|
|
<!--docid::SEC51::-->
|
|
<P>
|
|
|
|
<A NAME="IDX266"></A>
|
|
<A NAME="IDX267"></A>
|
|
Executable programs sometimes do not record the directories of the source
|
|
files from which they were compiled, just the names. Even when they do,
|
|
the directories could be moved between the compilation and your debugging
|
|
session. GDB has a list of directories to search for source files;
|
|
this is called the <EM>source path</EM>. Each time GDB wants a source file,
|
|
it tries all the directories in the list, in the order they are present
|
|
in the list, until it finds a file with the desired name. Note that
|
|
the executable search path is <EM>not</EM> used for this purpose. Neither is
|
|
the current working directory, unless it happens to be in the source
|
|
path.
|
|
</P><P>
|
|
|
|
If GDB cannot find a source file in the source path, and the
|
|
object program records a directory, GDB tries that directory
|
|
too. If the source path is empty, and there is no record of the
|
|
compilation directory, GDB looks in the current directory as a
|
|
last resort.
|
|
</P><P>
|
|
|
|
Whenever you reset or rearrange the source path, GDB clears out
|
|
any information it has cached about where source files are found and where
|
|
each line is in the file.
|
|
</P><P>
|
|
|
|
<A NAME="IDX268"></A>
|
|
<A NAME="IDX269"></A>
|
|
When you start GDB, its source path includes only <SAMP>`cdir'</SAMP>
|
|
and <SAMP>`cwd'</SAMP>, in that order.
|
|
To add other directories, use the <CODE>directory</CODE> command.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><CODE>directory <VAR>dirname</VAR> <small>...</small></CODE>
|
|
<DD><DT><CODE>dir <VAR>dirname</VAR> <small>...</small></CODE>
|
|
<DD>Add directory <VAR>dirname</VAR> to the front of the source path. Several
|
|
directory names may be given to this command, separated by <SAMP>`:'</SAMP>
|
|
(<SAMP>`;'</SAMP> on MS-DOS and MS-Windows, where <SAMP>`:'</SAMP> usually appears as
|
|
part of absolute file names) or
|
|
whitespace. You may specify a directory that is already in the source
|
|
path; this moves it forward, so GDB searches it sooner.
|
|
<P>
|
|
|
|
<A NAME="IDX270"></A>
|
|
<A NAME="IDX271"></A>
|
|
<A NAME="IDX272"></A>
|
|
<A NAME="IDX273"></A>
|
|
<A NAME="IDX274"></A>
|
|
<A NAME="IDX275"></A>
|
|
<A NAME="IDX276"></A>
|
|
<A NAME="IDX277"></A>
|
|
<A NAME="IDX278"></A>
|
|
You can use the string <SAMP>`$cdir'</SAMP> to refer to the compilation
|
|
directory (if one is recorded), and <SAMP>`$cwd'</SAMP> to refer to the current
|
|
working directory. <SAMP>`$cwd'</SAMP> is not the same as <SAMP>`.'</SAMP>---the former
|
|
tracks the current working directory as it changes during your GDB
|
|
session, while the latter is immediately expanded to the current
|
|
directory at the time you add an entry to the source path.
|
|
</P><P>
|
|
|
|
<DT><CODE>directory</CODE>
|
|
<DD>Reset the source path to empty again. This requires confirmation.
|
|
<P>
|
|
|
|
<DT><CODE>show directories</CODE>
|
|
<DD><A NAME="IDX279"></A>
|
|
Print the source path: show which directories it contains.
|
|
</DL>
|
|
<P>
|
|
|
|
If your source path is cluttered with directories that are no longer of
|
|
interest, GDB may sometimes cause confusion by finding the wrong
|
|
versions of source. You can correct the situation as follows:
|
|
</P><P>
|
|
|
|
<OL>
|
|
<LI>
|
|
Use <CODE>directory</CODE> with no argument to reset the source path to empty.
|
|
<P>
|
|
|
|
<LI>
|
|
Use <CODE>directory</CODE> with suitable arguments to reinstall the
|
|
directories you want in the source path. You can add all the
|
|
directories in one command.
|
|
</OL>
|
|
<P>
|
|
|
|
<A NAME="Machine Code"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC52"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC51"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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>
|
|
<H2> 7.5 Source and machine code </H2>
|
|
<!--docid::SEC52::-->
|
|
<P>
|
|
|
|
You can use the command <CODE>info line</CODE> to map source lines to program
|
|
addresses (and vice versa), and the command <CODE>disassemble</CODE> to display
|
|
a range of addresses as machine instructions. When run under GNU Emacs
|
|
mode, the <CODE>info line</CODE> command causes the arrow to point to the
|
|
line specified. Also, <CODE>info line</CODE> prints addresses in symbolic form as
|
|
well as hex.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX280"></A>
|
|
<DT><CODE>info line <VAR>linespec</VAR></CODE>
|
|
<DD>Print the starting and ending addresses of the compiled code for
|
|
source line <VAR>linespec</VAR>. You can specify source lines in any of
|
|
the ways understood by the <CODE>list</CODE> command (see section <A HREF="gdb_8.html#SEC47">Printing source lines</A>).
|
|
</DL>
|
|
<P>
|
|
|
|
For example, we can use <CODE>info line</CODE> to discover the location of
|
|
the object code for the first line of function
|
|
<CODE>m4_changequote</CODE>:
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(gdb) info line m4_changequote
|
|
Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
We can also inquire (using <CODE>*<VAR>addr</VAR></CODE> as the form for
|
|
<VAR>linespec</VAR>) what source line covers a particular address:
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(gdb) info line *0x63ff
|
|
Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
<A NAME="IDX281"></A>
|
|
<A NAME="IDX282"></A>
|
|
After <CODE>info line</CODE>, the default address for the <CODE>x</CODE> command
|
|
is changed to the starting address of the line, so that <SAMP>`x/i'</SAMP> is
|
|
sufficient to begin examining the machine code (see section <A HREF="gdb_9.html#SEC58">Examining memory</A>). Also, this address is saved as the value of the
|
|
convenience variable <CODE>$_</CODE> (see section <A HREF="gdb_9.html#SEC62">Convenience variables</A>).
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX283"></A>
|
|
<A NAME="IDX284"></A>
|
|
<A NAME="IDX285"></A>
|
|
<A NAME="IDX286"></A>
|
|
<A NAME="IDX287"></A>
|
|
<DT><CODE>disassemble</CODE>
|
|
<DD>This specialized command dumps a range of memory as machine
|
|
instructions. The default memory range is the function surrounding the
|
|
program counter of the selected frame. A single argument to this
|
|
command is a program counter value; GDB dumps the function
|
|
surrounding this value. Two arguments specify a range of addresses
|
|
(first inclusive, second exclusive) to dump.
|
|
</DL>
|
|
<P>
|
|
|
|
The following example shows the disassembly of a range of addresses of
|
|
HP PA-RISC 2.0 code:
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(gdb) disas 0x32c4 0x32e4
|
|
Dump of assembler code from 0x32c4 to 0x32e4:
|
|
0x32c4 <main+204>: addil 0,dp
|
|
0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
|
|
0x32cc <main+212>: ldil 0x3000,r31
|
|
0x32d0 <main+216>: ble 0x3f8(sr4,r31)
|
|
0x32d4 <main+220>: ldo 0(r31),rp
|
|
0x32d8 <main+224>: addil -0x800,dp
|
|
0x32dc <main+228>: ldo 0x588(r1),r26
|
|
0x32e0 <main+232>: ldil 0x3000,r31
|
|
End of assembler dump.
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
Some architectures have more than one commonly-used set of instruction
|
|
mnemonics or other syntax.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX288"></A>
|
|
<A NAME="IDX289"></A>
|
|
<A NAME="IDX290"></A>
|
|
<A NAME="IDX291"></A>
|
|
<A NAME="IDX292"></A>
|
|
<A NAME="IDX293"></A>
|
|
<A NAME="IDX294"></A>
|
|
<DT><CODE>set disassembly-flavor <VAR>instruction-set</VAR></CODE>
|
|
<DD>Select the instruction set to use when disassembling the
|
|
program via the <CODE>disassemble</CODE> or <CODE>x/i</CODE> commands.
|
|
<P>
|
|
|
|
Currently this command is only defined for the Intel x86 family. You
|
|
can set <VAR>instruction-set</VAR> to either <CODE>intel</CODE> or <CODE>att</CODE>.
|
|
The default is <CODE>att</CODE>, the AT&T flavor used by default by Unix
|
|
assemblers for x86-based targets.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="Data"></A>
|
|
<HR SIZE="6">
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_8.html#SEC46"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_9.html#SEC53"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <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 & GNU inquiries & 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>
|