13.07.2015 Views

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

Java™ Application Development on Linux - Dator

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

156Chapter 5The Sun Microsystems Java Software <str<strong>on</strong>g>Development</str<strong>on</strong>g> KitStep completed: "thread=main", FetchURL.main(), line=48 bci=4848 for (i = 0; i < args.length; i++)main[1] step>Step completed: "thread=main", FetchURL.main(), line=53 bci=5753 }main[1] step>The applicati<strong>on</strong> exited$1. Here we tell the debugger where to break executi<strong>on</strong> to let us run debugger commands.We do so at the start of the FetchURL class’ main() method. If we did not set abreakpoint, the run would have run the program to terminati<strong>on</strong>, making it no differentfrom 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, al<strong>on</strong>g with somemore lines to either side. It is a handy way to get a little c<strong>on</strong>text. The standard “nextline” prompt isn’t enough for most of us to get c<strong>on</strong>text (unless, of course, we arelooking at a line-numbered printout of the source or an editor window at the sametime, which we often do).3. The step steps executi<strong>on</strong> <strong>on</strong>e “line” (what a line is can be a bit fuzzy when there’s alot of vertical whitespace in the source, or when multiple method calls occur <strong>on</strong> <strong>on</strong>eline). Note the informati<strong>on</strong> in the status message. The name of the thread is given (oursample is single-threaded, so it is always “main”), as is the line number in the sourcefile and the bci. Note that there is a very similar command, next, that advances to thenext line in the same stack frame. In other words, it w<strong>on</strong>’t step into method calls, itsteps over them.4, 5. Here we see two uses of the dump command. First, we apply it to this (which is animplicit argument to any n<strong>on</strong>static method call) to dump the currently executing object.The sec<strong>on</strong>d instance dumps the rc local variable, which is an accumulating stringc<strong>on</strong>taining the requested Web page. At the moment, it c<strong>on</strong>tains <strong>on</strong>ly the first few lines.6. Here we set a breakpoint <strong>on</strong> a specific source line number. We then use the c<strong>on</strong>tcommand to resume “full speed” code executi<strong>on</strong>.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!