From 84a0293e54f96efc582aafcfe1da717cf3b83ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 6 Nov 2024 15:53:38 +0100 Subject: [PATCH] Add basic register view --- Core/Debugger/DebugInterface.h | 3 +++ Core/MIPS/MIPSDebugInterface.h | 1 + UI/ImDebugger/ImDebugger.cpp | 37 ++++++++++++++++++++++++++++++++++ UI/ImDebugger/ImDebugger.h | 1 + UI/ImDebugger/ImDisasmView.cpp | 9 +++++---- UI/ImDebugger/ImDisasmView.h | 2 +- 6 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Core/Debugger/DebugInterface.h b/Core/Debugger/DebugInterface.h index 34e354b9c0..c8c40f18f4 100644 --- a/Core/Debugger/DebugInterface.h +++ b/Core/Debugger/DebugInterface.h @@ -51,6 +51,9 @@ public: virtual const char *GetName() = 0; virtual u32 GetGPR32Value(int reg) {return 0;} virtual void SetGPR32Value(int reg) {} + virtual float GetFPR32Value(int reg) { return -1.0f; } + virtual float GetVPR32Value(int reg) { return -1.0f; } + virtual u32 GetPC() = 0; virtual void SetPC(u32 _pc) = 0; virtual u32 GetLR() {return GetPC();} diff --git a/Core/MIPS/MIPSDebugInterface.h b/Core/MIPS/MIPSDebugInterface.h index 2a6e88f66f..61144c5aba 100644 --- a/Core/MIPS/MIPSDebugInterface.h +++ b/Core/MIPS/MIPSDebugInterface.h @@ -48,6 +48,7 @@ public: //overridden functions const char *GetName() override; u32 GetGPR32Value(int reg) override { return cpu->r[reg]; } + float GetFPR32Value(int reg) override { return cpu->f[reg]; } u32 GetPC() override { return cpu->pc; } u32 GetLR() override { return cpu->r[MIPS_REG_RA]; } void DisAsm(u32 pc, char *out, size_t outSize) override; diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index ca941e8499..f747118c3a 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -14,6 +14,38 @@ #include "UI/ImDebugger/ImDebugger.h" +void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) { + if (!ImGui::Begin("Registers", open)) { + ImGui::End(); + return; + } + + if (ImGui::BeginTabBar("RegisterGroups", ImGuiTabBarFlags_None)) { + if (ImGui::BeginTabItem("GPR")) { + for (int i = 0; i < 32; i++) { + const u32 value = mipsDebug->GetGPR32Value(i); + ImGui::Text("%s: %08x (%d)", mipsDebug->GetRegName(0, i).c_str(), value, value); + } + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("FPR")) { + for (int i = 0; i < 32; i++) { + float fvalue = mipsDebug->GetFPR32Value(i); + u32 fivalue; + memcpy(&fivalue, &fvalue, sizeof(fivalue)); + ImGui::Text("%s: %0.6f (%08x)", mipsDebug->GetRegName(1, i).c_str(), fvalue, fivalue); + } + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("VPR")) { + ImGui::Text("TODO"); + ImGui::EndTabItem(); + } + ImGui::EndTabBar(); + } + ImGui::End(); +} + void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) { // Snapshot the coreState to avoid inconsistency. const CoreState coreState = ::coreState; @@ -47,6 +79,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) { if (ImGui::BeginMenu("Window")) { ImGui::Checkbox("Dear ImGUI Demo", &demoOpen_); ImGui::Checkbox("CPU debugger", &disasmOpen_); + ImGui::Checkbox("Registers", ®sOpen_); ImGui::EndMenu(); } ImGui::EndMainMenuBar(); @@ -60,6 +93,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) { disasm_.Draw(mipsDebug, &disasmOpen_); } + if (regsOpen_) { + DrawRegisterView(mipsDebug, ®sOpen_); + } + ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) ImGui::End(); diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index 91b1cc8d05..9711db050b 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -60,4 +60,5 @@ struct ImDebugger { // Open variables. bool disasmOpen_ = true; bool demoOpen_ = false; + bool regsOpen_ = true; }; diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index d68d131ec0..25bf864aa8 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -156,7 +156,7 @@ void ImDisasmView::assembleOpcode(u32 address, const std::string &defaultText) { */ } -void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map &addressPositions, const BranchLine &line) { +void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map &addressPositions, const BranchLine &line) { u32 windowEnd = manager.getNthNextAddress(windowStart_, visibleRows_); float topY; @@ -185,6 +185,7 @@ void ImDisasmView::drawBranchLine(ImDrawList *drawList, Rect rect, std::map addressPositions; + std::map addressPositions; const std::set currentArguments = getSelectedLineArguments(); DisassemblyLineInfo line; for (int i = 0; i < visibleRows_; i++) { manager.getLine(address, displaySymbols_, line); - int rowY1 = rowHeight_ * i; - int rowY2 = rowHeight_ * (i + 1); + float rowY1 = rowHeight_ * i; + float rowY2 = rowHeight_ * (i + 1); addressPositions[address] = rowY1; diff --git a/UI/ImDebugger/ImDisasmView.h b/UI/ImDebugger/ImDisasmView.h index 7a88f65ebf..2279508b8e 100644 --- a/UI/ImDebugger/ImDisasmView.h +++ b/UI/ImDebugger/ImDisasmView.h @@ -134,7 +134,7 @@ private: void calculatePixelPositions(); bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData); void updateStatusBarText(); - void drawBranchLine(ImDrawList *list, ImDisasmView::Rect rc, std::map &addressPositions, const BranchLine &line); + void drawBranchLine(ImDrawList *list, ImDisasmView::Rect rc, std::map &addressPositions, const BranchLine &line); void CopyInstructions(u32 startAddr, u32 endAddr, CopyInstructionsMode mode); void NopInstructions(u32 startAddr, u32 endAddr); std::set getSelectedLineArguments();