jdb [ ''options''? [ ''class''? [ ''arguments''?
class.
for Java classes. It is a demonstration of the Java Platform Debugger Architecture that provides inspection and debugging of a local or remote Java Virtual Machine.
;Starting a jdb Session:
There are many ways to start a jdb session. The most frequently used way is to have jdb launch a new Java Virtual
Machine (VM) with the main class of the application to be
debugged. This is done by substituting the command jdb
for java(1)? in the command line. For example, if your
application's main class is !MyClass?, you use the following
command to debug it under jdb:
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 class's first instruc
tion.
that is already running. A VM that is to be debugged with jdb must be started with the following options:
|option|purpose
|-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% jdb -Xdebug \
You can then attach jdb to the VM with the following commmand:
example% jdb -attach 8000
in this case because jdb is connecting to an existing VM instead of launching a new one.
and all of them are supported by jdb. The Java Platform Debugger Architecture has additional documentation on these connection options.
;Basic jdb Commands: The following is a list of the basic jdb commands.The Java debugger supports other commands listed with the help command.
Notice that to display local (stack) variables, the class must have been compiled with the javac -g option.
The dump command supports the same set of expressions as the print command.
displays the list of recognized commands with a brief description.
For variables or fields of primitive types, the actual value is printed. For objects, a short description is printed. See the dump command for getting more information about an object.
print supports many simple Java expressions including those with method invocations. For example:
· print MyClass?.myStaticField · print myObj.myInstanceField · print i + j + k ... where i, j, and k are primitives and either fields or local variables. · print myObj.myMethod() ... if myMethod returns a non-null. · print new java.lang.String("Hello").length()
Many jdb commands are based on the setting of the current thread. The thread is spec ified with the thread index described in the threads command.
ning. For each thread, its name and cur rent status are printed, as well as an index that can be used for other commands. For example:
4. (java.lang.Thread)0x1 main running
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 cur rently running
sary breakpoints, use this command to start the execution of the debugged application. This command is available only when jdb launches the debuggedapplication(as opposed to attaching to an existing VM).
;Breakpoint Commands:
instruction of a method. For example:
stop at MyClass?:22Sets 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 begin ningofthemethod java.lang.String.length.
stop in MyClass?.init init identifies the MyClass? con
structor.
stop in MyClass?.clinitclinit identifies the static ini
tialization code for MyClass?.
breakpoint. For example,
MyClass?.myMethod(int,java.lang.String)
or
MyClass?.myMethod()
clearMyClass:45. Using the clear command with no argument displays a list of all breakpoints currently set.The cont command continues execution.
;Stepping Commands: The step command advances execution to the next line, whether it is in the current stack frame or a called method.The next command advances execution to the next line in the current stack frame.
;Exception Commands: When an exception occurs for which there is no catch statement anywhere in the throwing thread's call stack, the VM normally prints an exception trace and exits. When running under jdb, however, control returns to jdb at the offending throw. Use jdb to determine the cause of the exception.
other thrown exceptions. For example:
catch java.io.FileNotFoundException?
or
catch mypackage.!BigTroubleException?
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.
not cause the debugged VM to ignore spe cific exceptions, only the debugger.
on the command line, jdb accepts many of the same options as the java(1)? command, including -D, -classpath, and
The following additional options are accepted by jdb:
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.
where option is oneoftheoptions 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.
connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional docu mentation on these connection alternatives.
One page links to jdb(1):