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