IOS Crash, in two cases: one is an exception and the other is interrupt [semaphore].
#include <libkern/OSAtomic.h>
#include <execinfo.h>
System signal Interception processing method
void Signalhandler (int signal);
Handling method of abnormal interception
void Exceptionhandler (NSException *exception);
Const int32_t _uncaughtexceptionmaximum = 10;
void Signalhandler (int signal)
{
Volatile int32_t _uncaughtexceptioncount = 0;
int32_t Exceptioncount = OSAtomicIncrement32 (&_uncaughtexceptioncount);
if (Exceptioncount > _uncaughtexceptionmaximum)//If too much is not handled
{
Return
}
Get information
Nsmutabledictionary *userinfo =
[Nsmutabledictionary dictionarywithobject:[nsnumber numberwithint:signal] Forkey: Uncaughtexceptionhandlersignalkey];
Nsarray *callstack = [Exceptionhandler backtrace];
[UserInfo Setobject:callstack Forkey:singalexceptionhandleraddresseskey];
Now you can escalate the information to the server.
}
void Exceptionhandler (NSException *exception)
{
Volatile int32_t _uncaughtexceptioncount = 0;
int32_t Exceptioncount = OSAtomicIncrement32 (&_uncaughtexceptioncount);
if (Exceptioncount > _uncaughtexceptionmaximum)//If too much is not handled
{
Return
}
Nsarray *callstack = [Exceptionhandler backtrace];
Nsmutabledictionary *userinfo =[nsmutabledictionary dictionarywithdictionary:[exception UserInfo]];
[UserInfo Setobject:callstack Forkey:exceptionhandleraddresseskey];
Now you can escalate the information to the server.
}
@implementation Exceptionhandler
Get Call stack
+ (Nsarray *) backtrace
{
void* callstack[128];
int frames = BackTrace (callstack, 128);
Char **strs = Backtrace_symbols (callstack,frames);
Nsmutablearray *backtrace = [Nsmutablearray arraywithcapacity:frames];
for (int i=0;i<frames;i++)
{
[BackTrace addobject:[nsstring Stringwithutf8string:strs[i]];
}
Free (STRs);
return backtrace;
}
Register Crash blocker
-(void) Installexceptionhandler
{
Nssetuncaughtexceptionhandler (&exceptionhandler);
Signal (SIGHUP, Signalhandler);
Signal (SIGINT, Signalhandler);
Signal (Sigquit, Signalhandler);
Signal (SIGABRT, Signalhandler);
Signal (Sigill, Signalhandler);
Signal (SIGSEGV, Signalhandler);
Signal (SIGFPE, Signalhandler);
Signal (Sigbus, Signalhandler);
Signal (Sigpipe, Signalhandler);
}
@end
IOS Crash capture