Debugging the TicTacToe Applet
- Start the appletviewer in "-debug" mode, specifying an HTML
file with the applet to debug. If you have problems, make sure you can
first run the applet without the "-debug" flag. jdb will start,
and report that the sun.applet.AppletViewer class is loaded.
- Type "threads" to show the thread running at startup.
- Type "run" to start the AppletViewer.
- After the TicTacToe applet is displayed, type threads again.
This time, two threadgroups will be displayed: one for the AppletViewer
and one for the TicTacToe applet. Although all threads are running, try
examining the threads and classes as in the previous tutorial.
- To set a breakpoint, type "stop in TicTacToe.mouseUp". The
"stop in" command sets a breakpoint at the first Java bytecode in the
specified method. The "stop at <class:line>" will stop at the
first bytecode generated by a particular line in a Java source file.
- Click on a square in the TicTacToe applet. jdb will stop
the applet's execution at the breakpoint just set. Type "where"
to show the applet's stack. Type "threads" to see that the
current thread is at a breakpoint, and the other threads suspended.
- Type "step" to execute the first line in mouseUp(). Notice how
it entered the status() method. Step again to execute additional lines.
- Type the "use" command to see the path list jdb uses to
find source files (by default, the classpath). Type "list" to view
the current source. If TicTacToe.java isn't in your class path, change
the source path list using "use <path list>".
- Type "up" to examine the previous stack frame (mouseUp()).
Type "list" again to view its source." Type "down" to go
back to the status() stack frame.
- To see the local variables, type "locals", or the name
of the variable (use "this" to print the object whose method we are stopped
in). If no local variables are available, try this tutorial again after
re-compiling the TicTacToe applet using the "-g" option.
- Type "cont" to continue execution from the breakpoint. Click
another TicTacToe square to show that the breakpoint is still active.
- The breakpoint message shows the line number of the breakpoint. Try
clearing that breakpoint with "clear TicTacToe <line number>.
Type "cont" and click another TicTacToe square to verify that the
breakpoint is cleared.
- Congratulations! You are now a serious Java developer.
Copyright © 1995, Sun Microsystems, Inc.
Last updated September 5, 1995