From 40b1183f6bd07ba428171092a33147304ae27ca3 Mon Sep 17 00:00:00 2001 From: Nav Date: Sun, 5 Jun 2022 16:15:12 +0100 Subject: [PATCH] Moved vFlashDone GDB command packet handelr to separate class --- src/DebugServer/CMakeLists.txt | 1 + src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp | 6 ++++ .../Gdb/AvrGdb/CommandPackets/FlashDone.cpp | 35 +++++++++++++++++++ .../Gdb/AvrGdb/CommandPackets/FlashDone.hpp | 23 ++++++++++++ .../Gdb/CommandPackets/CommandPacket.cpp | 6 ---- 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.cpp create mode 100644 src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.hpp diff --git a/src/DebugServer/CMakeLists.txt b/src/DebugServer/CMakeLists.txt index 4bfd2c21..1414c1b7 100755 --- a/src/DebugServer/CMakeLists.txt +++ b/src/DebugServer/CMakeLists.txt @@ -33,4 +33,5 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/AvrGdb/CommandPackets/ReadMemoryMap.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/AvrGdb/CommandPackets/FlashErase.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/AvrGdb/CommandPackets/FlashWrite.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/AvrGdb/CommandPackets/FlashDone.cpp ) diff --git a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp index e3092236..e3bc5b4f 100644 --- a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp +++ b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp @@ -6,6 +6,7 @@ #include "CommandPackets/ReadMemoryMap.hpp" #include "CommandPackets/FlashErase.hpp" #include "CommandPackets/FlashWrite.hpp" +#include "CommandPackets/FlashDone.hpp" namespace Bloom::DebugServer::Gdb::AvrGdb { @@ -38,6 +39,7 @@ namespace Bloom::DebugServer::Gdb::AvrGdb using AvrGdb::CommandPackets::ReadMemoryMap; using AvrGdb::CommandPackets::FlashErase; using AvrGdb::CommandPackets::FlashWrite; + using AvrGdb::CommandPackets::FlashDone; if (rawPacket.size() >= 2) { if (rawPacket[1] == 'm') { @@ -61,6 +63,10 @@ namespace Bloom::DebugServer::Gdb::AvrGdb if (rawPacketString.find("vFlashWrite") == 0) { return std::make_unique(rawPacket); } + + if (rawPacketString.find("vFlashDone") == 0) { + return std::make_unique(rawPacket); + } } return GdbRspDebugServer::resolveCommandPacket(rawPacket); diff --git a/src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.cpp b/src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.cpp new file mode 100644 index 00000000..bf4a0d99 --- /dev/null +++ b/src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.cpp @@ -0,0 +1,35 @@ +#include "FlashDone.hpp" + +#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp" +#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp" + +#include "src/Logger/Logger.hpp" +#include "src/Exceptions/Exception.hpp" + +namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets +{ + using TargetController::TargetControllerConsole; + + using ResponsePackets::ErrorResponsePacket; + using ResponsePackets::OkResponsePacket; + + using namespace Bloom::Exceptions; + + FlashDone::FlashDone(const RawPacketType& rawPacket) + : MemoryAccessCommandPacket(rawPacket) + {} + + void FlashDone::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) { + Logger::debug("Handling FlashDone packet"); + + try { + targetControllerConsole.disableProgrammingMode(); + + debugSession.connection.writePacket(OkResponsePacket()); + + } catch (const Exception& exception) { + Logger::error("Failed to disabling programming mode - " + exception.getMessage()); + debugSession.connection.writePacket(ErrorResponsePacket()); + } + } +} diff --git a/src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.hpp b/src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.hpp new file mode 100644 index 00000000..af31b8b3 --- /dev/null +++ b/src/DebugServer/Gdb/AvrGdb/CommandPackets/FlashDone.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "MemoryAccessCommandPacket.hpp" + +namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets +{ + /** + * The FlashDone class implements the structure for the "vFlashDone" packet. + */ + class FlashDone: public MemoryAccessCommandPacket + { + public: + explicit FlashDone(const RawPacketType& rawPacket); + + void handle( + DebugSession& debugSession, + TargetController::TargetControllerConsole& targetControllerConsole + ) override; + }; +} diff --git a/src/DebugServer/Gdb/CommandPackets/CommandPacket.cpp b/src/DebugServer/Gdb/CommandPackets/CommandPacket.cpp index 7835e9c4..0c1f20c1 100644 --- a/src/DebugServer/Gdb/CommandPackets/CommandPacket.cpp +++ b/src/DebugServer/Gdb/CommandPackets/CommandPacket.cpp @@ -56,12 +56,6 @@ namespace Bloom::DebugServer::Gdb::CommandPackets return; } - if (packetString.find("vFlashDone") == 0) { - Logger::debug("Handling vFlashDone"); - debugSession.connection.writePacket(OkResponsePacket()); - return; - } - Logger::debug("Unknown GDB RSP packet: " + packetString + " - returning empty response"); // Respond with an empty packet