From c9d1dd92a3500235103cc4d982f0d77a8f96af6a Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 5 May 2022 20:13:30 +0100 Subject: [PATCH] Added "monitor version" command, to display the current Bloom version --- src/DebugServer/CMakeLists.txt | 1 + .../Gdb/CommandPackets/BloomVersion.cpp | 37 +++++++++++++++++++ .../Gdb/CommandPackets/BloomVersion.hpp | 24 ++++++++++++ src/DebugServer/Gdb/GdbRspDebugServer.cpp | 4 ++ 4 files changed, 66 insertions(+) create mode 100644 src/DebugServer/Gdb/CommandPackets/BloomVersion.cpp create mode 100644 src/DebugServer/Gdb/CommandPackets/BloomVersion.hpp diff --git a/src/DebugServer/CMakeLists.txt b/src/DebugServer/CMakeLists.txt index aa741892..dc754f83 100755 --- a/src/DebugServer/CMakeLists.txt +++ b/src/DebugServer/CMakeLists.txt @@ -19,6 +19,7 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/RemoveBreakpoint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/Monitor.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/ResetTarget.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/BloomVersion.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/ResponsePackets/SupportedFeaturesResponse.cpp # AVR GDB RSP Server diff --git a/src/DebugServer/Gdb/CommandPackets/BloomVersion.cpp b/src/DebugServer/Gdb/CommandPackets/BloomVersion.cpp new file mode 100644 index 00000000..5f1ca2b6 --- /dev/null +++ b/src/DebugServer/Gdb/CommandPackets/BloomVersion.cpp @@ -0,0 +1,37 @@ +#include "BloomVersion.hpp" + +#include + +#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp" +#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp" + +#include "src/Application.hpp" +#include "src/Helpers/Paths.hpp" +#include "src/Logger/Logger.hpp" +#include "src/Exceptions/Exception.hpp" + +namespace Bloom::DebugServer::Gdb::CommandPackets +{ + using TargetController::TargetControllerConsole; + + using ResponsePackets::ErrorResponsePacket; + using ResponsePackets::ResponsePacket; + + using Exceptions::Exception; + + BloomVersion::BloomVersion(Monitor&& monitorPacket) + : Monitor(std::move(monitorPacket)) + {} + + void BloomVersion::handle(DebugSession& debugSession, TargetControllerConsole&) { + Logger::debug("Handling BloomVersion packet"); + + debugSession.connection.writePacket(ResponsePacket(Packet::toHex( + std::string( + "Bloom v" + Application::VERSION.toString() + "\n" + + Paths::homeDomainName() + "\n" + + "Nav Mohammed\n" + ) + ))); + } +} diff --git a/src/DebugServer/Gdb/CommandPackets/BloomVersion.hpp b/src/DebugServer/Gdb/CommandPackets/BloomVersion.hpp new file mode 100644 index 00000000..45462c5e --- /dev/null +++ b/src/DebugServer/Gdb/CommandPackets/BloomVersion.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Monitor.hpp" + +namespace Bloom::DebugServer::Gdb::CommandPackets +{ + /** + * The BloomVersion class implements a structure for the "monitor version" GDB command. + * + * We just output Bloom's current version number. + */ + class BloomVersion: public Monitor + { + public: + explicit BloomVersion(Monitor&& monitorPacket); + + void handle( + DebugSession& debugSession, + TargetController::TargetControllerConsole& targetControllerConsole + ) override; + }; +} diff --git a/src/DebugServer/Gdb/GdbRspDebugServer.cpp b/src/DebugServer/Gdb/GdbRspDebugServer.cpp index f9d75a62..5a513bbb 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.cpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.cpp @@ -26,6 +26,7 @@ #include "CommandPackets/RemoveBreakpoint.hpp" #include "CommandPackets/Monitor.hpp" #include "CommandPackets/ResetTarget.hpp" +#include "CommandPackets/BloomVersion.hpp" // Response packets #include "ResponsePackets/TargetStopped.hpp" @@ -294,6 +295,9 @@ namespace Bloom::DebugServer::Gdb // This is a monitor packet auto monitorCommand = std::make_unique(rawPacket); + if (monitorCommand->command == "version") { + return std::make_unique(std::move(*(monitorCommand.get()))); + } if (monitorCommand->command == "reset") { return std::make_unique(std::move(*(monitorCommand.get()))); }