Contents|Index|Previous|Next
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 the following two considerations.

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, using the keystroke sequence, 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 using the keystroke sequence, Esc, Esc, or typed in the *scratch* buffer, or in your ‘.emacs’ file) makes Emacs instead call the “mygdb”program.

In the GDB I/O buffer, you can use these special keystroke sequences of Emacs commands in addition to the standard Shell mode commands (where C denotes the Ctrl key and M denotes the Meta, or diamond-shaped key):
 


Top|Contents|Index|Previous|Next