#ifndef _WIN32 #include "error_handling.h" #include #include #include #include #include #include #include void DumpProcessStack() { static boost::mutex guard; boost::mutex::scoped_lock lock(guard); char dumpCommand[512] = {}; snprintf((char*)dumpCommand, sizeof(dumpCommand), "gdb --pid=%d -ex \"thread apply all bt full\" > stack.txt", getpid()); FILE* st = popen(dumpCommand, "w"); if (st) { pclose(st); std::cout << "stack traces saved to stack.txt\n"; } else std::cout << "cannot dump stack\n"; } void SCHandlerRoutine(int signum) { std::cout << "signal caught: " << signum << "\n"; switch(signum) { case SIGSEGV: DumpProcessStack(); abort(); break; default: break; } } void setup_error_handling() { signal(SIGSEGV,SCHandlerRoutine); } #endif