2015-10-29 07:58:51 -04:00
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
* Copyright (C) 2000-2007 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2015-10-29 07:58:51 -04:00
|
|
|
|
|
|
|
#include "pbd/demangle.h"
|
|
|
|
|
2024-11-11 00:02:26 -05:00
|
|
|
#if defined(__GLIBCXX__) || defined(__APPLE__)
|
2015-10-29 07:58:51 -04:00
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
|
|
|
|
2024-11-11 00:02:26 -05:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <sstream>
|
|
|
|
#endif
|
|
|
|
|
2015-10-29 07:58:51 -04:00
|
|
|
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
|
|
|
{
|
2024-11-11 00:02:26 -05:00
|
|
|
#if defined(__GLIBCXX__) || defined(__APPLE__)
|
2015-10-29 07:58:51 -04:00
|
|
|
|
|
|
|
try {
|
2021-07-19 11:32:18 -04:00
|
|
|
int status;
|
2015-10-29 08:22:47 -04:00
|
|
|
char* realname = abi::__cxa_demangle (mangled_symbol.c_str(), 0, 0, &status);
|
2024-11-11 00:02:26 -05:00
|
|
|
if (!status) {
|
|
|
|
std::string demangled_symbol (realname);
|
|
|
|
free (realname);
|
|
|
|
return demangled_symbol;
|
|
|
|
}
|
|
|
|
return mangled_symbol;
|
2021-07-19 11:32:18 -04:00
|
|
|
} catch (...) {
|
|
|
|
/* may happen if realname == NULL */
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|
|
|
|
#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
|
|
|
{
|
2024-11-11 00:02:26 -05:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
|
|
|
std::string foo;
|
|
|
|
std::string symbol;
|
|
|
|
std::stringstream sstr (str);
|
|
|
|
|
|
|
|
/* format is:
|
|
|
|
|
|
|
|
[ DIGITS LIBRARY_NAME ADDRESS SYMBOL OFFSET ]
|
|
|
|
|
|
|
|
We just need symbol. If this was speed-critical code, we'd likely
|
|
|
|
use C style code to get symbol, but it's not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sstr >> foo;
|
|
|
|
sstr >> foo;
|
|
|
|
sstr >> foo;
|
|
|
|
sstr >> symbol;
|
|
|
|
|
|
|
|
return demangle_symbol (symbol);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
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);
|
2024-11-11 00:02:26 -05:00
|
|
|
#endif
|
2015-10-29 07:58:51 -04:00
|
|
|
}
|