From f7944ac6b4e59a5e8314c36080fb0829d2c9a9a4 Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 31 May 2021 00:03:18 +0100 Subject: [PATCH] Fixed bug with GDB RSP debug server handling stale packets --- src/DebugServers/GdbRsp/GdbRspDebugServer.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp b/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp index 759b9a71..d697cbf0 100644 --- a/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp +++ b/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp @@ -123,6 +123,10 @@ void GdbRspDebugServer::serve() { this->waitForConnection(); } + this->clientConnection->accept(this->serverSocketFileDescriptor); + Logger::info("Accepted GDP RSP connection from " + this->clientConnection->getIpAddress()); + this->eventManager.triggerEvent(std::make_shared()); + /* * Before proceeding with a new debug session, we must ensure that the TargetController is able to * service it. @@ -135,9 +139,10 @@ void GdbRspDebugServer::serve() { auto packets = this->clientConnection->readPackets(); - for (auto& packet : packets) { + // Only process the last packet - any others will likely be duplicates from an impatient client + if (!packets.empty()) { // Double-dispatch to appropriate handler - packet->dispatchToHandler(*this); + packets.back()->dispatchToHandler(*this); } } catch (const ClientDisconnected&) { @@ -192,10 +197,6 @@ void GdbRspDebugServer::waitForConnection() { } this->clientConnection = Connection(this->interruptEventNotifier); - this->clientConnection->accept(this->serverSocketFileDescriptor); - this->eventManager.triggerEvent(std::make_shared()); - - Logger::info("Accepted GDP RSP connection from " + this->clientConnection->getIpAddress()); } }