如何捕获 iPhone 上的所有程序中止错误?

发布于 2024-09-11 03:39:14 字数 977 浏览 2 评论 0原文

我为我的 iPhone 应用程序编写了一个未处理的错误模块,但由于某种原因,一些错误设法绕过了它。

我有一个异常处理程序和以下信号处理程序集:

NSSetUncaughtExceptionHandler(&handleException);
signal(SIGILL, handleSignal);
signal(SIGABRT, handleSignal);
signal(SIGFPE, handleSignal);
signal(SIGBUS, handleSignal);
signal(SIGSEGV, handleSignal);
signal(SIGSYS, handleSignal);
signal(SIGPIPE, handleSignal);

对于大多数东西(无法识别的选择器、浮点错误等),它都可以工作,但是例如当我运行以下代码时:

NSString* str = [NSString stringWithFormat:@"a"];
[str release];
[str retain];

它完全避免了我的错误处理程序,而是将其打印到安慰:

堆栈转储: 0. 在函数“@glgRunProcessor10”上运行“组合冗余指令”**

我有另一个打印了以下内容的函数(但我不记得我运行了什么代码来导致它):

堆栈转储: 0. 在函数“@gldLLVMFPTransform5”上运行“线性扫描寄存器分配器”

如果我这样做:

NSString* str = [NSString stringWithFormat:@"a"];
[str release];
[str init];

它根本不打印任何内容,而只是退出程序。

有谁知道确保捕获所有错误并通过处理程序例程运行的万无一失的方法?

I've written an unhandled error module for my iPhone app, but for some reason some errors are managing to bypass it.

I have an exception handler and the following signal handlers set:

NSSetUncaughtExceptionHandler(&handleException);
signal(SIGILL, handleSignal);
signal(SIGABRT, handleSignal);
signal(SIGFPE, handleSignal);
signal(SIGBUS, handleSignal);
signal(SIGSEGV, handleSignal);
signal(SIGSYS, handleSignal);
signal(SIGPIPE, handleSignal);

For most stuff (unrecognized selector, floating point errors, etc) it works, but for example when I run the following code:

NSString* str = [NSString stringWithFormat:@"a"];
[str release];
[str retain];

It avoids my error handler entirely and instead prints this to the console:

Stack dump:
0. Running pass 'Combine redundant instructions' on function '@glgRunProcessor10'**

I had another one that printed the following (but I can't remember what code I ran to cause it):

Stack dump:
0. Running pass 'Linear Scan Register Allocator' on function '@gldLLVMFPTransform5'

If I do this:

NSString* str = [NSString stringWithFormat:@"a"];
[str release];
[str init];

It doesn't print anything at all, but just exits the program.

Does anyone know of a surefire way to ensure that ALL errors get caught and run through a handler routine?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撕心裂肺的伤痛 2024-09-18 03:39:14

事实证明,异常处理程序每​​次都会被调用,但根据崩溃情况,stdout 和 stderr 可能在错误处理程序运行时已经关闭,这意味着 NSLog() 消息不会被打印。

我通过打开一个文件并将内容转储到该文件来确认。

Well, it turns out that the exception handler IS getting called every time, but depending on the crash circumstances, stdout and stderr might already be closed by the time the error handler runs, which means the NSLog() messages won't get printed.

I confirmed by opening a file and dumping stuff to that instead.

滥情空心 2024-09-18 03:39:14

我想这取决于您使用的 SDK。
我测试了以下代码:

NSString * str = [ NSString stringWithFormat: @"a" ];
[ str release ];
[ str retain ];

使用SDK 4.1,没有错误。看来运行时现在允许这样做。它只是将日志打印到控制台,但应用程序不会崩溃。

*** __NSAutoreleaseFreedObject():忽略先前释放的对象(0x5f52fb0)的释放

在 SDK 3.2 中,将调用信号处理程序(信号 ID:10)。

因此,请尝试使用不同的 SDK 版本进行测试。希望这有帮助...

I guess it depends on the SDK you are using.
I've tested the following code:

NSString * str = [ NSString stringWithFormat: @"a" ];
[ str release ];
[ str retain ];

With SDK 4.1, there's no error. It seems the runtime now allows that. It just prints a log to the console, but the app does not crash.

*** __NSAutoreleaseFreedObject(): release of previously deallocated object (0x5f52fb0) ignored

With SDK 3.2, the signal handler is called (signal ID: 10).

So try to test that with different SDK versions. Hope this help...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文