CSC161: Imperative Problem Solving and Data Structures
Grinnell College


Laboratory: The DDD Debugger

Summary: In this laboratory, you will experiment with the use of a graphical debugger DDD (Data Display Debugger), a helpful tool for debugging C programs in a Unix environment.

Prerequisites:

Contents:

Exercises

Exercise 0: Preparation

a. Use your favorite web browser to view the manual provided by Gnu for DDD (html version): http://www.gnu.org/software/ddd/manual/html_mono/ddd.html.

b. Follow the link for Sample Session. It should be the second item in the list.

c. Click on Sample Program to view the sample program, then cut and paste the program into a new file, sample.c, in your current directory.

d. Compile the sample program (to an executable named sample) with the following command. The option -g causes the executable to contain information needed by the debugger.

  gcc -Wall -ansi -g -o sample sample.c

d. Return to Gnu's sample DDD session (i.e., go back a page in your browser).

Exercise 1: Gnu's DDD Tutorial

In this exercise, I would like you to walk through the DDD tutorial provided by Gnu. Unfortunately, the sample code contains some C syntax that we have not studied yet, so you may not understand everything in the sample program. However, you will still learn a lot about the use of the debugger, and that is the point of this laboratory lesson.

a. Follow the instructions in the sample tutorial, except for the exceptions listed below. Stop at the end of the tutorial (i.e., when you run into the sample source code again), which is way before the end of the web page.

b. Return to the top of Gnu's tutorial, and scan through it again, this time making a crib sheet of the various DDD features you learned. I suggest recording how the various features are invoked and also brief descriptions of what they do. You may want to keep this crib sheet handy for future use!

Exercise 2: Various Shorts

a. Compile the program sample.c again, this time without using the option -g, and try to run it in DDD. (The purpose of this exercise is so that you may recognize the error it produces should you happen to see it again in the future.)

b. Re-compile sample.c with the debugging information included. Run ddd again. Move the mouse over various icons on the toolbar, and press the F1 key over some of them to read about what they do.

c. Try selecting What Now? from the Help menu (in the far upper-right corner of the DDD window). You may also want to try the Tip of the Day from the same menu.

Exercise 3: A Debugging Exercise

a. Copy or download the following bug-ridden C program: debugme.c.

b. Use what you have learned to track down and fix the bugs in this program with the help of DDD.

You may find the Interrupt button on the DDD Command Tool useful for this exercise. It will suspend your program -- a useful feature for locating infinite loops.

At some point during this exercise, try moving a breakpoint from one line to another by dragging the stopsign icon. (Let's see Eclipse do that!).

For Those with Extra Time

Extra 1: Shell Sort

If you are interested in learning more about the Shell Sort algorithm used in Gnu's DDD tutorial, you can read about it on Wikipedia.
Written: Marge Coahran, February 2007.