jdb.1 11.5 KB
Newer Older
1
." Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
."
." This code is free software; you can redistribute it and/or modify it
." under the terms of the GNU General Public License version 2 only, as
." published by the Free Software Foundation.
."
." This code is distributed in the hope that it will be useful, but WITHOUT
." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
." FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
." version 2 for more details (a copy is included in the LICENSE file that
." accompanied this code).
."
." You should have received a copy of the GNU General Public License version
." 2 along with this work; if not, write to the Free Software Foundation,
." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
."
18 19 20
." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
." or visit www.oracle.com if you need additional information or have any
." questions.
T
tbell 已提交
21
."
22
.TH jdb 1 "02 Jun 2010"
D
duke 已提交
23 24

.LP
T
tbell 已提交
25
.SH "Name"
D
duke 已提交
26 27
jdb \- The Java Debugger
.LP
T
tbell 已提交
28
.RS 3
D
duke 已提交
29 30 31 32 33

.LP
.LP
\f3jdb\fP helps you find and fix bugs in Java language programs.
.LP
T
tbell 已提交
34
.RE
D
duke 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
.SH "SYNOPSIS"
.LP

.LP
.nf
\f3
.fl
\fP\f3jdb\fP [ options ] [ class ] [ arguments ] 
.fl
.fi

.LP
.RS 3

.LP
T
tbell 已提交
50
.RS 3
D
duke 已提交
51 52 53 54 55 56 57 58 59
.TP 3
options 
Command\-line options, as specified below. 
.TP 3
class 
Name of the class to begin debugging. 
.TP 3
arguments 
Arguments passed to the \f2main()\fP method of \f2class\fP. 
T
tbell 已提交
60 61
.RE

D
duke 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
.LP
.RE
.SH "DESCRIPTION"
.LP

.LP
.LP
The Java Debugger, \f3jdb\fP, is a simple command\-line debugger for Java classes. It is a demonstration of the 
.na
\f2Java Platform Debugger Architecture\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.
.LP
.SS 
Starting a jdb Session
.LP
T
tbell 已提交
78
.RS 3
D
duke 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

.LP
.LP
There are many ways to start a jdb session. The most frequently used way is to have \f3jdb\fP launch a new Java Virtual Machine (VM) with the main class of the application to be debugged. This is done by substituting the command \f3jdb\fP for \f3java\fP in the command line. For example, if your application's main class is MyClass, you use the following command to debug it under JDB:
.LP
.nf
\f3
.fl
 % jdb MyClass 
.fl
\fP
.fi

.LP
.LP
When started this way, \f3jdb\fP invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that class's first instruction.
.LP
.LP
Another way to use \f3jdb\fP is by attaching it to a Java VM that is already running. Syntax for Starting a VM to which jdb will attach when the VM is running is as follows. This loads in\-process debugging libraries and specifies the kind of connection to be made.
.LP
.nf
\f3
.fl
\-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
.fl
\fP
.fi

.LP
.LP
For example, the following command will run the MyClass application, and allow \f3jdb\fP to connect to it at a later time.
.LP
.nf
\f3
.fl
 % java \-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
.fl
\fP
.fi

.LP
.LP
You can then attach \f3jdb\fP to the VM with the following commmand:
.LP
.nf
\f3
.fl
 % jdb \-attach 8000 
.fl
\fP
.fi

.LP
.LP
Note that "MyClass" is not specified in the \f3jdb\fP command line in this case because \f3jdb\fP is connecting to an existing VM instead of launching a new one.
.LP
.LP
There are many other ways to connect the debugger to a VM, and all of them are supported by \f3jdb\fP. The Java Platform Debugger Architecture has additional 
.na
\f2documentation\fP @
.fi
T
tbell 已提交
140
http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on these connection options. For information on starting a J2SE 1.4.2 or early VM for use with \f3jdb\fP see the 
D
duke 已提交
141 142 143
.na
\f21.4.2 documentation\fP @
.fi
T
tbell 已提交
144
http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
D
duke 已提交
145 146 147 148 149 150 151 152 153 154
.LP
.SS 
Basic jdb Commands
.LP
.LP
The following is a list of the basic \f3jdb\fP commands. The Java debugger supports other commands which you can list using \f3jdb\fP's \f2help\fP command.
.LP
.RS 3

.LP
T
tbell 已提交
155
.RS 3
D
duke 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168
.TP 3
help, or ? 
The most important \f3jdb\fP command, \f2help\fP displays the list of recognized commands with a brief description. 
.TP 3
run 
After starting \f3jdb\fP, and setting any necessary breakpoints, you can use this command to start the execution the debugged application. This command is available only when \f3jdb\fP launches the debugged application (as opposed to attaching to an existing VM). 
.TP 3
cont 
Continues execution of the debugged application after a breakpoint, exception, or step. 
.TP 3
print 
Displays Java objects and primitive values. For variables or fields of primitive types, the actual value is printed. For objects, a short description is printed. See the \f2dump\fP command below for getting more information about an object. 
.LP
T
tbell 已提交
169
\f2NOTE: To display local variables, the containing class must have been compiled with the \fP\f2javac(1)\fP\f2 \fP\f2\-g\fP option. 
D
duke 已提交
170 171 172 173
.LP
\f2print\fP supports many simple Java expressions including those with method invocations, for example: 
.RS 3
.TP 2
T
tbell 已提交
174
o
D
duke 已提交
175 176
\f2print MyClass.myStaticField\fP 
.TP 2
T
tbell 已提交
177
o
D
duke 已提交
178 179
\f2print myObj.myInstanceField\fP 
.TP 2
T
tbell 已提交
180
o
D
duke 已提交
181 182
\f2print i + j + k\fP \f2(i, j, k are primities and either fields or local variables)\fP 
.TP 2
T
tbell 已提交
183
o
D
duke 已提交
184 185
\f2print myObj.myMethod()\fP \f2(if myMethod returns a non\-null)\fP 
.TP 2
T
tbell 已提交
186
o
D
duke 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
\f2print new java.lang.String("Hello").length()\fP 
.RE
.TP 3
dump 
For primitive values, this command is identical to \f2print\fP. For objects, it prints the current value of each field defined in the object. Static and instance fields are included. 
.LP
The \f2dump\fP command supports the same set of expressions as the \f2print\fP command.  
.TP 3
threads 
List the threads that are currently running. For each thread, its name and current status are printed, as well as an index that can be used for other commands, for example: 
.RS 3

.LP
.nf
\f3
.fl
4. (java.lang.Thread)0x1 main      running
.fl
\fP
.fi
.RE
In this example, the thread index is 4, the thread is an instance of java.lang.Thread, the thread name is "main", and it is currently running, 
.TP 3
thread 
Select a thread to be the current thread. Many \f3jdb\fP commands are based on the setting of the current thread. The thread is specified with the thread index described in the \f2threads\fP command above. 
.TP 3
where 
\f2where\fP with no arguments dumps the stack of the current thread. \f2where all\fP dumps the stack of all threads in the current thread group. \f2where\fP \f2threadindex\fP dumps the stack of the specified thread. 
.LP
If the current thread is suspended (either through an event such as a breakpoint or through the \f2suspend\fP command), local variables and fields can be displayed with the \f2print\fP and \f2dump\fP commands. The \f2up\fP and \f2down\fP commands select which stack frame is current.  
T
tbell 已提交
217 218
.RE

D
duke 已提交
219 220 221 222 223
.LP
.RE
.SS 
Breakpoints
.LP
T
tbell 已提交
224
.RS 3
D
duke 已提交
225 226 227 228 229 230 231

.LP
.LP
Breakpoints can be set in \f3jdb\fP at line numbers or at the first instruction of a method, for example:
.LP
.RS 3
.TP 2
T
tbell 已提交
232
o
D
duke 已提交
233 234
\f2stop at MyClass:22\fP \f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)\fP 
.TP 2
T
tbell 已提交
235
o
D
duke 已提交
236 237
\f2stop in java.lang.String.length\fP \f2(sets a breakpoint at the beginnig of the method \fP\f2java.lang.String.length\fP) 
.TP 2
T
tbell 已提交
238
o
D
duke 已提交
239 240
\f2stop in MyClass.<init>\fP \f2(<init> identifies the MyClass constructor)\fP 
.TP 2
T
tbell 已提交
241
o
D
duke 已提交
242 243 244 245 246 247 248 249 250 251
\f2stop in MyClass.<clinit>\fP \f2(<clinit> identifies the static initialization code for MyClass)\fP 
.RE

.LP
.LP
If a method is overloaded, you must also specify its argument types so that the proper method can be selected for a breakpoint. For example, "\f2MyClass.myMethod(int,java.lang.String)\fP", or "\f2MyClass.myMethod()\fP".
.LP
.LP
The \f2clear\fP command removes breakpoints using a syntax as in "\f2clear\ MyClass:45\fP". Using the \f2clear\fP or command with no argument displays a list of all breakpoints currently set. The \f2cont\fP command continues execution.
.LP
T
tbell 已提交
252
.RE
D
duke 已提交
253 254 255
.SS 
Stepping
.LP
T
tbell 已提交
256
.RS 3
D
duke 已提交
257 258 259 260 261

.LP
.LP
The \f2step\fP commands advances execution to the next line whether it is in the current stack frame or a called method. The \f2next\fP command advances execution to the next line in the current stack frame.
.LP
T
tbell 已提交
262
.RE
D
duke 已提交
263 264 265
.SS 
Exceptions
.LP
T
tbell 已提交
266
.RS 3
D
duke 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280

.LP
.LP
When an exception occurs for which there isn't a catch statement anywhere in the throwing thread's call stack, the VM normally prints an exception trace and exits. When running under \f3jdb\fP, however, control returns to \f3jdb\fP at the offending throw. You can then use \f3jdb\fP to diagnose the cause of the exception.
.LP
.LP
Use the \f2catch\fP command to cause the debugged application to stop at other thrown exceptions, for example: "\f2catch java.io.FileNotFoundException\fP" or "\f2catch mypackage.BigTroubleException\fP. Any exception which is an instance of the specifield class (or of a subclass) will stop the application at the point where it is thrown.
.LP
.LP
The \f2ignore\fP command negates the effect of a previous \f2catch\fP command.
.LP
.LP
\f2NOTE: The \fP\f2ignore\fP command does not cause the debugged VM to ignore specific exceptions, only the debugger.
.LP
T
tbell 已提交
281 282
.RE
.RE
D
duke 已提交
283 284 285 286 287 288 289 290 291 292
.SH "Command Line Options"
.LP

.LP
.LP
When you use \f3jdb\fP in place of the Java application launcher on the command line, \f3jdb\fP accepts many of the same options as the java command, including \f2\-D\fP, \f2\-classpath\fP, and \f2\-X<option>\fP.
.LP
.LP
The following additional options are accepted by \f3jdb\fP:
.LP
T
tbell 已提交
293
.RS 3
D
duke 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
.TP 3
\-help 
Displays a help message. 
.TP 3
\-sourcepath <dir1:dir2:...> 
Uses the given path in searching for source files in the specified path. If this option is not specified, the default path of "." is used. 
.TP 3
\-attach <address> 
Attaches the debugger to previously running VM using the default connection mechanism. 
.TP 3
\-listen <address> 
Waits for a running VM to connect at the specified address using standard connector. 
.TP 3
\-listenany 
Waits for a running VM to connect at any available address using standard connector. 
.TP 3
\-launch 
Launches the debugged application immediately upon startup of jdb. This option removes the need for using the \f2run\fP command. The debuged application is launched and then stopped just before the initial application class is loaded. At that point you can set any necessary breakpoints and use the \f2cont\fP to continue execution. 
.TP 3
\-listconnectors 
List the connectors available in this VM 
.TP 3
T
tbell 已提交
316
\-connect <connector\-name>:<name1>=<value1>,... 
D
duke 已提交
317 318 319 320 321 322 323 324 325 326 327 328 329
Connects to target VM using named connector with listed argument values. 
.TP 3
\-dbgtrace [flags] 
Prints info for debugging jdb. 
.TP 3
\-tclient 
Runs the application in the Java HotSpot(tm) VM (Client). 
.TP 3
\-tserver 
Runs the application in the Java HotSpot(tm) VM (Server). 
.TP 3
\-Joption 
Pass \f2option\fP to the Java virtual machine used to run jdb. (Options for the application Java virtual machine are passed to the \f3run\fP command.) For example, \f3\-J\-Xms48m\fP sets the startup memory to 48 megabytes. 
T
tbell 已提交
330 331
.RE

D
duke 已提交
332 333 334 335 336 337 338 339 340 341 342
.LP
.LP
Other options are supported for alternate mechanisms for connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional 
.na
\f2documentation\fP @
.fi
http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on these connection alternatives.
.LP
.SS 
Options Forwarded to Debuggee Process
.LP
T
tbell 已提交
343
.RS 3
D
duke 已提交
344 345 346 347 348 349 350
.TP 3
\-v \-verbose[:class|gc|jni] 
Turns on verbose mode. 
.TP 3
\-D<name>=<value> 
Sets a system property. 
.TP 3
T
tbell 已提交
351
\-classpath <directories separated by ":"> 
D
duke 已提交
352 353 354 355
Lists directories in which to look for classes. 
.TP 3
\-X<option> 
Non\-standard target VM option 
T
tbell 已提交
356 357
.RE

D
duke 已提交
358 359 360 361 362 363
.LP
.SH "SEE ALSO"
.LP

.LP
.LP
T
tbell 已提交
364
javac(1), java(1), javah(1), javap(1), javadoc(1).
D
duke 已提交
365 366
.LP