In the process of developing the app, we need to revise and optimize our code repeatedly, especially when the program bug, need to quickly find out the cause of the error, make changes to ensure the correct execution of the program.
Breakpoint debugging, is the most commonly used the simplest kind of debugging, can step by step tracking program execution process, get the value of the variable, quickly find the cause of the error.
1, the basic operation of the breakpoint
The operation of the breakpoint is very simple, with a few diagrams below to explain how to add, delete, edit, and use breakpoints.
2. Global Breakpoint
Sets a global breakpoint (an exception breakpoint), and when an error is encountered, the debug program automatically navigates to the bottom of the stack, jumping to the line where the error code is located.
3. Conditional breakpoint
Set a conditional breakpoint, when the condition is met, the breakpoint is triggered, suitable for use in the loop structure, can be accurately positioned to a loop.
4. Symbol Breakpoint
A symbolic breakpoint can break a call to a specified function, or you can navigate to the code where the exception occurred and print the exception information.
5, NSLog output
During debugging, it is often necessary to output the required information through the NSLog on the console. The NSLog output consumes system resources, and the output data may reveal confidential information in the app, where all nslog output must be masked before the release of the official version.
NSLog In addition to the output of basic information, for the structure can also be output once.
6. Dynamic output
In the course of debugging the program, you can also output the desired information from the console by NSLog, in addition to viewing the values of the variables under Xcode by debugging breakpoints. Using the NSLog output requires that you write the information you want to output before you run it, and that if there is a change, it needs to be recompiled to run, very inefficient.
The following is a very simple and practical way, in the process of running the program, by inputting the corresponding instructions in the console, you can quickly print out the required information, very convenient.
The dynamic output instructions are two, p and Po, similar to NSLog usage, p is used to print out general information, and PO is used to print out object information. The use of dynamic directives is used in conjunction with breakpoints, which enables the dynamic printing of information when the output program executes to a breakpoint.
iOS Debugging-breakpoint debugging and dynamic output