All of know the importance of the breakpoints during debugging. But do you know apart from setting a breakpoint on a line, there are other ways to set a breakpoint? Lets explore the breakpoints supported by Eclipse.

Line Breakpoint


This is the simplest breakpoint that everyone knows about. Double click the ruler and a breakpoint is set. Whenever that particular line is executed, the breakpoint is hit. If you want the breakpoint to be hit only certain conditions are met, then you can specify it in the breakpoint properties.

 

Line Breakpoing

Exception Breakpoint


When exceptions are passed over several layers, they are often wrapped or discarded in another exception. When you want to find out the origins of the original exception, then the Exception Breakpoint will help you. Once you add a breakpoint on an Exception (The action is available the Breakpoints view toolbar), the execution will be suspended whenever this Exception is thrown or caught.



Class Load Breakpoint


If you have troubles with classloading this might come handy. Double click the ruler in the line the class is defined. You will get a Classloading Exception. When the class is loaded, the breakpoint is triggered and you can inspect who is trying to load this class (or where is it used for the first time)



Watchpoint


You have a field, which is initialized to some value in the constructor. But during execution, you hit an NPE on that field. There are numerous places where it could have been changed and it would be a hard task to find all the places, set a breakpoint and then debug it. A Watchpoint on that field comes handy. You can break the execution not just the places where the field is modified, but also in the places where it is accessed. To add a watchpoint for a field, again double click the ruler on the line where it is declared.



Method Breakpoint


Not just fields, even methods can have a breakpoint. Again, double click the ruler, you get a method breakpoint. Now everytime this method is executed, the breakpoint will be hit. At a glance, this might sound like a useless thing, as you can always set a line breakpoint on the first line of a method. But this can break the execution even when the method exits. So if your method spans for 2000 lines with two dozen returns in there, this breakpoint is very useful to find out where and what is being returned from the method.



Printpoint


When you are able to reproduce a problem when running, but not debugging, then its potentially a race condition in a multithreaded app. Because you hit a breakpoint, you suspend that thread by default and the other threads might keep executing. It will be near to impossible to debug it and the only way to trace the race condition is to modify the code and insert sysout statements. Enter printpoint, you don't have to modify the code to do this. This is essentially a conditional breakpoint (either a Method Breakpoint or a Line Breakpoint), which has "return false" as the last statement in the condition. In this way, you get to execute the code in the condition clause, but don't have to break the execution. I wish I knew this feature when I was debugging a server bug in my previous job :-(

 

More articles :

» Creating the defacto RCP Mail application

  In many of the RCP related tips in this website and other sites, the starting point would be this one liner "Create the RCP Mail application". Instead of repeatedly this step in those tips, I've put the steps in this item. Step 1: Open the "New"...

» API Tooling Tutorial

IntroductionRecently, while fixing a bug, there was a discussion in the emails going on whether adding a new field to an interface in the API would break the binary compatibility to the existing clients. I strongly believed that only adding a method...

» Top 10 mistakes in Eclipse Plug-in Development

Having trained a lot of new comers to the Eclipse plug-in development, I've seen certain common mistakes repeated all the time. I've tried to compile a top 10 list of such common mistakes, so next time you hit them, you will know that you are not...

» Remember the State

As a rule of thumb, your application should try to remember the state across sessions. So when a user hits the close button and then opens it after few mins/days, it should present exactly in the same way where he left. In this tip, I'm going to...

» e4: First e4 RCP Application

The next big thing in Eclipse is Eclipse 4.0 dubbed as e4. It will be released in 2010. That doesn't mean that the 3.x stream will be deprecated or discontinued. The 3.x releases will go on for "few" years till everyone boards the 4.0. But clearly...

Subscribe To

Unless stated, all the text contents of this site is available under Eclipse Public License