Exd_bad_acceeeerror, acc.exe application error

Source: Internet
Author: User

Exd_bad_acceeeerror, acc.exe application error

During iOS development, common bugs are usually easier to locate, but the EXD_BAD_ACCEEE issue is hard to locate. This document records the process of solving the EXD_BAD_ACCEEE problem. First, let's talk about the EXC_BAD_ACCESS error. It can be said that the 90% error is caused by the release operation on a released object.

1. Override the respondsToSelector method of the object. In reality, the last object accessed before EXEC_BAD_ACCESS appears.

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.

2. Use NSZombieEnabled

I believe many people know that NSZombies is used to help debug EXC_BAD_ACCESS, but sometimes the required information cannot be found. What should I do?

The following is an example of the hello world code:

NSString* hello = [NSString stringWithFormat:@"Hello world"];  NSLog(@"What you say is %@",hello);  [hello release]; 

After running, the EXC_BAD_ACCESS error occurs. But no other prompts are displayed. In this case, right-click the application name under executables, select get info, and enter the environment variable (NSZombieEnabled, MallocStackLogging) in arguments)

After the program runs again, crash,

 

This time we can see that the problem is "message sent to dealloced object", but we still don't know which statement caused it. Therefore, we need to enter the following statement on gdb:

Shell malloc_history pid address

So What Are pid and address? Let's take a look at the crash image and use the following command to quickly determine where the pid and address come from. My command is:

Shell malloc_history 596 0x5f3ef80

When the program is run again, a large amount of stack trace information will appear during the crash process, such:

Based on this information, you can find the problem that occurs in [BadAccessViewController viewDidLoad] and is related to + [NSString stringWithFormat.

Finally, remember to delete or set the environment variables NSZombieEnabled and MallocStackLogging to NO, because they will not actually release the memory.

3. Set a Global breakpoint to quickly locate the row of the problematic code

XCode debugging tips-set a Global breakpoint to quickly locate the row of the problematic code

The above reproduced to: http://mobile.51cto.com/iphone-279455.htm

 

Note: The answer on stackoverflow: http://stackoverflow.com/questions/327082/exc-bad-access-signal-received

 

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.