diff options
author | Chris Wilson <chris+github@qwirx.com> | 2014-02-11 10:29:25 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2014-02-11 10:29:25 +0000 |
commit | fd10bf6ffcb925557ce37d48e55587b7332cf585 (patch) | |
tree | af4d008d6e3866396bc92a9640592f689f6fcc21 /lib | |
parent | a2eceab5420eeb240bc4e5b81b374e76a93ede1d (diff) |
Simplify C++ name demangling code, and its memory allocation tracking.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/common/Utils.cpp | 78 |
1 files changed, 33 insertions, 45 deletions
diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index decc80e8..a1647f11 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -83,62 +83,50 @@ void SplitString(const std::string &String, char SplitOn, std::vector<std::strin #ifdef SHOW_BACKTRACE_ON_EXCEPTION static std::string demangle(const std::string& mangled_name) { + std::string demangled_name = mangled_name; + #ifdef HAVE_CXXABI_H + char buffer[1024]; int status; + size_t length = sizeof(buffer); -#include "MemLeakFindOff.h" char* result = abi::__cxa_demangle(mangled_name.c_str(), - NULL, NULL, &status); -#include "MemLeakFindOn.h" + buffer, &length, &status); - if (result == NULL) + if (status == 0) { - if (status == 0) - { - BOX_WARNING("Demangle failed but no error: " << - mangled_name); - } - else if (status == -1) - { - BOX_WARNING("Demangle failed with " - "memory allocation error: " << - mangled_name); - } - else if (status == -2) - { - // Probably non-C++ name, don't demangle - /* - BOX_WARNING("Demangle failed with " - "with invalid name: " << - mangled_name); - */ - } - else if (status == -3) - { - BOX_WARNING("Demangle failed with " - "with invalid argument: " << - mangled_name); - } - else - { - BOX_WARNING("Demangle failed with " - "with unknown error " << status << - ": " << mangled_name); - } - - return std::string(mangled_name); + demangled_name = result; + } + else if (status == -1) + { + BOX_WARNING("Demangle failed with " + "memory allocation error: " << + mangled_name); + } + else if (status == -2) + { + // Probably non-C++ name, don't demangle + /* + BOX_WARNING("Demangle failed with " + "with invalid name: " << + mangled_name); + */ + } + else if (status == -3) + { + BOX_WARNING("Demangle failed with " + "with invalid argument: " << + mangled_name); } else { - std::string output = result; -#include "MemLeakFindOff.h" - free(result); -#include "MemLeakFindOn.h" - return output; + BOX_WARNING("Demangle failed with " + "with unknown error " << status << + ": " << mangled_name); } - #else // !HAVE_CXXABI_H - return mangled_name; #endif // HAVE_CXXABI_H + + return demangled_name; } void DumpStackBacktrace() |