diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/common/demangle.cpp | 37 | ||||
-rw-r--r-- | src/common/demangle.h | 12 | ||||
-rw-r--r-- | src/core/arm/arm_interface.cpp | 22 |
4 files changed, 56 insertions, 19 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 45332cf95..bd6ac6716 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -38,6 +38,8 @@ add_library(common STATIC common_precompiled_headers.h common_types.h concepts.h + demangle.cpp + demangle.h div_ceil.h dynamic_library.cpp dynamic_library.h @@ -175,7 +177,7 @@ endif() create_target_directory_groups(common) target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads) -target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd) +target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd demangle) if (YUZU_USE_PRECOMPILED_HEADERS) target_precompile_headers(common PRIVATE precompiled_headers.h) diff --git a/src/common/demangle.cpp b/src/common/demangle.cpp new file mode 100644 index 000000000..f4246f666 --- /dev/null +++ b/src/common/demangle.cpp @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "common/demangle.h" +#include "common/scope_exit.h" + +namespace llvm { +char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status); +} + +namespace Common { + +std::string DemangleSymbol(const std::string& mangled) { + auto is_itanium = [](const std::string& name) -> bool { + // A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'. + auto pos = name.find_first_not_of('_'); + return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z'; + }; + + if (mangled.empty()) { + return mangled; + } + + char* demangled = nullptr; + SCOPE_EXIT({ std::free(demangled); }); + + if (is_itanium(mangled)) { + demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr); + } + + if (!demangled) { + return mangled; + } + return demangled; +} + +} // namespace Common diff --git a/src/common/demangle.h b/src/common/demangle.h new file mode 100644 index 000000000..f072d22f3 --- /dev/null +++ b/src/common/demangle.h @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <string> + +namespace Common { + +std::string DemangleSymbol(const std::string& mangled); + +} // namespace Common diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp index 2df7b0ee8..8aa7b9641 100644 --- a/src/core/arm/arm_interface.cpp +++ b/src/core/arm/arm_interface.cpp @@ -1,14 +1,12 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#ifndef _MSC_VER -#include <cxxabi.h> -#endif - #include <map> #include <optional> + #include "common/bit_field.h" #include "common/common_types.h" +#include "common/demangle.h" #include "common/logging/log.h" #include "core/arm/arm_interface.h" #include "core/arm/symbols.h" @@ -71,20 +69,8 @@ void ARM_Interface::SymbolicateBacktrace(Core::System& system, std::vector<Backt const auto symbol_set = symbols.find(entry.module); if (symbol_set != symbols.end()) { const auto symbol = Symbols::GetSymbolName(symbol_set->second, entry.offset); - if (symbol.has_value()) { -#ifdef _MSC_VER - // TODO(DarkLordZach): Add demangling of symbol names. - entry.name = *symbol; -#else - int status{-1}; - char* demangled{abi::__cxa_demangle(symbol->c_str(), nullptr, nullptr, &status)}; - if (status == 0 && demangled != nullptr) { - entry.name = demangled; - std::free(demangled); - } else { - entry.name = *symbol; - } -#endif + if (symbol) { + entry.name = Common::DemangleSymbol(*symbol); } } } |