Debugging Programs with gdb

CS 325

gdb is a utility for debugging and executing programs. In order to be able to debug a program written in C or C++, it has to be compiled with the -g option:
gcc -g -o filename filename.c...
g++ -g -o filename filename.cc...
To start off gdb, type gdb filename at the command line. A few messages are printed, and then you are left at the (gdb) prompt:

      % gdb filename
      <various messages>
      (gdb)
Some of the important and most often used commands at the gdb prompt:

The commands in the file .gdbinit are executed as gdb initializes. gdb executes (if present) the file in the home directory. Then, this process is repeated using the current working directory. For more information on gdb, run the info (see the man page) facility from the shell prompt, then use the m command to enter the gdb documentation. You may also look at the man pages and gdb's help system.



Thomas P. Kelliher 2009-02-09
Tom Kelliher