当前位置:网站首页>How idea breaks point debugging

How idea breaks point debugging

2022-06-13 07:20:00 Focus on writing bugs


When writing code , Sometimes we need to keep track of how the code works , Using breakpoint debugging is a good way , Next, let's talk about how to IDEA Using breakpoints for debugging

1. To set breakpoints

Directly in the line number field of the code where you need the break point , Click on , You can set the breakpoint , As shown in the figure
 Insert picture description here

Here is a supplement to the understanding of breakpoints : Breakpoints are in front of the code , for example 11 The breakpoint of the line is set at 11 In front of the line of code , signify , When the program runs to 11 Line code breakpoints , The first 11 Line of code doesn't actually run

2. debugging

Click the green triangle to run the program , Click the green Ladybug to run the debugging program
 Insert picture description here

The program will enter the debugging interface , Breakpoint markers at the line of code , All turned into red arrows , The blue part indicates the number of lines the program has stopped
At the bottom is the debug window , The left part of the debug window is the method stack , That is, the following methods are called earlier , The right part of the debug window is the value of the variable
 Insert picture description here

3. Basic operation of debugging

3.1 step over

 Insert picture description here

At the top of the debug window , It means : Go to the next step , If the current line breakpoint is a method , Do not enter the current method . That is, from the code line A, Skip to the next line of code A + 1, And execute the original A Line code
for example :
Now let's go to the 12 Line code (12 Line not executed ), Current map There is only one element in , We can go down here Variables Confirm that there is only one element in
 Insert picture description here

When we click step over when : The first 12 The line contents are executed ,map Of size Turn into 2, The program comes to the 13 That's ok
 Insert picture description here

3.2 step into Follow Force step into

Both of them mean : Go to the next step , If the current line breakpoint is a method , Then enter the current method . But there's a difference ,step into Only for custom methods , If the corresponding method is the method of the official library , Does not enter the method body . but Force step into, Whatever the method is , Will enter the method body
give an example :
When it comes to 15 That's ok , A custom function :
 Insert picture description here

Use step into
 Insert picture description here

Then it enters the method body
 Insert picture description here

But if this is the official library method , Can't get into :
 Insert picture description here

here , If you need to enter the method body , You need to use Force step into:
 Insert picture description here

Enter here to hashmap in
 Insert picture description here

3.3 step out

Jump out of , That is, when we run in the method body , Don't want to continue running line by line , Want to go directly back to the method of the previous level , Then use step out Jump out of
Such as the above debugging , We enter hashmap in :
 Insert picture description here

Use :step out Jump out of
 Insert picture description here
 Insert picture description here

3.4 resume program

Restore program run , If the code below the breakpoint has a breakpoint, it will stop at the next breakpoint , That is, jump from one breakpoint to another
 Insert picture description here

for example : Program debugging to 13 That's ok , Click on Resume Program, Run directly to the next breakpoint 15 Stop at the right place
 Insert picture description here

After execution :
 Insert picture description here

3.5 mute breakpoints

Invalidate all breakpoints , Invalidate all breakpoints , You can run the rest of the program directly
 Insert picture description here

3.6 view breakpoints

View the information of all breakpoints
 Insert picture description here

Query results : You can see the information of all breakpoints you have set :
 Insert picture description here

3.6 Conditional breakpoints

Judge whether the breakpoint stops , Right click the breakpoint to set :
 Insert picture description here

for example , If we set the breakpoint like this , During our debugging , This code will stop 100 Time , If I just want it to be greater than 90 It's time to stop ?
 Insert picture description here

We can do this , Set conditional breakpoints :
 Insert picture description here

After setting , The breakpoint will be added “?”
 Insert picture description here

When debugging , When you stop :
 Insert picture description here

原网站

版权声明
本文为[Focus on writing bugs]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270549489139.html