2022-03-24 19:06:09 +00:00
|
|
|
#include "AvrGdbRsp.hpp"
|
|
|
|
|
|
2022-03-27 19:44:02 +01:00
|
|
|
// Command packets
|
|
|
|
|
#include "CommandPackets/ReadMemory.hpp"
|
|
|
|
|
#include "CommandPackets/WriteMemory.hpp"
|
2022-05-14 22:43:08 +01:00
|
|
|
#include "CommandPackets/ReadMemoryMap.hpp"
|
2022-05-28 22:47:25 +01:00
|
|
|
#include "CommandPackets/FlashErase.hpp"
|
2022-05-29 17:18:29 +01:00
|
|
|
#include "CommandPackets/FlashWrite.hpp"
|
2022-06-05 16:15:12 +01:00
|
|
|
#include "CommandPackets/FlashDone.hpp"
|
2022-03-27 19:44:02 +01:00
|
|
|
|
2022-03-31 16:05:39 +01:00
|
|
|
namespace Bloom::DebugServer::Gdb::AvrGdb
|
2022-03-24 19:06:09 +00:00
|
|
|
{
|
|
|
|
|
using namespace Bloom::Exceptions;
|
|
|
|
|
|
|
|
|
|
using Bloom::Targets::TargetRegisterDescriptor;
|
|
|
|
|
using Bloom::Targets::TargetRegisterType;
|
|
|
|
|
|
2022-03-27 18:32:13 +01:00
|
|
|
AvrGdbRsp::AvrGdbRsp(
|
|
|
|
|
const DebugServerConfig& debugServerConfig,
|
2022-04-15 22:05:50 +01:00
|
|
|
EventListener& eventListener,
|
|
|
|
|
EventFdNotifier& eventNotifier
|
2022-03-27 18:32:13 +01:00
|
|
|
)
|
2022-04-15 22:05:50 +01:00
|
|
|
: GdbRspDebugServer(debugServerConfig, eventListener, eventNotifier)
|
2022-03-27 18:32:13 +01:00
|
|
|
{}
|
|
|
|
|
|
2022-03-24 19:06:09 +00:00
|
|
|
void AvrGdbRsp::init() {
|
2022-03-31 16:05:39 +01:00
|
|
|
DebugServer::Gdb::GdbRspDebugServer::init();
|
2022-03-24 19:06:09 +00:00
|
|
|
|
2022-03-27 18:32:13 +01:00
|
|
|
this->gdbTargetDescriptor = TargetDescriptor(
|
|
|
|
|
this->targetControllerConsole.getTargetDescriptor()
|
|
|
|
|
);
|
2022-03-24 19:06:09 +00:00
|
|
|
}
|
2022-03-27 19:44:02 +01:00
|
|
|
|
|
|
|
|
std::unique_ptr<Gdb::CommandPackets::CommandPacket> AvrGdbRsp::resolveCommandPacket(
|
|
|
|
|
const RawPacketType& rawPacket
|
|
|
|
|
) {
|
|
|
|
|
using AvrGdb::CommandPackets::ReadMemory;
|
|
|
|
|
using AvrGdb::CommandPackets::WriteMemory;
|
2022-05-14 22:43:08 +01:00
|
|
|
using AvrGdb::CommandPackets::ReadMemoryMap;
|
2022-05-28 22:47:25 +01:00
|
|
|
using AvrGdb::CommandPackets::FlashErase;
|
2022-05-29 17:18:29 +01:00
|
|
|
using AvrGdb::CommandPackets::FlashWrite;
|
2022-06-05 16:15:12 +01:00
|
|
|
using AvrGdb::CommandPackets::FlashDone;
|
2022-03-27 19:44:02 +01:00
|
|
|
|
|
|
|
|
if (rawPacket.size() >= 2) {
|
|
|
|
|
if (rawPacket[1] == 'm') {
|
2022-08-30 02:04:35 +01:00
|
|
|
return std::make_unique<ReadMemory>(rawPacket, this->gdbTargetDescriptor.value());
|
2022-03-27 19:44:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rawPacket[1] == 'M') {
|
2022-08-30 02:04:35 +01:00
|
|
|
return std::make_unique<WriteMemory>(rawPacket, this->gdbTargetDescriptor.value());
|
2022-03-27 19:44:02 +01:00
|
|
|
}
|
2022-05-14 22:43:08 +01:00
|
|
|
|
|
|
|
|
const auto rawPacketString = std::string(rawPacket.begin() + 1, rawPacket.end());
|
|
|
|
|
|
|
|
|
|
if (rawPacketString.find("qXfer:memory-map:read::") == 0) {
|
|
|
|
|
return std::make_unique<ReadMemoryMap>(rawPacket);
|
|
|
|
|
}
|
2022-05-28 22:47:25 +01:00
|
|
|
|
|
|
|
|
if (rawPacketString.find("vFlashErase") == 0) {
|
|
|
|
|
return std::make_unique<FlashErase>(rawPacket);
|
|
|
|
|
}
|
2022-05-29 17:18:29 +01:00
|
|
|
|
|
|
|
|
if (rawPacketString.find("vFlashWrite") == 0) {
|
|
|
|
|
return std::make_unique<FlashWrite>(rawPacket);
|
|
|
|
|
}
|
2022-06-05 16:15:12 +01:00
|
|
|
|
|
|
|
|
if (rawPacketString.find("vFlashDone") == 0) {
|
|
|
|
|
return std::make_unique<FlashDone>(rawPacket);
|
|
|
|
|
}
|
2022-03-27 19:44:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GdbRspDebugServer::resolveCommandPacket(rawPacket);
|
|
|
|
|
}
|
2022-05-14 22:43:08 +01:00
|
|
|
|
|
|
|
|
std::set<std::pair<Feature, std::optional<std::string>>> AvrGdbRsp::getSupportedFeatures() {
|
|
|
|
|
auto supportedFeatures = GdbRspDebugServer::getSupportedFeatures();
|
|
|
|
|
|
2022-06-05 17:01:14 +01:00
|
|
|
// The AVR GDB server supports the 'qXfer:memory-map:read' GDB command.
|
2022-05-14 22:43:08 +01:00
|
|
|
supportedFeatures.insert({
|
|
|
|
|
Feature::MEMORY_MAP_READ, std::nullopt
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return supportedFeatures;
|
|
|
|
|
}
|
2022-03-24 19:06:09 +00:00
|
|
|
}
|