Within Emacs on Unix, how can I debug a C or C++ program?
You can debug a C or C++ program using GDB, the
GNU debugger, which was developed by the same organization
that released Emacs. You can easily integrate it with Emacs
to interactively debug programs. While you can use it from the
Unix prompt, it has additional functionality when you use
it within the Emacs editor. To use GDB, first compile your program
using the -g option in cc or
gcc, for example:
Then, to start a separate window for the debugger and load the
executable, while editing foo.c within Emacs, enter:
GDB is very similar to the dbx debugger. The
run command will run a program, and the step
command will execute a program step by step.
For more help, refer to Step-by-step example for using GDB within Emacs to debug a C or C++ program. You could also use the
help command inside of GDB to access nested information
on other commands and their syntax.
This document was developed with support from the National Science Foundation (NSF) under Grant No. 0503697 to the University of Chicago and subcontracted to Indiana University. Additional support was provided by IU through its participation in the TeraGrid, which is supported by the NSF under Grants No. 0833618, SCI451237, SCI535258, and SCI504075. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the NSF.
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on December 17, 2008.







