首页 > 移动平台 > 详细

cocos2d-x 安卓 ios崩溃dump

时间:2015-04-25 23:58:05      阅读:446      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!