2015-10-29 07:58:51 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2000-2007 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pbd/demangle.h"
|
|
|
|
|
|
|
|
#if defined(__GLIBCXX__)
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::string
|
2015-10-29 08:22:47 -04:00
|
|
|
PBD::demangle_symbol (const std::string& mangled_symbol)
|
2015-10-29 07:58:51 -04:00
|
|
|
{
|
|
|
|
#if defined(__GLIBCXX__)
|
|
|
|
int status;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2015-10-29 08:22:47 -04:00
|
|
|
char* realname = abi::__cxa_demangle (mangled_symbol.c_str(), 0, 0, &status);
|
|
|
|
std::string demangled_symbol (realname);
|
2015-10-29 07:58:51 -04:00
|
|
|
free (realname);
|
2015-10-29 08:22:47 -04:00
|
|
|
return demangled_symbol;
|
2015-10-29 07:58:51 -04:00
|
|
|
} catch (std::exception) {
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-29 08:41:38 -04:00
|
|
|
/* Note: on win32, you can use UnDecorateSymbolName.
|
|
|
|
See http://msdn.microsoft.com/en-us/library/ms681400%28VS.85%29.aspx
|
|
|
|
See also: http://msdn.microsoft.com/en-us/library/ms680344%28VS.85%29.aspx
|
|
|
|
*/
|
|
|
|
|
2015-10-29 08:22:47 -04:00
|
|
|
return mangled_symbol;
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
2015-10-29 08:22:47 -04:00
|
|
|
PBD::demangle (std::string const& str)
|
2015-10-29 07:58:51 -04:00
|
|
|
{
|
2015-10-29 08:22:47 -04:00
|
|
|
std::string::size_type const b = str.find_first_of ("(");
|
2015-10-29 07:58:51 -04:00
|
|
|
|
|
|
|
if (b == std::string::npos) {
|
2015-10-29 08:22:47 -04:00
|
|
|
return demangle_symbol (str);
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|
|
|
|
|
2015-10-29 08:22:47 -04:00
|
|
|
std::string::size_type const p = str.find_last_of ("+");
|
2015-10-29 07:58:51 -04:00
|
|
|
if (p == std::string::npos) {
|
2015-10-29 08:22:47 -04:00
|
|
|
return demangle_symbol (str);
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((p - b) <= 1) {
|
2015-10-29 08:22:47 -04:00
|
|
|
return demangle_symbol (str);
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|
|
|
|
|
2015-10-29 08:22:47 -04:00
|
|
|
std::string const symbol = str.substr (b + 1, p - b - 1);
|
2015-10-29 07:58:51 -04:00
|
|
|
|
2015-10-29 08:22:47 -04:00
|
|
|
return demangle_symbol (symbol);
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|