diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/common/demangle.h | 33 | ||||
| -rw-r--r-- | src/core/arm/arm_interface.cpp | 18 |
3 files changed, 39 insertions, 15 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 45332cf95..57eec57b5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -38,6 +38,7 @@ 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.h | ||
| 41 | div_ceil.h | 42 | div_ceil.h |
| 42 | dynamic_library.cpp | 43 | dynamic_library.cpp |
| 43 | dynamic_library.h | 44 | dynamic_library.h |
| @@ -175,7 +176,7 @@ endif() | |||
| 175 | create_target_directory_groups(common) | 176 | create_target_directory_groups(common) |
| 176 | 177 | ||
| 177 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads) | 178 | target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile Threads::Threads) |
| 178 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd) | 179 | target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd demangle) |
| 179 | 180 | ||
| 180 | if (YUZU_USE_PRECOMPILED_HEADERS) | 181 | if (YUZU_USE_PRECOMPILED_HEADERS) |
| 181 | target_precompile_headers(common PRIVATE precompiled_headers.h) | 182 | target_precompile_headers(common PRIVATE precompiled_headers.h) |
diff --git a/src/common/demangle.h b/src/common/demangle.h new file mode 100644 index 000000000..1c4143629 --- /dev/null +++ b/src/common/demangle.h | |||
| @@ -0,0 +1,33 @@ | |||
| 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 llvm { | ||
| 9 | char* itaniumDemangle(const char* mangled_name, char* buf, size_t* n, int* status); | ||
| 10 | } | ||
| 11 | |||
| 12 | namespace Common { | ||
| 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 && name[pos] == 'Z'; | ||
| 18 | }; | ||
| 19 | |||
| 20 | char* demangled = nullptr; | ||
| 21 | if (is_itanium(mangled)) { | ||
| 22 | demangled = llvm::itaniumDemangle(mangled.c_str(), nullptr, nullptr, nullptr); | ||
| 23 | } | ||
| 24 | |||
| 25 | if (!demangled) { | ||
| 26 | return mangled; | ||
| 27 | } | ||
| 28 | |||
| 29 | std::string ret = demangled; | ||
| 30 | std::free(demangled); | ||
| 31 | return ret; | ||
| 32 | } | ||
| 33 | } // namespace Common \ No newline at end of file | ||
diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp index 2df7b0ee8..a34200539 100644 --- a/src/core/arm/arm_interface.cpp +++ b/src/core/arm/arm_interface.cpp | |||
| @@ -7,8 +7,10 @@ | |||
| 7 | 7 | ||
| 8 | #include <map> | 8 | #include <map> |
| 9 | #include <optional> | 9 | #include <optional> |
| 10 | |||
| 10 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 11 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | #include "common/demangle.h" | ||
| 12 | #include "common/logging/log.h" | 14 | #include "common/logging/log.h" |
| 13 | #include "core/arm/arm_interface.h" | 15 | #include "core/arm/arm_interface.h" |
| 14 | #include "core/arm/symbols.h" | 16 | #include "core/arm/symbols.h" |
| @@ -71,20 +73,8 @@ void ARM_Interface::SymbolicateBacktrace(Core::System& system, std::vector<Backt | |||
| 71 | const auto symbol_set = symbols.find(entry.module); | 73 | const auto symbol_set = symbols.find(entry.module); |
| 72 | if (symbol_set != symbols.end()) { | 74 | if (symbol_set != symbols.end()) { |
| 73 | const auto symbol = Symbols::GetSymbolName(symbol_set->second, entry.offset); | 75 | const auto symbol = Symbols::GetSymbolName(symbol_set->second, entry.offset); |
| 74 | if (symbol.has_value()) { | 76 | if (symbol) { |
| 75 | #ifdef _MSC_VER | 77 | 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 | } | 78 | } |
| 89 | } | 79 | } |
| 90 | } | 80 | } |