ios如何生成crash报告

时间:2023-03-09 05:25:28
ios如何生成crash报告
#include <signal.h>
#include <execinfo.h> void OnProcessExceptionHandler(int sigl)
{
do
{
std::string str = ""; void* arrayList[];
int count = backtrace(arrayList, );
char** pStr = backtrace_symbols(arrayList, count);
if (pStr == NULL)
break; for (int i=; i<count; i++)
{
str += pStr[i];
str += "\n";
} if (str.size() <= )
break; char buffer[] = "";
time_t t = time(NULL);
tm* pTm = localtime(&t);
sprintf(buffer, "[TRACE]%02d:%02d:%02d : \n", 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), , pFile);
fwrite(str.c_str(), str.size(), , pFile);
fclose(pFile);
}
while (false); exit();
} 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 ;
}