NAME
jdb - Java debugger
SYNOPSIS
jjddbb [ options ] [ class ] [ arguments ] PPAARRAAMMEETTEERRSSoptions Command-line options.
class Name of the class to begin debugging. arguments Arguments passed to the mmaaiinn(()) method of class.DESCRIPTION
The Java debugger, jjddbb, is a simple command-line debugger for Java
classes. It is a demonstration of the JJaavvaa PPllaattffoorrmm DDeebbuuggggeerr AArrcchhiitteecc-
ttuurree that provides inspection and debugging of a local or remote Java Virtual Machine. SSttaarrttiinngg aa jjddbb SSeessssiioonnThere are many ways to start a jdb session. The most frequently used
way is to have jjddbb launch a new Java Virtual Machine (VM) with the main class of the application to be debugged. This is done by substituting the command jjddbb for jjaavvaa(1) in the command line. For example, if your application's main class is MMyyCCllaassss, you use the following command to debug it under jjddbb:eexxaammppllee%% jjddbb MMyyCCllaassss
When started this way, jjddbb invokes a second Java VM with any specifiedparameters, loads the specified class, and stops the VM before execut-
ing that class's first instruction. Another way to use jjddbb is by attaching it to a Java VM that is already running. A VM that is to be debugged with jjddbb must be started with the following options:+----------+-------------------+
| ooppttiioonn | ppuurrppoossee |+----------+-------------------+
|-XXddeebbuugg | Enables debugging support in the VM. |
+----------+-------------------+
|-XXrruunnjjddwwpp::ttrraannss- | Loads in-process debugging libraries |
|ppoorrtt==ddttssoocckkeett,, | and specifies the kind of connection | |sseerrvveerr==yy,,ssuussppeenndd==nn | to be made. |+----------+-------------------+
For example, the following command will run the MMyyCCllaassss application and allow jjddbb to connect to it at a later time:eexxaammppllee%% jjaavvaa -XXddeebbuugg \\
-XXrruunnjjddwwpp::ttrraannssppoorrtt==ddttssoocckkeett,,aaddddrreessss==88000000,,sseerrvveerr==yy,,ssuussppeenndd==nn \\
CCllaassss You can then attach jjddbb to the VM with the following command:eexxaammppllee%% jjddbb -aattttaacchh 88000000
Note that MMyyCCllaassss is not specified in the jjddbb command line in this case because jjddbb 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 jjddbb. The Java Platform Debugger Architecture has additional documentation on these connection options. BBaassiicc jjddbb CCoommmmaannddss The following is a list of the basic jjddbb commands. The Java debugger supports other commands listed with the hheellpp command. Notice that to display local (stack) variables, the class must havebeen compiled with the jjaavvaacc -gg option.
ccoonntt Continues execution of the debugged application after a breakpoint, exception, or step. dduummpp For primitive values, this command is identical to pprriinntt. For objects, it prints the current value of each field defined in the object. Static and instance fields are included. The dduummpp command supports the same set of expressions as the pprriinntt command. hheellpp, or ?? As the most important jjddbb command, hheellpp displays the list of recognized commands with a brief description.pprriinntt Displays Java objects and primitive values. For vari-
ables or fields of primitive types, the actual value is printed. For objects, a short description is printed. See the dduummpp command for getting more information about an object. pprriinntt supports many simple Java expressions including those with method invocations. For example: +o pprriinntt MMyyCCllaassss..mmyySSttaattiiccFFiieelldd +o pprriinntt mmyyOObbjj..mmyyIInnssttaanncceeFFiieelldd +o pprriinntt i ++ j ++ k ... where i, j, and k are primitives and either fields or local variables. o print myObj.myMethod() . i myMethod rtrsnon-null.
+o pprriinntt nneeww jjaavvaa..llaanngg..SSttrriinngg((""HHeelllloo""))..lleennggtthh(()) tthhrreeaadd Selects a thread to be the current thread. Many jjddbb commands are based on the setting of the current thread. The thread is specified with the thread index described in the tthhrreeaaddss ccoommmmaanndd.. tthhrreeaaddss 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. For example: 44.. ((jjaavvaa..llaanngg..TThhrreeaadd))00xx11 mmaaiinn rruunnnniinngg In this example, the thread index is 44, the thread is an instance of jjaavvaa..llaanngg..TThhrreeaadd, the thread name is mmaaiinn, and it is currently runningrruunn After starting jjddbb, and setting any necessary break-
points, use this command to start the execution of the debugged application. This command is available only when jjddbb launches the debugged application (as opposed to attaching to an existing VM). wwhheerree The wwhheerree subcommand with no arguments dumps the stackof the current thread (which is set with the tthhrreeaadd com-
mand). Using wwhheerree aallll dumps the stack of all threads in the current thread group. Using wwhheerree threadindex dumps the stack of the specified thread. If the current thread is suspended (either through an event such as abreakpoint or through the ssuussppeenndd command), local vari-
ables and fields can be displayed with the pprriinntt and dduummpp commands. The uupp and ddoowwnn commands select which stack frame is current. BBrreeaakkppooiinntt CCoommmmaannddss Breakpoints are set in jjddbb at line numbers or at the first instruction of a method. For example: ssttoopp aatt MMyyCCllaassss::2222 Sets a breakpoint at the first instruction for line 2222 of the source file containing MMyyCCllaassss. ssttoopp iinn jjaavvaa..llaanngg..SSttrriinngg..lleennggtthh Sets a breakpoint at the beginning of the method jjaavvaa..llaanngg..SSttrriinngg..lleennggtthh. ssttoopp iinn MMyyCCllaassss..init init identifies the MMyyCCllaassss constructor. ssttoopp iinn MMyyCCllaassss..clinit clinit identifies the static initialization code for MMyyCCllaassss. 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, MyClass.myMethod(int,java.lang.String) or MyClass.myMethod()The cclleeaarr command removes breakpoints using a syntax as in cclleeaarrMy-
Class:45.. Using the cclleeaarr command with no argument displays a list of all breakpoints currently set. The ccoonntt command continues execution. SStteeppppiinngg CCoommmmaannddss The sstteepp command advances execution to the next line, whether it is in the current stack frame or a called method. The nneexxtt command advances execution to the next line in the current stack frame. EExxcceeppttiioonn CCoommmmaannddss When an exception occurs for which there is no catch statement anywherein the throwing thread's call stack, the VM normally prints an excep-
tion trace and exits. When running under jjddbb, however, control returns to jjddbb at the offending throw. Use jjddbb to determine the cause of the exception. ccaattcchh Causes the debugged application to stop at other thrown exceptions. For example: ccaattcchh jjaavvaa..iioo..FFiilleeNNoottFFoouunnddEExxcceeppttiioonn or ccaattcchh mmyyppaacckkaaggee..BBiiggTTrroouubblleeEExxcceeppttiioonn 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. iiggnnoorree Negates the effect of a previous ccaattcchh command. Notice that the iiggnnoorree command does not cause the debugged VM to ignore specific exceptions, only the debugger. OOPPTTIIOONNSS When using jjddbb in place of the Java application launcher on the command line, jjddbb accepts many of the same options as the jjaavvaa(1) command,including -DD, -ccllaassssppaatthh, and -XXoption.
The following additional options are accepted by jjddbb:-ssoouurrcceeppaatthh 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.-aattttaacchh address
Attaches the debugger to previously running VM using the default connection mechanism.-llaauunncchh Launches the debugged application immediately upon
startup of jjddbb. This option removes the need for using the rruunn command. The debuged application is launched and then stopped just before the initial applicationclass is loaded. At that point, you can set any neces-
sary breakpoints and use the ccoonntt command to continue execution.-JJ ooppttiioonn Pass option to the Java virtual machine, where option is
one of the options described on the man page for thejava application launcher, java(1). For example, -J-
Xms48m sets the startup memory to 48 megabytes. It is acommon convention for -JJ to pass options to the underly-
ing virtual machine. Other options are supported for alternate mechanisms for connecting thedebugger and the VM it is to debug. The Java Platform Debugger Archi-
tecture has additional documentation on these connection alternatives.SEE ALSO
jjaavvaa(1), jjaavvaacc(1), jjaavvaaddoocc(1), jjaavvaahh(1), jjaavvaapp(1)12 Nov 2001 jdb(1)