From 93baf2236980d8cddd80da0b93955ab087f1516b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 8 Dec 2024 15:12:13 +0100 Subject: [PATCH] ImDebugger: Add frame-stepping and a "skim" button (single-steps while held down) --- Core/Core.cpp | 22 ++++++++++++++++++++-- Core/Core.h | 1 + Core/HLE/HLE.cpp | 5 +++-- UI/ImDebugger/ImDebugger.cpp | 35 ++++++++++++++++++++++++++++------- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 9e3c92318b..cb6d9ca1e0 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -85,6 +85,7 @@ CoreState preGeCoreState = CORE_BOOT_ERROR; volatile bool coreStatePending = false; static bool powerSaving = false; +static bool g_breakAfterFrame = false; static MIPSExceptionInfo g_exceptionInfo; @@ -176,6 +177,10 @@ void Core_RunLoopUntil(u64 globalticks) { return; case CORE_RUNNING_CPU: mipsr4k.RunLoopUntil(globalticks); + if (g_breakAfterFrame && coreState == CORE_NEXTFRAME) { + g_breakAfterFrame = false; + coreState = CORE_STEPPING_CPU; + } break; // Will loop around to go to RUNNING_GE or NEXTFRAME, which will exit. case CORE_RUNNING_GE: switch (gpu->ProcessDLQueue()) { @@ -217,8 +222,15 @@ bool Core_RequestCPUStep(CPUStepType type, int stepSize) { ERROR_LOG(Log::CPU, "Can't submit two steps in one host frame"); return false; } - // Out-steps don't need a size. - _dbg_assert_(stepSize != 0 || type == CPUStepType::Out); + // Some step types don't need a size. + switch (type) { + case CPUStepType::Out: + case CPUStepType::Frame: + break; + default: + _dbg_assert_(stepSize != 0); + break; + } g_cpuStepCommand = { type, stepSize }; return true; } @@ -303,6 +315,12 @@ static void Core_PerformCPUStep(MIPSDebugInterface *cpu, CPUStepType stepType, i Core_Resume(); break; } + case CPUStepType::Frame: + { + g_breakAfterFrame = true; + Core_Resume(); + break; + } default: // Not yet implemented break; diff --git a/Core/Core.h b/Core/Core.h index b0205a3e5a..0b20d2ac6a 100644 --- a/Core/Core.h +++ b/Core/Core.h @@ -42,6 +42,7 @@ enum class CPUStepType { Into, Over, Out, + Frame, }; // Async, called from gui diff --git a/Core/HLE/HLE.cpp b/Core/HLE/HLE.cpp index 2916cf96f2..517fb759ac 100644 --- a/Core/HLE/HLE.cpp +++ b/Core/HLE/HLE.cpp @@ -77,6 +77,9 @@ static int idleOp; // Split syscall support. NOTE: This needs to be saved in DoState somehow! static int splitSyscallEatCycles = 0; +// Stats +static double hleSteppingTime = 0.0; +static double hleFlipTime = 0.0; struct HLEMipsCallInfo { u32 func; @@ -752,12 +755,10 @@ void *GetQuickSyscallFunc(MIPSOpcode op) { return (void *)&CallSyscallWithoutFlags; } -static double hleSteppingTime = 0.0; void hleSetSteppingTime(double t) { hleSteppingTime += t; } -static double hleFlipTime = 0.0; void hleSetFlipTime(double t) { hleFlipTime = t; } diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index c477d2eef4..343aaa5b65 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -1030,22 +1030,43 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, CoreStat ImGui::BeginDisabled(coreState != CORE_STEPPING_CPU); ImGui::SameLine(); - if (ImGui::SmallButton("Step Into")) { + ImGui::Text("Step: "); + ImGui::SameLine(); + + if (ImGui::SmallButton("Into")) { u32 stepSize = disasmView_.getInstructionSizeAt(mipsDebug->GetPC()); Core_RequestCPUStep(CPUStepType::Into, stepSize); } - - ImGui::SameLine(); - if (ImGui::SmallButton("Step Over")) { - u32 stepSize = disasmView_.getInstructionSizeAt(mipsDebug->GetPC()); - Core_RequestCPUStep(CPUStepType::Over, stepSize); + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("F11"); } ImGui::SameLine(); - if (ImGui::SmallButton("Step Out")) { + if (ImGui::SmallButton("Over")) { + u32 stepSize = disasmView_.getInstructionSizeAt(mipsDebug->GetPC()); + Core_RequestCPUStep(CPUStepType::Over, stepSize); + } + if (ImGui::IsItemHovered()) { + ImGui::SetTooltip("F10"); + } + + ImGui::SameLine(); + if (ImGui::SmallButton("Out")) { Core_RequestCPUStep(CPUStepType::Out, 0); } + ImGui::SameLine(); + if (ImGui::SmallButton("Frame")) { + Core_RequestCPUStep(CPUStepType::Frame, 0); + } + + ImGui::SameLine(); + ImGui::SmallButton("Skim"); + if (ImGui::IsItemActive()) { + u32 stepSize = disasmView_.getInstructionSizeAt(mipsDebug->GetPC()); + Core_RequestCPUStep(CPUStepType::Into, stepSize); + } + ImGui::EndDisabled(); ImGui::SameLine();