From 00774c49aef33d698132658c4191c6835bc10941 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Wed, 21 May 2014 14:33:44 +0200 Subject: [PATCH] Demangle function names. --- malloctrace_main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/malloctrace_main.cpp b/malloctrace_main.cpp index cb01174..6c6d0ee 100644 --- a/malloctrace_main.cpp +++ b/malloctrace_main.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "libbacktrace/backtrace.h" @@ -35,6 +36,22 @@ void printUsage(ostream& out) out << "malloctrace_main MALLOCTRACE_LOG_FILE..." << endl; } +string demangle(const char* function) +{ + if (!function || function[0] != '_' || function[1] != 'Z') { + return {function}; + } + + string ret; + int status = 0; + char* demangled = abi::__cxa_demangle(function, 0, 0, &status); + if (demangled) { + ret = demangled; + free(demangled); + } + return ret; +} + struct Module { Module(string _fileName, uintptr_t baseAddress, bool isExe) @@ -69,9 +86,12 @@ struct Module backtrace_syminfo(backtraceState, baseAddress + offset, [] (void *data, uintptr_t /*pc*/, const char *symname, uintptr_t /*symval*/, uintptr_t /*symsize*/) { if (symname) { - *reinterpret_cast(data) = symname; + *reinterpret_cast(data) = demangle(symname); } }, &errorCallback, &ret); + if (ret.empty()) { + ret = "??"; + } return ret; } -- 2.7.4