Finally, it's worth seeing what the Variables view can do.
execute()
method.openInformation()
call and navigate to Run | Step Into Selection.title
in the the Variables view.Hello
in the bottom half of the Variables view and change it to Goodbye
:execute()
method, highlight event in the Variables view.java.util.Date()
and the right-hand side will show the current time.java.util.Date()
and choose Re-evaluate Watch Expression. The right-hand pane shows the new value.The Eclipse debugger has many powerful features, and the ability to inspect (and change) the state of the program is one of the more important ones.
Watch expressions, when combined with conditional breakpoints, can be used to find out when data becomes corrupted or used to show the state of a particular object's value.
Expressions can also be evaluated based on objects in the Variables view, and the code completion is available to select methods, with the result being shown with Display.
Q1. How can an Eclipse plug-in be launched in debug mode?
Q2. How can certain packages be avoided when debugging?
Q3. What are the different types of breakpoints that can be set?
Q4. How can a loop debugged that only exhibits a bug after 256 iterations?
Q5. How can a breakpoint be set on a method when its argument is null?
Q6. What does inspecting an object do?
Q7. How can the value of an expression be calculated?
Using the conditional breakpoint to stop at a certain method is fine if the data is simple, but sometimes there needs to be more than one expression. To implement additional functionality, the breakpoint can be delegated to a breakpoint()
method in a Utility
class. The following steps will help you to work with breakpoints:
Utility
class with a static method breakpoint()
, this will return a true
value if the breakpoint should stop and false
otherwise:public class Utility { public static boolean breakpoint() { System.out.println("Breakpoint"); return false; } }
execute()
method, which calls Utility.breakpoint()
.breakpoint()
method to return true
instead of false
. Run the action again. The debugger will stop.breakpoint()
method to take the message as an argument, along with a Boolean value that is returned to say if the breakpoint should stop.Utility.breakpoint( ((org.eclipse.swt.widgets.Event)event.trigger).stateMask != 0,"Breakpoint")
breakpoint()
method to take a varargs Object
array, and use that in conjunction with the message to use String.format()
for the resulting message:Utility.breakpoint( ((org.eclipse.swt.widgets.Event)event.trigger).stateMask != 0,"Breakpoint" %s %h",event, new java.util.Date().getTime()))