preface
Daily moving bricks, daily stepping on pits, more and more doubt their own development skills, only slowly accumulated into.
Introduction to Remote Debugging
The big difference between backend development and client development is to locate the vulnerabilities in the server code.
1. Higher requirements for exception handling and log collection. 2, the server analysis of the problem is much, not with mobile phone operation to locate the problem.
- Locating code vulnerabilities on the server by looking at exception messages and business logs is limited; we want to see dynamic information (e.g., which classes are actually loaded at runtime?). .
- Of course, we can also use it on the server
Java
Debugging tools, but oftenProduction environments have more constraintsNot all debugging tools are available (for security or other features).
This requires some means of remote debugging or even breakpoint debugging of the code on the server. This article will show you how to do remote debugging and breakpoint debugging with the IDEA development tool.
The relevant information
- Remote debugging requires some pre-configuration on the server, not that you can debug code directly on the server.
- Debug mode affects performance, and even security, and cannot be enabled all the time.
- JVM performance suffers because debug mode blocks tuning operations by the JVM itself.
- You are advised to perform the test on the Intranet or in a test environment. Do not expose the test to the Internet because of potential security threats.
Enable the Java remote debugging mode
- Java Platform Debugging Architecture (JPDA) provides a series of apis as part of the Java Debug Wire Protocol (JDWP).
- JDWP is a protocol for application processes to communicate with debuggers for remote debugging of Java applications.
Enable debugging Mode
- Add the following command to the JVM run parameter to see that two JVM options are used,
-Xdebug
with-Xrunjdwp
.-Xdebug
Enable debugging,-Xrunjdwp
Configure the JDWP protocol with the necessary parameters.
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
Copy the code
- JDWP protocol parameters
Dt_socket: configures the socket communication port. Dt_shmem: Application and debugger interact using shared memory. Therefore, the debugger and application must be on the same machine, so remote debugging does not require this option.
- The other parameters
Suspend: Indicates whether to suspend the debugging process before attaching it to the application process. The default value is Y. Enable this option if you want to debug the application initialization logic.
We practice
The test environment
- A server running a Java application starts with a script.
- The IDEA of 2019.01.02
steps
- First, take a look at the JVM parameter information
ps -ef | grep java
Copy the code
- In the startup script, add debugging options, and restart the Java application.
IDEA Remote debugging configuration procedure
- Edit Configurations…
- Select Remote and enter the corresponding IP address and port.
- Click debug to start debugging!! .
conclusion
This article introduced the basic concepts of remote debugging and how it can be done with an IDE. Tomcat also has the JDWP protocol to debug code remotely, although it hasn’t been tried yet.
reference
- Stackify.com/java-remote…