From 9ce755cd0739161e6f4e30991780f42fff4b9736 Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Wed, 29 Apr 2026 17:47:47 +0200 Subject: [PATCH] gdb: Remove all stepping support and full CPU halt --- src/core/arm/skyeye_common/armstate.cpp | 2 +- src/core/core.cpp | 14 -------- src/core/gdbstub/gdbstub.cpp | 48 ++----------------------- src/core/gdbstub/gdbstub.h | 20 ----------- src/core/gdbstub/hio.cpp | 10 ------ 5 files changed, 3 insertions(+), 91 deletions(-) diff --git a/src/core/arm/skyeye_common/armstate.cpp b/src/core/arm/skyeye_common/armstate.cpp index 9de68dc11..8ea916dbf 100644 --- a/src/core/arm/skyeye_common/armstate.cpp +++ b/src/core/arm/skyeye_common/armstate.cpp @@ -612,7 +612,7 @@ void ARMul_State::ServeBreak() { Kernel::Thread* thread = system.Kernel().GetCurrentThreadManager().GetCurrentThread(); system.GetRunningCore().SaveContext(thread->context); - if (last_bkpt_hit || GDBStub::IsMemoryBreak() || GDBStub::GetCpuStepFlag()) { + if (last_bkpt_hit || GDBStub::IsMemoryBreak()) { last_bkpt_hit = false; GDBStub::Break(); GDBStub::SendTrap(thread, 5); diff --git a/src/core/core.cpp b/src/core/core.cpp index 597f4c525..eb53b247e 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -89,16 +89,6 @@ System::ResultStatus System::RunLoop(bool tight_loop) { running_core->SaveContext(thread->context); } GDBStub::HandlePacket(*this); - - // If the loop is halted and we want to step, use a tiny (1) number of instructions to - // execute. Otherwise, get out of the loop function. - if (GDBStub::GetCpuHaltFlag()) { - if (GDBStub::GetCpuStepFlag()) { - tight_loop = false; - } else { - return ResultStatus::Success; - } - } } Signal signal{Signal::None}; @@ -269,10 +259,6 @@ System::ResultStatus System::RunLoop(bool tight_loop) { } } - if (GDBStub::IsServerEnabled()) { - GDBStub::SetCpuStepFlag(false); - } - Reschedule(); return status; diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index a2c4ff7ec..114ac9bab 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -137,8 +137,6 @@ static Kernel::Thread* current_thread = nullptr; // so default to a port outside of that range. u16 gdbstub_port = 24689; -bool halt_loop = true; -bool step_loop = false; bool send_trap = false; // If set to false, the server will never be started and no @@ -666,7 +664,6 @@ static void ReadCommand() { return; } else if (c == 0x03) { LOG_INFO(Debug_GDBStub, "gdb: found break command\n"); - halt_loop = true; SendSignal(current_thread, SIGTRAP); return; } else if (c != GDB_STUB_START) { @@ -916,18 +913,6 @@ void Break(bool is_memory_break) { memory_break = is_memory_break; } -/// Tell the CPU that it should perform a single step. -static void Step() { - if (command_length > 1) { - RegWrite(PC_REGISTER, GdbHexToInt(command_buffer + 1), current_thread); - UpdateCPUThreadContext(); - } - step_loop = true; - halt_loop = true; - send_trap = true; - ClearAllInstructionCache(); -} - bool IsMemoryBreak() { if (!IsConnected()) { return false; @@ -939,8 +924,6 @@ bool IsMemoryBreak() { /// Tell the CPU to continue executing. static void Continue() { memory_break = false; - step_loop = false; - halt_loop = false; ClearAllInstructionCache(); } @@ -1132,7 +1115,8 @@ void HandlePacket(Core::System& system) { WriteMemory(); break; case 's': - Step(); + // Single step, return ENOTSUP + SendReply("E5F"); return; case 'C': case 'c': @@ -1181,17 +1165,9 @@ void DeferStart() { static void Init(u16 port) { if (!server_enabled) { - // Set the halt loop to false in case the user enabled the gdbstub mid-execution. - // This way the CPU can still execute normally. - halt_loop = false; - step_loop = false; return; } - // Setup initial gdbstub status - halt_loop = true; - step_loop = false; - breakpoints_execute.clear(); breakpoints_read.clear(); breakpoints_write.clear(); @@ -1239,9 +1215,6 @@ static void Init(u16 port) { if (gdbserver_socket < 0) { // In the case that we couldn't start the server for whatever reason, just start CPU // execution like normal. - halt_loop = false; - step_loop = false; - LOG_ERROR(Debug_GDBStub, "Failed to accept gdb client"); } else { LOG_INFO(Debug_GDBStub, "Client connected.\n"); @@ -1285,22 +1258,6 @@ bool IsConnected() { return IsServerEnabled() && gdbserver_socket != -1; } -bool GetCpuHaltFlag() { - return halt_loop; -} - -void SetCpuHaltFlag(bool halt) { - halt_loop = halt; -} - -bool GetCpuStepFlag() { - return step_loop; -} - -void SetCpuStepFlag(bool is_step) { - step_loop = is_step; -} - void SendTrap(Kernel::Thread* thread, int trap) { if (!send_trap) { return; @@ -1310,7 +1267,6 @@ void SendTrap(Kernel::Thread* thread, int trap) { SendSignal(thread, trap); - halt_loop = true; send_trap = false; } }; // namespace GDBStub diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index fc0c7df23..8a021580b 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h @@ -92,26 +92,6 @@ BreakpointAddress GetNextBreakpointFromAddress(VAddr addr, GDBStub::BreakpointTy */ bool CheckBreakpoint(VAddr addr, GDBStub::BreakpointType type); -// If set to true, the CPU will halt at the beginning of the next CPU loop. -bool GetCpuHaltFlag(); - -/** - * If set to true, the CPU will halt at the beginning of the next CPU loop. - * - * @param halt whether to halt on the next loop - */ -void SetCpuHaltFlag(bool halt); - -// If set to true and the CPU is halted, the CPU will step one instruction. -bool GetCpuStepFlag(); - -/** - * When set to true, the CPU will step one instruction when the CPU is halted next. - * - * @param is_step - */ -void SetCpuStepFlag(bool is_step); - /** * Send trap signal from thread back to the gdbstub server. * diff --git a/src/core/gdbstub/hio.cpp b/src/core/gdbstub/hio.cpp index 00eab9061..cbc528672 100644 --- a/src/core/gdbstub/hio.cpp +++ b/src/core/gdbstub/hio.cpp @@ -23,9 +23,6 @@ enum class Status { static std::atomic request_status{Status::NoRequest}; -static std::atomic was_halted = false; -static std::atomic was_stepping = false; - } // namespace /** @@ -97,14 +94,9 @@ void SetHioRequest(Core::System& system, const VAddr addr) { current_hio_request_addr = addr; request_status = Status::NotSent; - was_halted = GetCpuHaltFlag(); - was_stepping = GetCpuStepFlag(); - // Now halt, so that no further instructions are executed until the request // is processed by the client. We will continue after the reply comes back Break(); - SetCpuHaltFlag(true); - SetCpuStepFlag(false); system.GetRunningCore().ClearInstructionCache(); } @@ -195,8 +187,6 @@ void HandleHioReply(Core::System& system, const u8* const command_buffer, request_status = Status::NoRequest; // Restore state from before the request came in - SetCpuStepFlag(was_stepping); - SetCpuHaltFlag(was_halted); system.GetRunningCore().ClearInstructionCache(); }