Saturday, September 14, 2013

Use Your Tools - Eclipse Debugging

One of the things I love about pair programming is I get to learn from others on how they use their tools. Some of these are simple, but I wanted to share some of the ones I have found useful.

And since one of the main reasons of using an IDE is to debug code, I decided I would start there.

Drop to Frame. I just discovered this one recently and it makes debugging so much easier. In the debug window if you right click the point where the Thread is suspended you see a menu option Drop to Frame. Its not clear from the name what it does but if you are stepping through the code and want to go back it drops to the beginning of the stack frame. The eclipse notes that not all VMs will support it, but if it does it saves me so much time when I step past my breakpoint.

Attaching source code. I'm surprised at the number of people working with open source code that don't step into the code to find out what its doing. If your jars don't have the source included you can still include it. In the Java Build Path window, go to libraries and expand some of the jars, double click Source Attachment and browse to a path where you have the source code. Just make sure that you are using the same version as the compiled code.

Breakpoint properties. Ever have to set a breakpoint in a loop and step through until you get to the iteration you are interested in. If you right click or Ctrl + double click on a breakpoint and go to properties, you can set a hit count property to break on. You can also set a conditional or break when a value changes. If you need to break on a certain error or when a certain class loads you can set those breakpoints from the Run Menu.

Variables Window. This window is probably the most known, you can see all the variables declared. Some people seem surprised that you can even change the value of variables on the fly here.You can also navigate to the variable type and declaration. There are other options on the view menu for things like showing constants or references.

Display Window. I can't understand why this is not loaded by default, but its not. So go to Window->Show View->Other and Search for Display. I like it because I can use intellisense, inspect variables and even execute code, and then copy and paste working code back into my IDE.

These are just a few of the ones I think are useful, I'm sure there are many more. If you know of any other useful ones feel free to share it in the comments.

Also I'm using Eclipse Juno for this and if you want more details on some of these views or features of the IDE the Eclipse Reference Docs is actually pretty good.