Remote debugging of a test environment using eclipse

Source: Internet
Author: User

Reprint please indicate the source

Author: Xiao Watanabe
Article Address: https://greatestrabit.github.io/2016/06/23/debug/

For engineers who use eclipse for everyday programming, debugging is a daily work. For the general sense of the debugging process, I believe that every engineer friends are proficient. Here are some of the more useful advanced features in debugging.

Remote debugging

Because of the difference in deployment environment, I believe many friends have encountered the development environment of the normal test function in the test environment and even production environment in the case of a bug. In general, the production environment can be used in a single way, that is, through the log to obtain the environment context in the run, Parse the log file and try to reproduce the bug. This will bring a lot of problems. First, the analysis of logs is a time-consuming task; second, existing logging does not necessarily reflect the problem, and you may need to repeat the process multiple times (analyze log-to-guess issues, and deploy- > get logs) to slowly approach the problem. In the case of a test environment, we have an alternative means of remote debugging: To start the program in debug mode in a test environment, and use eclipse to set breakpoints in the project for debugging.

1. Start the program in the test environment in debug mode

In the case of an independent Javase program, only a few parameters can be added at startup.
Java-xdebug-xrunjdwp:transport=dt_socket,server=y,address=11111,suspend=y-jar Calc.jar
If you start normally, you will see the following screen:
650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Remote%20debug%20server.png "alt=" Remote debug Server "style=" Border:0px;vertical-align:middle;height:auto; "/>

2. Using Eclipse for remote debugging

Configure the debug properties in the corresponding project in eclipse as follows:
650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Remote%20debug%20client.jpg "alt=" Remote Debug Client "style=" Border:0px;vertical-align:middle;height:auto; "/>

3. Start Remote debugging

Click the Debug button in the previous step to start debugging.
If everything works, you can start debugging programs on your test environment just as you would a local program.

4. Issues to be aware of
  1. If the program needs to receive input from the console, it should be entered in the console in the test environment.

  2. You need to be aware of inconsistencies in the code of your test environment and in your development environment. If the number of breakpoints set in eclipse corresponds exactly to a blank line in the test environment program, you will not be able to jump into the breakpoint and look as if debugging did not succeed. This situation does not occur in local debugging. Because local debugging cannot set a breakpoint on a blank line. The following is an example of a code inconsistency.
    Actual code comparison:
    650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Debugcode.jpg "alt=" Debugcode "style=" Border:0px;vertical-align:middle;height:auto; "/>
    The effect after operation is as follows:
    650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Remote%20debugging.png "alt=" Remote Debugging "style=" Border:0px;vertical-align:middle;height:auto; "/>
    Note the comparison between 2 and 3, in 3 should have the variable index at 2 does not appear.

    5.tomcat Remote Debugging

    Remote debugging of Tomcat requires that Tomcat be started in debug mode with the Start command (assuming the user is already in the Tomcat/bin directory):
    ./catalina.sh JPDA Start
    It is important to note that the latest version of Tomcat restricts debug listening addresses, allowing only 127.0.0.1 access, so if you debug on a non-local machine, you need to modify the settings:
    650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Remote%20debug%20tomcat.png "alt=" Remote Debug Tomcat "style=" Border:0px;vertical-align:middle;height:auto; "/>
    Change the jpda_address variable in the diagram from the original 127.0.0.1:8000 to 8000.
    There is no difference between the settings on the eclipse side and the settings in step 2nd.

    Conditional breakpoint

    Using conditional breakpoints is a good choice if you need to debug data in a loop. Set the breakpoint at the specified location, and right-click further to set the breakpoint property as follows:
    650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Condition%20debug.jpg "alt=" condition Debug "style=" Border:0px;vertical-align:middle;height:auto; "/>
    When debugging, the program is interrupted at the qualifying point.

    Exception Breakpoint

    Breakpoints can be set not only on a line, but also on the entire project. Typically, suppose you know that the program will throw NullPointerException somewhere, but not every run will appear, you can set an exception breakpoint for the project, as follows:
    650) this.width=650; "Src=" https://raw.githubusercontent.com/greatestrabit/greatestrabit.github.io/master/img/ Project%20breakpoint.jpg "alt=" Project Breakpoint "style=" Border:0px;vertical-align:middle;height:auto; "/>
    The program will break in the place where the nullpointerexception is thrown.

See the code in this article: GitHub

This article from the "Dream do not know is a guest" blog, please be sure to keep this source http://greatestrabit.blog.51cto.com/11375247/1792440

Remote debugging of a test environment using eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.