mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
parent
9b319d05ee
commit
ad1a11f882
@ -133,7 +133,6 @@ void StackTrace::Print(std::ostream& fp, int ignoreFrames) const
|
|||||||
path = path.SubStr(slashp + 1);
|
path = path.SubStr(slashp + 1);
|
||||||
|
|
||||||
message = path + ": " + sym_demangled + " (" + String(sym_end);
|
message = path + ": " + sym_demangled + " (" + String(sym_end);
|
||||||
message += " (" + Utility::GetSymbolSource(m_Frames[i]) + ")";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,9 +147,7 @@ void StackTrace::Print(std::ostream& fp, int ignoreFrames) const
|
|||||||
# endif /* HAVE_BACKTRACE_SYMBOLS */
|
# endif /* HAVE_BACKTRACE_SYMBOLS */
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
for (int i = ignoreFrames + 1; i < m_Count; i++) {
|
for (int i = ignoreFrames + 1; i < m_Count; i++) {
|
||||||
fp << "\t(" << i - ignoreFrames - 1 << ") "
|
fp << "\t(" << i - ignoreFrames - 1 << "): "
|
||||||
<< Utility::GetSymbolSource(m_Frames[i])
|
|
||||||
<< ": "
|
|
||||||
<< Utility::GetSymbolName(m_Frames[i])
|
<< Utility::GetSymbolName(m_Frames[i])
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
@ -85,43 +85,6 @@ String Utility::GetTypeName(const std::type_info& ti)
|
|||||||
return DemangleSymbolName(ti.name());
|
return DemangleSymbolName(ti.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Looks up source file name and line number information for the specified
|
|
||||||
* ELF executable and RVA.
|
|
||||||
*
|
|
||||||
* @param exe The ELF file.
|
|
||||||
* @param rva The RVA.
|
|
||||||
* @returns Source file and line number.
|
|
||||||
*/
|
|
||||||
String Utility::Addr2Line(const String& exe, uintptr_t rva)
|
|
||||||
{
|
|
||||||
#ifndef _WIN32
|
|
||||||
std::ostringstream msgbuf;
|
|
||||||
msgbuf << "addr2line -s -e " << Application::GetExePath(exe) << " " << std::hex << rva << " 2>/dev/null";
|
|
||||||
|
|
||||||
String args = msgbuf.str();
|
|
||||||
|
|
||||||
FILE *fp = popen(args.CStr(), "r");
|
|
||||||
|
|
||||||
if (!fp)
|
|
||||||
return "RVA: " + Convert::ToString(rva);
|
|
||||||
|
|
||||||
char buffer[512] = {};
|
|
||||||
fgets(buffer, sizeof(buffer), fp);
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
String line = buffer;
|
|
||||||
boost::algorithm::trim_right(line);
|
|
||||||
|
|
||||||
if (line.GetLength() == 0)
|
|
||||||
return "RVA: " + Convert::ToString(rva);
|
|
||||||
|
|
||||||
return line;
|
|
||||||
#else /* _WIN32 */
|
|
||||||
return String();
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
}
|
|
||||||
|
|
||||||
String Utility::GetSymbolName(const void *addr)
|
String Utility::GetSymbolName(const void *addr)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DLADDR
|
#ifdef HAVE_DLADDR
|
||||||
@ -155,36 +118,6 @@ String Utility::GetSymbolName(const void *addr)
|
|||||||
return "(unknown function)";
|
return "(unknown function)";
|
||||||
}
|
}
|
||||||
|
|
||||||
String Utility::GetSymbolSource(const void *addr)
|
|
||||||
{
|
|
||||||
#ifdef HAVE_DLADDR
|
|
||||||
Dl_info dli;
|
|
||||||
|
|
||||||
if (dladdr(addr, &dli) > 0) {
|
|
||||||
uintptr_t rva = reinterpret_cast<uintptr_t>(addr) - reinterpret_cast<uintptr_t>(dli.dli_fbase);
|
|
||||||
return Addr2Line(dli.dli_fname, rva);
|
|
||||||
}
|
|
||||||
#endif /* HAVE_DLADDR */
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
char buffer[sizeof(SYMBOL_INFO)+MAX_SYM_NAME * sizeof(TCHAR)];
|
|
||||||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
|
||||||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
|
||||||
pSymbol->MaxNameLen = MAX_SYM_NAME;
|
|
||||||
|
|
||||||
DWORD64 dwAddress = (DWORD64)addr;
|
|
||||||
DWORD dwDisplacement;
|
|
||||||
|
|
||||||
IMAGEHLP_LINE64 line;
|
|
||||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
|
||||||
|
|
||||||
if (SymGetLineFromAddr64(GetCurrentProcess(), dwAddress, &dwDisplacement, &line))
|
|
||||||
return String(line.FileName) + ":" + Convert::ToString(line.LineNumber);
|
|
||||||
#endif /* _WIN32 */
|
|
||||||
|
|
||||||
return "(unknown file/line)";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs wildcard pattern matching.
|
* Performs wildcard pattern matching.
|
||||||
*
|
*
|
||||||
|
@ -60,9 +60,7 @@ class I2_BASE_API Utility
|
|||||||
public:
|
public:
|
||||||
static String DemangleSymbolName(const String& sym);
|
static String DemangleSymbolName(const String& sym);
|
||||||
static String GetTypeName(const std::type_info& ti);
|
static String GetTypeName(const std::type_info& ti);
|
||||||
static String Addr2Line(const String& exe, uintptr_t rva);
|
|
||||||
static String GetSymbolName(const void *addr);
|
static String GetSymbolName(const void *addr);
|
||||||
static String GetSymbolSource(const void *addr);
|
|
||||||
|
|
||||||
static bool Match(const String& pattern, const String& text);
|
static bool Match(const String& pattern, const String& text);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user