You may not know the remote debugging techniques

problem

  1. In our daily development, testing personnel in a test environment experiencing a problem, the problem is not sufficient to lock the log, can not wait to remotely debug the code
  2. Previous article describes SpringBoot start, main method directly in the IDE application to run, skip SpringBoot of Jarlanucher, I do not know how to debug the boot process Jarlanucher
  3. For Tomcat source code, but they could not start the debugging process of Tomcat
  4. PC configuration is not high, can not run a large number of micro-services, hire a virtual machine running on a micro cloud service, you can only rely on manually add logs to troubleshoot, influence the development efficiency

If you encounter these problems knowing where to start, then you have to look at remote debugging, rather than marking time to solve the problem with the vagaries of the old method

text

In a very long time, I have always thought debugging (Debug) is the IDE functionality, and only local debugging a program for remote environment is powerless. Github learned a good view of Chinese open source projects Java Agent, the project even teach developers how to use remote debugging, I realized that JVM also provides a set of tools so good at Issue in, really Brief Encounter ah !!!

Java Agent

Java Agent provides the ability to modify the bytecode a run-time developers, such as JVM-level AOP, do not restart the application to directly modify the byte code, the use of this technology can play a lot of application code can not be achieved tricks.

JDPA

JDPA full name of the Java Platform Debugger Architecture (Java Platform Debugger Architecture), defines the debugging architecture on the Java platform, including three main components: JVMTI (Java Virtual Machine Tool Interface), JDI (Java debug wire protocol) and JDWP (Java debug Interface)

JDWP

JDWP full name of the Java Debug Wire Protocol, defines the communication protocol between the debugger to debug and remote JVM

JDPA system is very complex, we as developers first learn how to use it. Usage is very simple, start the application parameters plus the following parameters like

-agentlib:jdwp=transport=dt_socket,address=6666,server=y,suspend=n

Then select which IDE Remote Java Application, fill in the corresponding IP and port, you can happily remote debugging

  • agentlib: jdwp use the Java Agent technology, as the selection agent JDWP
  • transport = dt_socket using the socket as a means of communication, in fact, windows support socket and shared memory, while Linux only supports socket
  • address monitor port
  • server = y indicates that the JVM will soon be commissioning
  • suspend = n Description JVM running immediately, if set to y, represents the future of the JVM until the debugger will be attached, and is suitable for application initialization debugging scenarios

summary

  • Java Agent provides a very powerful expansion capabilities
  • JDPA remote debugging is very easy to use, provides a more efficient way for us to solve the problem
  • More shopping Github, even if English is not good, but also to start Chinese open source projects to start, not to mention more and more people are excellent open-source projects, the absolute benefit

Guess you like

Origin juejin.im/post/5d3c0bdc51882505974ff065