void CLoadScreen::SetLoadMessage(const std::string& text, bool replace_lastline) { Watchdog::ClearTimer(WDT_LOAD); boost::recursive_mutex::scoped_lock lck(mutex); if (!replace_lastline) { if (oldLoadMessages.empty()) { oldLoadMessages = curLoadMessage; } else { oldLoadMessages += "\n" + curLoadMessage; } } curLoadMessage = text; LOG("%s", text.c_str()); LOG_CLEANUP(); if (LuaIntro) LuaIntro->LoadProgress(text, replace_lastline); //! Check the FPU state (needed for synced computations), //! some external libraries which get linked during loading might reset those. //! Here it is done for the loading thread, for the mainthread it is done in CLoadScreen::Update() good_fpu_control_registers(curLoadMessage.c_str()); if (!mtLoading) { Update(); Draw(); } }
static void HangDetectorLoop() { Threading::SetThreadName("watchdog"); while (!hangDetectorThreadInterrupted) { spring_time curtime = spring_gettime(); bool hangDetected = false; for (unsigned int i = 0; i < WDT_LAST; ++i) { if (!threadSlots[i].active) continue; WatchDogThreadInfo* th_info = registeredThreads[i]; spring_time curwdt = th_info->timer; if (spring_istime(curwdt) && curtime > curwdt && (curtime - curwdt) > hangTimeout) { if (!hangDetected) { LOG_L(L_WARNING, "[Watchdog] Hang detection triggered for Spring %s.", SpringVersion::GetFull().c_str()); #ifdef USE_GML LOG_L(L_WARNING, "MT with %d threads.", GML::ThreadCount()); #endif } LOG_L(L_WARNING, " (in thread: %s)", threadNames[i]); hangDetected = true; th_info->timer = curtime; } } if (hangDetected) { CrashHandler::PrepareStacktrace(); for (unsigned int i = 0; i < WDT_LAST; ++i) { if (!threadSlots[i].active) continue; WatchDogThreadInfo* th_info = registeredThreads[i]; CrashHandler::Stacktrace(th_info->thread, threadNames[i]); LOG_CLEANUP(); } CrashHandler::CleanupStacktrace(); } boost::this_thread::sleep(boost::posix_time::seconds(1)); } }
void CleanupStacktrace(const int logLevel) { LOG_CLEANUP(); }
static void Stacktrace(bool* aiCrash, pthread_t* hThread = NULL, const char* threadName = NULL, const int logLevel = LOG_LEVEL_ERROR) { #ifndef DEDICATED Watchdog::ClearTimer(); #endif if (threadName != NULL) { LOG_I(logLevel, "Stacktrace (%s) for Spring %s:", threadName, (SpringVersion::GetFull()).c_str()); } else { LOG_I(logLevel, "Stacktrace for Spring %s:", (SpringVersion::GetFull()).c_str()); } bool containsDriverSo = false; // OpenGL lib -> graphic problem bool containedAIInterfaceSo = false; bool containedSkirmishAISo = false; std::vector<std::string> stacktrace; std::vector< std::pair<std::string,uintptr_t> > symbols; // Get untranslated stacktrace symbols { // process and analyse the raw stack trace std::vector<void*> buffer(MAX_STACKTRACE_DEPTH + 2); int numLines; if (hThread && Threading::GetCurrentThread() != *hThread) { LOG_I(logLevel, " (Note: This stacktrace is not 100%% accurate! It just gives an impression.)"); LOG_CLEANUP(); numLines = thread_backtrace(*hThread, &buffer[0], buffer.size()); // stack pointers } else { numLines = backtrace(&buffer[0], buffer.size()); // stack pointers buffer.erase(buffer.begin()); // pop Stacktrace() buffer.erase(buffer.begin()); // pop HandleSignal() numLines -= 2; } numLines = (numLines > MAX_STACKTRACE_DEPTH) ? MAX_STACKTRACE_DEPTH : numLines; char** lines = backtrace_symbols(&buffer[0], numLines); // give them meaningfull names stacktrace.reserve(numLines); for (int l = 0; l < numLines; l++) { stacktrace.push_back(lines[l]); } free(lines); } if (stacktrace.empty()) { LOG_I(logLevel, " Unable to create stacktrace"); return; } // Extract important data from backtrace_symbols' output { for (std::vector<std::string>::iterator it = stacktrace.begin(); it != stacktrace.end(); ++it) { std::pair<std::string,uintptr_t> data; // prepare for TranslateStackTrace() const std::string path = ExtractPath(*it); const std::string absPath = CreateAbsolutePath(path); data.first = absPath; data.second = ExtractAddr(*it); symbols.push_back(data); // check if there are known sources of fail on the stack containsDriverSo = (containsDriverSo || (path.find("libGLcore.so") != std::string::npos)); containsDriverSo = (containsDriverSo || (path.find("psb_dri.so") != std::string::npos)); containsDriverSo = (containsDriverSo || (path.find("i965_dri.so") != std::string::npos)); containsDriverSo = (containsDriverSo || (path.find("fglrx_dri.so") != std::string::npos)); if (!containedAIInterfaceSo && (absPath.find("Interfaces") != std::string::npos)) { containedAIInterfaceSo = true; } if (!containedSkirmishAISo && (absPath.find("Skirmish") != std::string::npos)) { containedSkirmishAISo = true; } } // Linux Graphic drivers are known to fail with moderate OpenGL usage if (containsDriverSo) { LOG_I(logLevel, "This stack trace indicates a problem with your graphic card driver. " "Please try upgrading or downgrading it. " "Specifically recommended is the latest driver, and one that is as old as your graphic card. " "Also try lower graphic details and disabling Lua widgets in spring-settings.\n"); } // if stack trace contains AI and AI Interface frames, // it is very likely that the problem lies in the AI only if (containedSkirmishAISo) { containedAIInterfaceSo = false; } if (containedAIInterfaceSo) { LOG_I(logLevel, "This stack trace indicates a problem with an AI Interface library."); if (aiCrash) *aiCrash = true; } if (containedSkirmishAISo) { LOG_I(logLevel, "This stack trace indicates a problem with a Skirmish AI library."); if (aiCrash) *aiCrash = true; } LOG_CLEANUP(); } // Translate it TranslateStackTrace(&stacktrace, symbols); // Print out the translated StackTrace unsigned numLine = 0; for (std::vector<std::string>::iterator it = stacktrace.begin(); it != stacktrace.end(); ++it) { LOG_I(logLevel, " <%u> %s", numLine++, it->c_str()); } }