Debug in Eclipse

Source: Internet
Author: User

First, the basic process of debugging

    1. Set a breakpoint (double-click the line to the left of the breakpoint you want to set)
    2. Enter debug mode (right-click > Debug mode on the class to be debugged, select according to demand)
    3. Start debugging

Second, the common operation in debug

  1. Continue with "F8": Continue running the program until the next breakpoint is suspended.
  2. Stepping into "F5": Executes the next line of valid code, detects the calling method, and enters the called method.
        • (Valid code: the code to be executed in this run.) For example, if the condition is False, if{} is an invalid code)
  3. Stepping Over "F6": Executes the next line of valid code.
  4. Step back to "F7": Executes the current method (until the breakpoint) and returns to the call (if any). (F7 is not valid when no caller is available)
  5. Step into the filter: After activation, when stepping (F5/F6/F7), encountered the filtered portion, will not stop, continue to execute. It is common to filter out the underlying code in the JDK or other libraries, or you can filter the frame part of the code in your own code base. (Settings: Windows > Preferences >Java> Debugging > stepping through filtering)
  6. Suspend/Resume: temporarily suspend a thread. Typically used for debugging multi-threaded applications.
  7. Drag-and-drop to frame: back to the beginning of the current method , the changes to the variables in the previous execution are all reset to the start state, but the role outside the program is irreversible (such as database operations, file operations, etc.). Can be used to modify code, change the value of variables, etc., repeatedly debugging the attention of a certain piece of code. "It's not just the current method, it's also possible to jump there by clicking on any of the frames in the current call stack (except the start frame)."
  8. Terminate: Forcibly closes all threads and ends this debug.

Iii. Summary of Breakpoints

1. Breakpoint Type

    1. Line breakpoint: Executes to the row pending. The most common form of breakpoints, double-click Add at the line number.
    2. Method Breakpoint: Suspend when entering/exiting the method. Hit the breakpoint at the entrance to the method. Features: The breakpoint can be hit in the JDK source code (line breakpoint not), so as to see the method call stack.
    3. Exception Breakpoint: Suspend when an exception occurs. Run > Add a Java exception breakpoint, or click Add Exception Breakpoint. you can use placeholders * and? to represent any string and any character, respectively.
    4. Class load breakpoint: Suspends when the specified class is loaded. Run > Add Class Mount breakpoint to add a class load breakpoint. used when debugging class loading (static methods, static code blocks, and so on).
    5. Variable Observer: Specifies that a member variable is suspended when a specified change occurs. Double-click the line number at the declaration member variable to add. You can choose to suspend when the variable is accessed, modified, or reached the specified condition.

2. Breakpoint Properties

On the breakpoint, right-click > Breakpoint Properties to set. These properties can be set by these breakpoints to change the way the hold is suspended.

    1. Hit Count: number of executions. When set, suspends when the program X executes to this breakpoint. Used for debugging in loops.
    2. Trigger point: Trigger Points. Once set, the breakpoint will only take effect if it is triggered.
    3. Suspend mode: Suspends the thread/hangs the VM. The former is typically used for multi-threading when the thread is suspended (a single thread can also be used, the same as the suspension VM effect).
    4. Conditional: Conditional breakpoint. When set, suspends only when the specified condition is met. Two options available: The condition is true/variable value changed. When you select condition as true, you should fill in the conditional expression in the condition bar, and when you select variable value change, you should fill in the variable expression in the condition bar.

Iv. Other Skills

1. In the first line of the Main method stop: Run > Debug Configuration, select "Stop in Main". When set, the program runs to the first row of the main function pending.

2. Expressions: You can observe some of the variables you are interested in, or you can add some of your own expressions, or you can see the results of a line of code running. Window > Show views > expressions, open Expression view, and then add expressions and observe dynamics. To evaluate an expression, select a row and right-click > Check where the value is requested.

Reference: Eclipse Debugger: 0 distance Contact combat skills

Debug in 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.