blob: 6e0b94394b15fa604915cf5266a35e6b95bcdba6 [file] [log] [blame]
bpatel87d64cc2010-07-14 15:42:06 -07001." Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
duke6e45e102007-12-01 00:00:00 +00002." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3."
4." This code is free software; you can redistribute it and/or modify it
5." under the terms of the GNU General Public License version 2 only, as
6." published by the Free Software Foundation.
7."
8." This code is distributed in the hope that it will be useful, but WITHOUT
9." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11." version 2 for more details (a copy is included in the LICENSE file that
12." accompanied this code).
13."
14." You should have received a copy of the GNU General Public License version
15." 2 along with this work; if not, write to the Free Software Foundation,
16." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17."
ohair2283b9d2010-05-25 15:58:33 -070018." Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19." or visit www.oracle.com if you need additional information or have any
20." questions.
tbell16c34dd2009-05-04 18:28:26 -070021."
bpatel87d64cc2010-07-14 15:42:06 -070022.TH jdb 1 "02 Jun 2010"
duke6e45e102007-12-01 00:00:00 +000023
24.LP
tbell16c34dd2009-05-04 18:28:26 -070025.SH "Name"
duke6e45e102007-12-01 00:00:00 +000026jdb \- The Java Debugger
27.LP
tbell16c34dd2009-05-04 18:28:26 -070028.RS 3
duke6e45e102007-12-01 00:00:00 +000029
30.LP
31.LP
32\f3jdb\fP helps you find and fix bugs in Java language programs.
33.LP
tbell16c34dd2009-05-04 18:28:26 -070034.RE
duke6e45e102007-12-01 00:00:00 +000035.SH "SYNOPSIS"
36.LP
37
38.LP
39.nf
40\f3
41.fl
42\fP\f3jdb\fP [ options ] [ class ] [ arguments ]
43.fl
44.fi
45
46.LP
47.RS 3
48
49.LP
tbell16c34dd2009-05-04 18:28:26 -070050.RS 3
duke6e45e102007-12-01 00:00:00 +000051.TP 3
52options
53Command\-line options, as specified below.
54.TP 3
55class
56Name of the class to begin debugging.
57.TP 3
58arguments
59Arguments passed to the \f2main()\fP method of \f2class\fP.
tbell16c34dd2009-05-04 18:28:26 -070060.RE
61
duke6e45e102007-12-01 00:00:00 +000062.LP
63.RE
64.SH "DESCRIPTION"
65.LP
66
67.LP
68.LP
69The Java Debugger, \f3jdb\fP, is a simple command\-line debugger for Java classes. It is a demonstration of the
70.na
71\f2Java Platform Debugger Architecture\fP @
72.fi
73http://java.sun.com/javase/6/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.
74.LP
75.SS
76Starting a jdb Session
77.LP
tbell16c34dd2009-05-04 18:28:26 -070078.RS 3
duke6e45e102007-12-01 00:00:00 +000079
80.LP
81.LP
82There 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:
83.LP
84.nf
85\f3
86.fl
87 % jdb MyClass
88.fl
89\fP
90.fi
91
92.LP
93.LP
94When 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.
95.LP
96.LP
97Another 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.
98.LP
99.nf
100\f3
101.fl
102\-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
103.fl
104\fP
105.fi
106
107.LP
108.LP
109For example, the following command will run the MyClass application, and allow \f3jdb\fP to connect to it at a later time.
110.LP
111.nf
112\f3
113.fl
114 % java \-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
115.fl
116\fP
117.fi
118
119.LP
120.LP
121You can then attach \f3jdb\fP to the VM with the following commmand:
122.LP
123.nf
124\f3
125.fl
126 % jdb \-attach 8000
127.fl
128\fP
129.fi
130
131.LP
132.LP
133Note 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.
134.LP
135.LP
136There 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
137.na
138\f2documentation\fP @
139.fi
tbell16c34dd2009-05-04 18:28:26 -0700140http://java.sun.com/javase/6/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
duke6e45e102007-12-01 00:00:00 +0000141.na
142\f21.4.2 documentation\fP @
143.fi
tbell16c34dd2009-05-04 18:28:26 -0700144http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
duke6e45e102007-12-01 00:00:00 +0000145.LP
146.SS
147Basic jdb Commands
148.LP
149.LP
150The 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.
151.LP
152.RS 3
153
154.LP
tbell16c34dd2009-05-04 18:28:26 -0700155.RS 3
duke6e45e102007-12-01 00:00:00 +0000156.TP 3
157help, or ?
158The most important \f3jdb\fP command, \f2help\fP displays the list of recognized commands with a brief description.
159.TP 3
160run
161After 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).
162.TP 3
163cont
164Continues execution of the debugged application after a breakpoint, exception, or step.
165.TP 3
166print
167Displays 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.
168.LP
tbell16c34dd2009-05-04 18:28:26 -0700169\f2NOTE: To display local variables, the containing class must have been compiled with the \fP\f2javac(1)\fP\f2 \fP\f2\-g\fP option.
duke6e45e102007-12-01 00:00:00 +0000170.LP
171\f2print\fP supports many simple Java expressions including those with method invocations, for example:
172.RS 3
173.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700174o
duke6e45e102007-12-01 00:00:00 +0000175\f2print MyClass.myStaticField\fP
176.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700177o
duke6e45e102007-12-01 00:00:00 +0000178\f2print myObj.myInstanceField\fP
179.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700180o
duke6e45e102007-12-01 00:00:00 +0000181\f2print i + j + k\fP \f2(i, j, k are primities and either fields or local variables)\fP
182.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700183o
duke6e45e102007-12-01 00:00:00 +0000184\f2print myObj.myMethod()\fP \f2(if myMethod returns a non\-null)\fP
185.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700186o
duke6e45e102007-12-01 00:00:00 +0000187\f2print new java.lang.String("Hello").length()\fP
188.RE
189.TP 3
190dump
191For 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.
192.LP
193The \f2dump\fP command supports the same set of expressions as the \f2print\fP command.
194.TP 3
195threads
196List 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:
197.RS 3
198
199.LP
200.nf
201\f3
202.fl
2034. (java.lang.Thread)0x1 main running
204.fl
205\fP
206.fi
207.RE
208In 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,
209.TP 3
210thread
211Select 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.
212.TP 3
213where
214\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.
215.LP
216If 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.
tbell16c34dd2009-05-04 18:28:26 -0700217.RE
218
duke6e45e102007-12-01 00:00:00 +0000219.LP
220.RE
221.SS
222Breakpoints
223.LP
tbell16c34dd2009-05-04 18:28:26 -0700224.RS 3
duke6e45e102007-12-01 00:00:00 +0000225
226.LP
227.LP
228Breakpoints can be set in \f3jdb\fP at line numbers or at the first instruction of a method, for example:
229.LP
230.RS 3
231.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700232o
duke6e45e102007-12-01 00:00:00 +0000233\f2stop at MyClass:22\fP \f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)\fP
234.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700235o
duke6e45e102007-12-01 00:00:00 +0000236\f2stop in java.lang.String.length\fP \f2(sets a breakpoint at the beginnig of the method \fP\f2java.lang.String.length\fP)
237.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700238o
duke6e45e102007-12-01 00:00:00 +0000239\f2stop in MyClass.<init>\fP \f2(<init> identifies the MyClass constructor)\fP
240.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700241o
duke6e45e102007-12-01 00:00:00 +0000242\f2stop in MyClass.<clinit>\fP \f2(<clinit> identifies the static initialization code for MyClass)\fP
243.RE
244
245.LP
246.LP
247If 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".
248.LP
249.LP
250The \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.
251.LP
tbell16c34dd2009-05-04 18:28:26 -0700252.RE
duke6e45e102007-12-01 00:00:00 +0000253.SS
254Stepping
255.LP
tbell16c34dd2009-05-04 18:28:26 -0700256.RS 3
duke6e45e102007-12-01 00:00:00 +0000257
258.LP
259.LP
260The \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.
261.LP
tbell16c34dd2009-05-04 18:28:26 -0700262.RE
duke6e45e102007-12-01 00:00:00 +0000263.SS
264Exceptions
265.LP
tbell16c34dd2009-05-04 18:28:26 -0700266.RS 3
duke6e45e102007-12-01 00:00:00 +0000267
268.LP
269.LP
270When 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.
271.LP
272.LP
273Use 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.
274.LP
275.LP
276The \f2ignore\fP command negates the effect of a previous \f2catch\fP command.
277.LP
278.LP
279\f2NOTE: The \fP\f2ignore\fP command does not cause the debugged VM to ignore specific exceptions, only the debugger.
280.LP
tbell16c34dd2009-05-04 18:28:26 -0700281.RE
282.RE
duke6e45e102007-12-01 00:00:00 +0000283.SH "Command Line Options"
284.LP
285
286.LP
287.LP
288When 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.
289.LP
290.LP
291The following additional options are accepted by \f3jdb\fP:
292.LP
tbell16c34dd2009-05-04 18:28:26 -0700293.RS 3
duke6e45e102007-12-01 00:00:00 +0000294.TP 3
295\-help
296Displays a help message.
297.TP 3
298\-sourcepath <dir1:dir2:...>
299Uses the given path in searching for source files in the specified path. If this option is not specified, the default path of "." is used.
300.TP 3
301\-attach <address>
302Attaches the debugger to previously running VM using the default connection mechanism.
303.TP 3
304\-listen <address>
305Waits for a running VM to connect at the specified address using standard connector.
306.TP 3
307\-listenany
308Waits for a running VM to connect at any available address using standard connector.
309.TP 3
310\-launch
311Launches 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.
312.TP 3
313\-listconnectors
314List the connectors available in this VM
315.TP 3
tbell16c34dd2009-05-04 18:28:26 -0700316\-connect <connector\-name>:<name1>=<value1>,...
duke6e45e102007-12-01 00:00:00 +0000317Connects to target VM using named connector with listed argument values.
318.TP 3
319\-dbgtrace [flags]
320Prints info for debugging jdb.
321.TP 3
322\-tclient
323Runs the application in the Java HotSpot(tm) VM (Client).
324.TP 3
325\-tserver
326Runs the application in the Java HotSpot(tm) VM (Server).
327.TP 3
328\-Joption
329Pass \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.
tbell16c34dd2009-05-04 18:28:26 -0700330.RE
331
duke6e45e102007-12-01 00:00:00 +0000332.LP
333.LP
334Other options are supported for alternate mechanisms for connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional
335.na
336\f2documentation\fP @
337.fi
338http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on these connection alternatives.
339.LP
340.SS
341Options Forwarded to Debuggee Process
342.LP
tbell16c34dd2009-05-04 18:28:26 -0700343.RS 3
duke6e45e102007-12-01 00:00:00 +0000344.TP 3
345\-v \-verbose[:class|gc|jni]
346Turns on verbose mode.
347.TP 3
348\-D<name>=<value>
349Sets a system property.
350.TP 3
tbell16c34dd2009-05-04 18:28:26 -0700351\-classpath <directories separated by ":">
duke6e45e102007-12-01 00:00:00 +0000352Lists directories in which to look for classes.
353.TP 3
354\-X<option>
355Non\-standard target VM option
tbell16c34dd2009-05-04 18:28:26 -0700356.RE
357
duke6e45e102007-12-01 00:00:00 +0000358.LP
359.SH "SEE ALSO"
360.LP
361
362.LP
363.LP
tbell16c34dd2009-05-04 18:28:26 -0700364javac(1), java(1), javah(1), javap(1), javadoc(1).
duke6e45e102007-12-01 00:00:00 +0000365.LP
duke6e45e102007-12-01 00:00:00 +0000366