Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the code parameter in EXC_BAD_ACCESS mean?

I've been using Objective C on iOS for about a month but have a lot of prior C++ experience.

My understanding of EXC_BAD_ACCESS is that it's essentially a Segmentation Fault, i.e. an attempt to access memory outside of allowed region. Though oddly enough I've also seen SIGSEGV specifically somewhere in a crashing iOS app. I notice that there is a code parameter (e.g. code=1) as part of this exception and I'm wondering what that code specifically means.

I've poked around google and can't seem to find formal documentation on this error, and apparently I'm not alone. Does anyone know what the code parameter here means?

like image 804
Joey Carson Avatar asked Nov 13 '14 18:11

Joey Carson


People also ask

What does thread 1 Exc_bad_access mean?

What does EXC_BAD_ACCESS mean? EXC_BAD_ACCESS is an exception raised as a result of accessing bad memory. We're constantly working with pointers to memory in Swift that link to a specific memory address. An application will crash whenever we try to access a pointer that is invalid or no longer exists.

What is Exc_bad_access Kern_invalid_address?

Code Block. Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000. This indicates that your app crash because it tried to referenced NULL. Code Block.


1 Answers

If you look at the crash log that's generated on your device, you'll see:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at <some address>

For further description of the code parameter associated with an exception, you can refer to usr/include/mach/kern_return.h. It provides moderately-readable constant names along with short comment blurbs associated with the constant values.

The fastest way to open that file is to type the constant KERN_INVALID_ADDRESS into your Xcode file and choose "Jump to Definition". ;)

FYI: code=1 relates directly to KERN_INVALID_ADDRESS. The comment blurb associated with this constant reads:

/* Specified address is not currently valid. */
like image 186
Ian MacDonald Avatar answered Oct 13 '22 17:10

Ian MacDonald