Penguin
Annotated edit history of jdb(1) version 5, including all changes. View license author blame.
Rev Author # Line
1 JaredWigmore 1 !!!NAME
2 ;:jdb - Java debugger
3
4 !!!SYNOPSIS
5 jdb [[ ''options'' ] [[ ''class'' ] [[ ''arguments'' ]
6
7 !!!PARAMETERS
8 ;options: Command-line options.
9
10 ;class:Name of the class to begin debugging.
11
4 CraigBox 12 ;arguments:Arguments passed to the main() method of class.
1 JaredWigmore 13
14 !!!DESCRIPTION
4 CraigBox 15
16 The Java debugger, jdb, is a simple command-line debugger for Java classes. It is a demonstration of the Java Platform Debugger Architecture that provides inspection and
1 JaredWigmore 17 debugging of a local or remote Java Virtual Machine.
18
4 CraigBox 19 Starting a jdb Session: There are many ways to start a jdb session. The most frequently used way is to have jdb launch a new Java Virtual Machine (VM) with the main class of the application to be debugged. This is done by substituting the command jdb for java(1) in the command line. For example, if your application's main class is !MyClass, you use the following command to debug it under jdb:
20
21 example% jdb !MyClass
1 JaredWigmore 22
4 CraigBox 23 When started this way, jdb invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that class's first instruction.
1 JaredWigmore 24
4 CraigBox 25 Another way to use jdb is by attaching it to a Java VM that is already running. A VM that is to be debugged with jdb must be started with the following options:
1 JaredWigmore 26
4 CraigBox 27 |Option|Purpose
1 JaredWigmore 28 |-Xdebug| Enables debugging support in the VM.
5 JohnMcPherson 29 |-Xrunjdwp:trans�port=dt_socket,server=y,suspend=n|Loads in-process debugging libraries and specifies the kind of connection to be made.
1 JaredWigmore 30
4 CraigBox 31 For example, the following command will run the !MyClass application and allow jdb to connect to it at a later time:
1 JaredWigmore 32
4 CraigBox 33 example% jdb -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
1 JaredWigmore 34
5 JohnMcPherson 35 You can then attach jdb to the VM with the following command:
1 JaredWigmore 36
4 CraigBox 37 example% jdb -attach 8000
1 JaredWigmore 38
4 CraigBox 39 Note that !MyClass is not specified in the jdb command line in this case because jdb is connecting to an existing VM instead of launching a new one.
1 JaredWigmore 40
4 CraigBox 41 There are many other ways to connect the debugger to a VM, and all of them are supported by jdb. The Java Platform Debugger Architecture has additional documentation on
1 JaredWigmore 42 these connection options.
43
4 CraigBox 44 !Basic jdb Commands:
1 JaredWigmore 45
4 CraigBox 46 The following is a list of the basic jdb commands. The Java debugger supports other commands listed with the help command.
1 JaredWigmore 47
4 CraigBox 48 Notice that to display local (stack) variables, the class must have been compiled with the javac -g option.
1 JaredWigmore 49
4 CraigBox 50 ;__cont__:Continues execution of the debugged application after a breakpoint, exception, or step.
51 ;__dump__:For primitive values, this command is identical to print. For objects, it prints the current value of each field defined in the object. Static and instance fields are included. %%% The dump command supports the same set of expressions as the print command.
52 ;__help, or ?__: As the most important jdb command, help displays the list of recognized commands with a brief description.
53 ;__print__: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 dump command for getting more information about an object.
1 JaredWigmore 54
4 CraigBox 55 print supports many simple Java expressions including those with method invocations. For example:
1 JaredWigmore 56
4 CraigBox 57 print !MyClass.myStaticField
58 print myObj.myInstanceField
59 print i + j + k
60 ;:where i, j, and k are primitives and either fields or local variables.
61 print myObj.myMethod()
62 ;:if myMethod returns a non-null.
63 print new java.lang.String("Hello").length()
1 JaredWigmore 64
4 CraigBox 65 ;__thread__: Selects a thread to be the current thread. Many jdb commands are based on the setting of the current thread. The thread is specified with the thread index described in the threads command.
66 ;__threads__: Lists 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:
1 JaredWigmore 67
4 CraigBox 68 4. (java.lang.Thread)0x1 main running
1 JaredWigmore 69
4 CraigBox 70 ;: 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
71 ;__run__: After starting jdb, and setting any necessary breakpoints, use this command to start the execution of the debugged application. This command is available only when jdb launches the debugged application(as opposed to attaching to an existing VM).
1 JaredWigmore 72
4 CraigBox 73 ;__where__: The where subcommand with no arguments dumps the stack of the current thread (which is set with the thread command). Using where all dumps the stack of all threads in the current thread group. Using where threadindex dumps the stack of the specified thread. If the current thread is suspended (either through an event such as a breakpoint or through the suspend command), local variables and fields can be displayed with the print and dump commands. The up and down commands select which stack frame is current.
1 JaredWigmore 74
4 CraigBox 75 !Breakpoint Commands
1 JaredWigmore 76
4 CraigBox 77 Breakpoints are set in jdb at line numbers or at the first instruction of a method. For example:
1 JaredWigmore 78
4 CraigBox 79 stop at !MyClass:22
80 Sets a breakpoint at the first instruction for line 22 of the source file containing !MyClass.
1 JaredWigmore 81
4 CraigBox 82 stop in java.lang.String.length
83 Sets a breakpoint at the beginning of the method java.lang.String.length.
1 JaredWigmore 84
4 CraigBox 85 stop in !MyClass.init
86 init identifies the !MyClass constructor.
1 JaredWigmore 87
4 CraigBox 88 stop in !MyClass.clinit
89 clinit identifies the static initialization code for !MyClass.
1 JaredWigmore 90
5 JohnMcPherson 91 If a method is overloaded, you must also specify its argu�ment types so that the proper method can be selected for breakpoint. For example,
1 JaredWigmore 92
4 CraigBox 93 !MyClass.myMethod(int,java.lang.String)
1 JaredWigmore 94
95 or
96
4 CraigBox 97 !MyClass.myMethod()
1 JaredWigmore 98
4 CraigBox 99 The clear command removes breakpoints using a syntax as in clearMyClass:45. Using the clear command with no argument displays a list of all breakpoints currently set.The
1 JaredWigmore 100 cont command continues execution.
101
4 CraigBox 102 !Stepping Commands:
103
104 The step command advances execution to the next line, whether it is in the current stack frame or a called method.The next command advances execution to the next
1 JaredWigmore 105 line in the current stack frame.
106
4 CraigBox 107 !Exception Commands
1 JaredWigmore 108
4 CraigBox 109 When an exception occurs for which there is no catch statement anywhere in the throwing thread's call stack, the VM normally prints an exception trace and exits. When
110 running under jdb, however, control returns to jdb at the offending throw. Use jdb to determine the cause of the exception.
1 JaredWigmore 111
4 CraigBox 112 ;__catch__:Causes the debugged application to stop at other thrown exceptions. For example:
1 JaredWigmore 113
4 CraigBox 114 catch java.io.!FileNotFoundException
115 ;:or
116 catch mypackage.!BigTroubleException
1 JaredWigmore 117
4 CraigBox 118 ;: Any exception which is an instance of the specified class (or of a subclass) will stop the application at the point where it is thrown.
1 JaredWigmore 119
4 CraigBox 120 ;__ignore__: Negates the effect of a previous catch command. Notice that the ignore command does not cause the debugged VM to ignore specific exceptions, only the debugger.
1 JaredWigmore 121
4 CraigBox 122 !!OPTIONS
1 JaredWigmore 123
4 CraigBox 124 When using jdb in place of the Java application launcher on the command line, jdb accepts many of the same options as the java(1) command, including -D, -classpath, and -Xoption.
1 JaredWigmore 125
126 The following additional options are accepted by jdb:
127
4 CraigBox 128 ;__-sourcepath dir1:dir2:...__: 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.
129 ;__-attach address__:Attaches the debugger to previously runningVM using the default connection mechanism.
130 ;__-launch__:Launches the debugged application immediately upon startup of jdb. This option removes the need for using the run 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 __cont__ command to continue execution.
131 ;__-J option__: Pass option to the Java virtual machine, where option is oneoftheoptions described on the man page for the java application launcher, java(1). For example, -J-Xms48m sets the startup memory to 48 megabytes. It is a common convention for -J to pass options to the underlying virtual machine.
1 JaredWigmore 132
5 JohnMcPherson 133 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 docu�
1 JaredWigmore 134 mentation on these connection alternatives.
135
4 CraigBox 136 !!SEE ALSO
1 JaredWigmore 137 java(1), javac(1), javadoc(1), javah(1), javap(1)
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.

PHP Warning

lib/blame.php:177: Warning: Invalid argument supplied for foreach()