Carleton DeTar

The gdb debugger

The GNU debugger gdb is very useful for tracking down errors in your code. Used by itself, gdb has a rather primitive user interface, and requires some practice to use. However, the initial effort in learning to use it is often repaid by the time it saves you finding programming errors. There is a somewhat nice emacs interface, discussed below. The standard Unix debugger dbx serves the same purpose with slightly different commands. Use the GNU debugger for programs compiled with GNU compilers g++, gcc, and g77 and the dbx debugger for others.

The gdb debugger is able to track the execution of your program line-by-line in the source code (C++, C or Fortran) and tell you the status of every variable you are computing. It is also possible to tell it to watch a particular variable and report when it changes. In order for the debugger to perform this trick, it is necessary to compile your code with a special option, so the compiled code contains information about the symbolic names of your variables and has the appropriate cross references to the source code.