From 2ff884fd11b44e26933b21ee6588aae9b71cead9 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 1 Mar 2024 20:56:46 +0100 Subject: [PATCH] feat: Replaced debug button functions with full debug menu --- plugins/builtin/romfs/lang/en_US.json | 2 +- .../source/content/main_menu_items.cpp | 16 ---- plugins/builtin/source/content/ui_items.cpp | 94 +++++++++++++++++-- 3 files changed, 85 insertions(+), 27 deletions(-) diff --git a/plugins/builtin/romfs/lang/en_US.json b/plugins/builtin/romfs/lang/en_US.json index dd2900ce4..7e877223d 100644 --- a/plugins/builtin/romfs/lang/en_US.json +++ b/plugins/builtin/romfs/lang/en_US.json @@ -500,7 +500,7 @@ "hex.builtin.setting.toolbar.icons": "Toolbar Icons", "hex.builtin.shortcut.next_provider": "Select next provider", "hex.builtin.shortcut.prev_provider": "Select previous provider", - "hex.builtin.title_bar_button.debug_build": "Debug build\nShift+Click to crash using exception\nCtrl+Click to crash using signal", + "hex.builtin.title_bar_button.debug_build": "Debug build\n\nSHIFT + Click to open Debug Menu", "hex.builtin.title_bar_button.feedback": "Leave Feedback", "hex.builtin.tools.ascii_table": "ASCII table", "hex.builtin.tools.ascii_table.octal": "Show octal", diff --git a/plugins/builtin/source/content/main_menu_items.cpp b/plugins/builtin/source/content/main_menu_items.cpp index c2514583d..819e5c61c 100644 --- a/plugins/builtin/source/content/main_menu_items.cpp +++ b/plugins/builtin/source/content/main_menu_items.cpp @@ -28,8 +28,6 @@ using namespace wolv::literals; namespace hex::plugin::builtin { - static bool s_demoWindowOpen = false; - namespace { bool noRunningTasks() { @@ -559,13 +557,6 @@ namespace hex::plugin::builtin { state = !state; } } - - #if defined(DEBUG) - ImGui::Separator(); - - ImGui::MenuItem("hex.builtin.menu.view.demo"_lang, "", &s_demoWindowOpen); - ImGui::MenuItem("hex.builtin.menu.view.debug"_lang, "", &hex::dbg::impl::getDebugWindowState()); - #endif }); } @@ -661,13 +652,6 @@ namespace hex::plugin::builtin { createWorkspaceMenu(); createExtrasMenu(); createHelpMenu(); - - (void)EventFrameEnd::subscribe([] { - if (s_demoWindowOpen) { - ImGui::ShowDemoWindow(&s_demoWindowOpen); - ImPlot::ShowDemoWindow(&s_demoWindowOpen); - } - }); } } \ No newline at end of file diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index c614ac495..e67270909 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -16,21 +16,15 @@ #include +#include + namespace hex::plugin::builtin { void addTitleBarButtons() { #if defined(DEBUG) ContentRegistry::Interface::addTitleBarButton(ICON_VS_DEBUG, "hex.builtin.title_bar_button.debug_build", []{ - if (ImGui::GetIO().KeyCtrl) { - // Explicitly trigger a segfault by writing to an invalid memory location - // Used for debugging crashes - *reinterpret_cast(0x10) = 0x10; - std::unreachable(); - } else if (ImGui::GetIO().KeyShift) { - // Explicitly trigger an abort by throwing an uncaught exception - // Used for debugging exception errors - throw std::runtime_error("Debug Error"); - std::unreachable(); + if (ImGui::GetIO().KeyShift) { + RequestOpenPopup::post("DebugMenu"); } else { hex::openWebpage("https://imhex.werwolv.net/debug"); } @@ -54,6 +48,82 @@ namespace hex::plugin::builtin { } } + static void drawDebugPopup() { + static bool showImGuiDemo = false; + static bool showImPlotDemo = false; + + ImGui::SetNextWindowSize(scaled({ 300, 150 }), ImGuiCond_Always); + if (ImGui::BeginPopup("DebugMenu")) { + if (ImGui::BeginTabBar("DebugTabBar")) { + if (ImGui::BeginTabItem("ImHex")) { + if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { + ImGui::Checkbox("Show Debug Variables", &dbg::impl::getDebugWindowState()); + + ImGuiExt::Header("Information"); + ImGuiExt::TextFormatted("Running Tasks: {0}", TaskManager::getRunningTaskCount()); + ImGuiExt::TextFormatted("Running Background Tasks: {0}", TaskManager::getRunningBackgroundTaskCount()); + ImGuiExt::TextFormatted("Last Frame Time: {0:.3f}ms", ImHexApi::System::getLastFrameTime() * 1000.0F); + } + ImGui::EndChild(); + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("ImGui")) { + if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { + auto ctx = ImGui::GetCurrentContext(); + ImGui::Checkbox("Show ImGui Demo", &showImGuiDemo); + ImGui::Checkbox("Show ImPlot Demo", &showImPlotDemo); + + if (ImGui::Button("Trigger Breakpoint in Item") || ctx->DebugItemPickerActive) + ImGui::DebugStartItemPicker(); + } + ImGui::EndChild(); + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Crashes")) { + if (ImGui::BeginChild("Scrolling", ImGui::GetContentRegionAvail())) { + if (ImGui::Button("Throw Exception")) { + TaskManager::doLater([] { + throw std::runtime_error("Test exception"); + }); + } + if (ImGui::Button("Access Invalid Memory")) { + TaskManager::doLater([] { + *reinterpret_cast(0x10) = 0x10; + std::unreachable(); + }); + } + if (ImGui::Button("Raise SIGSEGV")) { + TaskManager::doLater([] { + raise(SIGSEGV); + }); + } + if (ImGui::Button("Corrupt Memory")) { + TaskManager::doLater([] { + auto bytes = new u8[0xFFFFF]; + + delete[] bytes; + delete[] bytes; + }); + } + } + ImGui::EndChild(); + + ImGui::EndTabItem(); + } + + ImGui::EndTabBar(); + } + ImGui::EndPopup(); + } + + if (showImGuiDemo) + ImGui::ShowDemoWindow(&showImGuiDemo); + if (showImPlotDemo) + ImPlot::ShowDemoWindow(&showImPlotDemo); + } + static bool s_drawDragDropOverlay = false; static void drawDragNDropOverlay() { if (!s_drawDragDropOverlay) @@ -98,6 +168,10 @@ namespace hex::plugin::builtin { EventFrameEnd::subscribe(drawGlobalPopups); EventFrameEnd::subscribe(drawDragNDropOverlay); + #if defined(DEBUG) + EventFrameEnd::subscribe(drawDebugPopup); + #endif + EventFileDragged::subscribe([](bool entered) { s_drawDragDropOverlay = entered; });