
Chapter 25.
Using gdb under gnu Emacs
A special interface allows you to use gnu Emacs to view (and edit) the source files for the program
you are debugging with gdb.
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 gdb as a subprocess of Emacs, with input and output
through a newly created Emacs buffer.
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,
C-c C-c
for an interrupt,
C-c C-z
for a stop.
•
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 (
=
R
) 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
list
or search commands still produce output as usual, but you probably have no reason
to use them from Emacs.
Warning:
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. gdb can find programs by searching your environment’s
PATH
variable, so the gdb input
and output session proceeds normally; but Emacs does not get enough information back from gdb to locate
the source files in this situation. 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
M-x gdb
argument.
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,
M-x gdb
calls the program called
gdb
. If you need to call gdb by a different name (for
example, if you keep several configurations around, with different names) you can set the Emacs
variable
gdb-command-name
; for example,
(setq gdb-command-name "mygdb")
(preceded by
M-:
or
ESC :
, or typed in the
*scratch*
buffer, or in your
.emacs
file) makes Emacs
call the program named "
mygdb
" instead.
In the gdb I/O buffer, you can use these special Emacs commands in addition to the standard Shell
mode commands:
Содержание ENTERPRISE LINUX 3 - SECURITY GUIDE
Страница 1: ...Red Hat Enterprise Linux 3 Debugging with gdb ...
Страница 12: ...2 Chapter 1 Debugging with gdb ...
Страница 28: ...18 Chapter 4 Getting In and Out of gdb ...
Страница 34: ...24 Chapter 5 gdb Commands ...
Страница 44: ...34 Chapter 6 Running Programs Under gdb ...
Страница 68: ...58 Chapter 8 Examining the Stack ...
Страница 98: ...88 Chapter 10 Examining Data ...
Страница 112: ...102 Chapter 12 Tracepoints ...
Страница 118: ...108 Chapter 13 Debugging Programs That Use Overlays ...
Страница 138: ...128 Chapter 14 Using gdb with Different Languages ...
Страница 144: ...134 Chapter 15 Examining the Symbol Table ...
Страница 170: ...160 Chapter 19 Debugging remote programs ...
Страница 198: ...188 Chapter 21 Controlling gdb ...
Страница 204: ...194 Chapter 22 Canned Sequences of Commands ...
Страница 206: ...196 Chapter 23 Command Interpreters ...
Страница 216: ...206 Chapter 25 Using gdb under gnu Emacs ...
Страница 296: ...286 Chapter 27 gdb Annotations ...
Страница 300: ...290 Chapter 28 Reporting Bugs in gdb ...
Страница 322: ...312 Chapter 30 Using History Interactively ...
Страница 362: ...352 Appendix D gdb Remote Serial Protocol ...
Страница 380: ...370 Appendix F GNU GENERAL PUBLIC LICENSE ...
Страница 386: ...376 Appendix G GNU Free Documentation License ...
Страница 410: ......