blob: c102619323457e816aa4dde510a0591eb3f0946e [file] [log] [blame]
tbell16c34dd2009-05-04 18:28:26 -07001." Copyright 2002-2006 Sun Microsystems, Inc. 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."
18." Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
19." CA 95054 USA or visit www.sun.com if you need additional information or
20." have any questions.
tbell16c34dd2009-05-04 18:28:26 -070021."
22.TH jdb 1 "04 May 2009"
23." Generated from HTML by html2man (author: Eric Armstrong)
duke6e45e102007-12-01 00:00:00 +000024
25.LP
tbell16c34dd2009-05-04 18:28:26 -070026.SH "Name"
duke6e45e102007-12-01 00:00:00 +000027jdb \- The Java Debugger
28.LP
tbell16c34dd2009-05-04 18:28:26 -070029.RS 3
duke6e45e102007-12-01 00:00:00 +000030
31.LP
32.LP
33\f3jdb\fP helps you find and fix bugs in Java language programs.
34.LP
tbell16c34dd2009-05-04 18:28:26 -070035.RE
duke6e45e102007-12-01 00:00:00 +000036.SH "SYNOPSIS"
37.LP
38
39.LP
40.nf
41\f3
42.fl
43\fP\f3jdb\fP [ options ] [ class ] [ arguments ]
44.fl
45.fi
46
47.LP
48.RS 3
49
50.LP
tbell16c34dd2009-05-04 18:28:26 -070051.RS 3
duke6e45e102007-12-01 00:00:00 +000052.TP 3
53options
54Command\-line options, as specified below.
55.TP 3
56class
57Name of the class to begin debugging.
58.TP 3
59arguments
60Arguments passed to the \f2main()\fP method of \f2class\fP.
tbell16c34dd2009-05-04 18:28:26 -070061.RE
62
duke6e45e102007-12-01 00:00:00 +000063.LP
64.RE
65.SH "DESCRIPTION"
66.LP
67
68.LP
69.LP
70The Java Debugger, \f3jdb\fP, is a simple command\-line debugger for Java classes. It is a demonstration of the
71.na
72\f2Java Platform Debugger Architecture\fP @
73.fi
74http://java.sun.com/javase/6/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.
75.LP
76.SS
77Starting a jdb Session
78.LP
tbell16c34dd2009-05-04 18:28:26 -070079.RS 3
duke6e45e102007-12-01 00:00:00 +000080
81.LP
82.LP
83There 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:
84.LP
85.nf
86\f3
87.fl
88 % jdb MyClass
89.fl
90\fP
91.fi
92
93.LP
94.LP
95When 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.
96.LP
97.LP
98Another 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.
99.LP
100.nf
101\f3
102.fl
103\-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
104.fl
105\fP
106.fi
107
108.LP
109.LP
110For example, the following command will run the MyClass application, and allow \f3jdb\fP to connect to it at a later time.
111.LP
112.nf
113\f3
114.fl
115 % java \-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
116.fl
117\fP
118.fi
119
120.LP
121.LP
122You can then attach \f3jdb\fP to the VM with the following commmand:
123.LP
124.nf
125\f3
126.fl
127 % jdb \-attach 8000
128.fl
129\fP
130.fi
131
132.LP
133.LP
134Note 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.
135.LP
136.LP
137There 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
138.na
139\f2documentation\fP @
140.fi
tbell16c34dd2009-05-04 18:28:26 -0700141http://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 +0000142.na
143\f21.4.2 documentation\fP @
144.fi
tbell16c34dd2009-05-04 18:28:26 -0700145http://java.sun.com/j2se/1.4.2/docs/guide/jpda/conninv.html
duke6e45e102007-12-01 00:00:00 +0000146.LP
147.SS
148Basic jdb Commands
149.LP
150.LP
151The 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.
152.LP
153.RS 3
154
155.LP
tbell16c34dd2009-05-04 18:28:26 -0700156.RS 3
duke6e45e102007-12-01 00:00:00 +0000157.TP 3
158help, or ?
159The most important \f3jdb\fP command, \f2help\fP displays the list of recognized commands with a brief description.
160.TP 3
161run
162After 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).
163.TP 3
164cont
165Continues execution of the debugged application after a breakpoint, exception, or step.
166.TP 3
167print
168Displays 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.
169.LP
tbell16c34dd2009-05-04 18:28:26 -0700170\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 +0000171.LP
172\f2print\fP supports many simple Java expressions including those with method invocations, for example:
173.RS 3
174.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700175o
duke6e45e102007-12-01 00:00:00 +0000176\f2print MyClass.myStaticField\fP
177.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700178o
duke6e45e102007-12-01 00:00:00 +0000179\f2print myObj.myInstanceField\fP
180.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700181o
duke6e45e102007-12-01 00:00:00 +0000182\f2print i + j + k\fP \f2(i, j, k are primities and either fields or local variables)\fP
183.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700184o
duke6e45e102007-12-01 00:00:00 +0000185\f2print myObj.myMethod()\fP \f2(if myMethod returns a non\-null)\fP
186.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700187o
duke6e45e102007-12-01 00:00:00 +0000188\f2print new java.lang.String("Hello").length()\fP
189.RE
190.TP 3
191dump
192For 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.
193.LP
194The \f2dump\fP command supports the same set of expressions as the \f2print\fP command.
195.TP 3
196threads
197List 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:
198.RS 3
199
200.LP
201.nf
202\f3
203.fl
2044. (java.lang.Thread)0x1 main running
205.fl
206\fP
207.fi
208.RE
209In 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,
210.TP 3
211thread
212Select 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.
213.TP 3
214where
215\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.
216.LP
217If 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 -0700218.RE
219
duke6e45e102007-12-01 00:00:00 +0000220.LP
221.RE
222.SS
223Breakpoints
224.LP
tbell16c34dd2009-05-04 18:28:26 -0700225.RS 3
duke6e45e102007-12-01 00:00:00 +0000226
227.LP
228.LP
229Breakpoints can be set in \f3jdb\fP at line numbers or at the first instruction of a method, for example:
230.LP
231.RS 3
232.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700233o
duke6e45e102007-12-01 00:00:00 +0000234\f2stop at MyClass:22\fP \f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)\fP
235.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700236o
duke6e45e102007-12-01 00:00:00 +0000237\f2stop in java.lang.String.length\fP \f2(sets a breakpoint at the beginnig of the method \fP\f2java.lang.String.length\fP)
238.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700239o
duke6e45e102007-12-01 00:00:00 +0000240\f2stop in MyClass.<init>\fP \f2(<init> identifies the MyClass constructor)\fP
241.TP 2
tbell16c34dd2009-05-04 18:28:26 -0700242o
duke6e45e102007-12-01 00:00:00 +0000243\f2stop in MyClass.<clinit>\fP \f2(<clinit> identifies the static initialization code for MyClass)\fP
244.RE
245
246.LP
247.LP
248If 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".
249.LP
250.LP
251The \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.
252.LP
tbell16c34dd2009-05-04 18:28:26 -0700253.RE
duke6e45e102007-12-01 00:00:00 +0000254.SS
255Stepping
256.LP
tbell16c34dd2009-05-04 18:28:26 -0700257.RS 3
duke6e45e102007-12-01 00:00:00 +0000258
259.LP
260.LP
261The \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.
262.LP
tbell16c34dd2009-05-04 18:28:26 -0700263.RE
duke6e45e102007-12-01 00:00:00 +0000264.SS
265Exceptions
266.LP
tbell16c34dd2009-05-04 18:28:26 -0700267.RS 3
duke6e45e102007-12-01 00:00:00 +0000268
269.LP
270.LP
271When 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.
272.LP
273.LP
274Use 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.
275.LP
276.LP
277The \f2ignore\fP command negates the effect of a previous \f2catch\fP command.
278.LP
279.LP
280\f2NOTE: The \fP\f2ignore\fP command does not cause the debugged VM to ignore specific exceptions, only the debugger.
281.LP
tbell16c34dd2009-05-04 18:28:26 -0700282.RE
283.RE
duke6e45e102007-12-01 00:00:00 +0000284.SH "Command Line Options"
285.LP
286
287.LP
288.LP
289When 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.
290.LP
291.LP
292The following additional options are accepted by \f3jdb\fP:
293.LP
tbell16c34dd2009-05-04 18:28:26 -0700294.RS 3
duke6e45e102007-12-01 00:00:00 +0000295.TP 3
296\-help
297Displays a help message.
298.TP 3
299\-sourcepath <dir1:dir2:...>
300Uses the given path in searching for source files in the specified path. If this option is not specified, the default path of "." is used.
301.TP 3
302\-attach <address>
303Attaches the debugger to previously running VM using the default connection mechanism.
304.TP 3
305\-listen <address>
306Waits for a running VM to connect at the specified address using standard connector.
307.TP 3
308\-listenany
309Waits for a running VM to connect at any available address using standard connector.
310.TP 3
311\-launch
312Launches 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.
313.TP 3
314\-listconnectors
315List the connectors available in this VM
316.TP 3
tbell16c34dd2009-05-04 18:28:26 -0700317\-connect <connector\-name>:<name1>=<value1>,...
duke6e45e102007-12-01 00:00:00 +0000318Connects to target VM using named connector with listed argument values.
319.TP 3
320\-dbgtrace [flags]
321Prints info for debugging jdb.
322.TP 3
323\-tclient
324Runs the application in the Java HotSpot(tm) VM (Client).
325.TP 3
326\-tserver
327Runs the application in the Java HotSpot(tm) VM (Server).
328.TP 3
329\-Joption
330Pass \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 -0700331.RE
332
duke6e45e102007-12-01 00:00:00 +0000333.LP
334.LP
335Other options are supported for alternate mechanisms for connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional
336.na
337\f2documentation\fP @
338.fi
339http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on these connection alternatives.
340.LP
341.SS
342Options Forwarded to Debuggee Process
343.LP
tbell16c34dd2009-05-04 18:28:26 -0700344.RS 3
duke6e45e102007-12-01 00:00:00 +0000345.TP 3
346\-v \-verbose[:class|gc|jni]
347Turns on verbose mode.
348.TP 3
349\-D<name>=<value>
350Sets a system property.
351.TP 3
tbell16c34dd2009-05-04 18:28:26 -0700352\-classpath <directories separated by ":">
duke6e45e102007-12-01 00:00:00 +0000353Lists directories in which to look for classes.
354.TP 3
355\-X<option>
356Non\-standard target VM option
tbell16c34dd2009-05-04 18:28:26 -0700357.RE
358
duke6e45e102007-12-01 00:00:00 +0000359.LP
360.SH "SEE ALSO"
361.LP
362
363.LP
364.LP
tbell16c34dd2009-05-04 18:28:26 -0700365javac(1), java(1), javah(1), javap(1), javadoc(1).
duke6e45e102007-12-01 00:00:00 +0000366.LP
367
368.LP
369