ENG 101: Inlab #3 -- Winter 2005

You are expected to turn this in to your lab instructor at the start of your next lab period. It is worth approximately 0.5% of your course grade. Recall that you will be allowed to drop two in-lab assignments. The first page of this write-up must be stapled to the front of the printout you hand in for this assignment. The assignment is graded out of 30 points. As always, start your answer sheet with your name and unique name.
Before you can start this lab your GSI will have to show you how to display an array using ddd.

Compile the inlab3.cc program (from the website) using the -g flag. Run ddd on the executable created.

Set a breakpoint at:

Now press "run". Display (as the GSI showed you at the beginning of the lab) the array A as well as the variable SIZE.
Question #1: What is the value of A[2] according to the debugger?
Now press the "cont" button (continue).
Question #2: Where are you now? (That is, where is the green arrow pointing?)
Question #3: The variables you were displaying should have gone away (if you've done everything right.) Why do you think that is? (hint: you probably should use the word "scope" in your answer.)
Now try to display the array list. You should find that you can't do so. Either you get something like "(* int) 0x22ff000" or you get something like "1". The basic problem is that in the function we don't know how big the array is. This makes it impossible for the debugger to display the array correctly. In this case you need to go to the command window (The text on the bottom of the debugger) and type: "graph display list[0]@5" (the stuff in the quotes, not including the quotes themselves). This should pull up the array as a list in the display area.

What this did is provide a range of values to display. In general it will be of the form "graph display ARRAY_NAME[START]@NUM" where START is the first element to be displayed and NUM is how many elements to display.

Question #4: What is the value of list[2]?
Now clear the breakpoint in the printList function. Press finish.
Question #5: What line are you now executing?
Question #6: What values are now being displayed? Why do you think that is? (Again, think about scope).
"Finish" finishes the current function. That is it continues execution until just after a return occurs. This is handy when you are sure you understand what the function is doing and just want to get out of it.

Now press "next" twice. You should be at the second printList call.

Question #7: What is the value of A[2]? Why do you think it changed?
Notice that pressing "next" caused you to skip over the function sort(). It still executed but you didn't get to see what it was doing. Now press "step".
Question #8: Where are you now?
Question #9: What values are now being displayed? Why do you think that is? (Again, think about scope).

You have now finished the step-by-step directions. We will now just ask a few questions about the debugger. You may need to experiment a bit to get good answers.

Question #10: What is the difference between pressing "step" and "next"? Specifically, what happens if you press "step" when there is a function call on the current line? What if you press "next" in the same situation? What if there is no function call on that line?
Question #11: In general, what does pressing "cont" do? What will be the next line the debugger will stop at if "cont" is pressed?