#include "AvrGdbRsp.hpp" // Command packets #include "CommandPackets/ReadRegister.hpp" #include "CommandPackets/ReadRegisters.hpp" #include "CommandPackets/WriteRegister.hpp" #include "CommandPackets/ReadMemory.hpp" #include "CommandPackets/WriteMemory.hpp" #include "CommandPackets/ReadMemoryMap.hpp" #include "CommandPackets/FlashErase.hpp" #include "CommandPackets/FlashWrite.hpp" #include "CommandPackets/FlashDone.hpp" namespace DebugServer::Gdb::AvrGdb { using namespace Exceptions; using Targets::TargetRegisterDescriptor; using Targets::TargetRegisterType; AvrGdbRsp::AvrGdbRsp( const DebugServerConfig& debugServerConfig, EventListener& eventListener, EventFdNotifier& eventNotifier ) : GdbRspDebugServer(debugServerConfig, eventListener, eventNotifier) {} void AvrGdbRsp::init() { DebugServer::Gdb::GdbRspDebugServer::init(); this->gdbTargetDescriptor = TargetDescriptor( this->targetControllerService.getTargetDescriptor() ); } std::unique_ptr AvrGdbRsp::resolveCommandPacket( const RawPacket& rawPacket ) { using AvrGdb::CommandPackets::ReadRegister; using AvrGdb::CommandPackets::ReadRegisters; using AvrGdb::CommandPackets::WriteRegister; using AvrGdb::CommandPackets::ReadMemory; using AvrGdb::CommandPackets::WriteMemory; using AvrGdb::CommandPackets::ReadMemoryMap; using AvrGdb::CommandPackets::FlashErase; using AvrGdb::CommandPackets::FlashWrite; using AvrGdb::CommandPackets::FlashDone; if (rawPacket.size() >= 2) { if (rawPacket[1] == 'p') { return std::make_unique(rawPacket); } if (rawPacket[1] == 'g') { return std::make_unique(rawPacket); } if (rawPacket[1] == 'P') { return std::make_unique(rawPacket); } if (rawPacket[1] == 'm') { return std::make_unique(rawPacket, this->gdbTargetDescriptor.value()); } if (rawPacket[1] == 'M') { return std::make_unique(rawPacket, this->gdbTargetDescriptor.value()); } const auto rawPacketString = std::string(rawPacket.begin() + 1, rawPacket.end()); if (rawPacketString.find("qXfer:memory-map:read::") == 0) { return std::make_unique(rawPacket); } if (rawPacketString.find("vFlashErase") == 0) { return std::make_unique(rawPacket); } if (rawPacketString.find("vFlashWrite") == 0) { return std::make_unique(rawPacket); } if (rawPacketString.find("vFlashDone") == 0) { return std::make_unique(rawPacket); } } return GdbRspDebugServer::resolveCommandPacket(rawPacket); } std::set>> AvrGdbRsp::getSupportedFeatures() { auto supportedFeatures = GdbRspDebugServer::getSupportedFeatures(); // The AVR GDB server supports the 'qXfer:memory-map:read' GDB command. supportedFeatures.insert({ Feature::MEMORY_MAP_READ, std::nullopt }); return supportedFeatures; } }