debugging java programs using eclipse debugger
Post on 03-Feb-2016
142 Views
Preview:
DESCRIPTION
TRANSCRIPT
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 1/30
DEBUGGING JAVA DEBUGGING JAVA PROGRAMS USING PROGRAMS USING
ECLIPSE DEBUGGERECLIPSE DEBUGGER
SPECIAL JAVA SUBJECTSPECIAL JAVA SUBJECT
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 2/30
OverviewOverview What is a debugging
Debugging is the process of locating the source of programming errors (often called bugs) and correcting them
What is a debugger? Set of tools that let us:
Pause a running program at any point Examine the contents of the variables
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 3/30
OverviewOverview Why a debugging?:
Debug our code (Why isn’t it working) Get a better understanding of Java and OOP
Required debugging skills: Understanding a break point Stepping througth a program Examining the contents of program variables
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 4/30
OverviewOverview Basic debugging steps:
Switch to the Debug Perspective Set one or more Breakpoint(s) Run the Debugger (debug as program) Step Over a Method Call. Step Into a Method. Step return Inspecting Variables. Debugging into Java Classes. Review the Method Call Stack.
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 5/30
Load project from achive (.zip) fileLoad project from achive (.zip) file
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 6/30
Show line numbersShow line numbers
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 7/30
Starting a debug sessionStarting a debug session
1. Tell debugger where to pause2. Run program in debug mode:
Set breakPoints Debug as Java Application
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 8/30
Starting a debug sessionStarting a debug session
Shaded area
Breakpoint marker
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 9/30
Eclipse Debug PerspectiveEclipse Debug Perspective
Debug Toolbar
Debug view (panel)
Debug Perspective
Java Perspective
Editor (source) view
Variable/Breakpoint view
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 10/30
Debug ToolBarDebug ToolBarResume
Suspend
Terminate
Step Into
Step Return
Step Over Drop to Frame
Step Filters
Resume : Execute the program until it ends, or until a breakpoint
Suspend: Pause an executing program; it is almost never used (except to stop an infinite loop).
Terminate: Terminate a debugging session; we can always start a new debugging session by rerunning the program: that is, by clicking the debug button.
Step Into: Stop at the first Java statement inside a call to the method in the line about to be executed;
Step Over: Execute one Java statement; Step Return: Execute all Java statements until the end
of a method;
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 11/30
Part 1Part 1 Switch to the Debug Perspective Set one or more Breakpoint(s) Run the Debugger (debug as program) Step Over a Method Call. Step Into a Method. Step return Review the Method Call Stack (FILO).
Example: Class: MyLibrary Method: main
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 12/30
Part 2Part 2 Examine variable content
Resume Button Run to Line (CTRL-L) Expression view Variable view Display view Console view Watch -> Expression Display (CTRL-SHIFT-D) Inspect (CTRL-SHIFT-I)
Example: Class: MyLibrary Method: main
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 13/30
Add Watch ExpressionAdd Watch Expression
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 14/30
Watch and Display ViewsWatch and Display Views
Inspect
Expression
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 15/30
Part 3Part 3 Debugging MyLibrary class
Debug as JUnit Test (/test/MyLibraryTest.class) Method check out
Add Java Exception BreakPoint Executing code while debugging Adding watch expressions Modifying code while debugging
Select Closing Element (Expression):ALT-SHIFT-UP/DOWN
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 16/30
Add Java Exception BreakPointAdd Java Exception BreakPoint
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 17/30
BreakPoint PropertiesBreakPoint Properties
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 18/30
Preferences ConfigurationPreferences Configuration
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 19/30
Part 4Part 4
Hit counts and conditional Breakpoints checkIn method
Class BreakPoints and WatchPoints Suspend command Step into Selection
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 20/30
Hit countsHit counts
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 21/30
Conditional BreakPointsConditional BreakPoints
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 22/30
WatchPointWatchPoint
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 23/30
Step into SelectionStep into Selection
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 24/30
Test Object ReferenceTest Object Reference
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 25/30
Debugging into Java ClassesDebugging into Java Classes Attaching source code allows us to browse
source code but not debug into source code To debug Java Classes, need special version of
Java Runtime Engine (JRE) This version is included with JDK 1.6
(“C:\Program Files\Java\jdk1.6.0\jre”) Need to configure Eclipse to use this special JRE Test method: addBook
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 26/30
Configure Eclipse Configure Eclipse
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 27/30
Configure EclipseConfigure Eclipse
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 28/30
Configure EclipseConfigure Eclipse
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 29/30
Configure EclipseConfigure Eclipse
Khoa CNTT – ĐH Nông Lâm TP. HCM 05/2008 30/30
Step FilterStep Filter
top related