Refactored GDB server base class, making it a template class, allowing for much more flexibility for derived target-specific implementations

This commit is contained in:
Nav
2024-10-25 22:22:25 +01:00
parent 72d0c28d08
commit 8be311cbc0
40 changed files with 675 additions and 780 deletions

View File

@@ -0,0 +1,39 @@
#pragma once
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "src/DebugServer/Gdb/DebugSession.hpp"
#include "src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp"
#include "src/Targets/TargetDescriptor.hpp"
#include "src/Services/TargetControllerService.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
class CommandPacket: public Gdb::CommandPackets::CommandPacket
{
public:
explicit CommandPacket(const RawPacket& rawPacket)
: Gdb::CommandPackets::CommandPacket(rawPacket)
{}
explicit CommandPacket(const Gdb::CommandPackets::CommandPacket& commandPacket)
: Gdb::CommandPackets::CommandPacket(commandPacket)
{}
virtual ~CommandPacket() = default;
/**
* Should handle the command for the current active debug session.
*
* @param debugSession
* The current active debug session.
*
* @param TargetControllerService
*/
virtual void handle(
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) = 0;
};
}

View File

@@ -23,33 +23,31 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using ::Exceptions::Exception;
using Exceptions::InvalidCommandOption;
EepromFill::EepromFill(Monitor&& monitorPacket, const TargetDescriptor& gdbTargetDescriptor)
: Monitor(std::move(monitorPacket))
, eepromAddressSpaceDescriptor(gdbTargetDescriptor.eepromAddressSpaceDescriptor)
, eepromMemorySegmentDescriptor(gdbTargetDescriptor.eepromMemorySegmentDescriptor)
EepromFill::EepromFill(Gdb::CommandPackets::Monitor&& monitorPacket)
: CommandPacket(monitorPacket)
, rawFillValue(monitorPacket.commandArguments.size() >= 3 ? monitorPacket.commandArguments[2] : std::string{})
{}
void EepromFill::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
Logger::info("Handling EepromFill packet");
try {
if (this->commandArguments.size() < 3 || this->commandArguments[2].empty()) {
if (this->rawFillValue.empty()) {
throw InvalidCommandOption{"Fill value required"};
}
const auto eepromSize = this->eepromMemorySegmentDescriptor.size();
const auto& rawFillValue = this->commandArguments[2];
const auto eepromSize = gdbTargetDescriptor.eepromMemorySegmentDescriptor.size();
const auto fillValue = Services::StringService::dataFromHex(
rawFillValue.size() >= 3 && rawFillValue[0] == '0'
&& (rawFillValue[1] == 'X' || rawFillValue[1] == 'x')
? rawFillValue.substr(2)
: rawFillValue
this->rawFillValue.size() >= 3 && this->rawFillValue[0] == '0'
&& (this->rawFillValue[1] == 'X' || this->rawFillValue[1] == 'x')
? this->rawFillValue.substr(2)
: this->rawFillValue
);
const auto fillValueSize = fillValue.size();
@@ -87,9 +85,9 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
Logger::debug("Filling EEPROM with values: " + hexValues);
targetControllerService.writeMemory(
this->eepromAddressSpaceDescriptor,
this->eepromMemorySegmentDescriptor,
this->eepromMemorySegmentDescriptor.addressRange.startAddress,
gdbTargetDescriptor.eepromAddressSpaceDescriptor,
gdbTargetDescriptor.eepromMemorySegmentDescriptor,
gdbTargetDescriptor.eepromMemorySegmentDescriptor.addressRange.startAddress,
std::move(data)
);

View File

@@ -1,14 +1,12 @@
#pragma once
#include <cstdint>
#include <string>
#include "CommandPacket.hpp"
#include "src/DebugServer/Gdb/CommandPackets/Monitor.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
/**
@@ -16,17 +14,16 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
*
* This command fills the target's EEPROM with the given value.
*/
class EepromFill: public Gdb::CommandPackets::Monitor
class EepromFill: public CommandPackets::CommandPacket
{
public:
const Targets::TargetAddressSpaceDescriptor& eepromAddressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& eepromMemorySegmentDescriptor;
std::string rawFillValue;
explicit EepromFill(Monitor&& monitorPacket, const TargetDescriptor& gdbTargetDescriptor);
explicit EepromFill(Gdb::CommandPackets::Monitor&& monitorPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -15,15 +15,13 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using namespace Exceptions;
FlashDone::FlashDone(const RawPacket& rawPacket, const TargetDescriptor& targetDescriptor)
FlashDone::FlashDone(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
, programMemoryAddressSpaceDescriptor(targetDescriptor.programAddressSpaceDescriptor)
, programMemorySegmentDescriptor(targetDescriptor.programMemorySegmentDescriptor)
{}
void FlashDone::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -42,8 +40,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
targetControllerService.enableProgrammingMode();
targetControllerService.writeMemory(
this->programMemoryAddressSpaceDescriptor,
this->programMemorySegmentDescriptor,
gdbTargetDescriptor.programAddressSpaceDescriptor,
gdbTargetDescriptor.programMemorySegmentDescriptor,
debugSession.programmingSession->startAddress,
std::move(debugSession.programmingSession->buffer)
);

View File

@@ -3,28 +3,21 @@
#include <cstdint>
#include <optional>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "CommandPacket.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
/**
* The FlashDone class implements the structure for the "vFlashDone" packet.
*/
class FlashDone: public Gdb::CommandPackets::CommandPacket
class FlashDone: public CommandPackets::CommandPacket
{
public:
const Targets::TargetAddressSpaceDescriptor& programMemoryAddressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& programMemorySegmentDescriptor;
explicit FlashDone(const RawPacket& rawPacket, const TargetDescriptor& targetDescriptor);
explicit FlashDone(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -16,10 +16,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using namespace Exceptions;
FlashErase::FlashErase(const RawPacket& rawPacket, const TargetDescriptor& targetDescriptor)
FlashErase::FlashErase(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
, programMemoryAddressSpaceDescriptor(targetDescriptor.programAddressSpaceDescriptor)
, programMemorySegmentDescriptor(targetDescriptor.programMemorySegmentDescriptor)
{
using Services::StringService;
@@ -45,8 +43,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
void FlashErase::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -59,8 +57,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
// We don't erase a specific address range - we just erase the entire program memory.
targetControllerService.eraseMemory(
this->programMemoryAddressSpaceDescriptor,
this->programMemorySegmentDescriptor
gdbTargetDescriptor.programAddressSpaceDescriptor,
gdbTargetDescriptor.programMemorySegmentDescriptor
);
debugSession.connection.writePacket(OkResponsePacket{});

View File

@@ -3,11 +3,7 @@
#include <cstdint>
#include <optional>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "CommandPacket.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -15,19 +11,17 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The FlashErase class implements the structure for the "vFlashErase" packet. Upon receiving this packet, the
* server is expected to erase a particular region of the target's flash memory.
*/
class FlashErase: public Gdb::CommandPackets::CommandPacket
class FlashErase: public CommandPackets::CommandPacket
{
public:
std::uint32_t startAddress = 0;
std::uint32_t bytes = 0;
const Targets::TargetAddressSpaceDescriptor& programMemoryAddressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& programMemorySegmentDescriptor;
explicit FlashErase(const RawPacket& rawPacket, const TargetDescriptor& targetDescriptor);
explicit FlashErase(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -40,8 +40,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
void FlashWrite::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {

View File

@@ -3,8 +3,7 @@
#include <cstdint>
#include <optional>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "src/DebugServer/Gdb/TargetDescriptor.hpp"
#include "CommandPacket.hpp"
#include "src/Targets/TargetMemory.hpp"
@@ -14,17 +13,17 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The FlashWrite class implements the structure for the "vFlashWrite" packet. Upon receiving this packet, the
* server is expected to write to a particular region of the target's flash memory.
*/
class FlashWrite: public Gdb::CommandPackets::CommandPacket
class FlashWrite: public CommandPackets::CommandPacket
{
public:
std::uint32_t startAddress = 0;
Targets::TargetMemoryAddress startAddress;
Targets::TargetMemoryBuffer buffer;
explicit FlashWrite(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -19,13 +19,13 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using Exceptions::Exception;
ReadMemory::ReadMemory(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor)
ReadMemory::ReadMemory(const RawPacket& rawPacket, const AvrGdbTargetDescriptor& gdbTargetDescriptor)
: ReadMemory(rawPacket, gdbTargetDescriptor, ReadMemory::extractPacketData(rawPacket))
{}
void ReadMemory::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -147,7 +147,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
ReadMemory::ReadMemory(
const RawPacket& rawPacket,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
ReadMemory::PacketData&& packetData
)
: CommandPacket(rawPacket)

View File

@@ -3,11 +3,10 @@
#include <cstdint>
#include <optional>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -15,7 +14,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The ReadMemory class implements a structure for "m" packets. Upon receiving these packets, the server is
* expected to read memory from the target and send it the client.
*/
class ReadMemory: public Gdb::CommandPackets::CommandPacket
class ReadMemory: public CommandPackets::CommandPacket
{
public:
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
@@ -23,11 +22,11 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
Targets::TargetMemoryAddress startAddress;
Targets::TargetMemorySize bytes;
ReadMemory(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor);
ReadMemory(const RawPacket& rawPacket, const AvrGdbTargetDescriptor& gdbTargetDescriptor);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;
@@ -42,7 +41,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
static PacketData extractPacketData(const RawPacket& rawPacket);
ReadMemory(
const RawPacket& rawPacket,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
PacketData&& packetData
);
};

View File

@@ -13,11 +13,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using Exceptions::Exception;
ReadMemoryMap::ReadMemoryMap(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor)
ReadMemoryMap::ReadMemoryMap(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
, eepromAddressSpaceDescriptor(gdbTargetDescriptor.eepromAddressSpaceDescriptor)
, programMemorySegmentDescriptor(gdbTargetDescriptor.programMemorySegmentDescriptor)
, eepromMemorySegmentDescriptor(gdbTargetDescriptor.eepromMemorySegmentDescriptor)
{
using Services::StringService;
@@ -41,8 +38,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
void ReadMemoryMap::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -53,18 +50,18 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* data via memory read/write packets.
*/
const auto ramSectionEndAddress = gdbTargetDescriptor.translateTargetMemoryAddress(
this->eepromMemorySegmentDescriptor.addressRange.endAddress,
this->eepromAddressSpaceDescriptor,
this->eepromMemorySegmentDescriptor
gdbTargetDescriptor.eepromMemorySegmentDescriptor.addressRange.endAddress,
gdbTargetDescriptor.eepromAddressSpaceDescriptor,
gdbTargetDescriptor.eepromMemorySegmentDescriptor
);
const auto ramSectionStartAddress = TargetDescriptor::SRAM_ADDRESS_MASK;
const auto ramSectionStartAddress = AvrGdbTargetDescriptor::SRAM_ADDRESS_MASK;
const auto ramSectionSize = ramSectionEndAddress - ramSectionStartAddress + 1;
const auto memoryMap =
std::string{"<memory-map>"}
+ "<memory type=\"ram\" start=\"" + std::to_string(ramSectionStartAddress) + "\" length=\"" + std::to_string(ramSectionSize) + "\"/>"
+ "<memory type=\"flash\" start=\"0\" length=\"" + std::to_string(this->programMemorySegmentDescriptor.size()) + "\">"
+ "<property name=\"blocksize\">" + std::to_string(this->programMemorySegmentDescriptor.pageSize.value()) + "</property>"
+ "<memory type=\"flash\" start=\"0\" length=\"" + std::to_string(gdbTargetDescriptor.programMemorySegmentDescriptor.size()) + "\">"
+ "<property name=\"blocksize\">" + std::to_string(gdbTargetDescriptor.programMemorySegmentDescriptor.pageSize.value()) + "</property>"
+ "</memory>"
+ "</memory-map>";

View File

@@ -2,11 +2,7 @@
#include <cstdint>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "CommandPacket.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -14,13 +10,9 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The ReadMemoryMap class implements a structure for the "qXfer:memory-map:read::..." packet. Upon receiving this
* packet, the server is expected to respond with the target's memory map.
*/
class ReadMemoryMap: public Gdb::CommandPackets::CommandPacket
class ReadMemoryMap: public CommandPackets::CommandPacket
{
public:
const Targets::TargetAddressSpaceDescriptor& eepromAddressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& programMemorySegmentDescriptor;
const Targets::TargetMemorySegmentDescriptor& eepromMemorySegmentDescriptor;
/**
* The offset of the memory map, from which to read.
*/
@@ -31,11 +23,11 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
*/
std::uint32_t length = 0;
explicit ReadMemoryMap(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor);
explicit ReadMemoryMap(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -4,7 +4,6 @@
#include "src/Targets/TargetRegisterDescriptor.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Services/StringService.hpp"
#include "src/Logger/Logger.hpp"
@@ -36,8 +35,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
void ReadRegister::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -46,7 +45,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
try {
Logger::debug("Reading GDB register ID: " + std::to_string(this->registerId));
if (this->registerId == TargetDescriptor::PROGRAM_COUNTER_GDB_REGISTER_ID) {
if (this->registerId == AvrGdbTargetDescriptor::PROGRAM_COUNTER_GDB_REGISTER_ID) {
/*
* GDB has requested the program counter. We can't access this in the same way as we do with other
* registers.
@@ -65,7 +64,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
return;
}
if (this->registerId == TargetDescriptor::STACK_POINTER_GDB_REGISTER_ID) {
if (this->registerId == AvrGdbTargetDescriptor::STACK_POINTER_GDB_REGISTER_ID) {
/*
* GDB has requested the program counter. We can't access this in the same way as we do with other
* registers.

View File

@@ -1,6 +1,6 @@
#pragma once
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
#include "src/DebugServer/Gdb/RegisterDescriptor.hpp"
@@ -10,7 +10,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The ReadRegister class implements a structure for the "p" command packet. In response to this packet, the server
* is expected to send register values for the requested register.
*/
class ReadRegister: public Gdb::CommandPackets::CommandPacket
class ReadRegister: public CommandPackets::CommandPacket
{
public:
GdbRegisterId registerId;
@@ -18,8 +18,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
explicit ReadRegister(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -22,14 +22,13 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using Exceptions::Exception;
ReadRegisters::ReadRegisters(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor)
ReadRegisters::ReadRegisters(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
, gpRegistersMemorySegmentDescriptor(gdbTargetDescriptor.gpRegistersMemorySegmentDescriptor)
{}
void ReadRegisters::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -60,7 +59,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
const auto bufferOffset = regDesc.startAddress
- this->gpRegistersMemorySegmentDescriptor.addressRange.startAddress;
- gdbTargetDescriptor.gpRegistersMemorySegmentDescriptor.addressRange.startAddress;
assert((buffer.size() - bufferOffset) >= regVal.size());

View File

@@ -2,11 +2,9 @@
#include <optional>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
#include "src/DebugServer/Gdb/RegisterDescriptor.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -14,16 +12,14 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The ReadRegisters class implements a structure for the "g" command packet. In response to this packet, the
* server is expected to send register values for all registers.
*/
class ReadRegisters: public Gdb::CommandPackets::CommandPacket
class ReadRegisters: public CommandPackets::CommandPacket
{
public:
const Targets::TargetMemorySegmentDescriptor& gpRegistersMemorySegmentDescriptor;
explicit ReadRegisters(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor);
explicit ReadRegisters(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -15,8 +15,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
{}
void VContContinueExecution::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {

View File

@@ -2,7 +2,7 @@
#include <cstdint>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -10,14 +10,14 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The VContContinueExecution class implements a structure for "vCont;c" and "vCont;C" packets. These packets
* instruct the server to continue execution on the target.
*/
class VContContinueExecution: public Gdb::CommandPackets::CommandPacket
class VContContinueExecution: public CommandPackets::CommandPacket
{
public:
explicit VContContinueExecution(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -17,10 +17,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using ResponsePackets::ErrorResponsePacket;
using ::Exceptions::Exception;
VContRangeStep::VContRangeStep(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor)
VContRangeStep::VContRangeStep(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
, programAddressSpaceDescriptor(gdbTargetDescriptor.programAddressSpaceDescriptor)
, programMemorySegmentDescriptor(gdbTargetDescriptor.programMemorySegmentDescriptor)
{
using Services::StringService;
@@ -44,8 +42,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
void VContRangeStep::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -61,7 +59,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
try {
const auto stepAddressRange = Targets::TargetMemoryAddressRange{this->startAddress, this->endAddress};
const auto stepByteSize = stepAddressRange.size() - 1; // -1 because the end address is exclusive
const auto& programMemoryAddressRange = this->programMemorySegmentDescriptor.addressRange;
const auto& programMemoryAddressRange = gdbTargetDescriptor.programMemorySegmentDescriptor.addressRange;
if (
stepAddressRange.startAddress > stepAddressRange.endAddress
@@ -91,8 +89,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
const auto instructionsByAddress = Decoder::decode(
stepAddressRange.startAddress,
targetControllerService.readMemory(
this->programAddressSpaceDescriptor,
this->programMemorySegmentDescriptor,
gdbTargetDescriptor.programAddressSpaceDescriptor,
gdbTargetDescriptor.programMemorySegmentDescriptor,
stepAddressRange.startAddress,
stepByteSize
)

View File

@@ -2,11 +2,8 @@
#include <cstdint>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemorySegmentDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
@@ -16,20 +13,17 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* step through a particular address range, and only report back to GDB when execution leaves that range, or when an
* external breakpoint has been reached.
*/
class VContRangeStep: public Gdb::CommandPackets::CommandPacket
class VContRangeStep: public CommandPackets::CommandPacket
{
public:
const Targets::TargetAddressSpaceDescriptor& programAddressSpaceDescriptor;
const Targets::TargetMemorySegmentDescriptor& programMemorySegmentDescriptor;
Targets::TargetMemoryAddress startAddress;
Targets::TargetMemoryAddress endAddress;
explicit VContRangeStep(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor);
explicit VContRangeStep(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -15,8 +15,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
{}
void VContStepExecution::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {

View File

@@ -2,21 +2,21 @@
#include <cstdint>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
/**
* The VContStepExecution class implements a structure for "vCont;s" and "vCont;S" packets.
*/
class VContStepExecution: public Gdb::CommandPackets::CommandPacket
class VContStepExecution: public CommandPackets::CommandPacket
{
public:
explicit VContStepExecution(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -13,8 +13,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
{}
void VContSupportedActionsQuery::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {

View File

@@ -3,7 +3,7 @@
#include <string>
#include <set>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -13,14 +13,14 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
*
* Responses to this command packet should take the form of a ResponsePackets::SupportedFeaturesResponse.
*/
class VContSupportedActionsQuery: public Gdb::CommandPackets::CommandPacket
class VContSupportedActionsQuery: public CommandPackets::CommandPacket
{
public:
explicit VContSupportedActionsQuery(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;

View File

@@ -16,13 +16,13 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
using namespace Exceptions;
WriteMemory::WriteMemory(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor)
WriteMemory::WriteMemory(const RawPacket& rawPacket, const AvrGdbTargetDescriptor& gdbTargetDescriptor)
: WriteMemory(rawPacket, gdbTargetDescriptor, WriteMemory::extractPacketData(rawPacket))
{}
void WriteMemory::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
@@ -116,7 +116,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
WriteMemory::WriteMemory(
const RawPacket& rawPacket,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
PacketData&& packetData
)
: CommandPacket(rawPacket)

View File

@@ -3,11 +3,10 @@
#include <cstdint>
#include <optional>
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
#include "src/Targets/TargetAddressSpaceDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
namespace DebugServer::Gdb::AvrGdb::CommandPackets
{
@@ -15,7 +14,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
* The WriteMemory class implements the structure for "M" packets. Upon receiving this packet, the server is
* expected to write data to the target's memory, at the specified start address.
*/
class WriteMemory: public Gdb::CommandPackets::CommandPacket
class WriteMemory: public CommandPackets::CommandPacket
{
public:
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor;
@@ -23,11 +22,11 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
Targets::TargetMemorySize bytes;
Targets::TargetMemoryBuffer buffer;
explicit WriteMemory(const RawPacket& rawPacket, const TargetDescriptor& gdbTargetDescriptor);
explicit WriteMemory(const RawPacket& rawPacket, const AvrGdbTargetDescriptor& gdbTargetDescriptor);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;
@@ -41,6 +40,6 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
};
static PacketData extractPacketData(const RawPacket& rawPacket);
WriteMemory(const RawPacket& rawPacket, const Gdb::TargetDescriptor& gdbTargetDescriptor, PacketData&& packetData);
WriteMemory(const RawPacket& rawPacket, const AvrGdbTargetDescriptor& gdbTargetDescriptor, PacketData&& packetData);
};
}

View File

@@ -46,15 +46,15 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
}
void WriteRegister::handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
TargetControllerService& targetControllerService
) {
Logger::info("Handling WriteRegister packet");
try {
if (this->registerId == TargetDescriptor::PROGRAM_COUNTER_GDB_REGISTER_ID) {
if (this->registerId == AvrGdbTargetDescriptor::PROGRAM_COUNTER_GDB_REGISTER_ID) {
if (this->registerValue.size() != 4) {
throw Exception{"Invalid PC value register size"};
}
@@ -72,7 +72,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
return;
}
if (this->registerId == TargetDescriptor::STACK_POINTER_GDB_REGISTER_ID) {
if (this->registerId == AvrGdbTargetDescriptor::STACK_POINTER_GDB_REGISTER_ID) {
if (this->registerValue.size() != 2) {
throw Exception{"Invalid SP register value size"};
}

View File

@@ -1,9 +1,8 @@
#pragma once
#include "src/DebugServer/Gdb/CommandPackets/CommandPacket.hpp"
#include "CommandPacket.hpp"
#include "src/DebugServer/Gdb/RegisterDescriptor.hpp"
#include "src/DebugServer/Gdb/AvrGdb/TargetDescriptor.hpp"
#include "src/Targets/TargetMemory.hpp"
@@ -12,7 +11,7 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
/**
* The WriteRegister class implements the structure for "P" packets.
*/
class WriteRegister: public Gdb::CommandPackets::CommandPacket
class WriteRegister: public CommandPackets::CommandPacket
{
public:
GdbRegisterId registerId;
@@ -21,8 +20,8 @@ namespace DebugServer::Gdb::AvrGdb::CommandPackets
explicit WriteRegister(const RawPacket& rawPacket);
void handle(
Gdb::DebugSession& debugSession,
const Gdb::TargetDescriptor& gdbTargetDescriptor,
DebugSession& debugSession,
const AvrGdbTargetDescriptor& gdbTargetDescriptor,
const Targets::TargetDescriptor& targetDescriptor,
Services::TargetControllerService& targetControllerService
) override;