Write a service-side program, open remote debugging in the development environment is very useful, restore the scene is very easy, let the requester send a request again. If local debugging is down, many environments may be different from the address configuration of the management service, adding variable factors.
Include in the JVM startup parameters that need to start service debugging (note: The parameters are preceded by the startup class name)
-xdebug-xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1234
Dt_socket: the means of communication used
Server: Whether you are actively connecting to the debugger or waiting for the debugger to connect as a server
Suspend: Whether to pause when the JVM is started and wait for the debugger to connect
Address: Addresses and ports, addresses can be omitted, and both are separated by colons
Based on the discussion in the documentation and StackOverflow, the JVM 1.5 version should use a command similar to the following (old or available):
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1234
is a agentlib on the line, the following parameters are not changed, if you use the IntelliJ remote debugging configuration, it will default to give these two parameters, let you put in the server JVM parameters.
Take a look at the official documentation below:
-xdebug
-Xdebug
Enables debugging capabilities in the JVM which is used by the Java Virtual machine Tools Interface (JVMTI). JVMTI is a low-level debugging interface used by debuggers and profiling tools. With it, you can inspect the state and control the execution of applications running in the JVM.
The subset of JVMTI that are most typically used by profilers are always available. However, the functionality used by debuggers to being able to step through the code and set breakpoints have some overhead Ociated with it and isn't always available. To enable this functionality you must use the -Xdebug
option.
WARNING: |
When running With-xdebug the JVM was not a running at it full speed. Thus, the option should not being used for applications if running in production environments. |
Operation
Format:-Xdebug
Include this option at startup.
For Example:
java
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n
myApp
-xrunjdwp
This option loads the JPDA reference implementation of JDWP. This library resides in the target VMS and uses JVMDI and JNI to interact with it. It uses a transport and the JDWP protocol to communicate with a separate debugger application.
Operation
Format:-Xrunjdwp:<name1>[=<value1>],<name2>[=<value2>]...
The -Xrunjdwp
option can be further qualified by specifying one of the sub-options listed in Table 2-8.
Table 2-8-xrunjdwp sub-options
Name |
Required? |
Default Value |
Description |
Help |
No |
N/A |
Prints a brief help message and exits the VM. |
Transport |
Yes |
None |
The Name of the transport to is connecting to debugger application. |
Server |
No |
N |
If "Y", listen for a debugger application to attach; Otherwise, attach to the debugger application at the specified address. If "Y" and no address is specified, choose a transport address @ which to listen for a debugger application, and print th e address to the standard output stream. |
Address |
Yes, if server=n
no, otherwise |
““ |
Transport address for the connection. If Server=n, attempt to attach to debugger application at the this address. If server=y, listen for a connection at the this address. |
Launch |
No |
None |
At completion of JDWP initialization, launch the process given in this string. This option is used-combination with onthrow and/or onuncaught-Provide "Just-in-time debugging" in which a debugger Process is launched if a particular event occurs in this VM. Note that the launched process was not a started in its own window. In most cases the launched process should is a small application which in turns launches the debugger application in its O WN window. The following strings is appended to the string given in this argument (space-delimited). They can aid the launched debugger in establishing a connection with this VM. The resulting string is executed. The value of the transport sub-option. The value of the address sub-option (or the generated address if one is not given) |
Onthrow |
No |
None |
Delay initialization of the JDWP library until an exception of the given class are thrown in this VM. The exception class name must be package-qualified. Connection establishment is included in JDWP initialization, so it won't begin until the exception is thrown. |
Onuncaught |
No |
N |
If "Y", delay initialization of the JDWP library until an uncaught exception are thrown in this VM. Connection establishment is included in JDWP initialization, so it won't begin until the exception is thrown. See the JDI specification for com.sun.jdi.ExceptionEvent for a definition of uncaught exceptions. |
Stdalloc |
No |
N |
By default, the JDWP reference implementation uses a alternate allocator for its memory allocation. If "Y", the standard C Runtime library allocator would be used. This option was mainly for testing; Use it with care. Deadlocks can occur in this VM if the alternative allocator is disabled. |
Strict |
No |
N |
If "Y", assume strict jvmdi conformance. This would disable all workarounds to known bugs in Jvmdi implementations. This option was mainly for testing and should was used with care. |
Suspend |
No |
"Y" |
If "Y", Vmstartevent has a suspend Policy of Suspend_all. If "n", Vmstartevent has a suspend policy of Suspend_none. |
For example:
-Xrunjdwp:transport=dt_socket,server=y,address=8000
myApp
This command:
- Listens for a socket connection on port 8000.
- Suspends this VM before main class loads (by
suspend=y
default).
- Once The debugger application connects, it can send a JDWP command to resume the VM.
This command:
- Chooses an available GKFX memory transport address and print it to
stdout
.
- Listens for a shared memory connection at the address.
- Allows the VM to begin executing before the debugger application attaches.
This command:
- Attaches to a running debugger application via socket in host Myhost at Port 8000.
- Suspends this VM before main class loads.
This command:
- Attaches to a running debugger application via shared memory at transport address
mysharedmemory
.
- Suspends this VM before main class loads.
This command:
- Waits for a instance of to is thrown in the this
java.io.IOException
VM.
- Suspends the VM (by
suspend=y
default).
- Listens for a socket connection on port 8000.
- Executes the following:
/usr/local/bin/debugstub dt_socket myhost:8000
The can launch a debugger process in a separate window which would attach to the this VM and begin debugging it.
This command:
- Waits for the uncaught exception to is thrown in the this VM.
- Suspends the VM.
- Selects a shared memory transport address and listen for a connection on that address.
- Executes the following:
d:\bin\debugstub.exe dt_shmem <address>
The Where is the <address>
selected shared memory address.
The can launch a debugger process in a separate window which would attach to the this VM and begin debugging it.
Another document (JPDA Connection and invocation Details):
Sun VM Invocation Options
This section describes the options necessary to invoke Sun VMs for debugging.
Sun ' s VM implementations require command line options to load the JDWP agent for debugging. From 5.0 onwards the -agentlib:jdwp option was used to load and specify options to the JDWP agent. For releases prior to 5.0, the -xdebug and -xrunjdwp options is used (the 5.0 implementation also Suppo RTS the -xdebugand -xrunjdwp options But the newer -agentlib:jdwp option is preferable as the J DWP Agent in 5.0 uses the JVM TI interface to the VM rather than the older Jvmdi interface).
If your debugger application uses the JDI Sun Command Line Launching Connector, the Connector would use the -xdebug and -xrunjdwp options as the Connector is used to connect to a pre-5.0 target VM.
If the target VM is 5.0 or newer the -agentlib:jdwp option is specified as follows:
- -agentlib:jdwp=<sub-options>
-
Loads The JPDA reference implementation of JDWP. This library resides in the target VM and uses JVM TI and JNI to interact with it. It uses a transport and the JDWP protocol to communicate with a separate debugger application. Specific sub-options is described below.
For releases prior to 5.0 the -xdebug and -xrunjdwp options is used:
- -xdebug
-
Enables debugging
- -xrunjdwp:<sub-options>
-
Loads The JPDA reference implementation of JDWP. This library resides in the target VMS and uses JVMDI and JNI to interact with it. It uses a transport and the JDWP protocol to communicate with a separate debugger application. Specific sub-options is described below.
-AGENTLIB:JDWP and-xrunjdwp sub-options
THE-AGENTLIB:JDWP and-xrunjdwp option can be further qualified with sub-options. The sub-options is specified as follows:
-agentlib:jdwp=<name1>[=<value1>],<name2>[=<value2>] ...
Or
-xrunjdwp:<name1>[=<value1>],<name2>[=<value2>] ...
The table below describes the options that can is used:
-xrunjdwp sub-options
name |
required? |
Default Value |
Description |
Help |
No |
N/A |
Prints a brief help message and exits the VM. |
Transport |
Yes |
None |
The Name of the transport to is connecting to debugger application. |
Server |
No |
N |
If "Y", listen for a debugger application to attach; Otherwise, attach to the debugger application at the specified address. If "Y" and no address is specified, choose a transport address @ which to listen for a debugger application, and print th e address to the standard output stream. |
Address |
Yes, if server=n No, otherwise |
"" |
Transport address for the connection. If Server=n, attempt to attach to debugger application at the this address. If server=y, listen for a connection at the this address. |
Timeout |
no |
"" |
If server=y Specifies the timeout, in milliseconds, to wait For the debugger to attach. If server=n Specifies the timeout, in milliseconds, to use when attaching to the debugger. Note that the timeout option is ignored by some transport implementations. |
Launch |
no |
none |
at completion of JDWP initialization, launch the process G Iven in this string. This option was used in combination with , onthrow and/or onuncaught to provide " Just-in-time debugging "in which a debugger process was launched when a particular event occurs in this VM. Note that the launched process was not a started in its own window. In most cases the launched process should is a small application which in turns launches the debugger application in its O WN window. The The following strings is appended to the string given in this argument (space-delimited). They can aid the launched debugger in establishing a connection with this VM. The resulting string is executed.
- the value of the transport sub-option.
- the value of the address sub-option (or the generated address if one is not given)
|
Onthrow |
No |
None |
Delay initialization of the JDWP library until an exception of the given class are thrown in this VM. The exception class name must be package-qualified. Connection establishment is included in JDWP initialization, so it won't begin until the exception is thrown. |
Onuncaught |
No |
N |
If "Y", delay initialization of the JDWP library until an uncaught exception are thrown in this VM. Connection establishment is included in JDWP initialization, so it won't begin until the exception is thrown. See the JDI specification for com.sun.jdi.ExceptionEvent for a definition of uncaught exceptions. |
Suspend |
No |
"Y" |
If "Y", Vmstartevent has a suspendpolicy of Suspend_all. If "n", Vmstartevent has a suspendpolicy of Suspend_none. |
Examples
-
- -agentlib:jdwp=transport=dt_socket,server=y,address=8000
-
-
Listen for a socket connection on port 8000. Suspend this VM before main class loads (Suspend=y by default). Once The debugger application connects, it can send a JDWP command to resume the VM.
-
-
- -agentlib:jdwp=transport=dt_socket,server=y,address=localhost:8000,timeout=5000
-
-
Listen for a socket connection on port 8000 on the loopback address only. Terminate If the debugger does not attach within 5 seconds. Suspend this VM before main class loads (Suspend=y by default). Once The debugger application connects, it can send a JDWP command to resume the VM.
-
-
- -agentlib:jdwp=transport=dt_shmem,server=y,suspend=n
-
-
Choose an available GKFX memory transport address and print it to stdout. Listen for a shared memory connection at the address. Allow the VM to begin executing before the debugger application attaches.
-
-
- -agentlib:jdwp=transport=dt_socket,address=myhost:8000
-
-
Attach to a running debugger application via socket in host Myhost at Port 8000. Suspend this VM before the main class loads.
-
-
- -agentlib:jdwp=transport=dt_shmem,address=mysharedmemory
-
-
Attach to a running debugger application via shared memory at transport address " mysharedmemory". Suspend this VM before the main class loads.
-
-
- -agentlib:jdwp=transport=dt_socket,server=y,address=8000,onthrow=java.io.ioexception,launch=/usr/local/bin/ Debugstub
-
Wait for a instance of Java.io.IOException to being thrown in the this
-
VM. Suspend the VM (suspend=y by default). Listen for a socket connection on port 8000. Execute the following: " /usr/local/bin/debugstub dt_socket myhost:8000". The can launch a debugger process in a separate window which would attach to the this VM and begin debugging it.
-
-
- -agentlib:jdwp=transport=dt_shmem,server=y,onuncaught=y,launch=d:\bin\debugstub.exe
-
Wait for the uncaught exception to is thrown in the this
-
VM. Suspend the VM. Select a shared memory transport address and listen for a connection on that address. Execute the following: " d:\bin\debugstub.exe dt_shmem <address>", where <address> is the Selected shared memory address. The can launch a debugger process in a separate window which would attach to the this VM and begin debugging it.
Java Remote Debugging