码迷,mamicode.com
首页 > 移动开发 > 详细

cocos2d-x 安卓 ios崩溃dump

时间:2015-04-25 23:59:46      阅读:375      评论:0      收藏:0      [点我收藏+]

标签:

在安卓和ios平台上可通过信号处理方式,在崩溃时打印Lua堆栈信息,方便分析bug
 
static void dumpHandler(int cause, siginfo_t * info, void *uap)
{
    CCLOG("Crash dump:");
    CCLuaEngine* pEngine = CCLuaEngine::defaultEngine();
    me_traceStack(pEngine->getLuaStack()->getLuaState());
    exit(1);
}

static void setupCrashReport()
{
 struct sigaction sa;
    sa.sa_sigaction = dumpHandler;
    sigemptyset (&sa.sa_mask);
    sa.sa_flags = SA_SIGINFO;
 for (int i=0; i<kNumSignals; ++i)
 {
  if (sigaction(kSignals[i], &sa, NULL) == -1)
   CCLOG("sigaction [%d] failed", i);
 }
    if (sigaction (SIGSEGV, &sa, 0)) {
  CCLOG("setup sigaction");
 }
}

#define SETUP_CRASH_REPORT() {setupCrashReport();}

void me_traceStack (lua_State *L) {
    lua_print(L);
    
    int level;
    lua_Debug ar;
    std::string t;
    char buff[1024];
    
    for (level = 1; level<11; ++level)
    {
        if (lua_getstack(L, level, &ar))
        {
            lua_getinfo(L, "Snl", &ar);
            sprintf(buff, "frame %d \n%s :%d in function [%s], %d\n", level, ar.short_src, ar.currentline, ar.name, ar.linedefined);
            t += buff;
        }
        else
        {
            sprintf(buff, "frame %d \nunknown\n", level);
            t += buff;
        }
    }
    CCLOG("Lua frame stack:\n%s", t.c_str());
}

 

 

cocos2d-x 安卓 ios崩溃dump

标签:

原文地址:http://www.cnblogs.com/duzib/p/4457102.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!