After completing this tutorial, you should be able to:
cp ~rodger/cps100e/ddd/* .
Once you have obtained the docount code (including the Makefile), and have looked over the code for these programs to see what they do, you're ready to get started using DDD. First, compile the code, type make docount and then make bookinfo
Now, start up ddd! Type ddd & at an xterm prompt and press enter (remember the '&' starts ddd in the background so you can still use the xterm).
Wait for three windows to pop up on screen. These are the main facilities of DDD. You should have one toolbar, one "Debugger Console", and the largest window should be blank. You'll want to load the compiled program into DDD so that you can start the debugging. Choose "open program" from the file menu of the Debugger Console window, and when the dialog pops up, choose the name of your program ("docount" in this case) from the list of files and then click on the Open button. DDD should then display the source code of the main function in the largest window. Now, you're ready to proceed.
Now, you'll want to set a breakpoint. For no particular reason at all, let's choose line 16 of docount.cc (this is the file that should already be loaded into the source code viewer window). We'll set our breakpoint at line 16 It's important to remember that DDD will break execution before it executes the line you set the breakpoint on. To set the breakpoint, move the mouse over the #16 that denotes the line number, and right click. A small menu should pop up. Choose the "set breakpoint" option. A tiny red stop sign will appear next to line 16. Now, DDD should break the program before anything is ever printed to cout. To see this in action, click on the green RUN button on the toolbar. The display in the Debugger console should say "Starting program ... " etc. Then, a line such as "Breakpoint 1, main() at docount.cc:16" should appear. This means the breakpoint has been reached. Normal program output should be outputted to the debugger console, but note that nothing has appeared yet. This is because you set the breakpoint on line 16. Thus, the code on line 16 has not been executed.
The breakpoints you set can be deleted or disabled by right-clicking on the line just as before. Except this time, you'll choose either the "disable breakpoint" or "delete breakpoint" options.
In order to set breakpoints in other files (ie, not in the main() function), choose the "Open Source" option from the File menu of DDD. The file dialog should appear; choose wordstrit.cc. Setting a breakpoint in this class implementation file is identical to setting breakpoints in the main() function. Set a breakpoint at line 43 in wordstrit.cc using the method described above. By clicking on Run again (restart the program as necessary), the program should break, once again, at the breakpoint.
While inside the loop, in the depths of the PrintBooks() function, you may choose to look at your position in the previous reference frame, i.e., the function from which you called PrintBooks(). To do this, press the 'Up' button. You will see that you are currently halted on line 64, on the line calling the function PrintBooks() within the function main(). You cannot go up any furhter than the main function. To descend back to your initial reference frame, use the 'Down' button.
At any point while stepping through the for loop, you may choose to forgo tracing through your program by pressing the 'Cont' (read: continue) button. Pressing the continue button will finish execution of your program.
Congrats. Now you know how to trace through programs.
Open the "Program Data" window by choosing the "Program Data" from the "Windows" menu; a window should appear. When the program breaks, click on the variable "books" on line 64 and click on the "Display()" button. Now a box should appear in the "Program Data" window. It is called "books" and display some other variables, such as myCapacity, mySize, myList. Click on the "books" box so that it is highlighted and then click on the "Display*()" button. (Note the asterisk). A second window should appear in the "Program Data" window. Select this new box and click on "Show()" to display it's contents. Here, you should see the title and the author of the first book in the vector called "books".
You can view all the other elements in the vector as well, for example, the second item. To do this, click the "New Display" button and type in "books.myList[1]" (remove the preceding asterisk if it exists). A new box will appear that has the data contained in the second vector element of books. You can use the "Show()" button on this new box as well. You can make other subsequent bits of data contained in the vector "books" appear by using the same method, but substitute a new number for "1" in the "books.myList[1]".
And now you're done with learning the basics of DDD. Hopefully, you'll like it and experiment around with it some more.
Send questions to Prof. Rodger.