The Quincy IDE has a full-featured and extremely useful set of features to help analyze the behavior of a program.
For example, you can:
There are several basic commands available to you in the debugger, as well as some advanced commands. The basic commands are quite useful, and are explained below.
Before starting the debugger, compile and build your program and correct any problems until you have 0 errors.
Next, go to Tools/Options/Build and make sure that "Debugging Information Added" is checked.
But - before handing in a floppy disk with your program, you may have to recompile and rebuild with debugging information turned off so the .exe file will fit on a floppy disk. To do this, uncheck the "Debugging Information Added" checkbox and recompile and rebuild for the floppy version.
Before you go any further, notice that you will want to see both the DOS Window and the Quincy Edit window. If the Quincy window is full screen, when you click on the Quincy window, the DOS window will "hide" behind the Quincy window. This is inconvenient. You should probably re-size the Quincy window so you can see the DOS window (one on the left and one on the right). If Quincy is full-screen, click on the restore button (at the upper right of the Quincy window, there are 3 small icons: an _ and a two-rectangle things, and an X. The restore icon is the two-rectangle thing. Now you should be able to see the sides of the Quincy window. Position the mouse over the side (border) of the window and notice that it turns into a two-headed arrow. You can now drag (i.e. press and hold down the button and move) the mouse to make the window narrower. You can likewise change the width of the DOS window. Position them so you can see both. |
Now move the cursor to the first executable line in your source code (or a later line if you prefer). Choose Debug/Step to Cursor (or press F10). The program will start up and execute until the instruction where your cursor is. It will then pause.
Notice that there is a little green arrow in the Quincy source code window indicating the next instruction that will be executed. Also notice that in your DOS window you only see any output produced up to the instruction you are stopped at.
Click in the Quincy window to make it active (so the top title bar is colored, not gray). Now you have several choices:
press F7 (Debug/Step) to execute one line (If the line contains a function call or a cin or cout, control will jump to the first instruction in the function, and you can the single-step through the function's code. If it is not a fucntion you wrote, you may not care to do this.) So do the F8 command instead.
press F8 (Debug/Step Over) to execute one line (if the line contains a function call, the function will be executed all-at-once).
move the cursor to a new point in the source code, and press F10 (Debug/Step to Cursor) to execute all the lines of code up to the new point, and then pause again.
press F9 to run the program normally (no more pauses). Do this if you have figured out what you want to change and you don't need to step through a bit at a time any more.
set a "watch" on one or more variables by pressing Ctrl-W (Debug/Watch) and typing the name of the variable. After you have done this, you will see the variable and its current value in a new pop-up window. If the value changes as you execute subsequent instructions, you will see the new value reflected in the Watch window. This is very valuable if your output answers are wrong: you can watch the values a variable takes on as the program runs, and determine the place where things first go wrong with it. You can also verify or confirm that that values are as you expect (or not).
When the program expects input, you will have to click in the DOS window, type in the input, press Enter, and then return to (click in) the Quincy window to continue with F7, F8, or whatever. This takes some getting used to. You should practice this stepping through the program with a program that works correctly.
Don't press F7 if the line has a cin or cout in it, unless you want to step through code that you won't understand. Use F8 instead to "step over" them - i.e. execute them without single-stepping through each line.
Use F7 and F8 to single step thru code while watching the value(s) of selected variables, and also to see the flow of execution: which branch of a decision is executed, how many times the body of a loop is executed, etc.
Use move the cursor and press F10 to jump ahead to a later part of the program without having to step-step-step to get there.
You can add or delete variables in the Watch window via the pushbuttons provided
Understand that the values of one function's variables cannot be "seen" while executing code in another function. The Watch Windows will indicate that these values are not available when this is so.
Type in the following code, exactly as shown, compile it, and run it under the debugger. Hand in a printed copy of the source code, stapled together with a standard-sized sheet of paper answering the questions that follow the code. Do not hand in a disk. This assignment is due in recitation at the beginning of the hour. If you make a mistake typing in the code, your answers could be wrong, so double-check what you type.
The comments ( //1 //2 etc.) are the "line numbers" referred to below.
#include <iostream> using namespace std; int main() { int i, j, k; int ans; string s; i = 4; // 1 j = 7; // 2 ans = 4 * j/i + 9; // 3 i = 0; // 4 while (ans > 0) // 5 { i++; // 6 ans--; // 7 } if (j % 2 / 2) // 8 ans = 1; // 9 else ans = 2; // 10 ans += k; // 11 return 0; }
What is the value of ans after line 2 has executed?
What is the value of ans after line 3 has executed?
What is the value of i just before line 8 has executed?
Does line 9 or line 10 execute?
What is the value of k before line 11 is executed? Why?
What is the value of ans after line 11 has executed?