|class||Name of the class to begin debugging.|
|arguments||Arguments passed to the main() method of class.|
example% jdb MyClass
When started this way, jdb invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that classs first instruction.
Another way to use jdb is by attaching it to a Java VM that is already running. A VM that is to be debugged with jdb must be started with the following options:
|-Xdebug||Enables debugging support in the VM.|
|-Xrunjdwp:transport=dt_socket, server=y,suspend=n||Loads in-process debugging libraries and specifies the kind of connection to be made.|
For example, the following command will run the MyClass application and allow jdb to connect to it at a later time:
example% java -Xdebug \ -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n \ yClass
You can then attach jdb to the VM with the following command:
example% jdb -attach 8000
Note that MyClass is not specified in the jdb command line in this case because jdb is connecting to an existing VM instead of launching a new one.
There are many other ways to connect the debugger to a VM, and all of them are supported by jdb. The Java Platform Debugger Architecture has additional documentation on these connection options.
Notice that to display local (stack) variables, the class must have been compiled with the javac -g option.
|cont||Continues execution of the debugged application after a breakpoint, exception, or step.|
For primitive values, this command is identical to
print. For objects, it prints the
current value of each field defined in the object.
Static and instance fields are included.
The dump command supports the same set of expressions as the print command.
|help, or ?||As the most important jdb command, help displays the list of recognized commands with a brief description.|
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.
dump command for
getting more information about an object.
print supports many simple Java expressions including those with method invocations. For example:
|thread||Selects a thread to be the current thread. Many jdb commands are based on the setting of the current thread. The thread is specified with the thread index described in the threads command.|
Lists 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.
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
|run||After starting jdb, and setting any necessary breakpoints, use this command to start the execution of the debugged application. This command is available only when jdb launches the debugged application (as opposed to attaching to an existing VM).|
|where||The where subcommand with no arguments dumps the stack of the current thread (which is set with the thread command). Using where all dumps the stack of all threads in the current thread group. Using where threadindex dumps the stack of the specified thread. If the current thread is suspended (either through an event such as a breakpoint or through the suspend command), local variables and fields can be displayed with the print and dump commands. The up and down commands select which stack frame is current.|
|stop at MyClass:22||Sets a breakpoint at the first instruction for line 22 of the source file containing MyClass.|
|stop in java.lang.String.length|
|Sets a breakpoint at the beginning of the method java.lang.String.length.|
|stop in MyClass.init||init identifies the MyClass constructor.|
|stop in MyClass.clinit||clinit identifies the static initialization code for MyClass.|
The clear command removes breakpoints using a syntax as in clearMyClass:45. Using the clear command with no argument displays a list of all breakpoints currently set. The cont command continues execution.
Causes the debugged application to stop at other thrown exceptions.
Any exception which is an instance of the specified class (or of a subclass) will stop the application at the point where it is thrown.
|ignore||Negates the effect of a previous catch command. Notice that the ignore command does not cause the debugged VM to ignore specific exceptions, only the debugger.|
The following additional options are accepted by jdb:
|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.|
|-attach address||Attaches the debugger to previously running VM using the default connection mechanism.|
|-launch||Launches the debugged application immediately upon startup of jdb. This option removes the need for using the run 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 cont command to continue execution.|
option to the Java virtual machine, where
option is one of the options described on the man page for the
java application launcher, java(1). For example,
-J-Xms48m sets the startup memory to 48 megabytes. It is a common convention for
-J to pass options to the underlying virtual machine.