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.
242 lines
9.2 KiB
HTML
242 lines
9.2 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: Emacs</TITLE>
|
|
|
|
<META NAME="description" CONTENT="Debugging with GDB: Emacs">
|
|
<META NAME="keywords" CONTENT="Debugging with GDB: Emacs">
|
|
<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="SEC241"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_23.html#SEC240"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_25.html#SEC242"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_25.html#SEC242"> >> </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_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H1> 23. Using GDB under GNU Emacs </H1>
|
|
<!--docid::SEC241::-->
|
|
<P>
|
|
|
|
<A NAME="IDX1256"></A>
|
|
<A NAME="IDX1257"></A>
|
|
A special interface allows you to use GNU Emacs to view (and
|
|
edit) the source files for the program you are debugging with
|
|
GDB.
|
|
</P><P>
|
|
|
|
To use this interface, use the command <KBD>M-x gdb</KBD> in Emacs. Give the
|
|
executable file you want to debug as an argument. This command starts
|
|
GDB as a subprocess of Emacs, with input and output through a newly
|
|
created Emacs buffer.
|
|
</P><P>
|
|
|
|
Running GDB under Emacs can be just like running GDB normally except for two
|
|
things:
|
|
</P><P>
|
|
|
|
<UL>
|
|
<LI>
|
|
All "terminal" input and output goes through an Emacs buffer, called
|
|
the GUD buffer.
|
|
<P>
|
|
|
|
This applies both to GDB commands and their output, and to the input
|
|
and output done by the program you are debugging.
|
|
</P><P>
|
|
|
|
This is useful because it means that you can copy the text of previous
|
|
commands and input them again; you can even use parts of the output
|
|
in this way.
|
|
</P><P>
|
|
|
|
All the facilities of Emacs' Shell mode are available for interacting
|
|
with your program. In particular, you can send signals the usual
|
|
way--for example, <KBD>C-c C-c</KBD> for an interrupt, <KBD>C-c C-z</KBD> for a
|
|
stop.
|
|
</P><P>
|
|
|
|
<LI>
|
|
GDB displays source code through Emacs.
|
|
<P>
|
|
|
|
Each time GDB displays a stack frame, Emacs automatically finds the
|
|
source file for that frame and puts an arrow (<SAMP>`=>'</SAMP>) at the
|
|
left margin of the current line. Emacs uses a separate buffer for
|
|
source display, and splits the screen to show both your GDB session
|
|
and the source.
|
|
</P><P>
|
|
|
|
Explicit GDB <CODE>list</CODE> or search commands still produce output as
|
|
usual, but you probably have no reason to use them from Emacs.
|
|
</UL>
|
|
<P>
|
|
|
|
We call this <EM>text command mode</EM>. Emacs 22.1, and later, also uses
|
|
a graphical mode, enabled by default, which provides further buffers
|
|
that can control the execution and describe the state of your program.
|
|
See section `GDB Graphical Interface' in <CITE>The GNU Emacs Manual</CITE>.
|
|
</P><P>
|
|
|
|
If you specify an absolute file name when prompted for the <KBD>M-x
|
|
gdb</KBD> argument, then Emacs sets your current working directory to where
|
|
your program resides. If you only specify the file name, then Emacs
|
|
sets your current working directory to to the directory associated
|
|
with the previous buffer. In this case, GDB may find your
|
|
program by searching your environment's <CODE>PATH</CODE> variable, but on
|
|
some operating systems it might not find the source. So, although the
|
|
GDB input and output session proceeds normally, the auxiliary
|
|
buffer does not display the current source and line of execution.
|
|
</P><P>
|
|
|
|
The initial working directory of GDB is printed on the top
|
|
line of the GUD buffer and this serves as a default for the commands
|
|
that specify files for GDB to operate on. See section <A HREF="gdb_16.html#SEC155">Commands to Specify Files</A>.
|
|
</P><P>
|
|
|
|
By default, <KBD>M-x gdb</KBD> calls the program called <TT>`gdb'</TT>. If you
|
|
need to call GDB by a different name (for example, if you
|
|
keep several configurations around, with different names) you can
|
|
customize the Emacs variable <CODE>gud-gdb-command-name</CODE> to run the
|
|
one you want.
|
|
</P><P>
|
|
|
|
In the GUD buffer, you can use these special Emacs commands in
|
|
addition to the standard Shell mode commands:
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><KBD>C-h m</KBD>
|
|
<DD>Describe the features of Emacs' GUD Mode.
|
|
<P>
|
|
|
|
<DT><KBD>C-c C-s</KBD>
|
|
<DD>Execute to another source line, like the GDB <CODE>step</CODE> command; also
|
|
update the display window to show the current file and location.
|
|
<P>
|
|
|
|
<DT><KBD>C-c C-n</KBD>
|
|
<DD>Execute to next source line in this function, skipping all function
|
|
calls, like the GDB <CODE>next</CODE> command. Then update the display window
|
|
to show the current file and location.
|
|
<P>
|
|
|
|
<DT><KBD>C-c C-i</KBD>
|
|
<DD>Execute one instruction, like the GDB <CODE>stepi</CODE> command; update
|
|
display window accordingly.
|
|
<P>
|
|
|
|
<DT><KBD>C-c C-f</KBD>
|
|
<DD>Execute until exit from the selected stack frame, like the GDB
|
|
<CODE>finish</CODE> command.
|
|
<P>
|
|
|
|
<DT><KBD>C-c C-r</KBD>
|
|
<DD>Continue execution of your program, like the GDB <CODE>continue</CODE>
|
|
command.
|
|
<P>
|
|
|
|
<DT><KBD>C-c <</KBD>
|
|
<DD>Go up the number of frames indicated by the numeric argument
|
|
(see section `Numeric Arguments' in <CITE>The GNU Emacs Manual</CITE>),
|
|
like the GDB <CODE>up</CODE> command.
|
|
<P>
|
|
|
|
<DT><KBD>C-c ></KBD>
|
|
<DD>Go down the number of frames indicated by the numeric argument, like the
|
|
GDB <CODE>down</CODE> command.
|
|
</DL>
|
|
<P>
|
|
|
|
In any source file, the Emacs command <KBD>C-x <KBD>SPC</KBD></KBD> (<CODE>gud-break</CODE>)
|
|
tells GDB to set a breakpoint on the source line point is on.
|
|
</P><P>
|
|
|
|
In text command mode, if you type <KBD>M-x speedbar</KBD>, Emacs displays a
|
|
separate frame which shows a backtrace when the GUD buffer is current.
|
|
Move point to any frame in the stack and type <KBD>RET</KBD> to make it
|
|
become the current frame and display the associated source in the
|
|
source buffer. Alternatively, click <KBD>Mouse-2</KBD> to make the
|
|
selected frame become the current one. In graphical mode, the
|
|
speedbar displays watch expressions.
|
|
</P><P>
|
|
|
|
If you accidentally delete the source-display buffer, an easy way to get
|
|
it back is to type the command <CODE>f</CODE> in the GDB buffer, to
|
|
request a frame display; when you run under Emacs, this recreates
|
|
the source buffer if necessary to show you the context of the current
|
|
frame.
|
|
</P><P>
|
|
|
|
The source files displayed in Emacs are in ordinary Emacs buffers
|
|
which are visiting the source files in the usual way. You can edit
|
|
the files with these buffers if you wish; but keep in mind that GDB
|
|
communicates with Emacs in terms of line numbers. If you add or
|
|
delete lines from the text, the line numbers that GDB knows cease
|
|
to correspond properly with the code.
|
|
</P><P>
|
|
|
|
A more detailed description of Emacs' interaction with GDB is
|
|
given in the Emacs manual (see section `Debuggers' in <CITE>The GNU Emacs Manual</CITE>).
|
|
</P><P>
|
|
|
|
<A NAME="GDB/MI"></A>
|
|
<HR SIZE="6">
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_25.html#SEC242"> >> </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_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 & 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>March, 27 2008</I>
|
|
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
|
|
"><I>texi2html</I></A>
|
|
|
|
</BODY>
|
|
</HTML>
|