Intrductin t Eclipse Using Eclipse s Debugger 16/04/2010 Prepared by Chris Panayitu fr EPL 233 1
Eclipse debugger and the Debug view Eclipse features a built-in Java debugger that prvides all standard debugging functinality ability t perfrm step executin t set breakpints and values t inspect variables and values t suspend and resume threads Additinally, yu can debug applicatins running n a remte machine. The Eclipse Platfrm is rbust in such a way that ther prgramming languages can use the debug facilities fr their respective language runtimes the same Eclipse Debug view is als available fr the C/C++ prgramming languages 16/04/2010 EPL 233 2
Eclipse debugger and the Debug view 16/04/2010 EPL 233 3
Debugging Java language prgrams Befre yu are able t debug yur prject, the cde needs t cmpile and run cleanly Yu first need t create a run cnfiguratin fr yur applicatin and make sure it starts prperly Next, yu need t set up the debug cnfiguratin in a similar way using the Run > Debug menu Yu als need t select the class t be used as the main Java class by the debugger Yu can have as many debug cnfiguratins fr a single prject as yu wish When the debugger is started (frm Run > Debug), it is pened in a new windw, and yu are ready t start debugging. 16/04/2010 EPL 233 4
Debugging Java language prgrams 16/04/2010 EPL 233 5
Setting breakpints When yu launch yur applicatin fr debugging, Eclipse switches t the Debug perspective autmatically the mst cmmn debugging prcedure is t set breakpints that will allw the inspectin f variables and the values inside cnditinal statements r lps T set breakpints in the Package Explrer view f the Java perspective walk thrugh the cde and place yur cursr n the marker bar (alng the left edge f the editr area) n the line with the suspected cde. Duble-click t set the breakpint. 16/04/2010 EPL 233 6
Cnditinal breakpints It's pssible t declare cnditinal breakpints triggered whenever the value f an expressin changes In additin, cde assist is available when typing in the cnditinal expressin 16/04/2010 EPL 233 7
Evaluating expressins T evaluate expressins in the editr in the Debug perspective, select the entire line where the prgram is stped (by a breakpint), and frm the cntext menu, select the Inspect ptin via Ctrl+Shift+I r rightclicking n the variable yu're interested in The expressin is evaluated in the cntext f the current stack frame, and the results are displayed in the Expressins view f Display windw. 16/04/2010 EPL 233 8
Scrapbking yur live cde The Display view allws yu t manipulate live cde in a scrapbk type fashin T manipulate a variable, simply type the name f the variable in the Display view, and yu'll be greeted with a familiar cntent assist 16/04/2010 EPL 233 9
Debugging running cde When the debugger stps at a breakpint, yu can cntinue the debugger sessin by selecting the Step Over ptin frm the Debug view tlbar This steps ver the highlighted line f cde and cntinues executin at the next line in the same methd (r it will cntinue in the methd frm which the current methd was called) The variables that are changed as a result f the last step are highlighted in a clr (default is yellw) Clrs can be changed in the debug preference pages. 16/04/2010 EPL 233 10
Debugging running cde T suspend the executin f threads in the Debug view, select a running thread and click Suspend in the Debug view tlbar The current call stack fr the thread is displayed, and the current line f executin is highlighted in the editr in the Debug perspective When a thread is suspended, the cursr is placed ver a variable in the Java editr, and the value f that variable is displayed in a small hvering windw Als, the tp stack frame f the thread is autmatically selected, and the visible variables in that stack frame are displayed in the Variables view Yu can examine the apprpriate variable in the Variables view by clicking its name 16/04/2010 EPL 233 11
Htswap Bug Fixing: On-the-fly cde fixing If yu are running Java Virtual Machine (JVM) V1.4 r higher, Eclipse supprts a feature called Htswap Bug Fixing (nt available in JVM V1.3 r lwer) It allws the changing f surce cde during a debugger sessin, which is better than exiting the applicatin, changing the cde, recmpiling, then starting anther debugging sessin T use this functin, simply change the cde in the editr and resume debugging This feature became available because JVM V1.4 is cmpatible with the Java Platfrm Debugger Architecture (JPDA). JPDA implements the ability t substitute mdified cde in a running applicatin If the prgram has nt fully executed when yu are dne debugging, select the Terminate ptin frm the cntext menu in the Debug view A cmmn mistake is t use Debug r Run instead f Resume while yu're in a debugger sessin This will launch anther debugger sessin rather than cntinuing the current ne. 16/04/2010 EPL 233 12
Practice Imprt the fllwing Java classes in Eclpise and debug them Circle.java Plymrph.java Regtancle.java Shape.java 16/04/2010 EPL 233 13