Step 8.4: Breakpointing a program


Step 8.4: Breakpointing a program

click to expand

Setting a breakpoint is quite easy (although it takes some fine motor control). You'll notice a gray column to the left of your source code in the editor. That is the breakpoint, or debug, column. If you right-click in that column just to the left of the desired source code line, a popup menu will appear, allowing you to, among other things, add a breakpoint. If a breakpoint already exists at that location, you will be able to remove or modify it (for example, enabling the breakpoint on a specific condition). Since no breakpoint exists, the Add Breakpoint option will be enabled. Select it to add the new breakpoint.

q 8.4(a) Right-click on the debug column to the left of the for loop.

q 8.4(b) Select Add Breakpoint.

click to expand
Figure 8.26: Click on the gray column next to your for loop and select Add Breakpoint.
Note  

A small blue ball will appear next to the line that has a breakpoint. However, setting a breakpoint is not sufficient to debug a program. You must also run the program in debug mode. This is done by using the Debug tool rather than the Run tool.

click to expand

To run the program in debug mode, you use the Debug tool in the main tool bar. The Debug tool works very much like the Run tool; it remembers the last thing you ran and assumes that you will be running the same thing this time. So, since the last thing you ran was indeed HelloWorld2, you can now just press the Debug tool.

To be sure you are running the right program, roll your mouse over the Debug tool, and you'll see the tool tip pop up with the text "Debug HelloWorld2". If it does not, you can always use the Debug dropdown, which works the same way as the Run tool's dropdown.

q 8.4(c) Click the Debug tool button.

click to expand
Figure 8.27: The Debug tool will default to the last thing you ran, which in this case is HelloWorld2.

Things now get interesting! Where in the world did all these windows come from? Well, this is the Debug perspective, which I introduced you to in Step 6. It is now here in full force, with all the windows full of goodies .

Figure 8.28 shows the default Debug perspective, with five windows. The bottom three are actually brought over from the Java perspective, but the top two are brand new.

click to expand
Figure 8.28: The many views of the Debug perspective.
  1. The Debug window, which shows the state of all processes, living or dead, on the machine.

  2. The Display window. This particular window has several stacked views that you can use to interact with the program. By default, it shows the Variables view.

    C., D., & E. The Editor, Outline, and Console views. These are actually all from the Java perspective, just resized and repositioned a bit.

click to expand
Figure 8.29: The Debug view.

The Debug view shows the various processes running (or no longer running). You can see the current one, which starts at the third line down, marked "HelloWorld2 [Java Application]". You'll see several threads, including three marked System Thread and one marked just Thread [main]. That one has an additional notation, (Suspended (breakpoint at line 5 in HelloWorld2)). which indicates that the thread is stopped at a breakpoint. Line 5 is the breakpoint, and you'll see that line indicated in the source display (Editor view) by a small blue arrow.

click to expand
Figure 8.30: The Variables view.

This view shows the variables. You can not only inspect the contents of any variable; you can also interact with them, changing the contents. You will use this view in a moment to change the count variable. The Variables view shares this window with several other views. The Breakpoints view is used to manage breakpoints, and the Expressions and Display views can be used to do more detailed analysis of variables, even invoking methods if necessary.




Eclipse
Eclipse: Step by Step (Step-by-Step series)
ISBN: 1583470441
EAN: 2147483647
Year: 2003
Pages: 90
Authors: Joe Pluta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net