Java Reference
In-Depth Information
Within the debugger, you can begin executing a program with the run command. The
following output shows what the debugger displays after you begin running the
WriteBytes class:
run WriteBytes
VM Started: Set deferred breakpoint WriteBytes:14
Breakpoint hit: “thread=main”, WriteBytes.main(), line=14 bci=413
14 for (int i = 0; i < data.length; i++)
After you have reached a breakpoint in the WriteBytes class, experiment with the fol-
lowing commands:
B
list —At the point where execution stopped, this command displays the source
code of the line and several lines around it. This requires access to the .java file of
the class where the breakpoint has been hit so that you must have
WriteBytes.java in either the current folder or one of the folders in your
Classpath .
n
locals —This command lists the values for local variables that are currently in use
or will soon be defined.
n
print text —This command displays the value of the variable, object, or array
element specified by text .
n
step —This command executes the next line and stops again.
n
cont —This command continues running the program at the point it was halted.
n
!! —This command repeats the previous debugger command.
n
After trying out these commands within the application, you can resume running the pro-
gram by clearing the breakpoint and using the cont command. Use the exit command to
end the debugging session.
The WriteBytes application creates a file called pic.gif . You can verify that this file
ran successfully by loading it with a web browser or image-editing software. You'll see a
small letter J in black and white.
After you have finished debugging a program and you're satisfied that it works correctly,
recompile it without the -g option.
Debugging Applets
You can't debug an applet by loading it using the jdb tool. Instead, use the -debug
option of the appletviewer , as in the following example:
appletviewer -debug AppInfo.html
Search WWH ::




Custom Search