What does the code parameter in EXC_BAD_ACCESS mean?

I have been using Objective-C on iOS for about a month, but have a lot of prior experience in C ++.

My understanding of EXC_BAD_ACCESS is that it is essentially a “segmentation error” , i.e. trying to access memory outside the allowed area. Although, oddly enough, I also saw SIGSEGV somewhere in the crash iOS app. I noticed that there is a code parameter in this exception (for example, code=1 ), and I wonder what exactly this means.

I poked Google and I can not find the official documentation for this error, and, apparently, I'm not alone. Does anyone know what the code parameter here means?

+6
source share
1 answer

If you look at the crash log generated on your device, you will see:

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

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

The fastest way to open this file is to enter the constant KERN_INVALID_ADDRESS in the Xcode file and select "Go to Definition" .;)

FYI: code=1 refers directly to KERN_INVALID_ADDRESS . The comments related to this constant say:

 /* Specified address is not currently valid. */ 
+6
source

Source: https://habr.com/ru/post/978153/


All Articles