Detailed explanation of the use of debug in IntelliJ idea

Time:2021-9-26

1、 Debug opening

The following interface is the interface of MAC 2020.1. First, take a look at the interface in debug mode in idea.

  • 1. Express withDebug modeTo start the service, the first button on the left starts in the run service mode. In development, we generally start the debug mode directly to facilitate debugging the code at any time.
  • 2、breakpoint: left click in the line number column on the left, orCtrl+F8Mark / cancel breakpoints, and the color of the breakpoint line can be set by yourself.
  • 3、Debug window: after the access request reaches the first breakpoint, the debug window is automatically activated. If it is not activated automatically, you can set it in the settings.
  • 4、Debug button: you can find the same corresponding function in run in the menu bar.
  • 5、Service button: you can turn off / start the service, set breakpoints, etc. here.
  • 6、Method invocation stack : all the methods debugged by this thread are displayed here. Check the [show all frames] button in the upper right corner, and the methods of other class libraries will not be displayed. Otherwise, there will be a lot of methods here. The following figure shows the methods of other class libraries.
  • 7、Variables: in the variables area, you can view the variables in the current method before the current breakpoint.

Detailed explanation of the use of debug in IntelliJ idea

Detailed explanation of the use of debug in IntelliJ idea

View variables

In the process of debugging, it is very necessary to track and view the changes of variables. Here are a few places where variables can be viewed in the idea. I believe most people understand it.

Calculation expression

Evaluate ExpressionThis expression can not only be a general variable or parameter, but also a method. When you call several methods in a row of code, you can look at the return value of a method in this way.

Smart step in

Think about how to select only one method to enter when there are several methods in one line of code. You can use step into or force step into, but these two operations will enter at one time according to the order of method calls, which is troublesome, so smart step into is very convenient.

Interrupt debug

How to interrupt the request during debugging without going through the rest of the process.

Detailed explanation of the use of debug in IntelliJ idea

You can see that this is where we broke on line 797.
It can be handled by forcing a return or throwing an exception.

Detailed explanation of the use of debug in IntelliJ idea

This method returns a string of type string, so you only need to add any return value, and then clickResume Program, you can forcibly terminate debug.

Detailed explanation of the use of debug in IntelliJ idea

Detailed explanation of the use of debug in IntelliJ idea

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

Seven Python code review tools recommended

althoughPythonLanguage is one of the most flexible development languages at present, but developers often abuse its flexibility and even violate relevant standards. So PythoncodeThe following common quality problems often occur: Some unused modules have been imported Function is missing arguments in various calls The appropriate format indentation is missing Missing appropriate spaces before and after […]