The debug function

The Debug mode is used to trace the running process of code. When exceptions occur during the running of a program, you can enable the Debug mode to analyze and locate the exception and the parameter changes during the running process. Usually we can also enable Debug mode to trace the running process of the code to learn the source code of the tripartite framework.

As a programmer, debugging skills are essential, and Android Studio provides us with powerful debugging capabilities. So let’s take a good look at the debugging capabilities that AS has for us today.

Single step debugging area

  1. Secondary mode: Show Execution Point (shortcut: Alt+F10)

(1) Click the button, and the icon will be positioned at the position of the cursor being debugged.

  1. Stem Over step (fast: F8)

(1) Step by step to the bottom of the execution, if a line has a method, it will not enter the method. (2) often used in the debugging process do not want to enter the call method situation.

  1. Step Into (F6)

(1) Step by step, if this step has the law into the method.

(2) Generally enter the custom method, will not enter the official class library method.

  1. Alt+Shift+F7

(1) You can enter the official class library.

(2) Help us learn and view the JDK source code.

  1. Setp Out Step Out (quick: F7)

(1) Exit from the method to the method call.

(2) When debugging, sometimes, do not want to view the method body, this time can use the step out.

  1. Drop Frame Rollback breakpoint

(2) When you want to call the method body again, you do not need to enable Debug again, you can use the fallback mode to execute.

  1. ### Run to Cursor (shortcut: Ctrl+R)

(2) If we now have a breakpoint on line 8 and a breakpoint on line 10, and the program is still at line 8, we move the cursor to line 9 and click this button, the program will run to line 9.

  1. ###Evaluate expression (Ctrl+U)

(1) Set the variable. In the box of computer expression, the value of the variable can be changed, so that it is convenient to debug other values.

Breakpoint management area

  1. Return (rerun)

(1) Clicking this button will stop the current application and restart it. In other words, when you want to re-debug, you can use this operation to, well, start over.

  1. Resume Program

(1) jump to the next breakpoint, can be understood as the next breakpoint; If there is no breakpoint, the run ends.

3.### Stop (1)

  1. View BreakPoints

Clicking this button will bring you to the Breakpoint management page, where you can view all breakpoints, manage or configure the behavior of breakpoints, such as: delete, modify property information…

  1. Mute BreakPoints

(1) This button is used to disable/start all breakpoints. If we get the result we want at a breakpoint and do not want to see other breakpoints, we can click this button to disable all breakpoints, and then the program will finish normally.

Breakpoint classification:

  • Conditional breakpoints

(1) Right-click the breakpoint to enter the condition of the breakpoint. (2) Pass the breakpoint condition, stop at the breakpoint only when the breakpoint condition is met, otherwise run directly.

  • Multithreaded debugging

(1) Multithreaded debugging, need to suspend the level of Thread.

  • Log breakpoint

When debugging, it is more likely to print the log to locate the exception code and use breakpoints to solve the problem after narrowing the scope. So the most common thing to do is to add log information in the code, output function parameters, return information, output we are interested in the variable information. The problem with this is that we need to recompile and run the program, add a lot of unnecessary code and are not easy to manage, so we can use log breakpoints. This type of breakpoint does not stop the program, but instead prints the log information we want it to print, and then continues execution.

  • Exception breakpoints

In some cases, we’re only interested in certain anomalies, or we’re only interested in anomalies; We want the program to break down if something happens to it; This is like preserving the scene, which will leave more clues, so that we can quickly find the root of the problem.

First we add an exception breakpoint by clicking: