Debugging with Eclipse

Ofcourse Eclipse has a debugger which you can use to debug your Java applications. Like most other debuggers you can set breakpoints, view variables, use watch expressions, inspect objects and use actions like 'step into', 'step over' and so on.

But Friday I discovered another nice feature while debugging: When you change some of your code while debugging you don't need to restart your application. Eclipse simply uses your new code. Something similar is possible with the debugger of Visual Studio 6 and will be possible again in Visual Studio 2005.

Here is a, rather stupid, example to illustrate it:

I created a method 'getList()' in the class 'Foobar' which should return a List with two elements. Ofcourse i create a UnitTest for it:

Debugging with Eclipse: an Example

Now suppose i just returned a new arraylist in getList() instead of the one i created in that function. Ofcourse the test will fail:

Debugging with Eclipse: an Example

So i set a breakpoint somewhere in the method 'getList()' (ofcourse i would have discovered the reason for the bug by now, but i told you it was a stupid example ;)). And i start debugging. When the debugger reaches my breakpoint I discover my mistake:

Debugging with Eclipse: an Example

ofcourse 'return new ArrayList<Integer>();' should be 'return l;', so I change it. Then I hit Ctrl+S to save the changes and (now comes the magic) Eclipse immediately notices the changes and sets the programcounter back to the beginning of the method:

Debugging with Eclipse: an Example

When i now continue, my UnitTest succeeds :):

Debugging with Eclipse: an Example

Another cool tool that can be useful while debugging is the BugDel Plugin. With this plugin it is very easy to use AOP [Aspect Oriented Programming] during debugging. With BugDel it is very easy to add aspects to specific lines or, by example, to all your getters and setters. See the website for some cool Flash-demos.

Comments

There are no comments.

Comment Atom Feed