Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

17
Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse

Transcript of Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Page 1: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Copyright © 2004 – 2013 Curt Hill

Java Debugging

In Eclipse

Page 2: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 3: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 4: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 5: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 6: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Java Perspective

Copyright © 2004 – 2013 Curt Hill

Page 7: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Debug Perspective

Copyright © 2004 – 2013 Curt Hill

Page 8: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 9: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Debug Button

Copyright © 2004 – 2013 Curt Hill

Page 10: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 11: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Setting

Copyright © 2004 – 2013 Curt Hill

Page 12: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Copyright © 2004 – 2013 Curt Hill

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

Page 13: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 14: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Variable Tab

Copyright © 2004 – 2013 Curt Hill

Page 15: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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

Page 16: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

Copyright © 2004 – 2013 Curt Hill

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)

Page 17: Copyright © 2004 – 2013 Curt Hill Java Debugging In Eclipse.

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