Attaching to a Java VM

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/j2se/1.3/docs/guide/jpda/conninv.html.

Required Options

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

Option Description
-classic Required for the JavaTM 2 Platform, Standard Edition, v. 1.3.1 or earlier.
-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: 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

For the J2SE platform v. 1.3.0:

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

For the J2SE platform v. 1.3.1:

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

For the J2SE platform v. 1.3.0:

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

For the J2SE platform v. 1.3.1:

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

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
The Debug Environment

Legal Notices