blob: 0de9458ff9ba43bab03e72adb1626efda963723e [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2007. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
<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/editor_vectortest_debug.png" 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> </p></li>
<li> In the Package Explorer view, select the <em>junit.samples</em> package
and select <strong>Debug As</strong>, and then <strong>Java
Application</strong>.&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</em> item in the dialog,
then click <strong>OK</strong>.
<p> <img src="images/select_java_app_dialog.png" alt="Type selection dialog"> </p>
<p><em>Note: You can also simply hit the debug button <img src="images/debug_button.png" alt="Debug button">
which will launch the currently selected resource or active editor. Select
<strong>Java Application </strong>when you are prompted to select a way
to debug VectorTest.</em></p>
<p><img src="images/select_how.png" alt="Select way to debug VectorTest"></p>
</li>
<li> The program will run until the breakpoint is reached.&nbsp; When the breakpoint is hit, execution
is suspended, and you are asked whether to open the Debug perspective. Click <strong>Yes</strong>.
Notice that the process is still active (not terminated) in
the Debug view. Other threads might still be running.
<p> <img src="images/workbench_debug_vectortest.png" alt="Debug perspective"> </p>
<em>Note: The breakpoint now has a checkmark overlay <img src="images/active_break_point.png" alt="Breakpoint with overlay"> since the class
VectorTest was loaded in the Java VM.</em> </li>
<li> In the editor in the Debug perspective, select <code>new Vector()</code> from the line above
where the breakpoint is set, and from its context menu, select <strong>Inspect</strong>.
<p> <img src="images/editor_vectortest_inspect.png" alt="VectorTest.java editor with selected breakpoint line showing context menu">
</p>
</li>
<li> The expression is evaluated in the context of the current stack frame,
and a pop-up appears which displays the results. You can send a result to
the Expressions view by pressing the key binding displayed in the pop-up.
</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 this.fFull tree in the Variables view until you can see
elementCount.
</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> (<img src="../images/org.eclipse.debug.ui/elcl16/stepover_co.png" alt="Step Over" >) 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).
<p> <img src="images/view_variables_1.png" alt="Variables view"> </p>
</li>
<li>In the variables view you can choose to see certain types as logical structures. This hides the implementation details of a
type and simply shows it as arrays or fields. You can define logical structures by yourself in the preference page <strong>Java &gt; Debug &gt; Logical Structures</strong>.
<p> <img src="images/view_variables_logical_structures.png" alt="fFull shown as logical structure"> </p>
</li>
<li> Try some other step buttons
(<strong>Step Into <img src="../images/org.eclipse.debug.ui/elcl16/stepinto_co.png" alt="Step Into" >,
Step Return <img src="../images/org.eclipse.debug.ui/elcl16/stepreturn_co.png" alt="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>
(<img src="../images/org.eclipse.debug.ui/elcl16/resume_co.png" alt="Resume" >) 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 class="nav_footer" id="nav_footer">Next Section: <A href="qs-14.htm">Evaluating expressions</A>
</P>
<p><img border="0" src="../images/ngrelc.png" alt="Related concepts" ><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.png" alt="Related tasks" ><br>
<a href="../tasks/task-add_line_breakpoints.htm">Adding breakpoints</a><br>
<a href="../tasks/task-resuming_threads.htm">Resuming the execution of suspended threads</a><br>
<a href="../tasks/task-running_and_debugging.htm">Running and debugging</a><br>
<a href="../tasks/task-suspending_threads.htm">Suspending threads</a></p>
<p><img src="../images/ngrelr.png" border="0" alt="Related reference"><br>
<a href="../reference/preferences/java/debug/ref-debug.htm">Debug preferences</a><br>
<a href="../reference/views/debug/ref-debug_view.htm">Debug view</a><br>
<a href="../reference/menus/run/ref-menu-run.htm">Run menu actions</a><br>
<a href="../reference/ref-toolbar-run.htm">Run and debug toolbar actions</a><br>
<a href="../reference/views/breakpoints/ref-breakpoints_view.htm">Breakpoints view</a><br>
<a href="../reference/views/console/ref-console_view.htm">Console view</a><br>
<a href="../reference/views/display/ref-display_view.htm">Display view</a><br>
<a href="../reference/views/expressions/ref-expressions_view.htm">Expressions view</a><br>
<a href="../reference/views/variables/ref-variables_view.htm">Variables view</a></p>
</body>
</html>