XCode debugging skills

Source: Internet
Author: User
Tags print object

Po command: the abbreviation of print object. The text description of the displayed object shows the string information obtained from the description message of the object ).

For example:

, I use the po command to display the content of an NSDictionary. Note: On the left side, we can see some information about dict: 3 key/value pairs, showing the data volume contained in the dict, and the expanded information shows the isa hierarchy, that is, the relationship between class and metaclass ). Right-click dict on the left and select "Print Description of" dict ". The dict details can be output on the console:

View plaincopyprint?

Print command: It is similar to formatting output, which can output different object information:

For example:

 

[Cpp]View plaincopyprint?

Note: 4 is the value of NSUTF8StringEncoding.

Info command: We can view the information of the memory address.

For example"Memory Address of info symbol"You can obtain the information about the symbol where the memory address is located:

 

[Cpp]View plaincopyprint?

For example"Info line * Memory Address"You can obtain the code line information of the memory address:

 

[Cpp]View plaincopyprint?

Show command: Displays information about GDB. For example, show version displays the GDB version.

 

[Cpp]View plaincopyprint?

Help Command: if you forget the syntax of a command, you can use the help command name to obtain help information. For example, help info shows the usage of the info command.

 

[Cpp]View plaincopyprint?

Set a breakpoint when a system throws an exception

Sometimes our program doesn't know where it is to run and crash is hard to reproduce. A conservative approach is to set a breakpoint before the system throws an exception. Specifically, it is to set a breakpoint at the objc_exception_throw. Step 1: Press CMD + 6 in XCode to go To the Breakpoint Management window. Click + in the lower right corner to add a new Symbolic Breakpoint. In the Symbol column, enter objc_exception_throw, click done. In this way, in Debug mode, if the program is about to throw an exception, the exception will be interrupted. For example, in the previous code, I asked [firstObjctcrashTest]; To throw an exception. After the breakpoint is set at objc_exception_throw, the program will be interrupted at this code, so that we can know where the code is going wrong.

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.