New GDB Monitor command packet class, for "qRcmd" command packets

This commit is contained in:
Nav
2022-04-08 22:18:52 +01:00
parent 908f1c42c9
commit 583b01fa34
4 changed files with 59 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/InterruptExecution.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/InterruptExecution.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/SetBreakpoint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/SetBreakpoint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/RemoveBreakpoint.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/RemoveBreakpoint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Gdb/CommandPackets/Monitor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/Gdb/ResponsePackets/SupportedFeaturesResponse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Gdb/ResponsePackets/SupportedFeaturesResponse.cpp
# AVR GDB Server # AVR GDB Server

View File

@@ -0,0 +1,27 @@
#include "Monitor.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/EmptyResponsePacket.hpp"
#include "src/Logger/Logger.hpp"
namespace Bloom::DebugServer::Gdb::CommandPackets
{
using ResponsePackets::EmptyResponsePacket;
Monitor::Monitor(const std::vector<unsigned char>& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() > 6) {
const auto decodedCommand = Packet::hexToData(
std::string(this->data.begin() + 6, this->data.end())
);
this->command = std::string(decodedCommand.begin(), decodedCommand.end());
}
}
void Monitor::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) {
Logger::error("Unknown custom GDB command (" + this->command + ") received.");
debugSession.connection.writePacket(EmptyResponsePacket());
}
}

View File

@@ -0,0 +1,24 @@
#pragma once
#include <cstdint>
#include "CommandPacket.hpp"
namespace Bloom::DebugServer::Gdb::CommandPackets
{
/**
* This is a base class for 'qRcmd' packets - invoked by the GDB 'monitor' command.
*/
class Monitor: public CommandPacket
{
public:
/**
* The decoded command string which was input by the GDB user.
*/
std::string command;
explicit Monitor(const std::vector<unsigned char>& rawPacket);
void handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) override;
};
}

View File

@@ -24,6 +24,7 @@
#include "CommandPackets/WriteRegister.hpp" #include "CommandPackets/WriteRegister.hpp"
#include "CommandPackets/SetBreakpoint.hpp" #include "CommandPackets/SetBreakpoint.hpp"
#include "CommandPackets/RemoveBreakpoint.hpp" #include "CommandPackets/RemoveBreakpoint.hpp"
#include "CommandPackets/Monitor.hpp"
// Response packets // Response packets
#include "ResponsePackets/TargetStopped.hpp" #include "ResponsePackets/TargetStopped.hpp"
@@ -265,6 +266,12 @@ namespace Bloom::DebugServer::Gdb
if (rawPacketString[1] == 'z') { if (rawPacketString[1] == 'z') {
return std::make_unique<CommandPackets::RemoveBreakpoint>(rawPacket); return std::make_unique<CommandPackets::RemoveBreakpoint>(rawPacket);
} }
if (rawPacketString.find("qRcmd") == 1) {
// This is a monitor packet
auto monitorCommand = std::make_unique<CommandPackets::Monitor>(rawPacket);
return monitorCommand;
}
} }
return std::make_unique<CommandPacket>(rawPacket); return std::make_unique<CommandPacket>(rawPacket);