/** * * This entry point is tailored for the Watchdog module. * Since the thread to be traced may be running, it requires a ThreadControls object in order to suspend/resume the thread. * @brief RemoteStacktrace */ void SuspendedStacktrace(Threading::ThreadControls* ctls, const std::string& threadName) { #if !(DEDICATED || UNIT_TEST) Watchdog::ClearTimer(); #endif assert(ctls != nullptr); assert(ctls->handle != 0); assert(threadName.size() > 0); LOG_L(L_WARNING, "Suspended-thread Stacktrace (%s) for Spring %s:", threadName.c_str(), (SpringVersion::GetFull()).c_str()); LOG_L(L_DEBUG, "SuspendedStacktrace[1]"); StackTrace stacktrace; // Get untranslated stacktrace symbols { // process and analyse the raw stack trace void* iparray[MAX_STACKTRACE_DEPTH]; ctls->Suspend(); const int numLines = thread_unwind(&ctls->ucontext, iparray, stacktrace); ctls->Resume(); LOG_L(L_DEBUG, "SuspendedStacktrace[2]"); if(numLines > MAX_STACKTRACE_DEPTH) { LOG_L(L_ERROR, "thread_unwind returned more lines than we allotted space for!"); } char** lines = backtrace_symbols(iparray, numLines); // give them meaningfull names ExtractSymbols(lines, stacktrace); } if (stacktrace.empty()) { LOG_L(L_WARNING, " Unable to create suspended stacktrace"); return; } LOG_L(L_DEBUG, "SuspendedStacktrace[3]"); // Translate symbols into code line numbers TranslateStackTrace(NULL, stacktrace, LOG_LEVEL_WARNING); LOG_L(L_DEBUG, "SuspendedStacktrace[4]"); // Print out the translated StackTrace LogStacktrace(LOG_LEVEL_WARNING, stacktrace); }
/** * This stack trace is tailored for the SIGSEGV / SIGILL / SIGFPE etc signal handler. * The thread to be traced is usually in a halted state, but the signal handler can provide siginfo_t and ucontext_t structures to help produce the trace using libunwind. * @brief PrepareStacktrace */ void HaltedStacktrace(const std::string& errstr, siginfo_t* siginfo, ucontext_t* ucontext) { LOG_L(L_ERROR, "Halted Stacktrace for Spring %s using libunwind:", (SpringVersion::GetFull()).c_str()); assert(siginfo != nullptr); assert(ucontext != nullptr); StackTrace stacktrace; LOG_L(L_DEBUG, "HaltedStacktrace[1]"); // Get untranslated stacktrace symbols { // process and analyse the raw stack trace void* iparray[MAX_STACKTRACE_DEPTH]; const int numLines = thread_unwind(nullptr, iparray, stacktrace); LOG_L(L_DEBUG, "HaltedStacktrace[2]"); if(numLines > MAX_STACKTRACE_DEPTH) { LOG_L(L_ERROR, "thread_unwind returned more lines than we allotted space for!"); } char** lines = backtrace_symbols(iparray, numLines); // give them meaningfull names ExtractSymbols(lines, stacktrace); } LOG_L(L_DEBUG, "HaltedStacktrace[3]"); if (stacktrace.empty()) { LOG_I(LOG_LEVEL_ERROR, " Unable to create stacktrace"); return; } // Translate it TranslateStackTrace(NULL, stacktrace, LOG_LEVEL_ERROR); LOG_L(L_DEBUG, "HaltedStacktrace[4]"); // Print out the translated StackTrace. Ignore the frames that occur inside the signal handler (before its line in the trace) -- they are likely some kind of padding or just garbage. LogStacktrace(LOG_LEVEL_ERROR, stacktrace); }
bool dynLibImplLinux::GetExportData( const char* dynamicLibraryName, SingleMapEntryArray& ExportEntriesArr, std::string& csPath_o ) { Elf* elf; struct link_map* lm; if ( !OpenDynamicLibrary( dynamicLibraryName, elf, lm, csPath_o ) ) { return false; } if ( GetDllEntry( csPath_o ) == NULL ) { Elf_Scn* section = 0; ElfW(Shdr) *shdr; FindSection( elf, SHT_SYMTAB, section, shdr ); std::list<std::string> symbols; ExtractSymbols( elf, section, shdr, STT_FUNC, symbols ); std::list<std::string>::iterator it; for ( it = symbols.begin( ) ; it != symbols.end( ) ; it++) { SINGLE_FUNCT_ENTRY newElement; newElement.csFunction = Demangle( it->c_str( ) ); // Use dlsym because st_value sometimes is 0 //newElement.dwData = (void*) (lm->l_addr + esym->st_value); newElement.dwData = dlsym( lm, it->c_str( ) ); newElement.csSymbol = *it; ExportEntriesArr.push_back( newElement ); } } CloseDynamicLibrary( elf ); return true; }
static void Stacktrace(bool* aiCrash, pthread_t* hThread = NULL, const char* threadName = NULL, const int logLevel = LOG_LEVEL_ERROR) { #if !(DEDICATED || UNIT_TEST) 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()); } StackTrace stacktrace; // Get untranslated stacktrace symbols { // process and analyse the raw stack trace void* iparray[MAX_STACKTRACE_DEPTH]; int numLines = thread_unwind(nullptr, iparray, stacktrace); if (numLines > MAX_STACKTRACE_DEPTH) { LOG_L(L_ERROR, "thread_unwind returned more lines than we allotted space for!"); } char** lines = backtrace_symbols(iparray, numLines); // give them meaningfull names ExtractSymbols(lines, stacktrace); } if (stacktrace.empty()) { LOG_I(logLevel, " Unable to create stacktrace"); return; } // Translate it TranslateStackTrace(aiCrash, stacktrace, logLevel); LogStacktrace(logLevel, stacktrace); }