Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger.

Similar presentations


Presentation on theme: "Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger."— Presentation transcript:

1 Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger

2 4-2 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works What we'll cover here  Using the debugger:  Starting the debugger  Setting breakpoints  Stepping through the code  Inspecting variables and expressions  Hot code replace

3 Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Using the debugger

4 4-4 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works The Eclipse debugger  The Eclipse Java tools include a world-class debugger.  To debug your code, you run it in debug mode.  You don't have to change your code or recompile it in any way.  Right-click on the Java file, then select Debug As  Java Application (instead of Run As  Java Application).

5 4-5 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works The debug perspective Source Console Execution Stack Variables, breakpoints, expressions

6 4-6 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Stop in main()  Depending on the structure of your code, you may want to stop the debugger in the main() method.  To do this, you have to create a debug configuration, just like you would a run configuration.

7 4-7 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Breakpoints  The simplest kind of breakpoint is a line breakpoint.  To create one, double-click in the margin next to a line of code.  Double-click the icon to remove it.  A method breakpoint stops when the debugger enters or exits a particular method.  You can set an exception breakpoint on a particular Java exception (caught or uncaught).

8 4-8 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Breakpoints  An expression breakpoint stops when a condition either becomes true or it changes.  An expression can be more than a simple variable name…  You can use code assist as you type an expression.  You can set a hit count on a breakpoint, telling Eclipse to stop after a breakpoint has been reached a certain number of times.

9 4-9 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works 1. 1.Resume – Continues execution until breakpoint or thread ends 2. 2.Suspend – Interrupts a running thread 3. 3.Terminate – Ends the execution of the selected thread 4. 4.Disconnect – Disconnect from a remote debugging session 5. 5.Remove terminated launches – Closes all terminated debug sessions 6. 6.Step Into – Steps into a method and executes its first line of code 7. 7.Step Over – Executes the next line of code in the current method 8. 8.Step Return – Continues execution until the end of the current method (until a return) 9. 9.Drop to Frame – Returns to a previous stack frame 10. 10.Step with Filters – Continues execution until the next line of code which is not filtered out Stepping through code 1 2 3 4 5 6 7 8 9 10

10 4-10 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Step filtering  You can set filters in your debugging session.  This tells the debugger not to stop on certain lines of code.  If you combine filters with the Step with Filters button, each step with the debugger (step into, step over or step return) will skip the filtered lines of code.

11 4-11 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Stack frames  Whenever a thread invokes a method, that invocation is added to the stack.  main() called getUserInput(), which called itsAMatch().  The Drop to Frame button lets you go backwards to the point at which a thread invoked a particular method.  Variable values are not reset to their previous state.

12 4-12 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Inspecting variables and expressions  The debugger has a variables view that shows all the variables currently in scope.  You can change the values of those variables if you want.  There's also an expressions view that lets you evaluate expressions.  These typically involve some variable in scope, but can be any Java language expression.  You can use static methods of a class not used in your code, for example.

13 4-13 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Re-running the debugger  Once you've run your code with the debugger, a reference to it appears in the Run menu. You can click your program's name in the Debug History menu to debug it again.  Debug Last Launched (F11) does the same thing.

14 4-14 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Advanced debugger features  Although the debugger that ships with the Eclipse SDK is a Java debugger, the debugger component itself can be extended.  The C Development Tools extend the Eclipse debugger to provide similar tools for C and C++ code, for example.  Eclipse also has a remote debugging feature that's very powerful.  The debugger is on one machine, the code being debugged is on another.  See eclipse.org/eclipse/faq/eclipse-faq.html #users_18 for more details on how to set up remote debugging.

15 Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Hot code replace

16 4-16 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Hot code replace  One of the coolest features of the Java debugger is the ability to replace code currently running in the debugger.  You don't have to restart the debugger or recreate the state of your program when you changed the code.  How it works:  The JVM you're using must support hot code replace (most JVMs 1.4.x and later do)  You can't do anything that changes the "signature" of a class (add or remove methods or instance variables, move it up and down in the class hierarchy, and so forth)  You typically can't change the main() method  You typically go back up the stack to whatever called the code you changed, but that's probably what you wanted to do anyway

17 4-17 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Hot code replace  Here's the console: Starting the example: Enter any string. To quit, type Quit. Quit You typed "Quit" Enter any string. To quit, type Quit. Quit You typed "Quit" Enter any string. To quit, type Quit.  Our code never exits, regardless of what we type. We'll run this through the debugger again…

18 4-18 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Hot code replace  We're stepping through the code when we realize the problem. This line: s.equals(exiting) should be: s.toString().equals(exiting.toString())  With hot code replace, we can fix the code without restarting the debugger.  As the debugging session continues, we can verify that our code change fixed the problem.

19 Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Summary

20 4-20 Making the most of © 2006 IBM Corporation. Presented by IBM developer Works Summary  We looked at the debugger in detail, including:  How to start the debugger  The different kinds of breakpoints and how to set them  Stepping through the code  Inspecting variables and expressions  How to use Eclipse's hot code replace feature


Download ppt "Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse debugger."

Similar presentations


Ads by Google