IDEA-debug debugging

1. Introduction and significance of Debug

1. What is the program DeBug?

Debug is a skill of debugging programs that program developers must know.

The ratio of program development to program debugging in an enterprise is 1:1.5. It can be said that if you don't know how to debug a program, you won't be able to engage in programming.

2. What can Debug help us do?

(1) Tracking the running process of the code.

(2) Location of abnormal program operation.

(3) Online problem tracking.

3. The significance of Debug for program learners

(1) Through debugging, the execution flow of the program can be better viewed.

(2) Complicated program logic is difficult to understand clearly through the teacher’s oral explanation. At this time, debugging can help students understand the program very well.

(3) Locate the problem and improve the ability of self-solving problems.

2. Debug steps in IDEA

1. Set a breakpoint (F9)

2. Debugging program (8 buttons)

Button Description
(Alt + F10): If your cursor is on another line or other page, click this button to jump to the current line of code execution
(F8): Step over, go down line by line, if there is a method on this line, it will not enter the method.
(F7): Step in. If there is a method in the current line, you can enter the method, which is generally used to enter the custom method, and will not enter the method of the official class library.
(Alt + Shift + F7): Force step into, you can enter any method, you can use this method to enter the official class library when viewing the underlying source code.
(Shift + F8): Step out, exit from the step-in method to the method call. At this time, the method has been executed, but the assignment has not been completed.
Rewind the breakpoint.
(Alt + F9): Run to the cursor, you can position the cursor to the line you need to view, and then use this function, the code will run to the cursor line without interruption.
(Alt + F8): Calculation expression.

3. Observe the variables

(1) There are three ways to view variables:

  • View variables in the program area
  • View variables in Debugger's Variables
  • Hovering the mouse over the variable name will pop up the value of the current variable

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-2CaKKSk6-1614217396334)(images\2019-09-28_165050.jpg)]

(2) View the output

3. Jump to the current line of code execution

Jump to the current code execution line (Alt + F10) [External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-i5kGCYdx-1614217396335) (IDEA-DeBug-copy. assets/2019-09-28_163744.jpg)]

Function: Switch the program window to the currently running program.

4. The use of step-by-step debugging

1. Step through debugging

Step over the debug button (F8) [External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-eGfrTDCC-1614217396336) (IDEA-DeBug-copy.assets/2019-09- 28_164022-1601005452664.jpg)]

2. Function

Step over, go down line by line, if there is a method on this line, it will not enter the method.

It is often used when you don't want to enter the called method body during debugging.

5. Step into the use of debugging

1. Step into debugging

Step over the debug button (F7) [External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-T9G60Cru-1614217396338) (IDEA-DeBug-copy.assets/2019-09- 28_162345-1601005519372.jpg)]

2. Function

Step in, go down line by line, if there is a method on this line, enter the method.

Generally used to enter custom methods, methods that will not enter the official class library.

6. The use of mandatory stepping into debugging

1. Compulsory step into debugging

Force step into debugging button (Alt + Shift + F7) [External link image transfer failed, the source site may have anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-lxwShNRW-1614217396338) (IDEA-DeBug-copy.assets /2019-09-28_164200.jpg)]

2. Function

Enter the official class library method.

Help us learn and view the JDK source code.

7. The use of step-out debugging

1. Step out of debugging

Step out of the debug button (Shift + F8) [External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-R3SWlce9-1614217396339) (IDEA-DeBug-copy.assets/2019- 09-28_164215.jpg)]

2. Function

Exit from the method to the method call.

When debugging, sometimes you will jump into the method body that you don't want to view, and use step out at this time.

8. Use of fallback breakpoint debugging

1. Rewind breakpoint

Back breakpoint button [External link image transfer failed, the source site may have an anti-theft chain mechanism, it is recommended to save the image and upload it directly (img-bbNmc8mx-1614217396340) (IDEA-DeBug-copy.assets/2019-09-28_164428. jpg)]

2. Function

Go back to the call of the current method.

When you want to review the execution process of the method body, you do not need to restart Debug, you can use the rollback breakpoint method.

9. Run to the cursor

1. Run to the cursor

Run the button at the cursor (F9) [External link image transfer failed, the source site may have an anti-leech link mechanism, it is recommended to save the image and upload it directly (img-xwwNVTiq-1614217396341) (IDEA-DeBug-copy.assets/2019-09- 28_164418.jpg)]

2. Function

Make the program run to the cursor without setting a breakpoint.

10. Calculation expression

1. Calculation expression

Calculation expression button (Alt + F8) [External link image transfer failed, the source site may have anti-leeching mechanism, it is recommended to save the image and upload it directly (img-1d7tLle7-1614217396341) (IDEA-DeBug-copy.assets/2019- 09-28_164437.jpg)]

[External link image transfer failed. The origin site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-rbsJbc9e-1614217396342)(images\2019-10-03_182159.jpg)]

2. Function

Set variables, in the calculation expression box, you can change the value of the variable, so that sometimes it is very convenient for us to debug various values.

11. Conditional breakpoints

1. Conditional breakpoint

Right-click the breakpoint, you can set the conditions for entering the breakpoint

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-qVt1RLri-1614217396343)(images\2019-10-03_182101.jpg)]

2. Function

By setting the breakpoint condition, it stops at the breakpoint when the condition is met, otherwise it runs directly.

12. Multi-threaded debugging

1. Steps

(1) For multi-threaded debugging, you need to adjust the breakpoint suspension level to Thread

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-Llob9ann-1614217396343)(images\2019-10-05_164127.jpg)]

(2) Select thread for debugging in Frame

image-20200925114949296

At the same time, in the expression, we can also make the following settings:

Thread.currentThread().getName()

/uploadPicture/image-20200925114949296.png" alt=“image-20200925114949296” style=“zoom:80%;” />

At the same time, in the expression, we can also make the following settings:

Thread.currentThread().getName()
image-20200925135141912

Guess you like

Origin blog.csdn.net/weixin_43334389/article/details/114061431