ios – EXC_BAD_ACCESS自动处理

前端之家收集整理的这篇文章主要介绍了ios – EXC_BAD_ACCESS自动处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在为iOS建立自己的信号和未捕获的异常处理程序.为了做到这一点,我使用这两个功能
NSSetUncaughtExceptionHandler(/*handler*/);

signal(/*signal const*/,/*signal handler*/);

我的问题是我无法使用EXC_BAD_ACCESS信号.是否有一些信号常数(如SIGABRT,SIGBUS)捕获EXC_BAD_ACCESS?如果没有,我该怎么处理?一些崩溃分析工具(lika PLCrashReporter,Crashlytics等)可以跟踪它…

解决方法

EXC_BAD_ACCESS不生成异常,因此您的第一个函数不适用于该情况.它产生信号SIGSEGV或SIGBUS.

请参阅可可与爱的Handling unhandled exceptions and signals.

更新

我刚刚检查了LLDB的源代码.它可能是TARGET_EXC_BAD_ACCESS = 0x91.

在RNBRemote.h中:

/* We translate the /usr/include/mach/exception_types.h exception types
   (e.g. EXC_BAD_ACCESS) to the fake BSD signal numbers that gdb uses
   in include/gdb/signals.h (e.g. TARGET_EXC_BAD_ACCESS).  These hard
   coded values for TARGET_EXC_BAD_ACCESS et al must match the gdb
   values in its include/gdb/signals.h.  */

#define TARGET_EXC_BAD_ACCESS      0x91
#define TARGET_EXC_BAD_INSTRUCTION 0x92
#define TARGET_EXC_ARITHMETIC      0x93
#define TARGET_EXC_EMULATION       0x94
#define TARGET_EXC_SOFTWARE        0x95
#define TARGET_EXC_BREAKPOINT      0x96

并在RNBRemote.cpp中:

// Translate any mach exceptions to gdb versions,unless they are
// common exceptions like a breakpoint or a soft signal.
switch (tid_stop_info.details.exception.type)
{
    default:                    signum = 0; break;
    case EXC_BREAKPOINT:        signum = SIGTRAP; break;
    case EXC_BAD_ACCESS:        signum = TARGET_EXC_BAD_ACCESS; break;
    case EXC_BAD_INSTRUCTION:   signum = TARGET_EXC_BAD_INSTRUCTION; break;
    case EXC_ARITHMETIC:        signum = TARGET_EXC_ARITHMETIC; break;
    case EXC_EMULATION:         signum = TARGET_EXC_EMULATION; break;
    case EXC_SOFTWARE:
        if (tid_stop_info.details.exception.data_count == 2 &&
            tid_stop_info.details.exception.data[0] == EXC_SOFT_SIGNAL)
            signum = tid_stop_info.details.exception.data[1];
        else
            signum = TARGET_EXC_SOFTWARE;
        break;
}

猜你在找的iOS相关文章