捕获崩溃信号 获取堆栈信息

void registerSignalHandler(void) {

    signal(SIGSEGV, handleSignalException);

    signal(SIGFPE, handleSignalException);

    signal(SIGBUS, handleSignalException);

    signal(SIGPIPE, handleSignalException);

    signal(SIGHUP, handleSignalException);

    signal(SIGINT, handleSignalException);

    signal(SIGQUIT, handleSignalException);

    signal(SIGABRT, handleSignalException);

    signal(SIGILL, handleSignalException);

}

void handleSignalException(int signal) {

    NSMutableString *crashString = [[NSMutableString alloc]init];

    void* callstack[128];

    int i, frames = backtrace(callstack, 128);

    char** traceChar = backtrace_symbols(callstack, frames);

    for (i = 0; i

        [crashString appendFormat:@"%s\n", traceChar[i]];

    }

    NSLog(crashString);

}

你可能感兴趣的:(捕获崩溃信号 获取堆栈信息)