blob: bdfbf0ba08ea8a1059413e988522d75ef20f05bf [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001.'" t
2." Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
3." DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4."
5." This code is free software; you can redistribute it and/or modify it
6." under the terms of the GNU General Public License version 2 only, as
7." published by the Free Software Foundation.
8."
9." This code is distributed in the hope that it will be useful, but WITHOUT
10." ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11." FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12." version 2 for more details (a copy is included in the LICENSE file that
13." accompanied this code).
14."
15." You should have received a copy of the GNU General Public License version
16." 2 along with this work; if not, write to the Free Software Foundation,
17." Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18."
19." Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20." CA 95054 USA or visit www.sun.com if you need additional information or
21." have any questions.
22." `
23.TH jdb 1 "05 Aug 2006"
24." Generated by html2roff
25
26.LP
27.SH NAME
28jdb \- The Java Debugger
29.LP
30
31.LP
32.LP
33\f3jdb\fP helps you find and fix bugs in Java language programs.
34.LP
35.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
50.TP 3
51options
52Command\-line options, as specified below.
53.TP 3
54class
55Name of the class to begin debugging.
56.TP 3
57arguments
58Arguments passed to the \f2main()\fP method of \f2class\fP.
59.LP
60.RE
61.SH "DESCRIPTION"
62.LP
63
64.LP
65.LP
66The Java Debugger, \f3jdb\fP, is a simple command\-line debugger for Java classes. It is a demonstration of the
67.na
68\f2Java Platform Debugger Architecture\fP @
69.fi
70http://java.sun.com/javase/6/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.
71.LP
72.SS
73Starting a jdb Session
74.LP
75
76.LP
77.LP
78There 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:
79.LP
80.nf
81\f3
82.fl
83 % jdb MyClass
84.fl
85\fP
86.fi
87
88.LP
89.LP
90When 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.
91.LP
92.LP
93Another 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.
94.LP
95.nf
96\f3
97.fl
98\-agentlib:jdwp=transport=dt_socket,server=y,suspend=n
99.fl
100\fP
101.fi
102
103.LP
104.LP
105For example, the following command will run the MyClass application, and allow \f3jdb\fP to connect to it at a later time.
106.LP
107.nf
108\f3
109.fl
110 % java \-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass
111.fl
112\fP
113.fi
114
115.LP
116.LP
117You can then attach \f3jdb\fP to the VM with the following commmand:
118.LP
119.nf
120\f3
121.fl
122 % jdb \-attach 8000
123.fl
124\fP
125.fi
126
127.LP
128.LP
129Note 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.
130.LP
131.LP
132There 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
133.na
134\f2documentation\fP @
135.fi
136http://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
137.na
138\f21.4.2 documentation\fP @
139.fi
140http://java.sun.com/j2se/1.4.2/docs/technotes/guides/jpda/conninv.html
141.LP
142.SS
143Basic jdb Commands
144.LP
145.LP
146The 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.
147.LP
148.RS 3
149
150.LP
151.TP 3
152help, or ?
153The most important \f3jdb\fP command, \f2help\fP displays the list of recognized commands with a brief description.
154.TP 3
155run
156After 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).
157.TP 3
158cont
159Continues execution of the debugged application after a breakpoint, exception, or step.
160.TP 3
161print
162Displays 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.
163.LP
164\f2NOTE: To display local variables, the containing class must have been compiled with the \fP\f2javac\fP\f2 \fP\f2\-g\fP option.
165.LP
166\f2print\fP supports many simple Java expressions including those with method invocations, for example:
167.RS 3
168.TP 2
169*
170\f2print MyClass.myStaticField\fP
171.TP 2
172*
173\f2print myObj.myInstanceField\fP
174.TP 2
175*
176\f2print i + j + k\fP \f2(i, j, k are primities and either fields or local variables)\fP
177.TP 2
178*
179\f2print myObj.myMethod()\fP \f2(if myMethod returns a non\-null)\fP
180.TP 2
181*
182\f2print new java.lang.String("Hello").length()\fP
183.RE
184.TP 3
185dump
186For 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.
187.LP
188The \f2dump\fP command supports the same set of expressions as the \f2print\fP command.
189.TP 3
190threads
191List 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:
192.RS 3
193
194.LP
195.nf
196\f3
197.fl
1984. (java.lang.Thread)0x1 main running
199.fl
200\fP
201.fi
202.RE
203In 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,
204.TP 3
205thread
206Select 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.
207.TP 3
208where
209\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.
210.LP
211If 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.
212.LP
213.RE
214.SS
215Breakpoints
216.LP
217
218.LP
219.LP
220Breakpoints can be set in \f3jdb\fP at line numbers or at the first instruction of a method, for example:
221.LP
222.RS 3
223.TP 2
224*
225\f2stop at MyClass:22\fP \f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)\fP
226.TP 2
227*
228\f2stop in java.lang.String.length\fP \f2(sets a breakpoint at the beginnig of the method \fP\f2java.lang.String.length\fP)
229.TP 2
230*
231\f2stop in MyClass.<init>\fP \f2(<init> identifies the MyClass constructor)\fP
232.TP 2
233*
234\f2stop in MyClass.<clinit>\fP \f2(<clinit> identifies the static initialization code for MyClass)\fP
235.RE
236
237.LP
238.LP
239If 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".
240.LP
241.LP
242The \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.
243.LP
244.SS
245Stepping
246.LP
247
248.LP
249.LP
250The \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.
251.LP
252.SS
253Exceptions
254.LP
255
256.LP
257.LP
258When 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.
259.LP
260.LP
261Use 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.
262.LP
263.LP
264The \f2ignore\fP command negates the effect of a previous \f2catch\fP command.
265.LP
266.LP
267\f2NOTE: The \fP\f2ignore\fP command does not cause the debugged VM to ignore specific exceptions, only the debugger.
268.LP
269.SH "Command Line Options"
270.LP
271
272.LP
273.LP
274When 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.
275.LP
276.LP
277The following additional options are accepted by \f3jdb\fP:
278.LP
279.TP 3
280\-help
281Displays a help message.
282.TP 3
283\-sourcepath <dir1:dir2:...>
284Uses the given path in searching for source files in the specified path. If this option is not specified, the default path of "." is used.
285.TP 3
286\-attach <address>
287Attaches the debugger to previously running VM using the default connection mechanism.
288.TP 3
289\-listen <address>
290Waits for a running VM to connect at the specified address using standard connector.
291.TP 3
292\-listenany
293Waits for a running VM to connect at any available address using standard connector.
294.TP 3
295\-launch
296Launches 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.
297.TP 3
298\-listconnectors
299List the connectors available in this VM
300.TP 3
301\-connect
302<connector\-name>:<name1>=<value1>,...
303Connects to target VM using named connector with listed argument values.
304.TP 3
305\-dbgtrace [flags]
306Prints info for debugging jdb.
307.TP 3
308\-tclient
309Runs the application in the Java HotSpot(tm) VM (Client).
310.TP 3
311\-tserver
312Runs the application in the Java HotSpot(tm) VM (Server).
313.TP 3
314\-Joption
315Pass \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.
316.LP
317.LP
318Other options are supported for alternate mechanisms for connecting the debugger and the VM it is to debug. The Java Platform Debugger Architecture has additional
319.na
320\f2documentation\fP @
321.fi
322http://java.sun.com/javase/6/docs/technotes/guides/jpda/conninv.html on these connection alternatives.
323.LP
324.SS
325Options Forwarded to Debuggee Process
326.LP
327.TP 3
328\-v \-verbose[:class|gc|jni]
329Turns on verbose mode.
330.TP 3
331\-D<name>=<value>
332Sets a system property.
333.TP 3
334\-classpath <directories separated by
335":">
336Lists directories in which to look for classes.
337.TP 3
338\-X<option>
339Non\-standard target VM option
340.LP
341.SH "SEE ALSO"
342.LP
343
344.LP
345.LP
346javac, java, javah, javap, javadoc.
347.LP
348
349.LP
350