使用PLCrashReporter,您可以在崩溃之前接收事件吗?

发布于 2024-12-02 23:24:27 字数 102 浏览 0 评论 0原文

一旦 PLCrashReporter 检测到错误(异常、信号等)但在应用程序终止之前,我们希望进行额外的处理(即记录当前状态)。有谁知道这是否可以使用 PLCrashReporter 实现?

We want to do additional processing (i.e. log the current state) once PLCrashReporter has detected an error (either an exception, signal, etc.) but before the app terminates. Does anyone know if this is possible using PLCrashReporter?

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

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

发布评论

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

评论(2

欢你一世 2024-12-09 23:24:27

为了扩展 Andreas 的答案——

我已经在主干中实现了对 -[PLCrashReporter setCrashCallbacks:] 的开发支持,它允许在程序退出之前执行崩溃后的函数。

由于实现可以在崩溃进程的上下文中执行的异步安全代码很困难,这最初没有包括在内——这已经足够困难了,我认为没有人愿意这样做。

引用我为 PLCrashReporter trunk 中的功能编写的文档(我还没有发布渲染副本,因为该功能尚未发布):

异步安全编程指南

Plausible CrashReporter 提供了对执行应用程序指定功能的支持崩溃报告写入磁盘后,崩溃报告器的信号处理程序的上下文。这是一个经常被要求的功能,并提供在崩溃时实现应用程序最终确定的能力。但是,编写用于在信号处理程序内部执行的代码非常困难,因此不建议这样做。

程序流程和信号处理程序

当调用信号处理程序时,程序的正常流程被中断,并且您的程序是未知的
状态。锁可能被持有,堆可能已损坏(或正在更新过程中),并且您的信号
处理程序可以调用在信号发生时正在执行的函数。这可能会导致死锁,
数据损坏和程序终止。

异步安全函数 操作系统

将函数的子集定义为异步安全的,并且可以从信号处理程序中安全地调用。如果
您确实实现了自定义崩溃后处理程序,它必须是异步安全的。 POSIX 定义的异步安全函数表
其他信息可从 CERT 编程指南中获取 - SIG30-C

最值得注意的是,Objective-C 运行时本身不是异步安全的,并且 Objective-C 不能在信号中使用
处理程序。

To expand on Andreas' answer --

I've implemented development support in trunk for -[PLCrashReporter setCrashCallbacks:], which permits the execution of a function post-crash, prior to the program exiting.

This wasn't originally included due to the difficulty of implementing async-safe code that can be executed in the context of a crashed process -- it's difficult enough to do that I didn't think anyone would want to do it.

To quote the documentation I wrote for the feature in PLCrashReporter trunk (I don't have a rendered copy posted yet, since the feature has not yet been released):

Async-Safe Programming Guide

Plausible CrashReporter provides support for executing an application specified function in the context of the crash reporter's signal handler, after the crash report has been written to disk. This was a regularly requested feature, and provides the ability to implement application finalization in the event of a crash. However, writing code intended for execution inside of a signal handler is exceptionally difficult, and is not recommended.

Program Flow and Signal Handlers

When the signal handler is called the normal flow of the program is interrupted, and your program is an unknown
state. Locks may be held, the heap may be corrupt (or in the process of being updated), and your signal
handler may invoke a function that was being executed at the time of the signal. This may result in deadlocks,
data corruption, and program termination.

Async-Safe Functions

A subset of functions are defined to be async-safe by the OS, and are safely callable from within a signal handler. If
you do implement a custom post-crash handler, it must be async-safe. A table of POSIX-defined async-safe functions
and additional information is available from the CERT programming guide - SIG30-C.

Most notably, the Objective-C runtime itself is not async-safe, and Objective-C may not be used within a signal
handler.

十二 2024-12-09 23:24:27

不,这是不可能的。您必须自己进行日志记录并将其存储在文件系统上。下次启动时,您可以将其与崩溃报告一起发送到您的服务器。例如,使用 QuincyKit,它使用 PLCrashReporter,然后使用您自己的服务器或 HockeyApp.net。

注:我是 QuincyKit 的开发者和 HockeyApp 的共同开发者。

No, this is not possible. You would have to do your own logging and store that on the filesystem. On the next startup, you could send it alongside the crash report to your server. E.g. using QuincyKit which uses PLCrashReporter and then your own server or HockeyApp.net.

Note: I am the developer of QuincyKit and co-developer of HockeyApp.

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