TestFlight has been giving me some SIGSEGV
crash reports.
I found a way to pinpoint the exact problem. However, to do this, I need to perform one last TFLog
exactly at the moment this crashes, which will contain important information to help me find the culprit code (because TestFlight's backtrace is currently useless to me).
I imagine that this is indeed possible - after all, TestFlight is capable of sending the crash report upon, well, crashing. But, where? Where can I put my TFLog
?
You can install a SIGSEGV
handler using sigaction
. From the handler, you can log what you need, then kill the app (e.g. with abort()
).
Example:
void sigsegv_handler(int signo, siginfo_t *info, void *ucontext) {
/* Inspect info to see where the crash occurred */
}
/* in main() or another suitable entry point */
struct sigaction sa;
sa.sa_sigaction = sigsegv_handler;
sigfillset(&sa.sa_mask);
sa.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
Note that sigsegv_handler
can access globals, etc. but may not be able to easily access local variables of the crashing stack frame. If you clarify what you need to log, it may be possible to work out how to extract that information from within the SIGSEGV handler.
Note too that some functions are technically not safe to call from a SIGSEGV handler. However, given that the entire app is about to die, you aren't likely to make things significantly worse by calling these functions (unless they cause a deadlock because you attempt to reacquire a lock, for example). Significantly, however, you will want to avoid calling malloc
or free
in the signal handler because your program may have crashed inside either one, and you definitely don't want to cause a second segfault from within your signal handler.