Xcode debugging skills

Source: Internet
Author: User
Method 1: Convert the code from: http://mmdev.iteye.com/blog/1498654xcode, and the code is the last line of failure code.

Sometimes the program crashes without knowing where the error occurs. For example, when exec_bad_access occurs in a program, although the nszombieenabled environment variable can be used in most cases to locate the problem, in a few cases, even if the nszombieenabled environment variable is set, I still don't know where the program crashed. You need to use the following code for help:

# Ifdef _ for_debug _
-(Bool) respondstoselector :( SEL) aselector {
Printf ("selector: % s \ n", [nsstringfromselector (aselector) utf8string]);
Return [Super respondstoselector: aselector];
}

# Endif

You need. m or. add the above Code to the MM file and add-D _ for_debug _ to other C flags (remember to add this flag only under debug configuration ). In this way, when your program crashes, the xcode console will accurately record the method of the last running object.

Method 2: http://www.cocoachina.com/macdev/cocoa/2010/0421/1151.html

There are many exceptions. When the breakpoint cannot be normally accessed, the program will exit directly, for example:


At this time, we do not even know where this error occurs. OK, Open Run> debugger to find the exit position of the program:

Then add a soft breakpoint run-> Manage breakpoints-> Add symbolic breakpoint,
And enter objc_exception_throw.

Run debugging again:



Is it easy to find the error :)


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.