Sunday, October 23, 2011

Conditional breakpoints in Eclipse

There is a very useful feature in many IDEs, that makes bug fixing much easier. I'm talking about conditional breakpoints. But unfortunately in Eclipse IDE its location is quite unintuitive
So to put conditional breakpoint you should:
  1. Put usual breakpoint. It may be done by clicking on the left margin of the editor or pressing Ctrl+Shift+B while you're on the line.
    Figure 1. Breakpoint marker in the left margin of the editor
  2. Right click on the breakpoint marker int the editor's left margin and select "Breakpoint properties..."
  3. In the appeared window tick "Conditional" and enter your condition in the editor. Note that key assist is available in this editor. 
  4. Figure 2. Breakpoint properties window configured for conditional breakpoint
    • If you want to stop every time expression returns true then select "Suspend when 'true'"
    • If you want to stop only when expression changes its value then select "Suspend when value changes"
  5.  Press OK. Note the breakpoint marker has changed.
Figure 3. Conditional breakpoint marker in the left margin of the editor