zoukankan      html  css  js  c++  java
  • ios如何生成crash报告

    #include <signal.h>
    #include <execinfo.h>
    
    void  OnProcessExceptionHandler(int sigl)
    {
        do 
        {
            std::string str = "";
    
            void* arrayList[128];
            int count = backtrace(arrayList, 128);
            char** pStr = backtrace_symbols(arrayList, count);
            if (pStr == NULL)
                break;
    
            for (int i=0; i<count; i++)
            {
                str += pStr[i];
                str += "
    ";
            }
    
            if (str.size() <= 0)
                break;
    
            char buffer[1024] = "";
            time_t t = time(NULL);
            tm* pTm  = localtime(&t);
            sprintf(buffer, "[TRACE]%02d:%02d:%02d : 
    ", pTm->tm_hour,pTm->tm_min,pTm->tm_sec);
    
            std::string logFile = "";//writeable dir
            logFile += "exception.txt";
            FILE* pFile = fopen(logFile.c_str(), "ab");
            if (pFile == NULL)
                break;
    
            fwrite(buffer, strlen(buffer), 1, pFile);
            fwrite(str.c_str(), str.size(), 1, pFile);
            fclose(pFile);
        } 
        while (false);
    
        exit(1);
    }
    
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        signal(SIGQUIT, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGILL, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGTRAP, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGABRT, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGEMT, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGFPE, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGBUS, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGSEGV, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGSYS, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGPIPE, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGALRM, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGXCPU, CrashReportSystem::OnProcessExceptionHandler);
        signal(SIGXFSZ, CrashReportSystem::OnProcessExceptionHandler);
    
        return 1;
    }
  • 相关阅读:
    iphone精简教程
    自己搭建云盘 – 简单的PHP网盘程序
    内存泄漏(I)
    App 基本图片配置(I)
    Git 工作环境配置
    MVC(I)
    ReactNative APP基本框架搭建 基于 React Navigation
    UI绘制原理及卡顿 掉帧原因
    ES6中Json、String、Map、Object之间的转换
    Invariant Violation: requireNativeComponent: "RNCWKWebView" was not found in the UIManager.
  • 原文地址:https://www.cnblogs.com/mrblue/p/3407670.html
Copyright © 2011-2022 走看看