iOS various debugging techniques

Source: Internet
Author: User

For software development, debugging is the skill that must learn, the importance is self-evident. For debugging skills, basically can be migrated, that is, you previously on other platforms mastered a lot of debugging skills, many can also be used in iOS development. Different languages, different IDE, different platform debugging, have same sex also have personality. Today we will learn the debugging techniques in iOS development, language take up for oc,ide of course is a powerful xcode. First of all, Xcode has provided a great convenience for us to debug the project.

"1. Normal breakpoint"

Breakpoints (breakpoint) are definitely the first major choice for the debugger and the basic skills to master. As the name suggests, the program pauses when it runs to a breakpoint. For example, the breakpoint hits 11 lines, then the program stops at line 11 (note: The program only runs to the first 10 lines, and the 11th line has not yet been executed ...). )。 As long as you click Next to the line of code, you can add a breakpoint, click again, you can make the breakpoint unavailable (disable, still exist, just do not work). The shortcut key for creating a breakpoint on a line is: command+\




And you can see the value of the parameter at the bottom of the debugging process:



"2. Conditional breakpoint"

The above breakpoint is just the most common, we can also configure the properties of the breakpoint, set the conditions, make the breakpoint more intelligent, right-key breakpoint into the Edit dialog box:



I use a loop as the test code:


The code in the loop takes one step at a time, and maybe that's not what I want. I want to interrupt the program when I is 3, debug, and write the following conditions:


When you set a condition for a i==3, the program breaks on that condition, not every time it arrives at that location. The output of the interrupt is as follows:




You can also set the Ignore parameter, ignoring the preceding N-time breakpoint running, and then interrupting the first n+1.


The debug output is as follows:



Also, you can see the number of times a function was invoked, set the action parameter as follows, and note that you should select automatically continue after evaluating actions.

.


The output results are as follows:



"3. Abnormal breakpoint"

The functionality of a breakpoint is not limited to the above mentioned. Developing iOS knows that if we crash the program because of the exception then the code goes straight to MAIN.M's main function. Why can't you run to the code that appears in the exception ... The exception breakpoint solves the problem for us, and the program terminates the line of code that appears in the exception. Create an exception breakpoint legend is as follows:



The creation is complete as shown below. If you encounter an exception crash, try using an exception breakpoint.



"4. Symbol Breakpoint Symbolic Breakpoint"

Symbol breakpoints are also created with an exception breakpoint. A general symbolic breakpoint can break execution when you specify a [class name method name].



Configure a symbolic breakpoint as follows: You can break execution when the Viewdidload method to the Viewcontroller class is executed.



If your symbol writes only one function name, it will break execution at the place where the function name appears. If you do, you will be interrupted when you run to doanimation. is not very strong.

.


"5.Analyze Analyzer"

The Analyze analyzer is a static tool that can analyze our programs to find out which variables we don't use, or some dead storage. The executive Analyze is as follows: Product-->analyze. The blue mark below is the result of static analysis.





Of course, we can set the time to compile the program while analyze, the following options are set to Yes.



"6.Profile Checker"

This tool is too NB, Words said, put a picture, we feel, I will be in the future blog slowly explain the use of the tool. Also opens in the Product-->profile.



"7 Zombie Objects"

In iOS, objects that have been released but not completely disappeared are called Zombie objects, and exceptions are made to release objects once again. Although the exception that has been generated by object release has been greatly reduced since the arc was used, it occasionally occurs. After you open the Zombie object mode, you can quickly navigate to the exception location. The opening mode is as follows: Product-->scheme-->edit Scheme. Tick the Enable Zombie objects.



"8.lldb Command"

The LLVM compiler is used in Xcode, which is recognized as the best C, C + +, OC, Swift compiler. And Lldb is the debugger in LLVM, we can use some simple commands to debug, I still put the above loop code as test code.



In breakpoint debugging, you print the variable information in the console console using the PO command and the Print command:



"9.NSLog Printing"

Should say NSLog printing information is a beginner's favorite debugging techniques, but also the most simple debugging, through the printed information to view the path of the program run. But print out less information, itself nslog inefficient, some people use macros to do a partial optimization, the code is as follows: Can print out the class name, the method name, detail time, line number.

[OBJC]   View plain  copy  print? #import   "ViewController.h"       #define  nslog (format, .)  do { \   fprintf (stderr,  "<%s : %d> %s\n", \    [[[nsstring stringwithutf8string:__file__] lastpathcomponent] utf8string], \    __line__, __func__); \   (NSLOG) (format),  # #__VA_ARGS__); \   fprintf (stderr,  "-------\ n"); \  } while  (0)       @interface  ViewController  ()       @end       @implementation   viewcontroller     

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.