From 904d9bb50b19083eb53ff98d961e178befaa4b0b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 27 Dec 2007 06:15:52 +0000 Subject: [PATCH] demangles symbols in assert tracebacks --- include/libtorrent/assert.hpp | 6 +++++- src/assert.cpp | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/assert.hpp b/include/libtorrent/assert.hpp index 246e3b51b..b3a66f043 100644 --- a/include/libtorrent/assert.hpp +++ b/include/libtorrent/assert.hpp @@ -33,7 +33,11 @@ POSSIBILITY OF SUCH DAMAGE. #ifndef TORRENT_ASSERT #include "libtorrent/config.hpp" -#include +#include + +#ifdef __GNUC__ +std::string demangle(char const* name); +#endif #if (defined __linux__ || defined __MACH__) && defined __GNUC__ && !defined(NDEBUG) diff --git a/src/assert.cpp b/src/assert.cpp index 1073e05a3..6991736f4 100644 --- a/src/assert.cpp +++ b/src/assert.cpp @@ -30,6 +30,35 @@ POSSIBILITY OF SUCH DAMAGE. */ +#ifdef __GNUC__ + +#include +#include +#include + +std::string demangle(char const* name) +{ +// in case this string comes + char const* start = strchr(name, '('); + if (start != 0) ++start; + else start = name; + char const* end = strchr(start, '+'); + + std::string in; + if (end == 0) in.assign(start); + else in.assign(start, end); + + size_t len; + int status; + char* unmangled = ::abi::__cxa_demangle(in.c_str(), 0, &len, &status); + if (unmangled == 0) return in; + std::string ret(unmangled); + free(unmangled); + return ret; +} + +#endif + #ifndef NDEBUG #include @@ -58,7 +87,7 @@ void assert_fail(char const* expr, int line, char const* file, char const* funct for (int i = 0; i < size; ++i) { - fprintf(stderr, "%d: %s\n", i, symbols[i]); + fprintf(stderr, "%d: %s\n", i, demangle(symbols[i]).c_str()); } free(symbols);