Sunday, January 20, 2013

Debugging follow-up: Eclipse

So as a follow up to my previous post, this one is more specific to where you'll find some of the tools of debugging in the IDE Eclipse. Both this and the previous post is targeted to my classmates to help them get started with debugging, but anyone that uses eclipse can check it out!

Lets start off the same place as the previous post, Breakpoints.

In Eclipse there are two simple ways of setting breakpoints. First one is to hit "Ctrl+shift+b". This will create a breakpoint on the current line your typing cursor is.
The other way is to double-click in the white space just left of the line numbers.

You can see in the picture below how there is an indication now of a blue ball on the line you've set your breakpoint on. If you right click this ball and pick breakpoint Properties... you'll get access to edit the conditional breakpoint options I mentioned in the advanced techniques on previous post.

on row 32 we can see the indication that we have a breakpoint set.

So how do we start debugging? Easy, on your toolbar you have these 3 buttons:


The middle one is the regular "build and run", the one to the right is just "run without rebuild".
But it's the one to the left we want to click to start debugging.
When we do this Eclipse tells us that it wants to change "Perspective". When we get this option, we want to press "yes". Now, DON'T PANIC! Your eclipse will change its layout.
So first, I'll tell you how to revert back. In the upper right corner you have buttons for changing the perspective or layout. the one to the very right is our debug perspective, and the one next to it is our regular coding perspective. So a perspective is just another word for "layout to fit what your current doing".

from left to right: open list of all perspective, Java EE persp(never used). Java persp., debugging persp.


We will now have some new windows to look at. One of these is the Variables window, this will show us the variables being changed in the current scope. We can also edit these values here.


If you right click a variable in the editor window of this perspective and pick "watch" you'll get another tab in this window that contains  your "watch list" of variables you want to keep watch on.

So now that we know where to look for our values and we're in debug perspective, we need to control the execution of our code. That's what these buttons in the toolbar are for:
From left to right we have: Step return (same as Step out), Step Over, and Step Into. Read my previous post to figure out what these do. The next one is the Resume button. and the last one to the right is terminate, it will shut down our program and stop debugging.

Lastly, we have a window simply called "debug". This window works as our callstack. So in the picture below we can see that we're right now in the function SetDate from the class Date that's been called from "dateTestProgram.main", the main function of our program and all of this happens in the main thread.


So there we go, you now have everything you will need to start being a more efficient coder!


No comments:

Post a Comment