added: symbol demangling helper
this is trivial enough to carry ourself instead of relying on dune-common
This commit is contained in:
parent
fd6e793b6a
commit
b125823f92
@ -32,6 +32,7 @@ list (APPEND MAIN_SOURCE_FILES
|
||||
src/opm/common/OpmLog/StreamLog.cpp
|
||||
src/opm/common/OpmLog/TimerLog.cpp
|
||||
src/opm/common/utility/ActiveGridCells.cpp
|
||||
src/opm/common/utility/Demangle.cpp
|
||||
src/opm/common/utility/FileSystem.cpp
|
||||
src/opm/common/utility/numeric/MonotCubicInterpolator.cpp
|
||||
src/opm/common/utility/OpmInputError.cpp
|
||||
@ -694,6 +695,7 @@ list( APPEND PUBLIC_HEADER_FILES
|
||||
opm/common/OpmLog/StreamLog.hpp
|
||||
opm/common/OpmLog/TimerLog.hpp
|
||||
opm/common/utility/ActiveGridCells.hpp
|
||||
opm/common/utility/Demangle.hpp
|
||||
opm/common/utility/FileSystem.hpp
|
||||
opm/common/utility/OpmInputError.hpp
|
||||
opm/common/utility/Serializer.hpp
|
||||
|
@ -8,6 +8,7 @@ set (opm-common_CONFIG_VAR
|
||||
HAVE_VALGRIND
|
||||
HAVE_FINAL
|
||||
HAVE_ECL_INPUT
|
||||
HAVE_CXA_DEMANGLE
|
||||
)
|
||||
|
||||
# dependencies
|
||||
|
32
opm/common/utility/Demangle.hpp
Normal file
32
opm/common/utility/Demangle.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2022 Equinor ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_DEMANGLE_HPP
|
||||
#define OPM_DEMANGLE_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
//! \brief Returns demangled name of symbol.
|
||||
//! \details Non-demangled name is return if demangling is not supported
|
||||
std::string demangle(const char* mangled_symbol);
|
||||
|
||||
}
|
||||
#endif //OPM_DEMANGLE_HPP
|
49
src/opm/common/utility/Demangle.cpp
Normal file
49
src/opm/common/utility/Demangle.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2022 Equinor ASA.
|
||||
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM 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 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <opm/common/utility/Demangle.hpp>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <typeinfo>
|
||||
|
||||
#if HAVE_CXA_DEMANGLE
|
||||
#include <cxxabi.h>
|
||||
#endif
|
||||
|
||||
namespace Opm {
|
||||
|
||||
std::string demangle(const char* mangled_symbol)
|
||||
{
|
||||
std::string name = mangled_symbol;
|
||||
|
||||
#if HAVE_CXA_DEMANGLE
|
||||
int status;
|
||||
char* demangled = abi::__cxa_demangle(mangled_symbol,
|
||||
nullptr, nullptr, &status);
|
||||
if (demangled) {
|
||||
name = demangled;
|
||||
free(demangled);
|
||||
}
|
||||
#endif
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user