Illustrations teach you how to use the remote debugging IntelliJ IDEA

1 Introduction

Today there was a line of Bug, and relatively pit is involved in debugging the next thing to micro-channel can not be associated line. Various traditional way is in the code and then re-log log Buried deploy debug, and then analyze the information in the log. If you log Buried unreasonable, it is necessary to modify the code constantly, non-stop package deployment. There is no operating Sao avoid the above problems?

2. Remote Debugging

Of course there is a solution, which is remote debugging (Remote debugging). Remote debugging enables developers to directly diagnose problems on the server or other online process that provides online tracking runtime errors and identify performance bottlenecks and methods source of the problem, so you can debug the same as in the local Debug remote server. Next we will use the popular Java IDE, produced by the JetBrains IntelliJ IDEA for remote debugging. Let the remote server supports remote debugging code running, the start time must be added the specific JVM parameters, which are:

-Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=${debug_port}
复制代码

Which debug_portis open to the server debug port, follow the local configuration will be used.

3. Use the remote debugging IDEA

IntelliJ IDEA for remote debugging is not complicated after following a few steps you can easily configure.

3.1 Local parameter configuration

Open the configuration panel in accordance with a new upper position of FIG Remote debug panel as follows:

In turn be configured in conjunction with the order shown on the map server and your local environment, and then click OK on the line. 2 and 4 wherein the step of distal ports that we specify debug_portthe port number.

3.2 JDWP agreement

Here's a little knowledge is a parameter jdwp. So what is jdwp?

JDWP is an acronym for Java Debug Wire Protocol, which defines the communication protocol between a debugger (debugger) and the target virtual machine (target vm). Target vm run in the Java program that we want to debug, it is no different from the general run of the JVM, but JDWP Agent loaded at startup and thus has the debugging functions. The debugger is our local debugger, it sends instructions to the operation of the target vm to obtain the status of target vm run-time control and remote execution of Java programs. Debugger and target vm runs respectively in their process, they communicate through JDWP communication protocol.

3.3 turn on remote debugging

Click the arrow shown in green beetle button (shortcut Shift + F9) to start the debugger, and then set a breakpoint in native code, allowing remote triggering logic breakpoint logic can be break point debugging.

Make sure that the code and the code remotely deployed locally debug exactly the same, any changes can not happen! Otherwise, the breakpoint will not be hit!

4. The number of points

In addition to the need to ensure consistency of code, there are some areas we need to pay attention here. Remote debugging of JDWP Agent should be disabled, that is, the distal end of the relevant parameters removed. Also in the remote debugging log will not be mapped to the local, of course, you can use some tools to map to the local remote log to provide a more powerful debugging features.

Also keep in mind, though remote debugging is a very powerful tool, but it is not a silver bullet! Production environment is not an appropriate target debugging, do not abuse!

5. Summary

As I described in this article as the use of IntelliJ IDEA for remote debugging is very simple, just a few steps to use. In some cases it easily solved our problem. But it should not be abused, should be rational use.

关注公众号:Felordcn获取更多资讯

Personal blog: https: //felord.cn

Guess you like

Origin juejin.im/post/5de68796518825124c50bb75