⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 running.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
on the current path, you can tell <CODE>jdb</CODE> to find the source with
the <CODE>use</CODE> command by giving it the source directory as a parameter.
In the following example the source is in a subdirectory or folder called
<CODE>book</CODE>.

</FONT>

<PRE>
main[1] list
Unable to find SimpleJdbTest.java
main[1] use book
main[1] list
6 		Panel p;
7 		Button b[];
8 		int counter=0;
9 
10 	=&gt; 	SimpleJdbTest() {
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>Looking at a Method</H4>
<P>

To see what happens in the <CODE>setup</CODE> method for 
<CODE>SimpleJdbText</CODE>,
use the <CODE>step</CODE> command to step through the 4 lines to
get to it.

</FONT>

<PRE>
main[1] step
main[1]
Breakpoint hit: java.awt.Frame.&lt;init&gt; (Frame:222)
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
But wait a minute! This is now the <CODE>Frame</CODE> class constructor! If you
keep stepping you follow the <CODE>Frame</CODE> Constructor and not the
<CODE>SimpleJdbText</CODE> class. Because <CODE>SimpleJdbTest</CODE>
extends the <CODE>Frame</CODE> class, the parent constructor, which
in this case is <CODE>Frame</CODE>, is called on your behalf. 

<P>
<H4>The <CODE>step up</CODE> Command</H4>
<P>

You could continue stepping and eventually you will
return to the <CODE>SimpleJdbTest</CODE> constructor, but to return immediately,
you can use the <CODE>step up</CODE> command to go back to the
<CODE>SimpleJdbTest</CODE> constructor.

</FONT>

<PRE>
main[1] step up
main[1]
Breakpoint hit: SimpleJdbTest.&lt;init&gt; 
                  (SimpleJdbTest:8)
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>The <CODE>next</CODE> Command</H4>
<P>

You can also use the <CODE>next</CODE> command to get to the
<CODE>setup</CODE> method. In this next example, the <CODE>jdb</CODE>
tool has approximated that the source line is outside
the constructor when it processed the last <CODE>step up</CODE> command. To return
to the constructor, use another <CODE>step</CODE> command, and to
get to the <CODE>setup</CODE> method, use a <CODE>next</CODE> command.
To debug the <CODE>setup</CODE> method, you can <CODE>step</CODE>
through the <CODE>setup</CODE> method.

</FONT>

<PRE>
main[1] step
Breakpoint hit: SimpleJdbTest.&lt;init&gt; 
                  (SimpleJdbTest:11)
main[1] list
7 		Button b[]=new Button[2];
8		int counter=0;
9
10 		SimpleJdbTest() {
11 			setSize(100,200);&lt;
12 			setup();
13 		}
14 		void setup (){
15 			p=new Panel();
16		}
main[1] next
Breakpoint hit: SimpleJdbTest.&lt;init&gt; 
                  (SimpleJdbTest:12)
main[1] step
Breakpoint hit: SimpleJdbTest.setup (SimpleJdbTest:15)
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>The <CODE>stop in</CODE> Command</H4>
<P>

<P>
Another way to get to the <CODE>setup</CODE> method is to use the
<CODE>stop in SimpleJdbTest.setup</CODE> command. You can list the source 
again to check where you are:

</FONT>

<PRE>
main[1] list
11 			setSize(100,200);
12 			setup();
13 		}
14 		void setup (){
15	=&gt;		p=new Panel();
16 			  b[0]= new Button("press");
17 			  p.add(b[0]);
18 			  add(p);
19
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>The <CODE>print</CODE> Command</H4>
<P>

The first thing the <CODE>setup</CODE> method does is create
a <CODE>Panel p</CODE>.
If you try to display the value of <CODE>p</CODE> with the
<CODE>print p</CODE> command, you will find that the value is <CODE>null</CODE>.

</FONT>

<PRE>
main[1] print p
p = null
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
This occurred because the line has not been executed and so field <CODE>p</CODE>
has not been assigned a value. You need to step over that assignment operation 
with the <CODE>next </CODE>command and then use the <CODE>print p</CODE>
command again.

</FONT>

<PRE>
<FONT SIZE="-1">
main[1] next

Breakpoint hit: SimpleJdbTest.setup (SimpleJdbTest:16)
main[1] print p
p = java.awt.Panel[panel0,0,0,0x0,invalid,
		     layout=java.awt.FlowLayout]
</FONT>
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>Setting Breakpoints on Overloaded Methods</H4>
<P>

Although stepping through small classes is fast, as a general rule on
larger applications, it is often a lot faster to set breakpoints. This
is partly because <CODE>jdb</CODE> has a very simple command set and no 
shortcuts, so each command has to be pasted or typed in full. 

<P>
To set a breakpoint in the <CODE>Button</CODE> class,  use 
<CODE>stop in java.awt.Button.&lt;init&gt;</CODE>

</FONT>

<PRE>
<FONT SIZE="-1">
main[1] stop in java.awt.Button.&lt;init&gt;
java.awt.Button.&lt;init&gt; is overloaded,
          use one of the following:
void &lt;init&gt;
void &lt;init&gt;java.lang.String)
</FONT>
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
The message explains why <CODE>jdb</CODE> cannot stop in this method 
without more information, but the message is slightly misleading as you 
do not need to specify the return type for overloaded methods, you just
need to be explicit about exactly which one of the overloaded methods you 
want to stop in. To stop in the 
<CODE>Button</CODE> constructor that creates this <CODE>Button</CODE>,
use <CODE>stop in java.awt.Button.&lt;init&gt;java.lang.String)</CODE>. 

<P>
<H4>The <CODE>cont</CODE> Command</H4>
<P>

To continue the <CODE>jdb</CODE> session, use the <CODE>cont</CODE> 
command. The next time the program creates a <CODE>Button</CODE> with a 
<CODE>String</CODE> as the constructor, <CODE>jdb</CODE> stops so
you can examine the output.

</FONT>

<PRE>
<FONT SIZE="-1">
main[1] cont
main[1]
Breakpoint hit: java.awt.Button.&lt;init&gt; 
                          (Button:130)
</FONT>
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
If the <CODE>Button</CODE> class had not been recompiled with debug 
information as described earlier, you would not see the internal fields 
from the <CODE>print</CODE> command.

<P>
<H4>Clearing Breakpoints</H4>
<P>

To clear this breakpoint and not stop every time a <CODE>Button</CODE> is
created use the <CODE>clear</CODE> command. This example uses the
<CODE>clear</CODE> command with no arguments to display the list of 
current breakpoints, and the <CODE>clear</CODE> command with the
<CODE>java.awt.Button:130.</CODE> argument to clear the
<CODE>java.awt.Button:130.</CODE> breakpoint.

</FONT>

<PRE>
main[1] clear
Current breakpoints set:
SimpleJdbTest:10
java.awt.Button:130
main[1] clear java.awt.Button:130
Breakpoint cleared at java.awt.Button: 130
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>Displaying Object Details</H4>
<P>

To display details about an object, use the <CODE>print</CODE> 
command to call the object's <CODE>toString</CODE> method, or use 
the <CODE>dump</CODE> command to display 
the object's fields and values. 

<P>
This example puts a breakpoint at line 17 and uses
the <CODE>print</CODE> and <CODE>dump</CODE> commands to print and 
dump the first <CODE>Button</CODE> object in the array of 
<CODE>Button</CODE> objects. 
The <CODE>dump</CODE> command output has been abbreviated.

</FONT>

<PRE>
main[1] stop at SimpleJdbTest:17
Breakpoint set at SimpleJdbTest:17
main[1] cont
main[1]
Breakpoint hit: SimpleJdbTest.setup (SimpleJdbTest:17)

main[1] print b[0]
b[0] = java.awt.Button[button1,0,0,0x0,invalid,
					label=press]
main[1] dump b[0]
b[0] = (java.awt.Button)0x163 {
private int componentSerializedDataVersion = 2
boolean isPacked = false
private java.beans.PropertyChangeSupport 
			changeSupport = null
long eventMask = 4096
transient java.awt.event.InputMethodListener 
			inputMethodListener = null
....
java.lang.String actionCommand = null
java.lang.String label = press
}
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
<H4>Ending the Session</H4>
<P>

<P>
That finishes the simple <CODE>jdb</CODE> examples. To terminate the 
<CODE>jdb</CODE> session, use the <CODE>quit</CODE> command:
</FONT>

<PRE>
0xee2f9820:class(SimpleJdbTest)
&gt; quit
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A NAME="remote"></A>
<H3>Remote Debugging</H3>

The <CODE>jdb</CODE> tool is an external process debugger, which means
it debugs the program by sending messages to and from a helper inside
the Java VM. This makes it is easy to debug a running program, and
helps you debug a program that interacts with the end user.
A remote debug session from the command-line does not interfere 
with the normal operation of the application.

<A NAME="session"></A>
<H4>Starting the Session</H4>

Before the Java 2 release, the only thing required to enable
remoted debugging was to start the program with the <CODE>-debug</CODE>
flag as the first argument, and if the application uses native libraries,
make the library name end in <CODE>_g</CODE>. For example,
you would need to copy <CODE>nativelib.dll</CODE> to <CODE>nativelib_g.dll</CODE>
to debug with that library.

<P>
In Java 2, things are a little more complicated. You need to tell the
Java VM where the <CODE>tools.jar</CODE> file is by using the 
<CODE>CLASSPATH</CODE> variable.  The <CODE>tools.jar</CODE> file
is normally found in the <CODE>lib</CODE> directory of the 
Java platform installation.

<P>
You also need to disable the Just In Time (JIT) compiler if one exists. The 
JIT compiler is disabled by setting the <CODE>java.compiler</CODE> property to 
<CODE>NONE</CODE> or to an empty string. Finally, as the <CODE>-classpath</CODE>
option overrides any previously set user classpath, you also need to add the 
<CODE>CLASSPATH</CODE> needed by your application. 

<P>
Putting all of this 
together, here is the command line needed to start a program in
remote debug mode. Put this all on one line and include all the classes
you need on the command line.

</FONT>

<PRE>
Windows:

$ java -debug -classpath C:\java\lib\tools.jar;. 
-Djava.compiler=NONE SimpleJdbTest
Agent password=4gk5hm

Unix:

$ java -debug -classpath /usr/java/lib/tools.jar:. 
-Djava.compiler=NONE SimpleJdbTest
Agent password=5ufhic
</PRE>

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

<P>
The output is the agent password (in this case, <CODE>4gk5hm</CODE>) if the 
program was successfully started.
The agent password is supplied when starting <CODE>jdb</CODE> 
so <CODE>jdb</CODE> can find the corresponding application 
started in debug mode on that machine. 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -