Extract util methods

This commit is contained in:
Christophe Bedard 2019-06-04 16:37:11 +02:00
parent 51f3c16205
commit ee813caaf1
5 changed files with 52 additions and 20 deletions

28
tracetools/src/utils.cpp Normal file
View file

@ -0,0 +1,28 @@
#if defined(WITH_LTTNG) && !defined(_WIN32)
#include <dlfcn.h>
#include <cxxabi.h>
#endif
const char * get_symbol(void * funptr) {
#define SYMBOL_UNKNOWN "UNKNOWN"
#if defined(WITH_LTTNG) && !defined(_WIN32)
#define SYMBOL_LAMBDA "[lambda]"
if (funptr == 0) {
return SYMBOL_LAMBDA;
}
Dl_info info;
if (dladdr(funptr, &info) == 0) {
return SYMBOL_UNKNOWN;
}
char * demangled = nullptr;
int status;
demangled = abi::__cxa_demangle(info.dli_sname, NULL, 0, &status);
// Use demangled symbol if possible
const char * demangled_val = (status == 0 ? demangled : info.dli_sname);
return (demangled_val != 0 ? demangled_val : SYMBOL_UNKNOWN);
#else
return SYMBOL_UNKNOWN;
#endif
}