1jdb(1)                      General Commands Manual                     jdb(1)
2
3
4

NAME

6       jdb - The Java Debugger
7
8       jdb helps you find and fix bugs in Java language programs.
9

SYNOPSIS

11       jdb [ options ] [ class ] [ arguments ]
12
13
14          options
15             Command-line options, as specified below.
16
17          class
18             Name of the class to begin debugging.
19
20          arguments
21             Arguments passed to the main() method of class.
22

DESCRIPTION

24       The  Java  Debugger,  jdb,  is  a simple command-line debugger for Java
25       classes. It is a demonstration of the Java Platform Debugger Architec‐
26       ture @
27       http://java.sun.com/javase/6/docs/technotes/guides/jpda/index.html that
28       provides inspection and debugging of a local or remote Java Virtual
29       Machine.
30
31   Starting a jdb Session
32       There are many ways to start a jdb session. The most frequently used
33       way is to have jdb launch a new Java Virtual Machine (VM) with the main
34       class of the application to be debugged. This is done by substituting
35       the command jdb for java in the command line. For example, if your
36       application's main class is MyClass, you use the following command to
37       debug it under JDB:
38
39        % jdb MyClass
40
41
42       When started this way, jdb invokes a second Java VM with any specified
43       parameters, loads the specified class, and stops the VM before execut‐
44       ing that class's first instruction.
45
46       Another way to use jdb is by attaching it to a Java VM that is already
47       running. Syntax for Starting a VM to which jdb will attach when the VM
48       is running is as follows. This loads in-process debugging libraries and
49       specifies the kind of connection to be made.
50
51       -agentlib:jdwp=transport=dt_socket,server=y,suspend=n
52
53
54       For example, the following command will run the MyClass application,
55       and allow jdb to connect to it at a later time.
56
57        % java -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
58
59
60       You can then attach jdb to the VM with the following commmand:
61
62        % jdb -attach 8000
63
64
65       Note that "MyClass" is not specified in the jdb command line in this
66       case because jdb is connecting to an existing VM instead of launching a
67       new one.
68
69       There are many other ways to connect the debugger to a VM, and all of
70       them are supported by jdb. The Java Platform Debugger Architecture has
71       additional documentation @
72       http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on
73       these connection options. For information on starting a J2SE 1.4.2 or
74       early VM for use with jdb see 1.4.2 documentation @
75       http://java.sun.com/j2se/1.4.2/docs/technotes/guides/jpda/conninv.html
76
77   Basic jdb Commands
78       The following is a list of the basic jdb commands. The Java debugger
79       supports other commands which you can list using jdb's help command.
80
81          help, or ?
82             The most important jdb command, help displays the list of recog‐
83             nized commands with a brief description.
84
85          run
86             After starting jdb, and setting any necessary breakpoints, you
87             can use this command to start the execution the debugged applica‐
88             tion. This command is available only when jdb launches the
89             debugged application (as opposed to attaching to an existing VM).
90
91          cont
92             Continues execution of the debugged application after a break‐
93             point, exception, or step.
94
95          print
96             Displays Java objects and primitive values. For variables or
97             fields of primitive types, the actual value is printed. For
98             objects, a short description is printed. See the dump command
99             below for getting more information about an object.
100
101          NOTE: To display local variables, the containing class must have
102          been compiled with the javac -g option.
103
104          print supports many simple Java expressions including those with
105          method invocations, for example:
106
107             * print MyClass.myStaticField
108
109             * print myObj.myInstanceField
110
111             * print i + j + k (i, j, k are primities and either fields or
112               local variables)
113
114             * print myObj.myMethod() (if myMethod returns a non-null)
115
116             * print new java.lang.String("Hello").length()
117
118          dump
119             For primitive values, this command is identical to print. For
120             objects, it prints the current value of each field defined in the
121             object. Static and instance fields are included.
122
123          The dump command supports the same set of expressions as the print
124          command.
125
126          threads
127             List the threads that are currently running. For each thread, its
128             name and current status are printed, as well as an index that can
129             be used for other commands, for example:
130
131
132             4. (java.lang.Thread)0x1 main      running
133          In this example, the thread index is 4, the thread is an instance of
134          java.lang.Thread, the thread name is "main", and it is currently
135          running,
136
137          thread
138             Select a thread to be the current thread. Many jdb commands are
139             based on the setting of the current thread. The thread is speci‐
140             fied with the thread index described in the threads command
141             above.
142
143          where
144             where with no arguments dumps the stack of the current thread.
145             where all dumps the stack of all threads in the current thread
146             group. where threadindex dumps the stack of the specified thread.
147
148          If the current thread is suspended (either through an event such as
149          a breakpoint or through the suspend command), local variables and
150          fields can be displayed with the print and dump commands. The up and
151          down commands select which stack frame is current.
152
153   Breakpoints
154       Breakpoints can be set in jdb at line numbers or at the first instruc‐
155       tion of a method, for example:
156
157          * stop at MyClass:22 (sets a breakpoint at the first instruction for
158            line 22 of the source file containing MyClass)
159
160          * stop in java.lang.String.length (sets a breakpoint at the beginnig
161            of the method java.lang.String.length)
162
163          * stop in MyClass.<init> (<init> identifies the MyClass constructor)
164
165          * stop in MyClass.<clinit> (<clinit> identifies the static initial‐
166            ization code for MyClass)
167
168
169       If a method is overloaded, you must also specify its argument types so
170       that the proper method can be selected for a breakpoint. For example,
171       "MyClass.myMethod(int,java.lang.String)", or "MyClass.myMethod()".
172
173       The clear command removes breakpoints using a syntax as in
174       "clear MyClass:45". Using the clear or command with no argument dis‐
175       plays a list of all breakpoints currently set. The cont command contin‐
176       ues execution.
177
178   Stepping
179       The step commands advances execution to the next line whether it is in
180       the current stack frame or a called method. The next command advances
181       execution to the next line in the current stack frame.
182
183   Exceptions
184       When an exception occurs for which there isn't a catch statement any‐
185       where in the throwing thread's call stack, the VM normally prints an
186       exception trace and exits. When running under jdb, however, control
187       returns to jdb at the offending throw. You can then use jdb to diagnose
188       the cause of the exception.
189
190       Use the catch command to cause the debugged application to stop at
191       other thrown exceptions, for example: "catch java.io.FileNotFoundExcep‐
192       tion" or "catch mypackage.BigTroubleException. Any exception which is
193       an instance of the specifield class (or of a subclass) will stop the
194       application at the point where it is thrown.
195
196       The ignore command negates the effect of a previous catch command.
197
198       NOTE: The ignore command does not cause the debugged VM to ignore spe‐
199       cific exceptions, only the debugger.
200

Command Line Options

202       When you use jdb in place of the Java application launcher on the com‐
203       mand line, jdb accepts many of the same options as the java command,
204       including -D, -classpath, and -X<option>.
205
206       The following additional options are accepted by jdb:
207
208       -help
209          Displays a help message.
210
211       -sourcepath <dir1:dir2:...>
212          Uses the given path in searching for source files in the specified
213          path. If this option is not specified, the default path of "." is
214          used.
215
216       -attach <address>
217          Attaches the debugger to previously running VM using the default
218          connection mechanism.
219
220       -listen <address>
221          Waits for a running VM to connect at the specified address using
222          standard connector.
223
224       -listenany
225          Waits for a running VM to connect at any available address using
226          standard connector.
227
228       -launch
229          Launches the debugged application immediately upon startup of jdb.
230          This option removes the need for using the run command. The debuged
231          application is launched and then stopped just before the initial
232          application class is loaded. At that point you can set any necessary
233          breakpoints and use the cont to continue execution.
234
235       -listconnectors
236          List the connectors available in this VM
237
238       -connect
239          <connector-name>:<name1>=<value1>,...  Connects to target VM using
240          named connector with listed argument values.
241
242       -dbgtrace [flags]
243          Prints info for debugging jdb.
244
245       -tclient
246          Runs the application in the Java HotSpot(tm) VM (Client).
247
248       -tserver
249          Runs the application in the Java HotSpot(tm) VM (Server).
250
251       -Joption
252          Pass option to the Java virtual machine used to run jdb. (Options
253          for the application Java virtual machine are passed to the run com‐
254          mand.) For example, -J-Xms48m sets the startup memory to 48
255          megabytes.
256
257       Other options are supported for alternate mechanisms for connecting the
258       debugger and the VM it is to debug. The Java Platform Debugger Archi‐
259       tecture has additional documentation @
260       http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on
261       these connection alternatives.
262
263   Options Forwarded to Debuggee Process
264       -v -verbose[:class|gc|jni]
265          Turns on verbose mode.
266
267       -D<name>=<value>
268          Sets a system property.
269
270       -classpath <directories separated by
271          ":"> Lists directories in which to look for classes.
272
273       -X<option>
274          Non-standard target VM option
275

SEE ALSO

277       javac, java, javah, javap, javadoc.
278
279                                  05 Aug 2006                           jdb(1)
Impressum