diff --git a/src/DebugServer/Gdb/DebugSession.cpp b/src/DebugServer/Gdb/DebugSession.cpp index ed4d1b84..45cc12ac 100644 --- a/src/DebugServer/Gdb/DebugSession.cpp +++ b/src/DebugServer/Gdb/DebugSession.cpp @@ -1,6 +1,7 @@ #include "DebugSession.hpp" #include "src/Logger/Logger.hpp" +#include "src/EventManager/EventManager.hpp" namespace Bloom::DebugServer::Gdb { @@ -16,9 +17,11 @@ namespace Bloom::DebugServer::Gdb this->supportedFeatures.insert({ Feature::PACKET_SIZE, std::to_string(this->connection.getMaxPacketSize()) }); + + EventManager::triggerEvent(std::make_shared()); } - void DebugSession::terminate() { - + DebugSession::~DebugSession() { + EventManager::triggerEvent(std::make_shared()); } } diff --git a/src/DebugServer/Gdb/DebugSession.hpp b/src/DebugServer/Gdb/DebugSession.hpp index 17e5d855..69b3f087 100644 --- a/src/DebugServer/Gdb/DebugSession.hpp +++ b/src/DebugServer/Gdb/DebugSession.hpp @@ -39,6 +39,12 @@ namespace Bloom::DebugServer::Gdb const TargetDescriptor& targetDescriptor ); - void terminate(); + DebugSession(const DebugSession& other) = delete; + DebugSession(DebugSession&& other) = delete; + + DebugSession& operator = (const DebugSession& other) = delete; + DebugSession& operator = (DebugSession&& other) = delete; + + ~DebugSession(); }; } diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.cpp b/src/DebugServer/Gdb/GdbRspDebugServer.cpp index 08c27266..a7743669 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.cpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.cpp @@ -3,6 +3,7 @@ #include #include +#include "src/EventManager/EventManager.hpp" #include "src/Logger/Logger.hpp" #include "Exceptions/ClientDisconnected.hpp" @@ -124,7 +125,7 @@ namespace Bloom::DebugServer::Gdb } void GdbRspDebugServer::close() { - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); if (this->serverSocketFileDescriptor.has_value()) { ::close(this->serverSocketFileDescriptor.value()); @@ -146,15 +147,11 @@ namespace Bloom::DebugServer::Gdb Logger::info("Accepted GDP RSP connection from " + connection->getIpAddress()); this->activeDebugSession.emplace( - DebugSession( - std::move(connection.value()), - this->getSupportedFeatures(), - this->getGdbTargetDescriptor() - ) + std::move(connection.value()), + this->getSupportedFeatures(), + this->getGdbTargetDescriptor() ); - EventManager::triggerEvent(std::make_shared()); - /* * Before proceeding with a new debug session, we must ensure that the TargetController is able to * service it. @@ -177,7 +174,7 @@ namespace Bloom::DebugServer::Gdb !targetControllerStateChangedEvent.has_value() || targetControllerStateChangedEvent->get()->state != TargetControllerState::ACTIVE ) { - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); throw DebugSessionAborted("TargetController not in service"); } } @@ -197,24 +194,24 @@ namespace Bloom::DebugServer::Gdb } catch (const ClientDisconnected&) { Logger::info("GDB RSP client disconnected"); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); return; } catch (const ClientCommunicationError& exception) { Logger::error( "GDB RSP client communication error - " + exception.getMessage() + " - closing connection" ); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); return; } catch (const ClientNotSupported& exception) { Logger::error("Invalid GDB RSP client - " + exception.getMessage() + " - closing connection"); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); return; } catch (const DebugSessionAborted& exception) { Logger::warning("GDB debug session aborted - " + exception.getMessage()); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); return; } catch (const DebugServerInterrupted&) { @@ -335,21 +332,10 @@ namespace Bloom::DebugServer::Gdb }; } - void GdbRspDebugServer::terminateActiveDebugSession() { - if (!this->activeDebugSession.has_value()) { - return; - } - - this->activeDebugSession->terminate(); - this->activeDebugSession = std::nullopt; - - EventManager::triggerEvent(std::make_shared()); - } - void GdbRspDebugServer::onTargetControllerStateChanged(const Events::TargetControllerStateChanged& event) { if (event.state == TargetControllerState::SUSPENDED && this->activeDebugSession.has_value()) { Logger::warning("TargetController suspended unexpectedly - terminating debug session"); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); } } @@ -364,14 +350,14 @@ namespace Bloom::DebugServer::Gdb } catch (const ClientDisconnected&) { Logger::info("GDB RSP client disconnected"); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); return; } catch (const ClientCommunicationError& exception) { Logger::error( "GDB RSP client communication error - " + exception.getMessage() + " - closing connection" ); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); return; } catch (const DebugServerInterrupted&) { diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.hpp b/src/DebugServer/Gdb/GdbRspDebugServer.hpp index 67e3b65a..b35c2edc 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.hpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.hpp @@ -176,12 +176,6 @@ namespace Bloom::DebugServer::Gdb */ virtual std::set>> getSupportedFeatures(); - - /** - * Terminates any active debug session (if any) by closing the connection to the GDB client. - */ - void terminateActiveDebugSession(); - /** * Should return the GDB target descriptor for the connected target. * diff --git a/src/TargetController/README.md b/src/TargetController/README.md index 6f963340..aa7c1704 100644 --- a/src/TargetController/README.md +++ b/src/TargetController/README.md @@ -102,7 +102,7 @@ the [GDB debug server implementation](../DebugServer/Gdb/README.md) will termina void GdbRspDebugServer::onTargetControllerStateChanged(const Events::TargetControllerStateChanged& event) { if (event.state == TargetControllerState::SUSPENDED && this->activeDebugSession.has_value()) { Logger::warning("TargetController suspended unexpectedly - terminating debug session"); - this->terminateActiveDebugSession(); + this->activeDebugSession.reset(); } } ```