## Name

jdb - The Java Debugger

f3jdb helps you find and fix bugs in Java language programs.

## SYNOPSIS

    f3
    f3jdb [ options ] [ class ] [ arguments ]

options Command-line options, as specified below.

class Name of the class to begin debugging.

arguments Arguments passed to the f2main() method of f2class.

## DESCRIPTION

The Java Debugger, f3jdb, is a simple command-line debugger for Java classes. It is a demonstration of the

f2Java Platform Debugger Architecture @

http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/index.html that provides inspection and debugging of a local or remote Java Virtual Machine.

##

Starting a jdb Session

There are many ways to start a jdb session. The most frequently used way is to have f3jdb 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 for f3java in the command line. For example, if your application's main class is MyClass, you use the following command to debug it under JDB:

    f3
     % jdb MyClass

When started this way, f3jdb invokes a second Java VM with any specified parameters, loads the specified class, and stops the VM before executing that class's first instruction.

Another way to use f3jdb 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.

    f3
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n

For example, the following command will run the MyClass application, and allow f3jdb to connect to it at a later time.

    f3
     % java -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n MyClass

You can then attach f3jdb to the VM with the following commmand:

    f3
     % jdb -attach 8000

Note that "MyClass" is not specified in the f3jdb command line in this case because f3jdb is connecting to an existing VM instead of launching a new one.

There are many other ways to connect the debugger to a VM, and all of them are supported by f3jdb. The Java Platform Debugger Architecture has additional

f2documentation @

http://docs.oracle.com/javase/7/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 see the

f21.4.2 documentation @

http://docs.oracle.com/javase/1.4.2/docs/guide/jpda/conninv.html

##

Basic jdb Commands

The following is a list of the basic f3jdb commands. The Java debugger supports other commands which you can list using f3jdb's f2help command.

help, or ? The most important f3jdb command, f2help displays the list of recognized commands with a brief description.

run After starting f3jdb, and setting any necessary breakpoints, you can use this command to start the execution the debugged application. This command is available only when f3jdb launches the debugged application (as opposed to attaching to an existing VM).

cont Continues execution of the debugged application after a breakpoint, exception, or step.

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 f2dump command below for getting more information about an object.
f2NOTE: To display local variables, the containing class must have been compiled with the f2javac(1)f2 f2-g option.
f2print supports many simple Java expressions including those with method invocations, for example:

o f2print MyClass.myStaticField

o f2print myObj.myInstanceField

o f2print i + j + k f2(i, j, k are primities and either fields or local variables)

o f2print myObj.myMethod() f2(if myMethod returns a non-null)

o f2print new java.lang.String("Hello").length()

dump For primitive values, this command is identical to f2print. For objects, it prints the current value of each field defined in the object. Static and instance fields are included.
The f2dump command supports the same set of expressions as the f2print command.

threads 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:

    f3
    4. (java.lang.Thread)0x1 main      running

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,

thread Select a thread to be the current thread. Many f3jdb commands are based on the setting of the current thread. The thread is specified with the thread index described in the f2threads command above.

where f2where with no arguments dumps the stack of the current thread. f2where all dumps the stack of all threads in the current thread group. f2where f2threadindex dumps the stack of the specified thread.
If the current thread is suspended (either through an event such as a breakpoint or through the f2suspend command), local variables and fields can be displayed with the f2print and f2dump commands. The f2up and f2down commands select which stack frame is current.

##

Breakpoints

Breakpoints can be set in f3jdb at line numbers or at the first instruction of a method, for example:

o f2stop at MyClass:22 f2(sets a breakpoint at the first instruction for line 22 of the source file containing MyClass)

o f2stop in java.lang.String.length f2(sets a breakpoint at the beginnig of the method f2java.lang.String.length)

o f2stop in MyClass.<init> f2(<init> identifies the MyClass constructor)

o f2stop in MyClass.<clinit> f2(<clinit> identifies the static initialization code for MyClass)

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)", or "f2MyClass.myMethod()".

The f2clear command removes breakpoints using a syntax as in "f2clear MyClass:45". Using the f2clear or command with no argument displays a list of all breakpoints currently set. The f2cont command continues execution.

##

Stepping

The f2step commands advances execution to the next line whether it is in the current stack frame or a called method. The f2next command advances execution to the next line in the current stack frame.

##

Exceptions

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, however, control returns to f3jdb at the offending throw. You can then use f3jdb to diagnose the cause of the exception.

Use the f2catch command to cause the debugged application to stop at other thrown exceptions, for example: "f2catch java.io.FileNotFoundException" or "f2catch mypackage.BigTroubleException. 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.

The f2ignore command negates the effect of a previous f2catch command.

f2NOTE: The f2ignore command does not cause the debugged VM to ignore specific exceptions, only the debugger.

## Command Line Options

When you use f3jdb in place of the Java application launcher on the command line, f3jdb accepts many of the same options as the java command, including f2-D, f2-classpath, and f2-X<option>.

The following additional options are accepted by f3jdb:

-help Displays a help message.

-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.

-attach <address> Attaches the debugger to previously running VM using the default connection mechanism.

-listen <address> Waits for a running VM to connect at the specified address using standard connector.

-listenany Waits for a running VM to connect at any available address using standard connector.

-launch Launches the debugged application immediately upon startup of jdb. This option removes the need for using the f2run 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 to continue execution.

-listconnectors List the connectors available in this VM

-connect <connector-name>:<name1>=<value1>,... Connects to target VM using named connector with listed argument values.

-dbgtrace [flags] Prints info for debugging jdb.

-tclient Runs the application in the Java HotSpot(tm) VM (Client).

-tserver Runs the application in the Java HotSpot(tm) VM (Server).

-Joption Pass f2option to the Java virtual machine used to run jdb. (Options for the application Java virtual machine are passed to the f3run command.) For example, f3-J-Xms48m sets the startup memory to 48 megabytes.

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

f2documentation @

http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html on these connection alternatives.

##

Options Forwarded to Debuggee Process

-v -verbose[:class|gc|jni] Turns on verbose mode.

-D<name>=<value> Sets a system property.

-classpath <directories separated by ":"> Lists directories in which to look for classes.

-X<option> Non-standard target VM option

## SEE ALSO

javac(1), java(1), javah(1), javap(1), javadoc(1).