• No results found

Debugging a program already running on the remote computer

In document Building Applications with JBuilder (Page 194-197)

already-running application, see “Debugging a program already running on the remote computer” on page 9-6.)

9 To terminate the application on the remote computer, stop the process in JBuilder. To close the Debug Server on the remote computer, choose the Debug Server’s File|Exit command.

Debugging a program already running on the remote computer

This section explains how to attach to a program that is already running on a remote computer and debug it using JBuilder on the client computer.

To do so, you will:

1 Run the application with VM debug options on the remote computer.

2 Use JBuilder on the client computer to attach to and debug the running application.

Important The source files for the application you are debugging must be available on the client computer. The compiled .class files must be available on the remote computer. They must match. Otherwise, unpredictable results may occur, including incorrect errors being generated or the debugger stopping on the wrong source code line. Every time you modify the source code, be sure to update the .class files on the remote computer.

For a tutorial that walks through attaching to an already running program, see Chapter 19, “Tutorial: Remote debugging.”

To start a program on the remote computer and attach to it,

1 Compile the application on the remote computer. You can also compile the application in JBuilder on the client computer, then copy or use File Transfer Protocol (FTP) to put .class files on the remote computer.

2 Run the application on the remote computer, using the following VM options.

• If JBuilder is installed on the remote computer, you can run your program from within JBuilder. Open the project, then edit the runtime configuration (Run|Configurations|Edit). Enter the following parameters into the VM Parameters field:

-Xdebug -Xnoagent -Djava.compiler=NONE

-Xrunjdwp:transport=dt_socket,server=y,address=3999,suspend=y

D e b u g g i n g a p r o g r a m a l r e a d y r u n n i n g o n t h e r e m o t e c o m p u t e r

• If you don’t have JBuilder on the remote computer, you need to run your program from the command line. Add the following VM options to the Java command line:

-Xdebug -Xnoagent -Djava.compiler=NONE

-Xrunjdwp:transport=dt_socket,server=y,address=3999,suspend=y

The address and suspend parameters are optional. They follow the server parameter and are separated by a comma. No spaces are allowed between the parameters.

• The address parameter, based on the selected transport, holds the port number/address through which the debugger communicates with the remote computer. This parameter makes configuration easier - you don’t need to continually modify the Address field on the Debug page of the Runtime Properties dialog box. If the Transport Type is set to dt_socket, the address parameter holds the port number. If it’s set to dt_shmem, this parameter is set to the unique address name. If you’re using XP, do not use 5000 for the address parameter. This address is reserved for the Universal Plug

& Play.

• The suspend parameter indicates whether the program is

suspended immediately when it is started. You can turn off this setting by specifying suspend=n. (If suspend=n and no breakpoints are set, the program will run to completion without stopping when you start it.)

Note To run the application with JDK 1.2x or 1.3x, use the java executable from the bin directory of your JDK installation, not the java.exe in the jre/bin directory. This allows the Java VM to load the debugger file (libjdwp.so in Unix; jdwp.dll in Windows), which is necessary for debugging. (This does not apply to JDK 1.4x.)

3 Open JBuilder on the client computer.

4 Open the project for the application already running on the remote computer.

5 Create a debug configuration (it can be part of an existing runtime configuration or a new configuration):

a Choose Run|Configurations. To create a new configuration, click the New button. To edit a configuration, choose it and click Edit.

b For a new configuration, enter a name in the Configuration Name field.

c Set the Build Target to None.

9-8 B u i l d i n g A p p l i c a t i o n s w i t h J B u i l d e r

D e b u g g i n g a p r o g r a m a l r e a d y r u n n i n g o n t h e r e m o t e c o m p u t e r

d Select the Debug tab.

6 Select the Enable Remote Debugging checkbox. Select the Attach option.

7 Fill in the following fields:

• Host Name - The name of the remote computer. localhost is the default. You may need to check the network settings on the remote computer to find the host name.

• Transport - The transport method options:

• Type: Either dt_socket (socket transport) or dt_shmem (shared memory transport - not available on Unix systems). For more information on transport methods, see “JPDA: Connection and Invocation Details - Transports.” at http://java.sun.com/products/

jpda/doc/conninv.html#Transports.

• Address:

• If the Transport Type is set to dt_socket, this parameter holds the port number for the remote computer you are communicating with. Use the default port number, 3999. Change this value only if the default value is in use. This value must match the address

D e b u g g i n g a p r o g r a m a l r e a d y r u n n i n g o n t h e r e m o t e c o m p u t e r parameter to the Java VM that starts the program on the remote computer. See Step 2 earlier in this section.

Important If you are running Windows XP, do not use 5000 as the port number/address through which the debugger communicates with a remote computer. XP reserves this port for the Universal Plug & Play.

• If dt_shmem is selected as the Transport Type, set the address parameter to the unique name for the remote computer you are communicating with. The default is javadebug.

8 Click OK two times to close the Runtime Configuration Properties and Project Properties dialog boxes.

9 Choose either Run|Step Over or Run|Step Into to start the debugger.

10If the suspend parameter for the VM on the remote computer is set to y (see Step 2 earlier in this section), click the Resume Program button on the debugger toolbar to proceed with debugging.

11To terminate the application, close the application on the remote computer.

12To detach from the remote computer, stop the process in JBuilder.

Note To launch and debug an application on the remote computer, see

“Launching and debugging a program on a remote computer” on page 9-2.

In document Building Applications with JBuilder (Page 194-197)

Related documents