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()); }
原文:http://www.cnblogs.com/duzib/p/4457102.html