From 4a9c26b73ed46cf4f6fc6223ddbf81c1005d2e6f Mon Sep 17 00:00:00 2001 From: Nav Date: Thu, 5 May 2022 20:14:23 +0100 Subject: [PATCH] Added "monitor version machine" command, to display the current Bloom version in JSON format --- src/DebugServer/CMakeLists.txt | 1 + .../CommandPackets/BloomVersionMachine.cpp | 41 +++++++++++++++++++ .../CommandPackets/BloomVersionMachine.hpp | 24 +++++++++++ src/DebugServer/Gdb/GdbRspDebugServer.cpp | 6 +++ 4 files changed, 72 insertions(+) create mode 100644 src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp create mode 100644 src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.hpp diff --git a/src/DebugServer/CMakeLists.txt b/src/DebugServer/CMakeLists.txt index dc754f83..a9a8bbf9 100755 --- a/src/DebugServer/CMakeLists.txt +++ b/src/DebugServer/CMakeLists.txt @@ -20,6 +20,7 @@ target_sources( ${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/CommandPackets/BloomVersionMachine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/ResponsePackets/SupportedFeaturesResponse.cpp # AVR GDB RSP Server diff --git a/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp b/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp new file mode 100644 index 00000000..e5b24187 --- /dev/null +++ b/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.cpp @@ -0,0 +1,41 @@ +#include "BloomVersionMachine.hpp" + +#include +#include +#include + +#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp" +#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp" + +#include "src/Application.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; + + BloomVersionMachine::BloomVersionMachine(Monitor&& monitorPacket) + : Monitor(std::move(monitorPacket)) + {} + + void BloomVersionMachine::handle(DebugSession& debugSession, TargetControllerConsole&) { + Logger::debug("Handling BloomVersionMachine packet"); + + debugSession.connection.writePacket(ResponsePacket(Packet::toHex( + QJsonDocument(QJsonObject({ + {"version", QString::fromStdString(Application::VERSION.toString())}, + {"components", QJsonObject({ + {"major", Application::VERSION.getMajor()}, + {"minor", Application::VERSION.getMinor()}, + {"patch", Application::VERSION.getPatch()}, + })}, + })).toJson().toStdString() + ))); + } +} diff --git a/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.hpp b/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.hpp new file mode 100644 index 00000000..17d5619f --- /dev/null +++ b/src/DebugServer/Gdb/CommandPackets/BloomVersionMachine.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "Monitor.hpp" + +namespace Bloom::DebugServer::Gdb::CommandPackets +{ + /** + * The BloomVersionMachine class implements a structure for the "monitor version machine" GDB command. + * + * We just output Bloom's current version number in JSON format. + */ + class BloomVersionMachine: public Monitor + { + public: + explicit BloomVersionMachine(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 5a513bbb..c5bef2f3 100644 --- a/src/DebugServer/Gdb/GdbRspDebugServer.cpp +++ b/src/DebugServer/Gdb/GdbRspDebugServer.cpp @@ -27,6 +27,7 @@ #include "CommandPackets/Monitor.hpp" #include "CommandPackets/ResetTarget.hpp" #include "CommandPackets/BloomVersion.hpp" +#include "CommandPackets/BloomVersionMachine.hpp" // Response packets #include "ResponsePackets/TargetStopped.hpp" @@ -298,6 +299,11 @@ namespace Bloom::DebugServer::Gdb if (monitorCommand->command == "version") { return std::make_unique(std::move(*(monitorCommand.get()))); } + + if (monitorCommand->command == "version machine") { + return std::make_unique(std::move(*(monitorCommand.get()))); + } + if (monitorCommand->command == "reset") { return std::make_unique(std::move(*(monitorCommand.get()))); }