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 | |||
| 38 | common_precompiled_headers.h | 38 | common_precompiled_headers.h |
| 39 | common_types.h | 39 | common_types.h |
| 40 | concepts.h | 40 | concepts.h |
| 41 | demangle.cpp | ||
| 42 | demangle.h | ||
| 41 | div_ceil.h | 43 | div_ceil.h |
| 42 | dynamic_library.cpp | 44 | dynamic_library.cpp |
| 43 | dynamic_library.h | 45 | dynamic_library.h |
| @@ -175,7 +177,7 @@ endif() | |||
| 175 | create_target_directory_groups(common) | 177 | create_target_directory_groups(common) |
| 176 | 178 | ||
| 177 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads) | 179 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads) |
| 178 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd) | 180 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd demangle) |
| 179 | 181 | ||
| 180 | if (YUZU_USE_PRECOMPILED_HEADERS) | 182 | if (YUZU_USE_PRECOMPILED_HEADERS) |
| 181 | target_precompile_headers(common PRIVATE precompiled_headers.h) | 183 | 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 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #include "common/demangle.h" | ||
| 5 | #include "common/scope_exit.h" | ||
| 6 | |||
| 7 | namespace llvm { | ||
| 8 | char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status); | ||
| 9 | } | ||
| 10 | |||
| 11 | namespace Common { | ||
| 12 | |||
| 13 | std::string DemangleSymbol(const std::string& mangled) { | ||
| 14 | auto is_itanium = [](const std::string& name) -> bool { | ||
| 15 | // A valid Itanium encoding requires 1-4 leading underscores, followed by 'Z'. | ||
| 16 | auto pos = name.find_first_not_of('_'); | ||
| 17 | return pos > 0 && pos <= 4 && pos < name.size() && name[pos] == 'Z'; | ||
| 18 | }; | ||
| 19 | |||
| 20 | if (mangled.empty()) { | ||
| 21 | return mangled; | ||
| 22 | } | ||
| 23 | |||
| 24 | char* demangled = nullptr; | ||
| 25 | SCOPE_EXIT({ std::free(demangled); }); | ||
| 26 | |||
| 27 | if (is_itanium(mangled)) { | ||
| 28 | demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr); | ||
| 29 | } | ||
| 30 | |||
| 31 | if (!demangled) { | ||
| 32 | return mangled; | ||
| 33 | } | ||
| 34 | return demangled; | ||
| 35 | } | ||
| 36 | |||
| 37 | } // 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 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | #include <string> | ||
| 7 | |||
| 8 | namespace Common { | ||
| 9 | |||
| 10 | std::string DemangleSymbol(const std::string& mangled); | ||
| 11 | |||
| 12 | } // 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 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project | 1 | // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | 3 | ||
| 4 | #ifndef _MSC_VER | ||
| 5 | #include <cxxabi.h> | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <map> | 4 | #include <map> |
| 9 | #include <optional> | 5 | #include <optional> |
| 6 | |||
| 10 | #include "common/bit_field.h" | 7 | #include "common/bit_field.h" |
| 11 | #include "common/common_types.h" | 8 | #include "common/common_types.h" |
| 9 | #include "common/demangle.h" | ||
| 12 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 13 | #include "core/arm/arm_interface.h" | 11 | #include "core/arm/arm_interface.h" |
| 14 | #include "core/arm/symbols.h" | 12 | #include "core/arm/symbols.h" |
| @@ -71,20 +69,8 @@ void ARM_Interface::SymbolicateBacktrace(Core::System& system, std::vector<Backt | |||
| 71 | const auto symbol_set = symbols.find(entry.module); | 69 | const auto symbol_set = symbols.find(entry.module); |
| 72 | if (symbol_set != symbols.end()) { | 70 | if (symbol_set != symbols.end()) { |
| 73 | const auto symbol = Symbols::GetSymbolName(symbol_set->second, entry.offset); | 71 | const auto symbol = Symbols::GetSymbolName(symbol_set->second, entry.offset); |
| 74 | if (symbol.has_value()) { | 72 | if (symbol) { |
| 75 | #ifdef _MSC_VER | 73 | entry.name = Common::DemangleSymbol(*symbol); |
| 76 | // TODO(DarkLordZach): Add demangling of symbol names. | ||
| 77 | entry.name = *symbol; | ||
| 78 | #else | ||
| 79 | int status{-1}; | ||
| 80 | char* demangled{abi::__cxa_demangle(symbol->c_str(), nullptr, nullptr, &status)}; | ||
| 81 | if (status == 0 && demangled != nullptr) { | ||
| 82 | entry.name = demangled; | ||
| 83 | std::free(demangled); | ||
| 84 | } else { | ||
| 85 | entry.name = *symbol; | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | } | 74 | } |
| 89 | } | 75 | } |
| 90 | } | 76 | } |