next up previous

Utilisation sous Emacs

A special interface allows you to use GNU Emacs to view (and
edit) the source files for the program you are debugging with

To use this interface, use the command `M-x gdb' in Emacs.
Give the executable file you want to debug as an argument.  This
command starts a GDB process as a subprocess of Emacs, with input
and output through a newly created Emacs buffer.

Using this GDB process is just like using GDB normally except for two things:

   * All "terminal" input and output goes through the Emacs buffer.  This
     applies both to GDB commands and their output, and to the input and
     output done by the program you are debugging.
     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.
     All the facilities of Emacs's Shell mode are available for this purpose.
   * GDB displays source code through Emacs.  Each time GDB displays a
     stack frame, Emacs automatically finds the source file for that frame
     and puts an arrow (`=>') at the left margin of the current line.
     Explicit GDB `list' or search commands still produce output as
     usual, but you probably will have no reason to use them.

In the GDB I/O buffer, you can use these special Emacs commands:

     Execute to another source line, like the GDB `step' command.
     Execute to next source line in this function, skipping all function
     calls, like the GDB `next' command.
     Execute one instruction, like the GDB `stepi' command.
     Move up one stack frame (and display that framés source file in
     Emacs), like the GDB `up' command.
     Move down one stack frame (and display that framés source file in
     Emacs), like the GDB `down' command.  (This means that you cannot
     delete words in the usual fashion in the GDB buffer; I am guessing you
     won't often want to do that.)
`C-c C-f'     
     Execute until exit from the selected stack frame, like the GDB
     `finish' command.

In any source file, the Emacs command `C-x SPC' (`gdb-break')
tells GDB to set a breakpoint on the source line point is on.

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 will cease
to correspond properly to the code.