4176N/A." Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A."
0N/A." This code is free software; you can redistribute it and/or modify it
0N/A." under the terms of the GNU General Public License version 2 only, as
0N/A." published by the Free Software Foundation.
0N/A."
0N/A." This code is distributed in the hope that it will be useful, but WITHOUT
0N/A." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A." version 2 for more details (a copy is included in the LICENSE file that
0N/A." accompanied this code).
0N/A."
0N/A." You should have received a copy of the GNU General Public License version
0N/A." 2 along with this work; if not, write to the Free Software Foundation,
0N/A." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A."
2362N/A." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A." or visit www.oracle.com if you need additional information or have any
2362N/A." questions.
1178N/A."
4880N/A.TH jdb 1 "16 Mar 2012"
0N/A
0N/A.LP
1178N/A.SH "Name"
0N/Ajdb \- The Java Debugger
0N/A.LP
0N/A.LP
0N/A\f3jdb\fP helps you find and fix bugs in Java language programs.
0N/A.LP
0N/A.SH "SYNOPSIS"
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A\fP\f3jdb\fP [ options ] [ class ] [ arguments ]
0N/A.fl
0N/A.fi
0N/A
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/Aoptions
0N/ACommand\-line options, as specified below.
0N/A.TP 3
0N/Aclass
0N/AName of the class to begin debugging.
0N/A.TP 3
0N/Aarguments
0N/AArguments passed to the \f2main()\fP method of \f2class\fP.
1178N/A.RE
1178N/A
0N/A.LP
0N/A.SH "DESCRIPTION"
0N/A.LP
0N/A.LP
0N/AThe Java Debugger, \f3jdb\fP, is a simple command\-line debugger for Java classes. It is a demonstration of the
0N/A.na
0N/A\f2Java Platform Debugger Architecture\fP @
0N/A.fi
4880N/Ahttp://docs.oracle.com/javase/7/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.
0N/A.LP
0N/A.SS
0N/AStarting a jdb Session
0N/A.LP
0N/A.LP
0N/AThere 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:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A % jdb MyClass
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AWhen 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.
0N/A.LP
0N/A.LP
0N/AAnother 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.
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A\-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AFor example, the following command will run the MyClass application, and allow \f3jdb\fP to connect to it at a later time.
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A % java \-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/AYou can then attach \f3jdb\fP to the VM with the following commmand:
0N/A.LP
0N/A.nf
0N/A\f3
0N/A.fl
0N/A % jdb \-attach 8000
0N/A.fl
0N/A\fP
0N/A.fi
0N/A
0N/A.LP
0N/A.LP
0N/ANote 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.
0N/A.LP
0N/A.LP
0N/AThere 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
0N/A.na
0N/A\f2documentation\fP @
0N/A.fi
4880N/Ahttp://docs.oracle.com/javase/7/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
0N/A.na
0N/A\f21.4.2 documentation\fP @
0N/A.fi
1178N/Ahttp://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
0N/A.LP
0N/A.SS
0N/ABasic jdb Commands
0N/A.LP
0N/A.LP
0N/AThe 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.
0N/A.LP
0N/A.RS 3
0N/A.TP 3
0N/Ahelp, or ?
0N/AThe most important \f3jdb\fP command, \f2help\fP displays the list of recognized commands with a brief description.
0N/A.TP 3
0N/Arun
0N/AAfter 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).
0N/A.TP 3
0N/Acont
0N/AContinues execution of the debugged application after a breakpoint, exception, or step.
0N/A.TP 3
0N/Aprint
4176N/ADisplays 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.
4176N/A.br
4176N/A.br
4176N/A\f2NOTE: To display local variables, the containing class must have been compiled with the \fP\f2javac(1)\fP\f2 \fP\f2\-g\fP option.
4176N/A.br
4176N/A.br
0N/A\f2print\fP supports many simple Java expressions including those with method invocations, for example:
0N/A.RS 3
0N/A.TP 2
1178N/Ao
0N/A\f2print MyClass.myStaticField\fP
0N/A.TP 2
1178N/Ao
0N/A\f2print myObj.myInstanceField\fP
0N/A.TP 2
1178N/Ao
0N/A\f2print i + j + k\fP \f2(i, j, k are primities and either fields or local variables)\fP
0N/A.TP 2
1178N/Ao
0N/A\f2print myObj.myMethod()\fP \f2(if myMethod returns a non\-null)\fP
0N/A.TP 2
1178N/Ao
0N/A\f2print new java.lang.String("Hello").length()\fP
0N/A.RE
0N/A.TP 3
0N/Adump
4176N/AFor 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.
4176N/A.br
4176N/A.br
4176N/AThe \f2dump\fP command supports the same set of expressions as the \f2print\fP command.
0N/A.TP 3
0N/Athreads
0N/AList 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:
0N/A.nf
0N/A\f3
0N/A.fl
0N/A4. (java.lang.Thread)0x1 main running
0N/A.fl
0N/A\fP
0N/A.fi
0N/AIn 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,
0N/A.TP 3
0N/Athread
0N/ASelect 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.
0N/A.TP 3
0N/Awhere
4176N/A\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.
4176N/A.br
4176N/A.br
4176N/AIf 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.
1178N/A.RE
1178N/A
0N/A.LP
0N/A.SS
0N/ABreakpoints
0N/A.LP
0N/A.LP
0N/ABreakpoints can be set in \f3jdb\fP at line numbers or at the first instruction of a method, for example:
0N/A.LP
0N/A.RS 3
0N/A.TP 2
1178N/Ao
0N/A\f2stop at MyClass:22\fP \f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)\fP
0N/A.TP 2
1178N/Ao
0N/A\f2stop in java.lang.String.length\fP \f2(sets a breakpoint at the beginnig of the method \fP\f2java.lang.String.length\fP)
0N/A.TP 2
1178N/Ao
0N/A\f2stop in MyClass.<init>\fP \f2(<init> identifies the MyClass constructor)\fP
0N/A.TP 2
1178N/Ao
0N/A\f2stop in MyClass.<clinit>\fP \f2(<clinit> identifies the static initialization code for MyClass)\fP
0N/A.RE
0N/A
0N/A.LP
0N/A.LP
0N/AIf 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".
0N/A.LP
0N/A.LP
0N/AThe \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.
0N/A.LP
0N/A.SS
0N/AStepping
0N/A.LP
0N/A.LP
0N/AThe \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.
0N/A.LP
0N/A.SS
0N/AExceptions
0N/A.LP
0N/A.LP
0N/AWhen 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.
0N/A.LP
0N/A.LP
0N/AUse 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.
0N/A.LP
0N/A.LP
0N/AThe \f2ignore\fP command negates the effect of a previous \f2catch\fP command.
0N/A.LP
0N/A.LP
0N/A\f2NOTE: The \fP\f2ignore\fP command does not cause the debugged VM to ignore specific exceptions, only the debugger.
0N/A.LP
0N/A.SH "Command Line Options"
0N/A.LP
0N/A.LP
0N/AWhen 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.
0N/A.LP
0N/A.LP
0N/AThe following additional options are accepted by \f3jdb\fP:
0N/A.LP
1178N/A.RS 3
0N/A.TP 3
0N/A\-help
0N/ADisplays a help message.
0N/A.TP 3
0N/A\-sourcepath <dir1:dir2:...>
0N/AUses the given path in searching for source files in the specified path. If this option is not specified, the default path of "." is used.
0N/A.TP 3
0N/A\-attach <address>
0N/AAttaches the debugger to previously running VM using the default connection mechanism.
0N/A.TP 3
0N/A\-listen <address>
0N/AWaits for a running VM to connect at the specified address using standard connector.
0N/A.TP 3
0N/A\-listenany
0N/AWaits for a running VM to connect at any available address using standard connector.
0N/A.TP 3
0N/A\-launch
0N/ALaunches 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.
0N/A.TP 3
0N/A\-listconnectors
0N/AList the connectors available in this VM
0N/A.TP 3
1178N/A\-connect <connector\-name>:<name1>=<value1>,...
0N/AConnects to target VM using named connector with listed argument values.
0N/A.TP 3
0N/A\-dbgtrace [flags]
0N/APrints info for debugging jdb.
0N/A.TP 3
0N/A\-tclient
0N/ARuns the application in the Java HotSpot(tm) VM (Client).
0N/A.TP 3
0N/A\-tserver
0N/ARuns the application in the Java HotSpot(tm) VM (Server).
0N/A.TP 3
0N/A\-Joption
0N/APass \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.
1178N/A.RE
1178N/A
0N/A.LP
0N/A.LP
0N/AOther options are supported for alternate mechanisms for connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional
0N/A.na
0N/A\f2documentation\fP @
0N/A.fi
4880N/Ahttp://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html on these connection alternatives.
0N/A.LP
0N/A.SS
0N/AOptions Forwarded to Debuggee Process
0N/A.LP
1178N/A.RS 3
0N/A.TP 3
0N/A\-v \-verbose[:class|gc|jni]
0N/ATurns on verbose mode.
0N/A.TP 3
0N/A\-D<name>=<value>
0N/ASets a system property.
0N/A.TP 3
1178N/A\-classpath <directories separated by ":">
0N/ALists directories in which to look for classes.
0N/A.TP 3
0N/A\-X<option>
0N/ANon\-standard target VM option
1178N/A.RE
1178N/A
0N/A.LP
0N/A.SH "SEE ALSO"
0N/A.LP
0N/A.LP
1178N/Ajavac(1), java(1), javah(1), javap(1), javadoc(1).
0N/A.LP
0N/A