blob: 8312e6a066a0fbd7fc344194c61987a39fab32aa [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css">
<title> Debugging your programs </title>
</head>
<body>
<h1> Debugging your programs </h1>
<p> In this section, you will debug a Java program. </p>
<ol>
<li> In the Package Explorer view in the Java perspective, double-click <em>junit.samples.VectorTest.java</em>
to open it in an editor. </li>
<li> Place your cursor on the vertical ruler along the left edge of the editor
area on the following line in the setUp() method:
<p> <code>fFull.addElement (new Integer(1));</code> </p>
<p> and double-click on the ruler to set a breakpoint. </p>
<p> <img src="../images/qs-68.gif" width=452 height=198 alt="VectorTest.java editor showing added breakpoint">
</p>
The breakpoint icon indicates the status of the breakpoint.&nbsp; The plain
blue breakpoint icon indicates that the breakpoint has been set, but not yet
installed.&nbsp;&nbsp;
<p>
<em>Note: Once the class is loaded by the Java VM, the breakpoint will be
installed and a checkmark overlay will be displayed on the breakpoint icon.</em> </li>
<li> In the Package Explorer view, select the <em>junit.samples</em> package
and select the Run menu. Within the Run menu, select Debug As, and then Java
Application.&nbsp; When you run a program from a package, you will be
prompted to choose a type from all classes in the package that define a <code>main
</code>method.&nbsp; </li>
<li> Select the <em>VectorTest - junit.samples - /JUnit</em> item in the dialog,
then click <strong>OK</strong>.
<p> <img src="../images/qs-69.gif" width=297 height=451 alt="Type selection dialog"> </p>
</li>
<li> The program will run until the breakpoint is reached.&nbsp; When the breakpoint is hit, the Debug perspective opens, and execution
is suspended. Notice that the process is still active (not terminated) in
the Debug view. Other threads might still be running.
<p> <img src="../images/qs-70.gif" alt="Debug perspective" width="685" height="563"> </p>
<em>Note: The breakpoint now has a checkmark overlay since the class
VectorTest was loaded in the Java VM.</em> </li>
<li> In the editor in the Debug perspective, select the entire line where the
breakpoint is set, and from its context menu, select <strong>Inspect</strong>.
<p> <img src="../images/qs-71.gif" alt="VectorTest.java editor with selected breakpoint line showing context menu" width="632" height="450">
</p>
</li>
<li> The expression is evaluated in the context of the current stack frame,
and the results are displayed in the Expressions view.
</li>
<li> Expressions that you evaluate while debugging a program will be listed in
this view. To delete an expression after working with it, select the
expression and choose <strong>Remove</strong> from its context menu.
</li>
<li> The Variables view (available on a tab along with the Expressions view) displays the values of the variables in the selected
stack frame. Expand the fFull tree in the Variables view until you can see
elementCount.
<p> <img src="../images/qs-72.gif" alt="Variables view" width="445" height="237"> </p>
</li>
<li> The variables (e.g., elementCount) in the Variables view will change when
you step
through VectorTest in the Debug view.&nbsp; To step through the code, click the <strong>Step Over</strong> button.&nbsp;
Execution will continue at the next line in the same method
(or, if you are at the end of a method, it will continue in the method from
which the current method was called).
</li>
<li> Try some other step buttons (<strong>Step Into, Step Return) </strong>to
step through the code.&nbsp; Note the differences in stepping techniques.
</li>
<li> You can end a debugging session by allowing the program to run to
completion or by terminating it.
<ul>
<li>You can continue to step over the code with the <strong>Step </strong>buttons
until the program completes.</li>
<li>You can click the&nbsp; <strong>Resume </strong>button to allow the
program to run until the next breakpoint is encountered or until the
program is completed.</li>
<li>You can select
<strong>Terminate</strong> from the context menu of the program's
process in the Debug view to terminate the program.</li>
</ul>
</li>
</ol>
<p><img border="0" src="../images/ngrelc.gif" alt="Related concepts" width="159" height="27"><br>
<a href="../concepts/cbrkpnts.htm">Breakpoints</a><br>
<a href="../concepts/cremdbug.htm">Remote debugging</a><br>
<a href="../concepts/clocdbug.htm">Local debugging</a></p>
<p><img border="0" src="../images/ngrelt.gif" alt="Related tasks" width="159" height="27"><br>
<a href="../tasks/tasks-144.htm">Adding breakpoints</a><br>
<a href="../tasks/tasks-135.htm">Resuming the execution of suspended threads</a><br>
<a href="../tasks/tasks-126.htm">Running and debugging</a><br>
<a href="../tasks/tasks-134.htm">Suspending threads</a></p>
<p><img src="../images/ngrelr.gif" width=159 height=27 border="0" alt="Related reference"><br>
<a href="../reference/ref-11.htm">Debug preferences</a><br>
<a href="../reference/ref-51.htm">Debug view</a><br>
<a href="../reference/ref-4.htm">Run and debug actions</a><br>
<a href="../reference/ref-35.htm">Breakpoints view</a><br>
<a href="../reference/ref-45.htm">Console view</a><br>
<a href="../reference/ref-52.htm">Display view</a><br>
<a href="../reference/ref-56.htm">Expressions view</a><br>
<a href="../reference/ref-74.htm">Variables view</a></p>
<p> <a href="../hglegal2003.htm"><img src="../images/ngibmcpy2003.gif" alt="Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved." border="0" height="14" width="324"></a>
</p>
</body>
</html>