void DtoDeclareTypeInfo(TypeInfoDeclaration* tid) { DtoResolveTypeInfo(tid); if (tid->ir.declared) return; tid->ir.declared = true; Logger::println("DtoDeclareTypeInfo(%s)", tid->toChars()); LOG_SCOPE; if (Logger::enabled()) { std::string mangled(tid->mangle()); Logger::println("type = '%s'", tid->tinfo->toChars()); Logger::println("typeinfo mangle: %s", mangled.c_str()); } IrGlobal* irg = tid->ir.irGlobal; assert(irg->value != NULL); // this is a declaration of a builtin __initZ var if (tid->tinfo->builtinTypeInfo()) { LLGlobalVariable* g = isaGlobalVar(irg->value); g->setLinkage(llvm::GlobalValue::ExternalLinkage); return; } // define custom typedef tid->llvmDefine(); }
void DebugHelper::backtrace_msg() { void ** traceBuffer = new void*[MAX_DEPTH]; uint32 depth = backtrace( traceBuffer, MAX_DEPTH ); char ** traceStringBuffer = backtrace_symbols( traceBuffer, depth ); for (uint32 i = 0; i < depth; i++) { // Format: <executable path>(<mangled-function-name>+<function // instruction offset>) [<eip>] std::string functionName; std::string traceString( traceStringBuffer[i] ); std::string::size_type begin = traceString.find( '(' ); bool gotFunctionName = (begin >= 0); if (gotFunctionName) { // Skip the round bracket start. ++begin; std::string::size_type bracketEnd = traceString.find( ')', begin ); std::string::size_type end = traceString.rfind( '+', bracketEnd ); std::string mangled( traceString.substr( begin, end - begin ) ); int status = 0; size_t demangledBufferLength = 0; char * demangledBuffer = abi::__cxa_demangle( mangled.c_str(), 0, &demangledBufferLength, &status ); if (demangledBuffer) { functionName.assign( demangledBuffer, demangledBufferLength ); // __cxa_demangle allocates the memory for the demangled // output using malloc(), we need to free it. free( demangledBuffer ); } else { // Didn't demangle, but we did get a function name, use that. functionName = mangled; } } std::string ss = (boost::format("Stack: #%1% %2%\n") % i % ((gotFunctionName) ? functionName.c_str() : traceString.c_str())).str(); #ifdef NO_USE_LOG4CXX #else LOG4CXX_INFO(g_logger, ss); #endif onMessage(KBELOG_PRINT, ss.c_str(), ss.size()); } free(traceStringBuffer); delete[] traceBuffer; }
std::string decode( char *message) { std::string msg(message); std::string res(message); std::string::size_type popen = msg.find('('); if ( popen != std::string::npos ) { std::string::size_type plus = msg.find('+'); res = std::string(message,popen+1) + " "; std::string mangled( message, popen+1, plus -popen -1 ); res += demangle(mangled) + " "; res += std::string( message + plus, message + strlen(message) ); } return res; }
void StackTraceUtils::Impl::getSymbolName( StackTraceHandler &handler, char8_t *rawSymbol) { do { char8_t *left = strchr(rawSymbol, '('); if (left == NULL) { break; } left++; char8_t *right = strchr(left, '+'); if (right == NULL) { break; } char8_t mangledBuf[128]; detail::LocalString mangled(mangledBuf, sizeof(mangledBuf)); mangled.tryAppend(left, right); int status = 0; char8_t *demangled = abi::__cxa_demangle(mangled.tryGet(), 0, 0, &status); if (demangled == NULL) { handler(mangled.tryGet(), -1); return; } try { handler(demangled, -1); } catch (...) { ::free(demangled); throw; } ::free(demangled); return; } while (false); handler("", -1); }
inline void DumpBacktrace(std::ostream& out, unsigned skip = 0) { static const size_t maxSize = 100; void *array[maxSize]; int size = backtrace(array, maxSize); if (size <= 0) return; boost::scoped_array<char*> symbols(backtrace_symbols(array, size)); if (!symbols) return; for (int i = skip; i < size; ++i) { std::string symbol(symbols[i]); std::string::size_type pos = symbol.find('('); std::string path(symbol, 0, pos); std::string mangled(symbol, pos + 1, symbol.find(')') - pos - 1); std::string offset; pos = mangled.find('+'); if (pos != std::string::npos) { offset.assign(mangled, pos + 1, mangled.length() - pos); mangled.erase(pos); } pos = symbol.find('['); std::string address(symbol, pos + 1, symbol.find(']', pos) - pos - 1); out << std::left << std::setw(3) << (i - skip + 1); boost::scoped_array<char> demangled(abi:: __cxa_demangle(mangled.c_str(), nullptr, nullptr, nullptr)); out << path << " "; if (demangled.get()) out << demangled.get() << " "; else if (!mangled.empty()) out << mangled << " "; if (!offset.empty()) out << "[+" << offset << "] "; out << "[" << address << "]" << std::endl; } }