Example: air traffic controller

Debugging in Eclipse Debugging 1 - Undergraduate Courses

Debugging1 Data Structures & AlgorithmsCS@VT 2012 McQuainDebugging in EclipseWe are built to make mistakes, coded for ThomasIt is one thing to show a man that he is in error, and another to put him in possession of the LockeDebugging2 Data Structures & AlgorithmsCS@VT 2012 McQuainPrerequisites for EclipseTo use Eclipse you must have an installed version of the java Runtime Environment (JRE).The latest version is available from Eclipse includes its own java compiler, it is not strictly necessary to have a version of the java Development Kit (JDK) installed on your computer. However, I recommend installing one anyway so that you can test your code against the "real" java latest version is available from: you install the JDK, I recommend putting it in a root-level directory, and making sure there are no spaces in the pathname for the Structures & AlgorithmsCS@VT 2012 McQuainEclipse WorkbenchThe initial Eclipse Workbench (my configuration):Restore ViewMinimize ViewMaximize ViewRestore ViewHover for info%Debugging4 Data Structures & AlgorithmsCS@VT 2012 McQuainEclipse java Perspective ToolbarChoose a PerspectiveNew Project / Save / Save All / PrintBuild ProjectStart Debugging + configurationsRun Project + configurationsRun Last Tool + configurationsDebugging5 Data Structures & Alg

Debugging 2 CS @VT Data Structures & Algorithms ©2012 McQuain Prerequisites for Eclipse To use Eclipse you musthave an installed version of the Java Runtime Environment (JRE). The latest version is available from java.com. Since Eclipse includes its own Java compiler, it …

Tags:

  Eclipse, Java, Debugging, Eclipse debugging

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Debugging in Eclipse Debugging 1 - Undergraduate Courses

1 Debugging1 Data Structures & AlgorithmsCS@VT 2012 McQuainDebugging in EclipseWe are built to make mistakes, coded for ThomasIt is one thing to show a man that he is in error, and another to put him in possession of the LockeDebugging2 Data Structures & AlgorithmsCS@VT 2012 McQuainPrerequisites for EclipseTo use Eclipse you must have an installed version of the java Runtime Environment (JRE).The latest version is available from Eclipse includes its own java compiler, it is not strictly necessary to have a version of the java Development Kit (JDK) installed on your computer. However, I recommend installing one anyway so that you can test your code against the "real" java latest version is available from: you install the JDK, I recommend putting it in a root-level directory, and making sure there are no spaces in the pathname for the Structures & AlgorithmsCS@VT 2012 McQuainEclipse WorkbenchThe initial Eclipse Workbench (my configuration).

2 Restore ViewMinimize ViewMaximize ViewRestore ViewHover for info%Debugging4 Data Structures & AlgorithmsCS@VT 2012 McQuainEclipse java Perspective ToolbarChoose a PerspectiveNew Project / Save / Save All / PrintBuild ProjectStart Debugging + configurationsRun Project + configurationsRun Last Tool + configurationsDebugging5 Data Structures & AlgorithmsCS@VT 2012 McQuainEclipse java Perspective ToolbarNew java Project / Package / ClassOpen Type / Open Task / Search + optionsGo to last edit locationBack/Next + more navigation optionsDebugging6 Data Structures & AlgorithmsCS@VT 2012 McQuainCreating a New java ProjectIn the Workbench, select File/New/ java Project:Debugging7 Data Structures & AlgorithmsCS@VT 2012 McQuainCreating a New java ProjectIn the resulting dialog box:Enter a name for the now, just take the defaults for the remaining Nextand then Finishin the next Structures & AlgorithmsCS@VT 2012 McQuainAdding Source for the DList ExampleDownload the file the course website Resources page, and place the contents into the srcdirectory for the Eclipse project you just created:Debugging9 Data Structures & AlgorithmsCS@VT 2012 McQuainPerforming a BuildBack in Eclipse , right-click on the project icon for DListand select the Projectmenu or click on the Build All button ( ) to compile the Structures & AlgorithmsCS@VT 2012 McQuainRunning the ProgramTo execute the program, click on the Run button ( ).

3 As indicated by the source code, the test driver writes its output to a file named :Unfortunately, there appears to be an error; the value 5 should have been added to the list and appear in the final listing of the it's not of initial listdisplay of list after deleting 5display of list after reinserting 5 Debugging11 Data Structures & AlgorithmsCS@VT 2012 McQuainControlling ExecutionNow, we have some clues about the error: The list appears to be OK after the first forloop completes; that doesn't indicate any problems with the add()method called there. The list appears to be OK after the call to the removeFirstOccurrenceOf()method; that doesn't indicate any problems there. The list is missing an element after the call to the second add()method; that seems to indicate the problem lies It would be useful to be able to run the program to a certain point, check the state of the list (and perhaps other variables), and then step carefully through the subsequent execution, watching just how things , Eclipse provides considerable support for doing just Structures & AlgorithmsCS@VT 2012 McQuainKinds of BreakpointsA breakpointmarks a location or condition under which we want the program's execution to be supports setting four kinds of breakpoints.

4 Line breakpointhalt when execution reaches a specific statementmethod breakpointhalt when execution enters/exits a specific methodexpression breakpointhalt when a user-defined condition becomes true, or changes valueexception breakpointhalt when a particular java exception occurs (caught or not)Debugging13 Data Structures & AlgorithmsCS@VT 2012 McQuainSetting a Line Breakpointline breakpointhalt when execution reaches a specific statementTo set one, just double-click in the editor margin next to the selected line of code:Debugging14 Data Structures & AlgorithmsCS@VT 2012 McQuainRunning to a BreakpointGo to the Runmenu and select Debug(or use the keyboard shortcut F11):Debugging15 Data Structures & AlgorithmsCS@VT 2012 McQuainDebug PerspectiveThis opens the Debug Perspective:You may see a different window layout; feel free to close other Views, like Outline if they are stackSourceDebugging16 Data Structures & AlgorithmsCS@VT 2012 McQuainUsing the Variables ViewAt this point, the list constructor has let's examine the structure:Objects are assigned unique IDs as they are created; these allow us to infer the physical Structures & AlgorithmsCS@VT 2012 McQuainUsing the Variables ViewExamine the values of the fields of frontand rear:OK, that looks just two guard nodes pointing at each other, neither holding a data : list28: : Structures & AlgorithmsCS@VT 2012 McQuainThe Debug Toolbar1.

5 Resume Continues execution until breakpoint or thread ends2. Suspend Interrupts a running thread3. Terminate Ends the execution of the selected thread4. Disconnect Disconnect from a remote Debugging session5. Remove terminated launches Closes all terminated debug sessions6. Step Into Steps into a method and executes its first line of code7. Step Over Executes the next line of code in the current method8. Step Return Continues execution until the end of the current method (until a return)9. Drop to Frame Returns to a previous stack with Filters Continues execution until the next line of code which is not filtered out1 2 3 4 5 6 7 8 9 10 Debugging19 Data Structures & AlgorithmsCS@VT 2012 McQuainStep-by-step ExecutionFor illustration, we'll examine the insertion of the first data node, step by step:Note the appearance of the variable iand its Structures & AlgorithmsCS@VT 2012 McQuainStep-by-step ExecutionClick the step-intobutton again.

6 Now we'll enter the call to add():Now, I don't really want to trace the constructor, much less the call to new, so this time I'll click the Structures & AlgorithmsCS@VT 2012 McQuainStep-over versus Step-intoThe difference is that if you are executing a method call (or invoking new, for example) in the current statement:step-intotakes you into the implementation of that methodstep-overcalls the method, but does not step you through its executionBoth are step-into is frustrating when system code is Structures & AlgorithmsCS@VT 2012 McQuainStep-by-step ExecutionSo, we see that the needed node has been properly initialized:Debugging23 Data Structures & AlgorithmsCS@VT 2012 McQuainStep-by-step ExecutionThree clicks on step-over(or step-into) bring us to this point:Debugging24 Data Structures & AlgorithmsCS@VT 2012 McQuainChecking the List Structure36: , that looks : list28: : Structures & AlgorithmsCS@VT 2012 McQuainResetting Breakpoints and ResumingOK, we've confirmed that the first data node is inserted properly.

7 Now we can remove the breakpoint at the forloop, and set one at the call to the removeFirstOccurrenceOf()method, and then click Resumeto continue execution:Debugging26 Data Structures & AlgorithmsCS@VT 2012 McQuainAfter ResumingA the List is ConstructedExecution proceeds to the new breakpoint:Debugging27 Data Structures & AlgorithmsCS@VT 2012 McQuainComplete List Structure2826: list30363747454353014569 Debugging28 Data Structures & AlgorithmsCS@VT 2012 McQuainStep Into removeFirstOccurrenceOf()Use step-intoand proceed to the whileloop that will walk to the first occurrence of the target value:Debugging29 Data Structures & AlgorithmsCS@VT 2012 McQuainIn removeFirstOccurrenceOf()Continue stepping until currentreaches the node holding the target value:Debugging30 Data Structures & AlgorithmsCS@VT 2012 McQuainAt End of removeFirstOccurrenceOf()Continue stepping through the ifstatement and examine the list structure right before the returnis executed:Debugging31 Data Structures & AlgorithmsCS@VT 2012 McQuainList DetailsDoes the list structure seem to be OK?

8 2826: list30363747435301469 Debugging32 Data Structures & AlgorithmsCS@VT 2012 McQuainBuggered List Structure (more detail)A careful examination indicates that something odd has happened:OK??474346455 Apparently the removal method did not correctly reset the prevpointer in the node after the node that was removed from the should check Structures & AlgorithmsCS@VT 2012 McQuainAnother ErrorA careful examination also reveals another bugDebugging34 Data Structures & AlgorithmsCS@VT 2012 McQuainA Look at the CodeIt should be obvious that two statements are missing from the given codeDebugging35 Data Structures & AlgorithmsCS@VT 2012 McQuainTesting Againdisplay of initial listdisplay of list after deleting 5display of list after reinserting 5 Let's execute the modified program:Now, the list contents seem to be so, more testing is in Structures & AlgorithmsCS@VT 2012 McQuainMethod Breakpointsmethod breakpointhalt when execution enters and/or exits a selected methodTo set one, just double-click in the editor margin next to the method header.

9 By default, this causes a break when execution enters the Structures & AlgorithmsCS@VT 2012 McQuainBreakpoint ViewGo to Window/Show Viewand open the Breakpoint can right-click on a selected breakpoint to alter its properties:Debugging38 Data Structures & AlgorithmsCS@VT 2012 McQuainBreakpoint View Toolbar1 2 3 4 5 6 7 8 91remove selected breakpoints2remove all breakpoints3show breakpoints4go to file for breakpoint5skip all breakpoints6expand all (details)7collapse all (details)8link with the Debug View9set a java exception breakpointDebugging39 Data Structures & AlgorithmsCS@VT 2012 McQuainException Breakpoints


Related search queries