diff options
| author | 2023-01-13 21:06:13 +0000 | |
|---|---|---|
| committer | 2023-01-14 04:43:21 +0000 | |
| commit | 80a55c1663ac600103e3d475c1f72b04e2e76f0f (patch) | |
| tree | ac18dcb7f4714b3324733724edd449c77356345c /src/common | |
| parent | Merge pull request #9605 from german77/mouse_mapping (diff) | |
| download | yuzu-80a55c1663ac600103e3d475c1f72b04e2e76f0f.tar.gz yuzu-80a55c1663ac600103e3d475c1f72b04e2e76f0f.tar.xz yuzu-80a55c1663ac600103e3d475c1f72b04e2e76f0f.zip | |
Add stacktrace symbol demangling
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/common/demangle.h | 33 |
2 files changed, 35 insertions, 1 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 | ||