[Development] daily remote debugging

Foreword

Daily moving bricks, daily trample pit, to question more and more of their own development skills, only slowly accumulate it a success.

About Remote Debugging

Engaged in development since the back-end, with the client to develop very different, it is to locate loopholes in the server code.

1, exception handling, high log collection requirements. 2. Analysis of the problem on the server more, not an operating problem with the positioning of a mobile phone.

  • Loopholes in the code on the positioning server , rely on watching exception information and business logs, there are still certain restrictions, we expect to see dynamic information (for example, we want to see the actual run-time class load which kind?).
  • Of course, we can also use on the server Javadebugging tool, but often produce more environmental constraints (for security or other characteristics), not all of the debugging tools are available.

This requires a number of ways, remote debugging even breakpoint debugging code on the server, this article will explain how to perform remote debugging and development tools combined with IDEA breakpoint debugging.

Related Information

  1. Remote debugging requires some pre-configured on the server, not to say that you can debug code directly on the server.
  2. Debug mode affects performance, and even security will also be affected, not always turn debug mode.
  3. JVM performance will be affected because the debug mode will optimize the operation of the shield JVM itself.
  4. Recommend intranet, the test environment is not recommended exposed network, there will be a potential security threat.

Open Java remote debugging mode

  • JPDA (Java Platform Debugging Architecture) provides a series of API, as JDWP (Java Debug Wire Protocol) protocol debugging part.
  • JDWP protocol is an application process to communicate with the debugging process for remote debugging Java applications.

Turn on debug mode

  • In the JVM operating parameters, add the following command, you can see the use of two JVM options, -Xdebugand -Xrunjdwp, -Xdebuga debugging, -Xrunjdwpconfiguration JDWP agreement, and there are some necessary parameters.
-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
复制代码
  • JDWP protocol parameters

dt_socket: Configure socket communication port. dt_shmem: Application process and debug processes that use shared memory to interact, therefore, the debugger and the application must be on a single machine, so the remote debugging do not need this option.

  • Other parameters

suspend: This parameter is used to specify whether the debugging process to attach before the application process, suspend application process, the default is y. If you want to debug application initialization logic, you need to enable this option.

Practical exercise

test environment

  • It ran a server on top of a Java application, using a script to start.
  • IDEA 2019.01.02

Steps

  • First, look JVM parameter information
ps -ef | grep java
复制代码

Configuration parameters before

  • In the startup script, add debug option, and restart the Java application.

Debugging option open

IDEA remote debugging configuration steps

  1. Edit Configurations...
  2. Select Remote, fill in the corresponding IP address and port.

IDEA Configuration

  1. Click debug, start debugging! ! ! .

Epilogue

This article introduces the basic concepts of remote debugging, as well as how to combine IDE to complete remote debugging. Tomcat also JDWP agreement can remotely debug the code, though not tried.

references

Guess you like

Origin juejin.im/post/5d4902a36fb9a06b017e3650