IOS debugging-breakpoint debugging and Dynamic Output
During App development, we need to modify and optimize our code repeatedly. In particular, when a program encounters a bug, We need to quickly find out the cause of the error and modify it, to ensure the proper execution of the program.
Breakpoint debugging is the most common and simple debugging method. You can track the program execution process step by step, get the variable value, and quickly find the cause of the error.
1. Basic breakpoint operations
Breakpoint operations are very simple. The following figure shows how to add, delete, edit, and use breakpoints.
2. Global breakpoint
Set a Global breakpoint (exception breakpoint). When an error occurs, the Debug program automatically locates the stack bottom information, that is, it jumps to the row where the error code is located.
3. Conditional breakpoint
When a condition breakpoint is set, the breakpoint is triggered only when the condition is met. It is suitable for loop structure and can be accurately located in a loop.
4. symbol breakpoint
A symbolic breakpoint can interrupt a specified function call, locate an exception code, and print the exception information.
5. NSLog output
During debugging, NSLog is often used to output the required information on the console. NSLog output consumes system resources, and the output data may expose the confidential information in the App. All NSLog output must be blocked before the official version is released.
In addition to the basic output information, NSLog can also output struct data at one time.
6. Dynamic Output
In the debugging process of a program, you can view the variable value under Xcode through breakpoint debugging, or use NSLog to output the desired information on the console. To use NSLog output, you need to write the information you want to output before running. If there is any change, you need to re-compile and run it, which is very inefficient.
The following describes a very simple and practical method. When the program is running, you can quickly print the required information by entering corresponding commands on the console.
There are two commands for dynamic output: p and po. Similar to NSLog usage, p is used to print output common information, and po is used to print output object information. Dynamic commands must be used with breakpoints to dynamically print the information when the output program runs to a breakpoint.