您的位置:首页 > 移动开发 > IOS开发

ios如何生成crash报告

2013-11-04 23:13 288 查看
#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 += "\n";
}

if (str.size() <= 0)
break;

char buffer[1024] = "";
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), 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: