ios EXC_BAD_ACCESS 自动处理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10315526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:03:55  来源:igfitidea点击:

EXC_BAD_ACCESS automatic handling

iosxcodeexception-handlingexc-bad-accesscrash-reports

提问by animal_chin

I'm trying to build my own signal and uncaught exception handler for iOS. To do this i use these two functions :

我正在尝试为 iOS 构建自己的信号和未捕获的异常处理程序。为此,我使用这两个函数:

NSSetUncaughtExceptionHandler(/*handler*/); 

and

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

My problem is that i can't make it work with EXC_BAD_ACCESS signal. Is there some signal constant (like SIGABRT, SIGBUS) to catch the EXC_BAD_ACCESS? If no, how can i handle it? Some crash analytics tools (lika PLCrashReporter, Crashlytics etc.) can trace it...

我的问题是我不能让它与 EXC_BAD_ACCESS 信号一起工作。是否有一些信号常量(如 SIGABRT、SIGBUS)来捕获 EXC_BAD_ACCESS?如果没有,我该如何处理?一些崩溃分析工具(如 PLCrashReporter、Crashlytics 等)可以跟踪它......

采纳答案by Hailei

EXC_BAD_ACCESSdoesn't generate an exception so you first function doesn't work with the case. It generates a signal SIGSEGVor SIGBUS.

EXC_BAD_ACCESS不会产生异常,所以你的第一个函数不适用于这种情况。它产生一个信号SIGSEGVSIGBUS

Please refer to Handling unhandled exceptions and signalsby Cocoa with Love.

请参阅Cocoa with Love处理未处理的异常和信号

Update

更新

I just checked the source code of LLDB. It might be TARGET_EXC_BAD_ACCESS= 0x91.

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

In RNBRemote.h:

在 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

and in RNBRemote.cpp:

在 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;
}