From 54d074fb6a21e55226b275e7890fbdbcea874f7c Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 30 Jul 2026 21:40:35 +1000 Subject: [PATCH] GDBServer: Retransmit rejected replies Keep the most recently framed RSP reply for each client and resend it when GDB returns a negative acknowledgement. Build acknowledgement and reply frames separately so only the reply packet is retained for protocol recovery. --- src/core/gdb_server.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/core/gdb_server.cpp b/src/core/gdb_server.cpp index ec1efcf73..615caeef0 100644 --- a/src/core/gdb_server.cpp +++ b/src/core/gdb_server.cpp @@ -45,6 +45,7 @@ public: void SendReply(std::string_view reply = std::string_view()); void SendLastStopReplyWithAck(); void SendReplyWithAck(std::string_view reply = std::string_view()); + void ResendLastReply(); protected: void OnConnected() override; @@ -56,6 +57,7 @@ private: bool m_seen_resume = false; u8 m_last_stop_signal = GDB_SIGNAL_INTERRUPT; + SmallString m_last_reply; }; } // namespace @@ -623,9 +625,8 @@ void GDBServer::ClientSocket::OnRead() if (GDBServer::IsPacketAck(current_packet)) { - // Eat ACKs. if (current_packet[0] == '-') - ERROR_LOG("Received negative ack"); + ResendLastReply(); packet_complete = true; break; @@ -702,7 +703,8 @@ void GDBServer::ClientSocket::SendAck() void GDBServer::ClientSocket::SendReply(std::string_view reply) { - SendPacket(SmallString::from_format("${}#{:02x}", reply, ComputeChecksum(reply))); + m_last_reply.format("${}#{:02x}", reply, ComputeChecksum(reply)); + SendPacket(m_last_reply); } void GDBServer::ClientSocket::SendLastStopReplyWithAck() @@ -712,7 +714,19 @@ void GDBServer::ClientSocket::SendLastStopReplyWithAck() void GDBServer::ClientSocket::SendReplyWithAck(std::string_view reply) { - SendPacket(SmallString::from_format("+${}#{:02x}", reply, ComputeChecksum(reply))); + SendAck(); + SendReply(reply); +} + +void GDBServer::ClientSocket::ResendLastReply() +{ + if (m_last_reply.empty()) + { + WARNING_LOG("Received negative acknowledgement without a previous reply."); + return; + } + + SendPacket(m_last_reply); } bool GDBServer::Initialize(u16 port)