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 :)