f78
Using GDB under GNU Emacs
To use this interface, use the command
Using GDB under Emacs 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’ Shell mode are available for interacting with
your program. In particular, you can send signals the usual way—for example,
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. Emacs uses a separate buffer for source display, and splits the screen to
show both your GDB session and the source.
Explicit GDB
Warning:
GDB can find programs by searching your environment’s
To avoid this problem, either start GDB mode from the directory where your
program resides, or specify an absolute file name when prompted for the
A similar confusion can result if you use the GDB file command to switch to
debugging a program in some other location, from an existing GDB buffer in Emacs.
By default, using the keystroke sequence,
For example,
In the GDB I/O buffer, you can use these special keystroke sequences of Emacs
commands in addition to the standard Shell mode commands:
Warning:
Warning:
Warning:
You can customize this further by defining elements of the list
gdb-print-command; once it is defined, you can format or otherwise process numbers picked up
by using the keystroke sequence,
In any source file, the Emacs command using the keystroke sequence,
If you accidentally delete the source-display buffer, an easy way to get it
back is to type the command,
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 correspon
37
d properly with the code.
If the directory where your program resides is not your current directory, it
can be easy to confuse Emacs about the location of the source files, in which
case the auxiliary display buffer does not appear to show your source.
Describe the features of Emacs’ GDB Mode.
Execute to another source line, like the GDB step command; also update the display window to show the current file and location.
Execute to next source line in this function, skipping all function calls,
like the GDB next command. Then update the display window to show the current file and location.
Execute one instruction, like the GDB stepi command; update display window accordingly.
Execute to next instruction, using the GDB nexti command; update display window accordingly.
Execute until exit from the selected stack frame, like the GDB finish command.
Continue execution of your program, like the GDB continue command.
In Emacs version 19, this command uses the keystroke sequence,
Go up the number of frames indicated by the numeric argument (see section
Numeric Arguments” in The GNU Emacs Manual), like the GDB up command.
In Emacs version 19, this command uses the keystroke sequence,
Go down the number of frames indicated by the numeric argument, like the GDB down command.
In Emacs version 19, this command uses the keystroke sequence,
Read the number where the cursor is positioned, and insert it at the end of
the GDB I/O buffer. For example, if you wish to disassemble code around an
address that was displayed earlier, type disassemble; then move the cursor to the address display, and pick up the argument for disassemble by using the keystroke sequence, C-x, &.