Compile the inlab3.cc program (from the website) using the -g flag. Run ddd on the executable created.
Set a breakpoint at:
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?)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.
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.)
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?"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.
Question #6: What values are now being displayed? Why do you think that is? (Again, think about scope).
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?