1
0
mirror of synced 2024-11-28 01:20:51 +01:00

feat: Replaced debug button functions with full debug menu

This commit is contained in:
WerWolv 2024-03-01 20:56:46 +01:00
parent 296af748ee
commit 2ff884fd11
3 changed files with 85 additions and 27 deletions

View File

@ -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",

View File

@ -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);
}
});
}
}

View File

@ -16,21 +16,15 @@
#include <toasts/toast_notification.hpp>
#include <csignal>
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<u8 *>(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<u32*>(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;
});