Transcription

CS1 LabUsing the Eclipse Debugger1PurposeThe purpose of this lab is to introduce you to the Eclipse debugger.2SubmissionSubmit a single document that contains screen shots of the items listed below. Do not capture the entire screen- only the indicated areas.On the course web page, reference Course Materials/Eclipse Debugger. This link provides details about tools thatgo beyond what this lab covers.3Steps1. Create a project.Download the file named EclipseDebugger.java and add it to the workspace you just created. You’ll use thisprogram throughout the lab. Run the program to see what it does (which isn’t much).2. Setting a break point. A break point is used to pause execution of your program. To set a break point, rightclick on the left margin of the editor (with EclipseDebugger.java open) next to a line of code. You should seea window that looks like this:1

Click Toggle Breakpoint to set (or unset) a break point. When a break point is set, a blue circle appears in themargin:Set a break point on line 23:ar new int[L];You can set as many break points as you like. They can be toggled on and off by right clicking in the leftmargin.3. Running the debugger.You can start the debugger by either2

(a) Right clicking the project (or the file name) and selecting Debug As Java Application:3

(b) Or selecting Debug from the Run option in the tool bar:4

In either case, the debugger will start and you’ll be presented with the following:Select Switch. This will change from the Java perspective to the Debugger perspective.You’ll notice that the tool bar has changed:Of particular interest are the three buttons with yellow arrows circled in red.(a) The first is Step Into5

(b) This second is Step Over(c) This third is Step ReturnThe names will become clear later.In addition, there is the Resume button.To the right, you’ll see the Debug view.The Variables tab shows variables and their values. For debugging purposes, you can monitor the values of thevariables as a program executes. The Breakpoints tab lists the break points you’ve set. They can be enabledas disabled from this tab.6

4. At this point, you should be in the debugger, with a break point set at line 23, and the linear new int[L];highlighted in green.Click Step Over once. This advances the program one instruction, and the highlight should have advanced tothe next line.Take a screen shot of the debugger view, showing the variables. Make sure you’ve clicked the expand arrow tothe left of ar to show the contents of the array. Label this screen shot 1.5. Continue to use the Step Over button. Make sure that after you step over line 25 (the println()), you enter 2integers separated by a space.Keep stepping over instructions. Note that the loop will require quite a few. Watch how the values of thevariables update as you do this.STOP when the last statement (line 31 - the println()) is highlighted. Take a screen shot of thedebugger view showing the values of all the variables. Label this screen shot 2.Step over the last few lines to finish execution.6. Start over. This time, instead of stepping over the next instruction when line 23 is highlighted, click the Resumebutton to complete execution of the program (don’t forget to enter input!).Note that - at any time - you can continue normal execution by clicking this button.7. Set a new break point at line 28:c max(a, b);You should now have two break points: the one you started with, and the one you just set. Start debuggingthe program. With line 23 highlighted, click the Resume. Execution should pause on line 28. Now, use theStep Into button instead of the Step Over button. Note which instruction is highlighted now.Take a screen shot of your program. Label this screen shot 3.Take a screen shot of the debugger view, making sure the Variables tab is visible. Label thisscreen shot 4.Use the Step Over button until line 13 (the return statement) is highlighted.Take a screen shot of the debugger view. Label this screen shot 5.Step over line 13.Take a screen shot of the debugger view. Label this screen shot 5.Resume execution.7

8. To return to the ’normal’ programming view, select Window/Perspective/Open Perspective/Java.8