- Starting a Debugging Session
- Attaching the Debugger to a Running Application
- Starting the Debugger Outside of the Project's Main Class
- Stepping Through Code
- Setting Breakpoints
- Managing Breakpoints
- Customizing Breakpoint Behavior
- Monitoring Variables and Expressions
- Backing Up from a Method to Its Call
- Monitoring and Controlling Execution of Threads
- Fixing Code During a Debugging Session
- Viewing Multiple Debugger Windows Simultaneously
Attaching the Debugger to a Running Application
If you need to debug an application that is running on another machine or is running in a different virtual machine, you can attach the IDE's debugger to that application:
- Start in debug mode the application that you are going to debug. This entails adding some special arguments to the script that launches the application.
For Windows users using a Sun JDK, the argument list might look like the following (all in one line and no space after -Xrunjdwp:):
java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_shmem,server=y,address=MyAppName,suspend=n -classpath C:\my_apps\classes mypackage.MyApp
On other operating systems (or on a Windows machine when you are debugging an application running on a different machine), the argument list might look something like the following:
java -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,address=8888,suspend=n -classpath HOME/my_apps/classes mypackage.MyApp
See Table 5-2 for a key to these options. For more complete documentation of the options, visit http://java.sun.com/products/jpda/doc/conninv.html.
Table 5-2. Debugger Launch Parameters
Launch Parameter or Subparameter
Description
-Xdebug
Enables the application to be debugged.
-Xnoagent
Disables the sun.tools.debug agent so that the JPDA debugger can properly attach its own agent.
-Djava.compiler=NONE
Disables the JIT (Just-In-Time) compiler.
-Xrunjdwp
Loads the reference implementation of the Java Debug Wire Protocol, which enables remote debugging.
transport
Name of the transport to be used when debugging the application. The value can be dt_shmem (for a shared memory connection) or dt_socket (for a socket connection). Shared memory connections are available only on Windows machines.
server
If this value equals n, the application attempts to attach to the debugger at the address specified in the address subparameter. If this value equals y, the application listens for a connection at this address.
address
For socket connections, specifies a port number used for communi-cation between the debugger and the application.
For shared memory connections, specifies a name that refers to the shared memory to be used. This name can consist of any combination of characters that are valid in filenames on a Windows machine except the backslash. You use this name in the Name field of the Attach dialog box when you attach the debugger to the running application.
suspend
If the value is n, the application starts immediately. If the value is y, the application waits until a debugger has attached to it before executing.
- In the IDE, open the project that contains the source code for the application to be debugged.
- Choose Run | Attach Debugger.
- In the Attach dialog box, select the connector from the Connector combo box.
Choose SharedMemoryAttach if you want to attach to an application that has been started with the dt_shem transport. Choose SocketAttach if you want to attach to an application that has been started with the dt_socket transport.
See the Connector row of Table 5-3 for information on the different types of connectors.
Table 5-3. Attach Dialog Box Fields
Field
Description
Connector
Specifies the type of JPDA connector to use. On Windows machines, you can choose between shared memory connectors and socket connectors. On other systems, you can only use a socket connector.
For both shared memory connectors and socket connectors, there are Attach and Listen variants. You can use an Attach connector to attach to a running application.
You can use a Listen connector if you want the running application to initiate the connection to the debugger. If you use the Listen connector, multiple applications running on different JVMs can connect to the debugger.
Transport
Specifies the JPDA transport protocol to use. This field is automatically filled in according to what you have selected in the Connector field.
Host
(Only for socket attach connections.) The host name of the computer where the debugged application is running.
Port
(Only for socket connections.) The port number that the application attaches to or listens on. You can assign a port number in the address subparameter of the Xrunjdwp parameter that you pass to the JVM of the application that is to be debugged. If you do not use this suboption, a port number is assigned automatically, and you can determine the assigned port number by looking at the output of the process.
Timeout
The number of seconds that the debugger waits for a connection to be established.
Name
(Only for shared memory connections.) Specifies the shared memory to be used for the debugging session. This value must correspond to the value of the address subparameter of the Xrunjdwp parameter that you pass to the JVM of the application that is to be debugged.
Local Address
(Only for socket listen connections.) The host name of the computer that you are running on.
- Fill in the rest of the fields. The fields that appear after Connector depend upon the kind of connector that you have selected. See Table 5-3 for a key to the different fields.