A Brief Introduction to DDD

If you've ever written a program, then unless it was trivial, you also had to debug it. Linux includes several debuggers in their distributions. However, they are all command-line debuggers which aren't very nice to use. Thankfully, the DDD (DataDisplay Debugger) is a front-end to all of these debuggers. To use DDD you must compile your code with debug information included. In C++ that means you should include the -g option on the g++ compile command. If you've never run DDD before, you may have to tell DDD to use the gdb debugger and not the dbx debugger. To do this you type "ddd --gdb" at the command-line prompt. You only have to do this once. Then you can quit DDD and when you run it later it will automatically use the gdb debugger. Subsequently, to run DDD you type "ddd prog" where prog is the name of your program. When you do this, a window like the one below pops up.

The window shows you the source code of the program. You can do the normal things you do in a debugger. You can:

One of the more important capabilities is being able to examine variables. To do this you highlight a variable in your code and click the Display button on the toolbar. The window will split and show the variable at the top of the screen. The split screen can be adjusted by dragging the small square that appears between the code frame and data frame at the far right-handside of the window. If your data contains pointers, you can doubleclick on the pointer to display the data that it points to.

Finally, if you are getting a segmentation fault (a pretty common occurrence) when running your program, you can just run the program (no fear of hanging Linux like MS Windows) in the debugger and it will show you the line that the segfault occurred on. You can use the "Status->Backtrace..." menu option to trace back through the run-time stack and examine variables to see what caused the segfault.

Debugging Java Programs

DDD automatically detects Java programs and serves as a front-end for the jdb debugger, too. Assuming your Java environment is set up, you can debug a Java program by typing "ddd file.class" where file.class is the name of your Java class file. Notice that you do not run your program using "ddd jdb file.class" or "ddd java file.class", you simply start DDD directly on the class file and it does the rest.