Attaching to a Java VM

See Also

Attaching to a Java VM requires two procedures:

Running the Java VM in Debugging Mode

The following sections describe the options necessary for running a virtual machine in debugging mode. Full documentation of the options is available at http://java.sun.com/products/jpda/doc/conninv.html.

Required Options

The following options are required to launch a VM for debugging.

Option Description
-Xdebug Enables debugging.
-Xnoagent Disables the sun.tools.debug agent so that the JPDA can attach its agent in a different manner.
-Djava.compiler=NONE Disables the JIT compiler.
-Xrunjdwp:<JDWP sub-options> Loads the JPDA reference implementation of JDWP. The suboptions are described in the following sections.

JDWP Suboptions for Microsoft Windows Systems

If you are running the IDE on a Microsoft Windows system, use the following JDWP suboptions:

transport=dt_shmem,server=y,address=myapp,suspend=n 

The address option specifies the name of the shared memory. The name can consist of any combination of characters, excluding the backslash. If these options do not work, try using the options described in the following section.

JDWP Suboptions for Other Operating Environments

The following JDWP suboptions are suitable for all operating systems:

transport=dt_socket,server=y,address=8888,suspend=n

The address option specifies the port number.

Sample Commands

Following are examples of commands that can be used to start a VM for debugging.

Microsoft Windows Systems

java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,address=myapp,suspend=n -classpath C:\MyApplications\classes mypackage.MyApp

All Other Environments

java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n -classpath $HOME/my_apps/classes mypackage.MyApp

Note If you are attaching to an application that is running on an instance of the Classic VM, add -classic as the first option in the command.

Attaching the Debugger to the Java VM

  1. From the main menu, choose Debug and choose Start Session and choose Attach.
  2. In the Attach dialog box, select a debugger.

    The remainder of the items in this dialog box depend on the debugger implementation and transport implementation you are using. See Attach Dialog Box for descriptions of the fields in the Attach dialog box.

See Also
Debugging on a 64-Bit Java VM

Legal Notices