本文整理汇总了C++中StackTrace::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ StackTrace::cbegin方法的具体用法?C++ StackTrace::cbegin怎么用?C++ StackTrace::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackTrace
的用法示例。
在下文中一共展示了StackTrace::cbegin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LogStacktrace
static void LogStacktrace(const int logLevel, StackTrace& stacktrace)
{
int colFileline = 0;
const std::string& exe_path = Platform::GetProcessExecutablePath();
const std::string& cwd_path = Platform::GetOrigCWD();
for (auto fit = stacktrace.begin(); fit != stacktrace.end(); fit++) {
for (auto eit = fit->entries.begin(); eit != fit->entries.end(); eit++) {
eit->abbrev_funcname = eit->funcname;
std::string fileline = eit->fileline;
if (fileline[1] == '?') { // case "??:?", ":?"
fileline = fit->symbol; // print raw backtrace_symbol
}
eit->abbrev_fileline = fileline;
int abbrev_start = 0;
if (fileline[0] == '/') { // See if we can shorten the file/line bit by removing the common path
if (CommonStringLength(fileline, exe_path, &abbrev_start) > 1) { // i.e. one char for first '/'
eit->abbrev_fileline = std::string(".../") + fileline.substr(abbrev_start, std::string::npos);
} else if (CommonStringLength(fileline, cwd_path, &abbrev_start) > 1) {
eit->abbrev_fileline = std::string("./") + fileline.substr(abbrev_start, std::string::npos);
}
}
if (eit->abbrev_funcname.size() > 100) {
eit->abbrev_funcname.resize(94);
eit->abbrev_funcname.append(" [...]");
}
colFileline = std::max(colFileline, (int)eit->abbrev_fileline.length());
}
}
bool hideSignalHandler = true;
// Print out the translated StackTrace
unsigned numLine = 0;
unsigned hiddenLines = 0;
while (numLine == 0) { // outer loop at most twice -- tries to find the signal handler once and if that doesn't work, then just print every frame
for (auto fit = stacktrace.cbegin(); fit != stacktrace.cend(); fit++) {
for (auto eit = fit->entries.begin(); eit != fit->entries.end(); eit++) {
if (hideSignalHandler) {
hiddenLines++;
if (eit->fileline.find("sigaction.c:?") == 0) {
hideSignalHandler = false;
LOG_I(logLevel, "(Signal handler calls suppressed [%d]. Inlined calls denoted by < > brackets.)", hiddenLines);
}
continue;
}
if (eit->inLine) {
LOG_I(logLevel, " <%02u> %*s %s", fit->level, colFileline, eit->abbrev_fileline.c_str(), eit->abbrev_funcname.c_str());
} else {
LOG_I(logLevel, "[%02u] %*s %s", fit->level, colFileline, eit->abbrev_fileline.c_str(), eit->abbrev_funcname.c_str());
}
numLine++;
}
}
hideSignalHandler = false;
}
}
示例2: TranslateStackTrace
/**
* @brief TranslateStackTrace
* @param stacktrace These are the lines and addresses produced by backtrace_symbols()
* Translates the module and address information from backtrace symbols into a vector of StackFrame objects,
* each with its own set of entries representing the function call and any inlined functions for that call.
*/
static void TranslateStackTrace(bool* aiCrash, StackTrace& stacktrace, const int logLevel)
{
// Extract important data from backtrace_symbols' output
bool containsDriverSo = false; // OpenGL lib -> graphic problem
bool containsAIInterfaceSo = false;
bool containsSkirmishAISo = false;
LOG_L(L_DEBUG, "TranslateStackTrace[1]");
for (auto it = stacktrace.begin(); it != stacktrace.end(); ++it) {
// prepare for addr2line()
const std::string path = ExtractPath(it->symbol);
const std::string absPath = CreateAbsolutePath(path);
it->path = absPath;
it->addr = ExtractAddr(*it);
LOG_L(L_DEBUG, "symbol = \"%s\", path = \"%s\", absPath = \"%s\", addr = 0x%lx", it->symbol.c_str(), path.c_str(), absPath.c_str(), it->addr);
// 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 (!containsAIInterfaceSo && (absPath.find("Interfaces") != std::string::npos)) {
containsAIInterfaceSo = true;
}
if (!containsSkirmishAISo && (absPath.find("Skirmish") != std::string::npos)) {
containsSkirmishAISo = true;
}
}
LOG_L(L_DEBUG, "TranslateStackTrace[2]");
// 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 (containsSkirmishAISo) {
containsAIInterfaceSo = false;
}
if (containsAIInterfaceSo) {
LOG_I(logLevel, "This stack trace indicates a problem with an AI Interface library.");
if (aiCrash) *aiCrash = true;
}
if (containsSkirmishAISo) {
LOG_I(logLevel, "This stack trace indicates a problem with a Skirmish AI library.");
if (aiCrash) *aiCrash = true;
}
LOG_L(L_DEBUG, "TranslateStackTrace[3]");
// Check if addr2line is available
static int addr2line_found = -1;
if (addr2line_found < 0)
{
FILE* cmdOut = popen(ADDR2LINE " --help", "r");
if (cmdOut == NULL) {
addr2line_found = false;
} else {
addr2line_found = true;
pclose(cmdOut);
}
}
if (!addr2line_found) {
LOG_L(L_WARNING, " addr2line not found!");
return;
}
LOG_L(L_DEBUG, "TranslateStackTrace[4]");
// Detect BaseMemoryAddresses of all Lib's found in the stacktrace
std::map<std::string,uintptr_t> binPath_baseMemAddr;
for (auto it = stacktrace.cbegin(); it != stacktrace.cend(); it++) {
binPath_baseMemAddr[it->path] = 0;
}
FindBaseMemoryAddresses(binPath_baseMemAddr);
LOG_L(L_DEBUG, "TranslateStackTrace[5]");
// Finally translate it:
// This is nested so that the outer loop covers all the entries for one library -- this means fewer addr2line calls.
for (auto it = binPath_baseMemAddr.cbegin(); it != binPath_baseMemAddr.cend(); it++) {
const std::string& modulePath = it->first;
//const uintptr_t& moduleAddr = it->second;
const std::string symbolFile = LocateSymbolFile(modulePath);
LOG_L(L_DEBUG, "modulePath: %s, symbolFile: %s", modulePath.c_str(), symbolFile.c_str());
//.........这里部分代码省略.........