Improve register view, fix follow PC, some cleanup

This commit is contained in:
Henrik Rydgård committed 2024-11-07 11:10:16 +01:00
1 parent 9c92978fcc
commit 99eb0bbd64
6 files changed
+80 -46

No files matched your search

+23 -21
View File
@@ -28,14 +28,14 @@ class DebugInterface {
public:
virtual int getInstructionSize(int instruction) {return 1;}
virtual bool isAlive() {return true;}
virtual bool isBreakpoint(unsigned int address) {return false;}
virtual void setBreakpoint(unsigned int address){}
virtual void clearBreakpoint(unsigned int address){}
virtual void clearAllBreakpoints() {}
virtual void toggleBreakpoint(unsigned int address){}
virtual unsigned int readMemory(unsigned int address){return 0;}
virtual unsigned int getPC() {return 0;}
virtual bool isAlive() = 0;
virtual bool isBreakpoint(unsigned int address) = 0;
virtual void setBreakpoint(unsigned int address) = 0;
virtual void clearBreakpoint(unsigned int address) = 0;
virtual void clearAllBreakpoints() = 0;
virtual void toggleBreakpoint(unsigned int address) = 0;
virtual unsigned int readMemory(unsigned int address) {return 0;}
virtual unsigned int getPC() = 0;
virtual void setPC(unsigned int address) {}
virtual void step() {}
virtual void runToBreakpoint() {}
@@ -44,30 +44,32 @@ public:
virtual bool initExpression(const char* exp, PostfixExpression& dest) { return false; };
virtual bool parseExpression(PostfixExpression& exp, u32& dest) { return false; };
virtual u32 GetHi() { return 0; };
virtual u32 GetLo() { return 0; };
virtual u32 GetHi() = 0;
virtual u32 GetLo() = 0;
virtual u32 GetLLBit() = 0;
virtual void SetHi(u32 val) { };
virtual void SetLo(u32 val) { };
virtual const char *GetName() = 0;
virtual u32 GetGPR32Value(int reg) {return 0;}
virtual void SetGPR32Value(int reg) {}
virtual u32 GetGPR32Value(int reg) = 0;
virtual void SetGPR32Value(int reg, u32 value) = 0;
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();}
virtual void DisAsm(u32 pc, char *out, size_t outSize) {
snprintf(out, outSize, "[%08x] UNKNOWN", pc);
}
virtual u32 GetLR() = 0;
virtual void DisAsm(u32 pc, char *out, size_t outSize) = 0;
// More stuff for debugger
virtual int GetNumCategories() {return 0;}
virtual int GetNumRegsInCategory(int cat) {return 0;}
virtual const char *GetCategoryName(int cat) {return 0;}
virtual std::string GetRegName(int cat, int index) { return ""; }
virtual int GetNumCategories() = 0;
virtual int GetNumRegsInCategory(int cat) = 0;
virtual const char *GetCategoryName(int cat) = 0;
virtual std::string GetRegName(int cat, int index) = 0;
virtual void PrintRegValue(int cat, int index, char *out, size_t outSize) {
snprintf(out, outSize, "%08X", GetGPR32Value(index));
}
virtual u32 GetRegValue(int cat, int index) {return 0;}
virtual u32 GetRegValue(int cat, int index) = 0;
virtual void SetRegValue(int cat, int index, u32 value) {}
};
+6
View File
@@ -49,6 +49,8 @@ public:
const char *GetName() override;
u32 GetGPR32Value(int reg) override { return cpu->r[reg]; }
float GetFPR32Value(int reg) override { return cpu->f[reg]; }
void SetGPR32Value(int reg, u32 value) override { cpu->r[reg] = value; }
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;
@@ -77,6 +79,10 @@ public:
return cpu->hi;
}
u32 GetLLBit() override {
return cpu->llBit;
}
u32 GetLo() override {
return cpu->lo;
}
+44 -18
View File
@@ -22,24 +22,54 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) {
if (ImGui::BeginTabBar("RegisterGroups", ImGuiTabBarFlags_None)) {
if (ImGui::BeginTabItem("GPR")) {
for (int i = 0; i < 32; i++) {
const int value = mipsDebug->GetGPR32Value(i);
if (value >= -1000000 && value <= 1000000) {
// Display small values in decimal.
ImGui::Text("%s: %08x (%d)", mipsDebug->GetRegName(0, i).c_str(), value, value);
} else {
// But not big ones to reduce clutter.
ImGui::Text("%s: %08x", mipsDebug->GetRegName(0, i).c_str(), value);
if (ImGui::BeginTable("gpr", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH)) {
ImGui::TableSetupColumn("regname", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("value_i", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextRow();
auto gprLine = [&](const char *regname, int value) {
ImGui::TableSetColumnIndex(0);
ImGui::Text("%s", regname);
ImGui::TableSetColumnIndex(1);
ImGui::Text("%08x", value);
if (value >= -1000000 && value <= 1000000) {
ImGui::TableSetColumnIndex(2);
ImGui::Text("%d", value);
}
ImGui::TableNextRow();
};
for (int i = 0; i < 32; i++) {
gprLine(mipsDebug->GetRegName(0, i).c_str(), mipsDebug->GetGPR32Value(i));
}
gprLine("hi", mipsDebug->GetHi());
gprLine("lo", mipsDebug->GetLo());
gprLine("pc", mipsDebug->GetPC());
gprLine("ll", mipsDebug->GetLLBit());
ImGui::EndTable();
}
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);
if (ImGui::BeginTable("fpr", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH)) {
ImGui::TableSetupColumn("regname", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("value_i", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableNextRow();
for (int i = 0; i < 32; i++) {
float fvalue = mipsDebug->GetFPR32Value(i);
u32 fivalue;
memcpy(&fivalue, &fvalue, sizeof(fivalue));
ImGui::TableSetColumnIndex(0);
ImGui::Text("%s", mipsDebug->GetRegName(1, i).c_str());
ImGui::TableSetColumnIndex(1);
ImGui::Text("%0.7f", fvalue);
ImGui::TableSetColumnIndex(2);
ImGui::Text("%08x", fivalue);
ImGui::TableNextRow();
}
ImGui::EndTable();
}
ImGui::EndTabItem();
}
@@ -102,10 +132,6 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug) {
if (regsOpen_) {
DrawRegisterView(mipsDebug, &regsOpen_);
}
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();
}
void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState coreState) {
@@ -155,7 +181,7 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState c
}
ImGui::SameLine();
ImGui::Checkbox("Follow PC", &followPC_);
ImGui::Checkbox("Follow PC", &disasmView_.followPC_);
ImGui::SetNextItemWidth(100);
if (ImGui::InputScalar("Go to addr: ", ImGuiDataType_U32, &gotoAddr_, NULL, NULL, "%08X", ImGuiInputTextFlags_EnterReturnsTrue)) {
-7
View File
@@ -28,10 +28,6 @@ class ImDisasmWindow {
public:
void Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState coreState);
void PCChanged() {
pcChanged_ = true;
}
private:
// We just keep the state directly in the window. Can refactor later.
@@ -41,9 +37,6 @@ private:
u32 gotoAddr_ = 0x1000;
bool followPC_ = true;
bool pcChanged_ = false;
ImDisasmView disasmView_;
};
+3
View File
@@ -465,6 +465,9 @@ void ImDisasmView::Draw(ImDrawList *drawList) {
int coreStep = Core_GetSteppingCounter();
if (coreStep != lastSteppingCount_) {
// A step has happened since last time. This means that we should re-center the cursor.
if (followPC_) {
gotoPC();
}
lastSteppingCount_ = coreStep;
}
+4
View File
@@ -18,6 +18,10 @@ public:
ImDisasmView();
~ImDisasmView();
// Public variables bounds to imgui checkboxes
bool followPC_ = true;
void Draw(ImDrawList *drawList);
void PopupMenu();