Debugging with ddd and gdb
General Information
Several ways to debug (remove errors) from a program
Desk check
Use the compiler
Ask a friend
Insert print statements
Use a debugger (e.g., gdb, ddd)
ddd Debugger
If you chose to use a debugger, that tool (program) needs to be available to you, just like any other program you might use. However, you also need to prepare the program you what to debug. This is done with the "-g" option on the compiler.
For example: to prepare hello.cpp for debugging, compile it with the "-g" option, e.g., "g++ -g hello.cpp"
Load the resulting executable (i.e., a.out) into the debugger when you start it up. For example: "ddd a.out"
Once in ddd you can
Set breakpoints -- places where the program execution will stop and wait
Execute one program line at a time using the "step" or "next" command
Watch how the program proceeds
Inspect variable values, and
Many other more sophisticated features
gdb Debugger
Note, ddd is built using gdb, so many of the things you can do in ddd, you can also do in gdb. The primary difference is that ddd uses graphics and gdb does not (only text). Therefore, gdb can be used with a terminal (text only) connection to the computer (like PuTTY).