![]() |
![]() |
VisualAge for Java includes an integrated visual debugger with a rich set of features. This section outlines some of these features.
You can open the debugger manually by selecting Debug, Debugger from the Window menu. If a program is running, you can suspend its thread and view its stack and variable values. Alternatively, the debugger will automatically open, with the current thread suspended, for any of several reasons:
When a program is running in the IDE and encounters a breakpoint, the running thread is suspended and the Debugger browser is opened so that you can work with the method stack and inspect variable values. In the IDE, you can set breakpoints in any text pane that is displaying source. Suppose that you want to set a breakpoint in the writeToDoFile method in the ToDoList class from the To-Do List program.
To set this breakpoint:
dataOutStream.write(fillList.get(i)+crlf);
You can also set a breakpoint on a line that does not already have a breakpoint by following these steps:
To remove a breakpoint in a source pane, double-click on the breakpoint indicator. You can also remove a breakpoint by following these steps:
Try removing the breakpoint you just set. Now reset it. You will be using this breakpoint in the next section to examine the features of the Debugger browser.
The Debugger browser opens automatically when the program you are executing reaches an active breakpoint or has an unhandled exception.
Now that we have set a breakpoint, let's run the To-Do List program to see what happens:
The thread you are debugging is selected in the All Programs/Threads list. The list of methods below the thread is the current stack. When you select a method in the stack the Visible Variables pane shows its visible variables. The Source pane shows the source where the breakpoint is set.
This value of the loop counter is exactly what you would expect after the loop has been executed once.
for (int i = fillList.getSize()-1; i >= 0; i--) {
Make this change in the Source pane of the Debugger page, and then select Save from the Edit menu.
Before you continue, return to the Breakpoints page and enable your breakpoints again by clicking the Global Enable Breakpoints button into the down position.
The debugger has many other features that you will find helpful for debugging your programs. To learn more about the following tasks, as well as others, see the online help for the integrated debugger.
Set conditional breakpoints
Sometimes you want a breakpoint to suspend the thread only under certain
conditions. A breakpoint can be configured so that an expression is evaluated before the
debugger decides to suspend execution. If the expression includes a boolean that evaluates
to true, the breakpoint suspends execution as usual. If it evaluates to false, the
breakpoint is ignored.
To configure a breakpoint, click mouse button 2 on its symbol in the margin of a source pane. Select Modify from the pop-up menu. Enter the expression in the field. See the online help for the integrated debugger for more details on configuring breakpoints.
Set external and caught exception breakpoints
Besides setting breakpoints in code in the workspace, you can also set
breakpoints on methods in external classes (classes that reside outside the workspace, in
the file system, and that are loaded at run-time). You can also specify exception types
that will break execution if they are thrown, even if your code catches and handles them.
See the online help for the integrated debugger for more details on external breakpoints
and breakpoints on caught exceptions.
Step through code
When a running thread has been suspended, you can step through code line by line
or method by method, in a variety of ways. This is a controlled way of checking variable
values at each point in your program.
Using inspectors to view and modify variables
You can open an inspector window to look closely at a particular variable in a
suspended thread. The inspector lets you view and modify variable values and evaluate
expressions.
![]() |
![]() |