Download presentation
Presentation is loading. Please wait.
Published byLenard Hunter Modified over 9 years ago
1
Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse
2
Copyright © 2004 – 2013 Curt Hill Myth and Reality The myth says that interpreted languages make debugging very easy, while compiled languages are harder to debug The former is true –VB and most BASICs have a good debugging engine The latter is false –C/C++/Java all have good run-time debuggers We now look at the facilities of Eclipse
3
Copyright © 2004 – 2013 Curt Hill The Debugging Facilities Eclipse comes with full featured debugging: –Display variables –Breakpoints –Single stepping –Run to any location –Reset program –Run at full speed All of these are available interactively at run-time
4
Copyright © 2004 – 2013 Curt Hill Features Breakpoints –A line of code that will stop the program just before it is executed –Allows programmer to examine or change variable values Variables and expressions –Allows a variable value to be displayed, while the program is running Single step –Execute a single line of code –A whole method may be treated as a single line or entered
5
It is all in perspective Recall that Eclipse has views and perspectives –A view is a single pane –A perspective is a collection of views The debug screen is a perspective Consider the next two screens Copyright © 2004 – 2013 Curt Hill
6
Java Perspective Copyright © 2004 – 2013 Curt Hill
7
Debug Perspective Copyright © 2004 – 2013 Curt Hill
8
Debugging There are two run buttons in either Java or Debug perspective The green circle with triangle does a regular run The bug icon does a debug run –If in Java perspective, Eclipse will ask whether you wish to change to Debug perspective upon finding a breakpoint Copyright © 2004 – 2013 Curt Hill
9
Debug Button Copyright © 2004 – 2013 Curt Hill
10
Breakpoints To set a breakpoint right click on gutter of the edit pane A drop down menu should allow setting a breakpoint If a breakpoint was there it could be cleared as well A breakpoint may also be cleared in the breakpoint tab Consider the next screen Copyright © 2004 – 2013 Curt Hill
11
Setting Copyright © 2004 – 2013 Curt Hill
12
Breakpoint Found The program will not be paused until the breakpoint is encountered The program is paused, but the debugger is ready to do things The upper right pane has various tabs that will show things –As does the run menu
13
Copyright © 2004 – 2013 Curt Hill Variables In the upper right hand pane there should be tab for variables It will only show the variables and parameters for this method The universal variable for a non- static method is this Opening it will show all the properties of the class See next screen
14
Variable Tab Copyright © 2004 – 2013 Curt Hill
15
Expressions Most things that are needed may be observed with the variable tab The expressions tab allows an expressions with variables and operators to be computed and viewed Copyright © 2004 – 2013 Curt Hill
16
Shortcut keys F6 execute one line –Treat a method call as one statement F5 execute one line –Enter to the first line of the method F8 resume execution (until next breakpoint) F7 will run until the end of the current method Ctrl F2 terminates the program –Also a button (a red square)
17
Android Foibles Using the back button in the emulator, executing finish() or executing the home screen ends the program Often Eclipse does not hear about it Thus, you often have to restore the Java perspective from the Windows menu Copyright © 2004 – 2013 Curt Hill
18
Lastly This ought to be enough for now There is plenty more to know, but we are unlikely to need it for this class There are also profiling tools –This would help find where a long running program is spending too much time Copyright © 2004 – 2013 Curt Hill
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.