EXC_BAD_ACCESS自动处理 [英] EXC_BAD_ACCESS automatic handling

查看:184
本文介绍了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



请请参阅可可与爱情处理未处理的异常和信号。 / p>

更新



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



在RNBRemote.h中:

  / *我们将/ usr/include/mach/exception_types.h异常类型
(例如EXC_BAD_ACCESS)转换为gdb使用$ b的假BSD信号include / gdb / signals.h中的$ b(例如TARGET_EXC_BAD_ACCESS)。 TARGET_EXC_BAD_ACCESS等人的这些硬
编码值必须与其include / gdb / signals.h中的gdb
值相匹配。 * /

#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:

  //将任何mach异常转换为gdb版本,除非它们是
//常见的异常,如断点或软信号。
switch(tid_stop_info.details.exception.type)
{
default:signum = 0;打破;
case EXC_BREAKPOINT:signum = SIGTRAP;打破;
case EXC_BAD_ACCESS:signum = TARGET_EXC_BAD_ACCESS;打破;
case EXC_BAD_INSTRUCTION:signum = TARGET_EXC_BAD_INSTRUCTION;打破;
case EXC_ARITHMETIC:signum = TARGET_EXC_ARITHMETIC;打破;
case EXC_EMULATION:signum = TARGET_EXC_EMULATION;打破;
case EXC_SOFTWARE:
if(tid_stop_info.details.exception.data_count == 2&&b
tid_stop_info.details.exception.data [0] == EXC_SOFT_SIGNAL)
signum = tid_stop_info.details.exception.data [1];
else
signum = TARGET_EXC_SOFTWARE;
break;
}


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

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 doesn't generate an exception so you first function doesn't work with the case. It generates a signal SIGSEGV or SIGBUS.

Please refer to Handling unhandled exceptions and signals by Cocoa with Love.

Update

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

In 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:

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

这篇关于EXC_BAD_ACCESS自动处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆