Java Reference
In-Depth Information
Step completed: "thread=main", FetchURL.main(), line=48 bci=48
48 for (i = 0; i < args.length; i++)
main[1] step
>
Step completed: "thread=main", FetchURL.main(), line=53 bci=57
53 }
main[1] step
>
The application exited
$
1.
Here we tell the debugger where to break execution to let us run debugger commands.
We do so at the start of the
FetchURL
class'
main()
method. If we did not set a
breakpoint, the
run
would have run the program to termination, making it no different
from running it with the
java
command (except perhaps a bit slower).
2.
The
list
command shows the source line that is about to be executed, along with some
more lines to either side. It is a handy way to get a little context. The standard “next
line” prompt isn't enough for most of us to get context (unless, of course, we are
looking at a line-numbered printout of the source or an editor window at the same
time, which we often do).
3.
The
step
steps execution one “line” (what a line is can be a bit fuzzy when there's a
lot of vertical whitespace in the source, or when multiple method calls occur on one
line). Note the information in the status message. The name of the thread is given (our
sample is single-threaded, so it is always “main”), as is the line number in the source
file and the
bci
. Note that there is a very similar command,
next
, that advances to the
next line
in the same stack frame
. In other words, it won't step into method calls, it
steps over them.
4, 5. Here we see two uses of the
dump
command. First, we apply it to
this
(which is an
implicit argument to any nonstatic method call) to dump the currently executing ob-
ject. The second instance dumps the
rc
local variable, which is an accumulating string
containing the requested Web page. At the moment, it contains only the first few lines.
6.
Here we set a breakpoint on a specific source line number. We then use the
cont
command to resume “full speed” code execution.