diff --git a/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp b/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp index f4c5ea73..759b9a71 100644 --- a/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp +++ b/src/DebugServers/GdbRsp/GdbRspDebugServer.cpp @@ -6,6 +6,7 @@ #include "Exceptions/ClientDisconnected.hpp" #include "Exceptions/ClientNotSupported.hpp" #include "Exceptions/ClientCommunicationError.hpp" +#include "Exceptions/DebugSessionAborted.hpp" #include "src/Exceptions/Exception.hpp" #include "src/Exceptions/InvalidConfig.hpp" #include "src/Logger/Logger.hpp" @@ -96,11 +97,23 @@ void GdbRspDebugServer::init() { Logger::info("GDB RSP address: " + this->listeningAddress); Logger::info("GDB RSP port: " + std::to_string(this->listeningPortNumber)); + this->eventListener->registerCallbackForEventType( + std::bind(&GdbRspDebugServer::onTargetControllerStateReported, this, std::placeholders::_1) + ); + this->eventListener->registerCallbackForEventType( std::bind(&GdbRspDebugServer::onTargetExecutionStopped, this, std::placeholders::_1) ); } +void GdbRspDebugServer::close() { + this->closeClientConnection(); + + if (this->serverSocketFileDescriptor > 0) { + ::close(this->serverSocketFileDescriptor); + } +} + void GdbRspDebugServer::serve() { try { if (!this->clientConnection.has_value()) { @@ -186,11 +199,10 @@ void GdbRspDebugServer::waitForConnection() { } } -void GdbRspDebugServer::close() { - this->closeClientConnection(); - - if (this->serverSocketFileDescriptor > 0) { - ::close(this->serverSocketFileDescriptor); +void GdbRspDebugServer::onTargetControllerStateReported(Events::EventPointer event) { + if (event->state == TargetControllerState::SUSPENDED && this->clientConnection.has_value()) { + Logger::warning("Terminating debug session - TargetController suspended unexpectedly"); + this->closeClientConnection(); } } diff --git a/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp b/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp index de7f4d4c..5b080d06 100644 --- a/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp +++ b/src/DebugServers/GdbRsp/GdbRspDebugServer.hpp @@ -169,6 +169,8 @@ namespace Bloom::DebugServers::Gdb return "GDB Remote Serial Protocol DebugServer"; }; + void onTargetControllerStateReported(Events::EventPointer event); + /** * If the GDB client is currently waiting for the target execution to stop, this event handler will issue * a "stop reply" packet to the client once the target execution stops.