diff --git a/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp b/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp index 6b0d687c..2aac0e02 100644 --- a/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp +++ b/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp @@ -64,9 +64,6 @@ namespace Bloom::DebugServer::Gdb::CommandPackets } // Respond with a SupportedFeaturesResponse packet, listing all supported GDB features by Bloom - debugSession.connection.writePacket(SupportedFeaturesResponse({ - {Feature::SOFTWARE_BREAKPOINTS, std::nullopt}, - {Feature::PACKET_SIZE, std::to_string(debugSession.connection.getMaxPacketSize())}, - })); + debugSession.connection.writePacket(SupportedFeaturesResponse(debugSession.supportedFeatures)); } } diff --git a/src/DebugServer/Gdb/DebugSession.cpp b/src/DebugServer/Gdb/DebugSession.cpp index cd647ee9..ed4d1b84 100644 --- a/src/DebugServer/Gdb/DebugSession.cpp +++ b/src/DebugServer/Gdb/DebugSession.cpp @@ -4,10 +4,19 @@ namespace Bloom::DebugServer::Gdb { - DebugSession::DebugSession(Connection&& connection, const TargetDescriptor& targetDescriptor) + DebugSession::DebugSession( + Connection&& connection, + const std::set>>& supportedFeatures, + const TargetDescriptor& targetDescriptor + ) : connection(std::move(connection)) + , supportedFeatures(supportedFeatures) , gdbTargetDescriptor(targetDescriptor) - {} + { + this->supportedFeatures.insert({ + Feature::PACKET_SIZE, std::to_string(this->connection.getMaxPacketSize()) + }); + } void DebugSession::terminate() { diff --git a/src/DebugServer/Gdb/DebugSession.hpp b/src/DebugServer/Gdb/DebugSession.hpp index 79f32111..17e5d855 100644 --- a/src/DebugServer/Gdb/DebugSession.hpp +++ b/src/DebugServer/Gdb/DebugSession.hpp @@ -4,14 +4,27 @@ #include "TargetDescriptor.hpp" #include "Connection.hpp" +#include "Feature.hpp" namespace Bloom::DebugServer::Gdb { class DebugSession { public: + /** + * The connection serving this debug session. + */ Connection connection; + /** + * A set of all GDB features supported for this debug session, along with any optional values (some GDB + * features can be specified with a value, such as Feature::PACKET_SIZE). + */ + std::set>> supportedFeatures; + + /** + * The GDB target descriptor of the connected target. + */ const TargetDescriptor& gdbTargetDescriptor; /** @@ -20,7 +33,11 @@ namespace Bloom::DebugServer::Gdb */ bool waitingForBreak = false; - DebugSession(Connection&& connection, const TargetDescriptor& targetDescriptor); + DebugSession( + Connection&& connection, + const std::set>>& supportedFeatures, + const TargetDescriptor& targetDescriptor + ); void terminate(); }; diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.cpp b/src/DebugServer/Gdb/GdbRspDebugServer.cpp index 132312d4..08c27266 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.cpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.cpp @@ -146,7 +146,11 @@ namespace Bloom::DebugServer::Gdb Logger::info("Accepted GDP RSP connection from " + connection->getIpAddress()); this->activeDebugSession.emplace( - DebugSession(std::move(connection.value()), this->getGdbTargetDescriptor()) + DebugSession( + std::move(connection.value()), + this->getSupportedFeatures(), + this->getGdbTargetDescriptor() + ) ); EventManager::triggerEvent(std::make_shared()); @@ -325,6 +329,12 @@ namespace Bloom::DebugServer::Gdb return std::make_unique(rawPacket); } + std::set>> GdbRspDebugServer::getSupportedFeatures() { + return { + {Feature::SOFTWARE_BREAKPOINTS, std::nullopt}, + }; + } + void GdbRspDebugServer::terminateActiveDebugSession() { if (!this->activeDebugSession.has_value()) { return; diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.hpp b/src/DebugServer/Gdb/GdbRspDebugServer.hpp index 26671189..67e3b65a 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.hpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.hpp @@ -163,6 +163,20 @@ namespace Bloom::DebugServer::Gdb */ virtual std::unique_ptr resolveCommandPacket(const RawPacketType& rawPacket); + /** + * Should return a set of GDB features supported by the GDB server. Each supported feature may come with an + * optional value. + * + * The set of features returned by this function will be stored against the active debug session object. + * + * Derived GDB server implementations may override this function to include any features that are specific to + * those implementations. + * + * @return + */ + virtual std::set>> getSupportedFeatures(); + + /** * Terminates any active debug session (if any) by closing the connection to the GDB client. */