Advanced Techniques for Eclipse debugging Java programs __debug

Source: Internet
Author: User
Tags java web

When you first started using Eclipse's debug, will only F5 F6 F7 F8, and even F7 are not very engaged in understanding how to use, when the capital is shallow, can not touch the need for complex debug code, slowly work deeply, the scene to touch more, you need a variety of debug techniques to improve the positioning of bug efficiency, Before looking for help to check the problem, see him open a variety of Windows debug all kinds of slip is envy envy hate, slowly long illness into medicine himself also used some of Eclipse's main debug techniques. Share it with a little bit of sorting.

F5678 these four basic skills are skipped, but the most basic skills can solve 90% problems, so although Skip said, but must be used very well, I believe that the park friends of the four people must be more than I used to slip. Logical Structure

The logical structure is mainly used to show the value of the collection data structure such as map, it only shows the logical part of the stored value, but it masks the detailed internal structure of the data structure, and makes it easier for us to view the values stored in the collection structure such as map, which is recommended to use.

This button is the display of the logical structure of the button, the following two figures, the above diagram is not to show the logical structure, the following diagram is the display of logical structure, it is obvious that the structure of the following diagram is more readable, you can focus on the debug variables.


Conditional debug

Conditional Debug uses a scenario that triggers a breakpoint when a condition needs to be met, such as a record with ID 12345, which triggers the breakpoint when the ID equals 12345.

Right-click a breakpoint to select a breakpoint property. Can see such a configuration box, the right text block can fill in the conditional code, such as id==12345, because each time to do this judgment, if the circulation number is very large, or a little bit slow, you can go to the toilet to pick up a water ah what, or very convenient.

Exception Breakpoint

An exception breakpoint can be configured to trigger a breakpoint only when it is in debug, and you do not need to debug to look for an exception.

Clicking on this red circle will eject the window of the abnormal breakpoint, list all the exception classes in your system, and then select the exception that requires the breakpoint to be OK.

Single Step Filtration

One step filter scenario is when we use F5 to follow a method inside, we often follow some of the methods that we do not need to see.

This.gettradedetail (UID, itemstr.substring (0,5))

such as this line of code, want to F5 into the gettradedetail inside, Will first execute the Itemstr.substring method, will first enter the substring method, and this method is the JDK string method, determine no problem, do not need to care, single-step filtering is to skip these we want to ignore the method directly to the target method inside a debug technique.

In the window > Preferencesjava > Debug > Step filtering Settings Filter, you can select which packages and classes you want to filter out. Also make sure that you have a single step filter enabled in the Debug view, as shown in the following figure. This filtering function is used when you use single step debugging.

The image above is a filter configuration that typically filters some of the JDK's classes and packages. The following figure is to turn on one-step filtering at debug time, otherwise it will not take effect.

Jump to Frame

Jumping to a frame is a kind of reentrant technique, in which eclipse can skip directly to any of the specified frames in the call stack and have the JVM rerun here. This allows you to rerun some of your code without needing to restart the code before debugging.

Note that variables that have been modified are not reset, and they retain the values at that time.

How to use: Select a frame in the call stack, click on the button "Jump to Hardwood"
Inspect

Inspect is used to view the value of an expression, and debug is a good view for a variable value, but it is not easy to view the value of an expression, or the sentence:

This.gettradedetail (UID, itemstr.substring (0,5))

If you want to see the value of Gettradedetail, you can't look at the value of the variable (although this is probably the assignment to a variable ...). To see this expression value, you need to inspect it by selecting the line expression, then right-clicking->inspect, or a more convenient shortcut key combination: Ctrl+shift+i, which pops up the following box showing the result of the expression:
Here to write a picture description

-Expressions

The expressions window is also used to look at the value of a variable or expression, open the Expression window in Windows->show viewz, and add the expression you want to observe in it, such as the sentence:

This.gettradedetail (UID, itemstr.substring (0,5))

Then debug, you can see the added expression results, in addition to the need to change value values. Display

Display is also used to observe and modify variable or expression, this should use more people, in windows->show viewz Open Display window, you can write expressions in the display window, Then right-click to select Display run View results or ctrl+shift+d shortcut key combination, the expression can be a line of code in the program or you write an assignment statement to change the value of the variable and so on.

Remote Debug

Remote debug can be used to debug the code on the remote server, to ensure that your local code and remote deployment of the code is consistent, you can debug the server code in this way, this is a great tool for Java Web Development, or the location of the server problem is simply a disaster.

Remote Debug requires the server-side to start the JVM to do some open and port configuration, the specific configuration of the Web a lot, search can be. Then, in the local debug configuration, double-click Add a remote Java application, fill in the remote host and configured the debug port, you can start debug, the following figure:

I usually use the main is this, if there are other feature, welcome to the park friends to add.

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.