CIT 594 Forté Tutorial III: Using the Debugger
In this tutorial you will be asked to download a Forté program. The program creates a random (but sorted) array of ten integers, and does a binary search for a given integer in the array. The binary search does not work correctly. The purpose of the tutorial is to demonstrate the use of Forté's built-in debugger.
http://www.cis.upenn.edu/~matuszek/cit594/Programs/binsearch.jar(by right-clicking on it and choosing
Save Target As...).
jar xvf binsearch.jar) or any zip utility. This will give you a folder named
Mount Filesystem...to mount the
BinarySearchfolder. (See previous tutorials if you don't know how to do this.) Open the binary search project.
binarySearchmethod--it should begin on line 134.
binarySearch(this should be line 135) by right-clicking anywhere on the line and choosing
Toggle Breakpoint. The line should turn bright red.
Toggle Breakpointcommand should more properly be called
Add/Remove Breakpoint; it adds a breakpoint if there is none, or removes on if there is.
int binarySearch(...)), it looks like you can do it, but the breakpoint won't actually work, because there isn't any executable code there--it's just a description of the method.
Debuggingtabbed pane. This opens a different set of windows: Source Editor (which is available in other tabbed panes as well), Output Window, and Debugger Window. Also notice that the set of debugging icons (immediately above the
Debuggingtab) has expanded. (This step can be omitted.)
Debug -> Startfrom the main menu, or click on the down-arrow/green-bug icon, or hit F5. Do not choose
Build -> Executeor click the green triangle; this will run the applet as usual, without starting the debugger.
New Arraybutton (more than once, if necessary) and type in a number that the binary search should find, but can't (a number that only occurs in position 0, 3, 6, or 9). When you click the
Searchbutton, the program will pause at your breakpoint and the debugging windows will appear (if they weren't already visible).
BinarySearch.binarySearch: 135, which is where you are: class, method, and line number. Click on the key next to it, and you will finally see something really useful: your variables including
target, and their current values. (Why doesn't it show
middle? Look at the Source Editor window for a clue.)
arrayshows you the values in the array.
thisgives you more information than you ever wanted to know about this
left. Don't click on the variable, just let the mouse hover over it. After a second, a tiny window pops up to show you the value of the variable. Test whether this trick also works for
middle. This technique is too slow for variables you want to examine often, but it's handy for examining variables that you seldom look at.
Add Watch.... The window that appears should have
leftin its text field (if not, you can type it in). Click
OK. Do the same for
array, if you like). Now go back to the Debugger Window and click the
Watchestab. Notice what has been added.
Debug -> Step Overfrom the main menu, or press the
F8key. Notice that line 135 in the Source Editor window has changed from blue back to red. The next line (136) is now the blue line. The blue line is the one you are about to execute; red lines indicate breakpoints. Blue covers red.
middleis still undefined.
Debug -> Step Overfrom the main menu once again, or press the
F8key again. Now line 137 is blue.
middleand given it the value
Debug), an icon you can click, and a keyboard shortcut.
F8] -- execute this complete statement. If the statement contains any method calls, "step over" the methods--that is, the methods are executed, but the debugger doesn't "look down" into their execution. (However, if the method contains a breakpoint, the debugger will pause there and show it to you.)
F7] -- start executing this statement. If the statement contains any method calls, the debugger "steps into" the method and pauses at the first executable statement in the called method. If this statement does not contain any method calls,
Step Intois exactly the same as
Ctrl-F7] -- this gets you out of a method that you have stepped into. Use this if you have stepped into a method by accident, or if you have simply seen all you want to see of that method.
Run to Cursor[
F4] -- puts a temporary breakpoint on the line containing your cursor, and executes up to that point. Use this to skip over a bunch of statements that you aren't really interested in.
Ctrl-F5] -- this executes all statements up until the next breakpoint that it encounters. If no more breakpoints are encountered, the program will continue to run until it is finished (or you quit it). Use this command when you have seen all you want to see at the current breakpoint.
Shift-F5] -- use this to quit debugging. Since you might have multiple debugging sessions going at the same time, you will be asked to select which ones to quit. Chances are there's only one, and it's checked, so just hit
binarySearch(there's only one). If you have already spotted it, pretend you haven't, and play around with the debugger some more.
Delete(or just hit the Delete key).
File -> Save All). If the command is grayed out, that's because Forté thinks the current version is already saved; but it's wrong. Although debugger settings are saved with the program, Forté doesn't realize that the debugger settings have changed. Make some minor change to the program (I usually add and delete a space), and try again.