Attaching the Debugger to a Running Process

When you debug a Java application, at least two virtual machines (VMs) must be running. One VM runs the IDE, and the other VM runs the application being debugged. If you start a debugging session by using the Debug and choose Start command, the IDE runs the second VM for you. If you start a debugging session by using the Debug and choose Attach command, you must explicitly launch the second VM.

Running a Virtual Machine 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 Virtual Machine

Once you start a VM in debugging mode, you can attach the IDE debugger to it.

  1. From the main window, choose Debug and choose Attach.
  2. In the Attach to VM dialog box, select a debugger type.

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

See also
The Debug Environment

Legal Notices