Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting.

Similar presentations


Presentation on theme: "©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting."— Presentation transcript:

1 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting breakpoints Stepping through the code Inspecting variables and expressions l Hot code replace

2 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 2 Slide 2 Using the debugger

3 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 3 Slide 3 The Eclipse debugger l The Eclipse Java tools include a world-class debugger. l To debug your code, you run it in debug mode. You don't have to change your code or recompile it in any way. l Right-click on the Java file, then select Debug As  Java Application (instead of Run As  Java Application).

4 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 4 Slide 4 The debug perspective Source Console Execution Stack Variables, breakpoints, expressions

5 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 5 Slide 5 Stop in main() Depending on the structure of your code, you may want to stop the debugger in the main() method. l To do this, you have to create a debug configuration, just like you would a run configuration.

6 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 6 Slide 6 Breakpoints l 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. l A method breakpoint stops when the debugger enters or exits a particular method. l You can set an exception breakpoint on a particular Java exception (caught or uncaught).

7 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 7 Slide 7 Breakpoints l 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. l You can set a hit count on a breakpoint, telling Eclipse to stop after a breakpoint has been reached a certain number of times.

8 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 8 Slide 8 1.Resume – Continues execution until breakpoint or thread ends 2.Suspend – Interrupts a running thread 3.Terminate – Ends the execution of the selected thread 4.Disconnect – Disconnect from a remote debugging session 5.Remove terminated launches – Closes all terminated debug sessions 6.Step Into – Steps into a method and executes its first line of code 7.Step Over – Executes the next line of code in the current method 8.Step Return – Continues execution until the end of the current method (until a return) 9.Drop to Frame – Returns to a previous stack frame 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

9 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 9 Slide 9 Step filtering l You can set filters in your debugging session. l This tells the debugger not to stop on certain lines of code. l 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.

10 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 10 Slide 10 Stack frames l Whenever a thread invokes a method, that invocation is added to the stack. main() called getUserInput(), which called itsAMatch(). l 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.

11 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 11 Slide 11 Inspecting variables and expressions l 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. l 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.

12 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 12 Slide 12 Re-running the debugger l 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. l Debug Last Launched (F11) does the same thing.

13 ©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 13 Slide 13 Advanced debugger features l 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. l 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.


Download ppt "©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 4 Slide 1 Slide 1 What we'll cover here l Using the debugger: Starting the debugger Setting."

Similar presentations


Ads by Google