Common eclipse debugging skills

Source: Internet
Author: User
ArticleDirectory
    • The local machine acts as the client
    • This machine acts as the server

This article is not original. ClickViewOriginal post

This article is intended for those who have just stepped out of school just a few years ago and have not used these advanced debugging skills.

 

I remember that when I graduated, I didn't even have a breakpoint, but I still used jcreate , even the graduation project is used system. out Find bug , it's really stupid to think about it. A week has passed since the start of work, in a 1 , 2 Search for millions of rows in the System bug , I still use system. out , the most painful thing at the time was to modify the Code , suspected bug , output it, and restart it. (at that time, I didn't know how to hot Replace the code ), it wasn't until one day that my mentor found such stupid debugging bug : Let me know the breakpoint for the first time, and I know that hot replacement can be performed after the code is modified, my half victim of Chinese education is a small step towards a better life.

 

 

1, Conditional breakpoint

Breakpoint is familiar to everyone.Eclipse Java Double-click the line header in the editing area to get a breakpoint, and the code stops running here.

Conditional breakpoint, as its name implies, is a breakpoint with certain conditions. The Code stops running at the breakpoint only when the conditions set by the user are met.

Right-click the breakpoint and select the last"Breakpoint properties"

The breakpoint attribute interface and the meaning of each option are as follows,

2, Variable breakpoint

Breakpoints can be used not only in statements, but also in variables,

It is the breakpoint of a variable. It can be stopped when the value of the variable is initialized or the value of the variable is changed. Of course, the breakpoint of the variable can also be conditional, the settings are the same as those described above.

3, Method breakpoint

 

The method breakpoint is to place the breakpoint at the entrance of the method,

The method breakpoint is particularly effective when JDKIn the source code JDK Debugging information is removed during compilation, so normal breakpoints cannot be hit, but the method breakpoint is acceptable. You can view the call stack of the method through this method.

4, Change variable value

The Code stops at the breakpoint, but the passed value is incorrect. How can I modify the variable value to ensure that the code continues to follow the correct process, or that an abnormal branch is always inaccessible, can I change the debugging conditions to see if the abnormal branch code is correct?

InDebug View Variables In a small window, we can see Mdestjarname The variable value is " F: \ study \ eclipsepro \ jardir \ jarhelp. Jar "

Right-click the variable and select"Change value ..." In the displayed dialog box, modify the variable value,

Or modify it in the Value View window below.CTR + S After saving, the variable value will change to the new value after modification.

5, Redebug

 

This debugging rollback is not omnipotent. It can only be rolled back in the stack frame of the current thread, that is, it can only be returned to the start of the call of the current thread at most.

During rollback, right-click the thread method to be rolled back and select "Drop to frame"

6, Remote debugging

Used to debugProgram, There are two ways,

1. The local machine acts as the client

2. The local machine acts as the server

The premise of using remote debugging is that the code on the server and client is consistent.

 

The local machine acts as the client

This machine is usually used as a client. You need to enable the remote debugging switch when the Java program on the remote server is started,

Virtual Machine parameters must be added to the server.

Versions earlier than 1.5 (available after 1.5): [-xdebug-xrunjdwp: Transport = dt_socket, Server = Y, address = 8000]

1.5 and later versions: [-agentlib: jdwp = transport = dt_socket, Server = Y, address = 8000]

F: \ study \ eclipsepro \ screensnap> JAVA-xdebug-xrunjdwp: Transport = dt_socket, Server = Y, address = 8000-jar screensnap3.jar

When connecting to the remote server, you need to create a new remote debugging program in eclipse

Note that the debug view cannot be automatically switched during connection. Do not assume that the local debugging program is not connected to the server.

 

This machine acts as the server

Compared with the local machine as the client, you only need to modify the "connection type"

 

At this time, eclipse will enter the pending connection status

The Connection Program uses the following parameters to connect to the local server. Replace the IP address with the IP address ~~

[-Agentlib: jdwp = transport = dt_socket, suspend = Y, address = 127.0.0.1: 8000]

F: \ study \ eclipsepro \ screensnap> JAVA-agentlib: jdwp = transport = dt_socket, suspend = Y, address = 127.0.0.1: 8000-jar screensnap3.jar

 

During remote debugging, local code modifications can be synchronized to remote, but are not written to remote files. That is to say, local modifications will be lost the next time you start the remote program, it does not affect the remote code used next time.

 

For more details about remote debugging, see [Use eclipse to remotely debug Java applications]

 

 

It seems that a breakpoint is missing. If the breakpoint is abnormal, complete it.

7. Exception breakpoint

I often encounter some exceptions, and then the program exits. It is difficult to find out where the exceptions occur. Fortunately, you can create an exception breakpoint,

We added an nullpointexception exception breakpoint. When an exception occurs, the Code stops at the exception. It should be helpful to locate the problem.

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.