demangles symbols in assert tracebacks

This commit is contained in:
Arvid Norberg 2007-12-27 06:15:52 +00:00
parent 86de8b8bf6
commit 904d9bb50b
2 changed files with 35 additions and 2 deletions

View File

@ -33,7 +33,11 @@ POSSIBILITY OF SUCH DAMAGE.
#ifndef TORRENT_ASSERT #ifndef TORRENT_ASSERT
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include <cassert> #include <string>
#ifdef __GNUC__
std::string demangle(char const* name);
#endif
#if (defined __linux__ || defined __MACH__) && defined __GNUC__ && !defined(NDEBUG) #if (defined __linux__ || defined __MACH__) && defined __GNUC__ && !defined(NDEBUG)

View File

@ -30,6 +30,35 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifdef __GNUC__
#include <cxxabi.h>
#include <string>
#include <stdlib.h>
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 #ifndef NDEBUG
#include <stdlib.h> #include <stdlib.h>
@ -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) 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); free(symbols);