Intro | Perspectives | Projects | Tips&Tricks | UML
Debugging a project
Using the debug button -
As in the case of running a project, you can debug by using the debug button (a small bug icon) on the toolbar or choosing Run | Debug Last Launched from the menu. If other projects have been debugged, pressing the debug button will begin debugging the last project that was debugged. Or, by pressing the small down arrow next to the debug icon, you can choose from a list of previous debugged projects. Above, the small down arrow icon has been pressed. A number of past projects are displayed, with the default project listed at the top (MicroArchitecture). If the current project is MicroArchitecture, you can click that choice (or you could have pressed the debug button). If you are working on a project that does not appear in the list, choose Debug As and then Java Application (assuming the project is not an Applet or JUNIT Test).
Important - if you have not defined any breakpoints, the project will execute to the end. If breakpoints exist, the code will execute up to the first breakpoint that is encountered. (See graphics below.)
The Debug Perspective
When you begin the debugger, the debug perspective will open, changing the screen layout (above). The debug perspective button (with a bug icon) appears near the upper left edge of the window (the perspectives toolbar). (Note: this is not the same as the debug button that you find along the top toolbar.) You can press the "J" button to return to the Java editing perspective (but don't forget to terminate the debugger if you don't plan to continue later). To remove the debug perspective button, right click and choose close. However, you can keep that button in view if you wish.
In the picture above, look at the top of the Debug panel (just below the main toolbar, under the menu). Toward the right edge, you should see a number of small buttons. The third button from the left is a square icon. Pressing that will terminate the debugger. Hover your mouse above the buttons to the right of the terminate button. You should then see the buttons for Step Into, Step Over, and Step Return. These should be the buttons you will use the most. (Step return executes the current method and returns to the method that called it.) The panel below the debug panel shows the source code and the current line, about to be executed. In this example, a breakpoint was defined on the "System.out..." line. When the debugger began, it executed and stopped at this line. The upper right panel displays the variables in scope and their values. Keep an eye on this panel as you step through a program.
Setting breakpoints
There are several ways to define breakpoints - a simple method is to open the editor and double left-click on the left margin on the line you wish to define. An alternate method is to single right-click and choose add breakpoint or disable breakpoint from the popup menu. Double left-clicking on a current breakpoint will disable it.
Starting debug - a review.
The best way to start debugging is to do the following (we assume here that you have not yet defined any breakpoints):
Look for the Variables panel to view attribute values as you step though the code.