diff --git a/lib/trace/include/hex/trace/stacktrace.hpp b/lib/trace/include/hex/trace/stacktrace.hpp index 5206cc0ba..b0671506d 100644 --- a/lib/trace/include/hex/trace/stacktrace.hpp +++ b/lib/trace/include/hex/trace/stacktrace.hpp @@ -21,6 +21,7 @@ namespace hex::trace { std::string implementationName; }; - StackTraceResult getStackTrace(); + StackTraceResult getStackTrace(); + [[nodiscard]] std::string demangle(const std::string &mangledName); } \ No newline at end of file diff --git a/lib/trace/source/stacktrace.cpp b/lib/trace/source/stacktrace.cpp index d402f9286..aff6e4340 100644 --- a/lib/trace/source/stacktrace.cpp +++ b/lib/trace/source/stacktrace.cpp @@ -3,21 +3,23 @@ #include -namespace { +namespace hex::trace { - [[maybe_unused]] std::string tryDemangle(const std::string &symbolName) { - if (auto variant1 = llvm::demangle(symbolName); variant1 != symbolName) - return variant1; + std::string demangle(const std::string &symbolName) { + if (auto result = llvm::demangle(symbolName); result != symbolName) + return result; - if (auto variant2 = llvm::demangle(std::string("_") + symbolName); variant2 != std::string("_") + symbolName) - return variant2; + if (auto result = llvm::demangle(std::string("_") + symbolName); result != std::string("_") + symbolName) + return result; + + if (auto result = llvm::demangle(std::string("_Z") + symbolName); result != std::string("_Z") + symbolName) + return result; return symbolName; } } - #if defined(HEX_HAS_STD_STACKTRACE) && __has_include() #include @@ -143,7 +145,7 @@ namespace { fileName = "??"; } - auto demangledName = tryDemangle(symbolName); + auto demangledName = demangle(symbolName); stackTrace.push_back(StackFrame { fileName, demangledName, lineNumber }); } @@ -180,7 +182,7 @@ namespace { dladdr(addresses[i], &info); auto fileName = info.dli_fname != nullptr ? std::filesystem::path(info.dli_fname).filename().string() : "??"; - auto demangledName = info.dli_sname != nullptr ? tryDemangle(info.dli_sname) : "??"; + auto demangledName = info.dli_sname != nullptr ? demangle(info.dli_sname) : "??"; result.push_back(StackFrame { std::move(fileName), std::move(demangledName), 0 }); } @@ -222,7 +224,7 @@ namespace { if (function == nullptr) function = "??"; - result.push_back(StackFrame { std::filesystem::path(fileName).filename().string(), tryDemangle(function), std::uint32_t(lineNumber) }); + result.push_back(StackFrame { std::filesystem::path(fileName).filename().string(), demangle(function), std::uint32_t(lineNumber) }); return 0; }, nullptr, nullptr); diff --git a/main/gui/CMakeLists.txt b/main/gui/CMakeLists.txt index 10d4c40eb..44fa77360 100644 --- a/main/gui/CMakeLists.txt +++ b/main/gui/CMakeLists.txt @@ -58,7 +58,7 @@ set_target_properties(main PROPERTIES target_compile_definitions(main PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}") -target_link_libraries(main PRIVATE libromfs-imhex libimhex libwolv ${LIBBACKTRACE_LIBRARIES} LLVMDemangle) +target_link_libraries(main PRIVATE libromfs-imhex libimhex libwolv ${LIBBACKTRACE_LIBRARIES}) if (WIN32) target_link_libraries(main PRIVATE usp10 wsock32 ws2_32 Dwmapi.lib Winmm.lib) diff --git a/main/gui/source/crash_handlers.cpp b/main/gui/source/crash_handlers.cpp index 10beb5ae4..8d461436a 100644 --- a/main/gui/source/crash_handlers.cpp +++ b/main/gui/source/crash_handlers.cpp @@ -13,11 +13,9 @@ #include #include -#include #include #include -#include #include #include @@ -164,7 +162,7 @@ namespace hex::crash { try { std::rethrow_exception(std::current_exception()); } catch (std::exception &ex) { - std::string exceptionStr = hex::format("{}()::what() -> {}", llvm::demangle(std::string("_Z") + typeid(ex).name()), ex.what()); + std::string exceptionStr = hex::format("{}()::what() -> {}", trace::demangle(typeid(ex).name()), ex.what()); handleCrash(exceptionStr); log::fatal("Program terminated with uncaught exception: {}", exceptionStr); diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index eee8cc8ef..29a566d67 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -49,8 +49,6 @@ add_imhex_plugin( source/content/window_decoration.cpp source/content/data_information_sections.cpp - source/content/helpers/demangle.cpp - source/content/data_processor_nodes/basic_nodes.cpp source/content/data_processor_nodes/control_nodes.cpp source/content/data_processor_nodes/decode_nodes.cpp @@ -130,7 +128,6 @@ add_imhex_plugin( ${JTHREAD_LIBRARIES} plcli libpl-gen - LLVMDemangle ) if (WIN32) diff --git a/plugins/builtin/include/content/helpers/demangle.hpp b/plugins/builtin/include/content/helpers/demangle.hpp deleted file mode 100644 index e5c0d8213..000000000 --- a/plugins/builtin/include/content/helpers/demangle.hpp +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include - -namespace hex::plugin::builtin { - - std::string demangle(const std::string &mangled); - -} \ No newline at end of file diff --git a/plugins/builtin/include/content/popups/popup_crash_recovered.hpp b/plugins/builtin/include/content/popups/popup_crash_recovered.hpp index f3446c957..ddf25769f 100644 --- a/plugins/builtin/include/content/popups/popup_crash_recovered.hpp +++ b/plugins/builtin/include/content/popups/popup_crash_recovered.hpp @@ -3,8 +3,7 @@ #include #include - -#include +#include #include @@ -20,7 +19,7 @@ namespace hex::plugin::builtin { void drawContent() override { ImGuiExt::TextFormattedWrapped("hex.builtin.popup.crash_recover.message"_lang); - ImGuiExt::TextFormattedWrapped(hex::format("Error: {}: {}", llvm::demangle(this->m_errorType), this->m_errorMessage)); + ImGuiExt::TextFormattedWrapped(hex::format("Error: {}: {}", trace::demangle(this->m_errorType), this->m_errorMessage)); if (ImGui::Button("hex.ui.common.okay"_lang)) { this->close(); diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index 4d0df05f8..0d39973b1 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -18,13 +17,13 @@ #include #include +#include #include #include #include #include -#include namespace hex::plugin::builtin { using namespace hex::literals; @@ -383,7 +382,7 @@ namespace hex::plugin::builtin { std::exit(EXIT_FAILURE); } - log::println("{}", hex::plugin::builtin::demangle(args[0])); + log::println("{}", trace::demangle(args[0])); std::exit(EXIT_SUCCESS); } diff --git a/plugins/builtin/source/content/helpers/demangle.cpp b/plugins/builtin/source/content/helpers/demangle.cpp deleted file mode 100644 index 6f95720eb..000000000 --- a/plugins/builtin/source/content/helpers/demangle.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -namespace hex::plugin::builtin { - - std::string demangle(const std::string &mangled) { - std::string result = llvm::demangle(mangled); - if (result.empty() || result == mangled) - result = llvm::demangle("_" + mangled); - - if (result.empty() || result == ("_" + mangled)) - result = mangled; - - return result; - } - -} \ No newline at end of file diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index 6779264a9..7a34ce1ec 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -3,11 +3,11 @@ #include #include +#include #include #include -#include #include namespace hex::plugin::builtin { @@ -75,7 +75,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addFunction(nsHexDec, "demangle", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { const auto mangledString = params[0].toString(false); - return hex::plugin::builtin::demangle(mangledString); + return trace::demangle(mangledString); }); } diff --git a/plugins/builtin/source/content/tools/demangler.cpp b/plugins/builtin/source/content/tools/demangler.cpp index cb3ff62c2..6bf92666e 100644 --- a/plugins/builtin/source/content/tools/demangler.cpp +++ b/plugins/builtin/source/content/tools/demangler.cpp @@ -1,10 +1,9 @@ #include #include - -#include +#include +#include #include -#include #include @@ -31,7 +30,7 @@ namespace hex::plugin::builtin { static float prevWindowWidth; if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) { - demangledName = hex::plugin::builtin::demangle(mangledName); + demangledName = trace::demangle(mangledName); if (demangledName == mangledName) { demangledName = "???"; diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 7d79be17a..2316b9b4c 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include @@ -13,7 +14,6 @@ #include #include -#include #include namespace hex::plugin::builtin { @@ -71,7 +71,7 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); ImGuiExt::TextFormatted("[ 0x{:08X} - 0x{:08X} ]", region.getStartAddress(), region.getEndAddress()); - auto demangledValue = hex::plugin::builtin::demangle(value); + auto demangledValue = trace::demangle(value); if (value != demangledValue) { ImGui::TableNextRow(); @@ -663,7 +663,7 @@ namespace hex::plugin::builtin { if (ImGui::MenuItemEx("hex.builtin.view.find.context.copy"_lang, ICON_VS_COPY)) ImGui::SetClipboardText(value.c_str()); if (ImGui::MenuItemEx("hex.builtin.view.find.context.copy_demangle"_lang, ICON_VS_FILES)) - ImGui::SetClipboardText(hex::plugin::builtin::demangle(value).c_str()); + ImGui::SetClipboardText(trace::demangle(value).c_str()); if (ImGui::BeginMenuEx("hex.builtin.view.find.context.replace"_lang, ICON_VS_REPLACE)) { if (ImGui::BeginTabBar("##replace_tabs")) { if (ImGui::BeginTabItem("hex.builtin.view.find.context.replace.hex"_lang)) {