ddd : a graphical unix debugger


  1. What is ddd?

    ddd is short for data display debugger. A debugger is a utility that allows you an easy way of observing what is going on "inside" your program as it is executed, or what exactly your program was doing when it crashed.

    Traditional unix debuggers (like gdb or dbx) are text-based. They provide a command-line interface for interaction -- you type text commands at the command line to interact with the debugger. ddd takes a GUI (graphical user interface) based approach -- instead of interacting with the debugger using text, the preferred mode is to interact through a visual interface.

    Note however that even when you are using ddd, the underlying debugger you are really using is still gdb or dbx or some such text-based debugger. ddd is actually a "wrapper" around the underlying debugger providing additional functionality and a graphic interface.

    You should know that, as of this writing, ddd does not seem all too easy to use or user-friendly. It also tends to crash sometimes. So, although you may want to check it out as an example of a GUI-based unix debugger, you should use it at your own risk, and for most purposes a text-based debugger like gdb may be more convenient and efficient to use for this course.


  2. Where can you run ddd?

    You can use ddd if you are programming under unix. ddd is available on CAEN's SUN workstations. It is located in the directory /usr/um/bin. Include this directory in your path and invoke ddd from the unix shell by simply typing

    ddd filename

    where filename is the name of the executable you are trying to debug (Note: in order to use the debugger on the executable, you should have compiled with the -g flag; thus, if you were compiling a file called file1.cpp, you should have compiled it thus: g++ -g file1.cpp -o file1.o -- and then you should have typed ddd file1.o at the unix prompt to start the debugging session.


  3. What things can ddd do for you?

    ddd can do four main kinds of things to help you debug:

    i) Start your program and run it within the debugger.

    When you started ddd by typing

    ddd filename,

    you would have seen the source code corresponding to the executable displayed. You can also select the source code through File->Open Program from the menu.

    To run the program from within the debugger, choose Program->Run from the menu.

    A separate tool window contains buttons for common useful debugging commands. You can get to this window by selecting View->Command Tool from the main menu. Note that there is also a separate command line window (at the bottom of the screen) into which debugging commands can be typed. (If you use this command line window for interacting with gdb, you would essentially be interacting with the underlying debugger. e.g. gdb, just as if you were running it in text mode.

    A program data window can also be opened where you can choose to view program variables in graphical or table style format (see below):

    ii) Make your program stop on specified conditions.

    One of the most useful things about debuggers is the ability to set breakpoints. A breakpoint is a place in the program which, as soon as it is reached, will cause the program to be suspended, affording you a chance to examine the internal state of the program at that point.

    To get a feel for how to set breakpoints and use them, try out the following: Select View->Source Window from the main menu (You may need to select it twice, as the first time you select it, you may end up looking at the data window instead). Once you are in the source window with your source code displayed, move your cursor to the line where you wish to set the breakpoint. Then click on the button marked "Break" in the second line of the main menu. A red stop sign appears on the line in the source window that you have chosen. This means that the breakpoint is now set. If you now run your program (by choosing Program->Run, for example), you will find that the program stops at the point where you set the breakpoint.

    Note that when you move the cursor to a line where a breakpoint is already set, the "Break button" in the menu changes to a "Clear" button. You can clear the breakpoint by clicking on this button.

    iii) Examine what has happened, when your program has stopped.

    When your program has stopped as a result of the breakpoint you
    had set, you get an opportunity to peek at what is going on "inside" your program at that moment. For example, you can choose Data->Display Local Variables from the menu. This will show you the current values of the local variables in your program at that point in the execution, in the data window. If you were using nested function calls, you can select Status->Backtrace from the main menu to look at the call stack. There are many other things that you can examine, such as the content of memory addresses, arguments to functions, etc -- experiment with the options available by clicking on "Data" in the menu.

    One useful way to examine complex data structures is to use the graphical data display feature of ddd. The data window holds displays showing names and the values of variables. The display is updated each time the program stops. To create a new display, select the desired variable by clicking mouse button 1 on its name. The variable name is copied to the argument field. By clicking the `Display ()' button, a new display is created in the data window. The data window opens automatically as soon as you create a display. To dereference a pointer, select the originating pointer value or name and click on the `Display *()' button. A new display showing the dereferenced pointer value is created.

    When you wish to resume running your program after examining all that you wished to examine at the breakpoint you stopped, you can select Cont (Continue) from the View->Command Tool window. Alternatively, you may also wish to go through your program one step at a time, doing further examinations at each step. In that case, you will want to select the Step option from the View->Command Tool window.

    iv) Change things in your program, so you can experiment with correcting the effects of the bug.

    Use the `Set' button in the menu to change values of variables displayed in the data window, and resume execution. The program runs with the altered values in place (Note: ddd unfortunately crashes often when doing this).


  4. Some things you should know about:

    Debuggers themselves are complex programs which occasionally do crash. So don't be surprised if ddd occasionally crashes on you when you're using it for debugging.


  5. For more information on related topics:


    Check out the CAEN technical note C/C++ Programming on the Unix Platform .


S. Bhattacharyya 1/13/99