The traditional way
Sometimes in debugging we want to trace the code at a breakpoint under certain conditions, so what we do is every time this breakpoint is hit we check manually if this the case we want to trace or not.Eclipse way !
Eclipse has a neat feature called conditional breakpoint. This feature enables you to enable the breakpoint if certain conditions is met. Now each time the breakpoint is reached, the expression is evaluated in the context of the breakpoint execution, and the breakpoint is either ignored or honored.Example
Suppose we have this sample code1: public static void initialize()
2: {
3: final List activities = getActivities();
4:
5: for (Iterator i = activities.iterator(); i.hasNext();)
6: {
7: final NestedActivity nestedActivity=(NestedActivity) i.next();
8: final SmallActivities[] smallActivities=nestedActivity.
9: getSmallActivities();
10:
11: doSomething(nestedActivity, smallActivities);
12: }
13: }
And we want to put a conditional breakpoint at line 11 before executing the doSomething(..) method to trace a nestedActivity called debugging, so here is what we do:
- Create breakpoint at line
- Right click at the breakpiont then breakpoint properties
- The properties of the breakpoint window will open
- Check Enable condition
- Write In the Condition field the expression for the breakpoint condition (notice the code assistant)
- Do one of the following:
- If you want the breakpoint to stop every time the condition evaluates to true, select the condition is 'true' option. The expression provided must be a Boolean expression.
- If you want the breakpoint to stop only when the result of the condition changes, select the value of condition changes option.
- If you want the breakpoint to stop every time the condition evaluates to true, select the condition is 'true' option. The expression provided must be a Boolean expression.