Presentation is loading. Please wait.

Presentation is loading. Please wait.

Debugging Techniques.

Similar presentations


Presentation on theme: "Debugging Techniques."— Presentation transcript:

1 Debugging Techniques

2 Overview Visibility into VM state VM state is also mutable
Lots of tools for altering execution

3 Hot Swap Replace the code for a given class within a running VM
Swap out the body of a method Can’t change class hierarchy or class “shape” Can only replace loaded classes, not load new ones Must wait for class file to be loaded Lost when VM is restarted Methods currently on the stack will run with their original code

4 Breakpoint Types Line Method Standard, most commonly used
Stop on method entry or exit Can be set at the interface or superclass level Excruciatingly slow in IntelliJ

5 Breakpoint Types Watchpoint Exception
Stop on member variable access or modification Very useful when you don’t know where a value is being set Access option is rarely used Exception Stop when an exception is thrown Stops for subclasses being thrown as well

6 Breakpoint Conditions
Expression that must evaluate to true or the breakpoint is skipped Much faster than stopping, inspecting, and continuing But not really fast enough for code that’s executed thousands of times Can include method calls

7 Breakpoint Options Instance filter Pass count Suspend policy
Only stop if a particular object is the “this” pointer Pass count Skip the first n instances of the breakpoint, then enable Suspend policy Stop all threads Stop single thread Don’t stop any threads Log any expression to the console instead

8 Watch Window Supports essentially any Java statement/expression
Use it aggressively to call methods instead of poking through data structures To invoke methods, must be on a breakpoint or step (not paused)

9 Watch Window Tricks Runaway thread (infinite loop, etc)
Set a breakpoint in that thread Set a local or member variable to null Continue NPE stops thread Test development Set breakpoint on current last line of test code Write the next line of code in the watch window Once you get it right, move into the test itself Repeat

10 Watch Windows Tricks Cache busting Exception logging
Set a breakpoint on the line of code that checks for a cached value Set a watch that clears the entire cache, or removes that item Step through code that reloads the cache Exception logging Sometimes exceptions are completely swallowed Set a breakpoint with exception in scope Call e.printStackTrace(), view the stack in the console

11 Misc Selective Step-Into Pop stack frame
Shift-F7 lets you choose target method on the current line Avoid the step into/out repeats to get to your desired destination Pop stack frame Immediately exit the current method VM will re-invoke the same method Any side effects have already happened, but local variables are reset


Download ppt "Debugging Techniques."

Similar presentations


Ads by Google