From d3c7cddb82c9c3414bfbbb34f63a2f7ee6b59710 Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 22 Nov 2023 00:37:29 +0000 Subject: [PATCH] Added `TargetFamily` to `TargetDescriptor` and comparability check in AVR GDB debug server --- src/DebugServer/DebugServerComponent.cpp | 6 ++++++ src/DebugServer/DebugServerComponent.hpp | 9 +++++++++ src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp | 3 ++- src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.hpp | 1 + src/Targets/Microchip/AVR/AVR8/Avr8.cpp | 1 + src/Targets/TargetDescriptor.hpp | 15 ++++++++++++--- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/DebugServer/DebugServerComponent.cpp b/src/DebugServer/DebugServerComponent.cpp index 88a8dcb5..36ceb2c4 100644 --- a/src/DebugServer/DebugServerComponent.cpp +++ b/src/DebugServer/DebugServerComponent.cpp @@ -14,6 +14,7 @@ namespace DebugServer DebugServerComponent::DebugServerComponent(const DebugServerConfig& debugServerConfig) : debugServerConfig(debugServerConfig) + , targetDescriptor((Services::TargetControllerService()).getTargetDescriptor()) {} void DebugServerComponent::run() { @@ -42,8 +43,13 @@ namespace DebugServer { "avr-gdb-rsp", [this] () -> std::unique_ptr { + if (this->targetDescriptor.family != Targets::TargetFamily::AVR8) { + throw Exceptions::Exception("The AVR GDB RSP server is only compatible with AVR8 targets."); + } + return std::make_unique( this->debugServerConfig, + this->targetDescriptor, *(this->eventListener.get()), this->interruptEventNotifier ); diff --git a/src/DebugServer/DebugServerComponent.hpp b/src/DebugServer/DebugServerComponent.hpp index 617c2f69..bc1aa99a 100644 --- a/src/DebugServer/DebugServerComponent.hpp +++ b/src/DebugServer/DebugServerComponent.hpp @@ -7,12 +7,16 @@ #include "src/Helpers/Thread.hpp" #include "src/ProjectConfig.hpp" + #include "src/Helpers/EventFdNotifier.hpp" #include "src/EventManager/EventListener.hpp" #include "src/EventManager/Events/Events.hpp" #include "ServerInterface.hpp" +#include "src/Services/TargetControllerService.hpp" +#include "src/Targets/TargetDescriptor.hpp" + namespace DebugServer { /** @@ -47,6 +51,11 @@ namespace DebugServer */ DebugServerConfig debugServerConfig; + /** + * The current target descriptor. + */ + Targets::TargetDescriptor targetDescriptor; + /** * This EventFdNotifier is injected into this->eventListener. It can be used by server implementations to * interrupt blocking I/O calls upon an event being triggered. For more, see the "Servicing events" section in diff --git a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp index 841628ed..28af8436 100644 --- a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp +++ b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.cpp @@ -26,11 +26,12 @@ namespace DebugServer::Gdb::AvrGdb AvrGdbRsp::AvrGdbRsp( const DebugServerConfig& debugServerConfig, + const Targets::TargetDescriptor& targetDescriptor, EventListener& eventListener, EventFdNotifier& eventNotifier ) : GdbRspDebugServer(debugServerConfig, eventListener, eventNotifier) - , gdbTargetDescriptor(TargetDescriptor(this->targetControllerService.getTargetDescriptor())) + , gdbTargetDescriptor(targetDescriptor) {} DebugSession* AvrGdbRsp::startDebugSession(Connection&& connection) { diff --git a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.hpp b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.hpp index 1e648366..3401c1aa 100644 --- a/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.hpp +++ b/src/DebugServer/Gdb/AvrGdb/AvrGdbRsp.hpp @@ -14,6 +14,7 @@ namespace DebugServer::Gdb::AvrGdb public: AvrGdbRsp( const DebugServerConfig& debugServerConfig, + const Targets::TargetDescriptor& targetDescriptor, EventListener& eventListener, EventFdNotifier& eventNotifier ); diff --git a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp index b44ab97c..47e832ad 100644 --- a/src/Targets/Microchip/AVR/AVR8/Avr8.cpp +++ b/src/Targets/Microchip/AVR/AVR8/Avr8.cpp @@ -268,6 +268,7 @@ namespace Targets::Microchip::Avr::Avr8Bit TargetDescriptor Avr8::getDescriptor() { auto descriptor = TargetDescriptor( this->signature.toHex(), + TargetFamily::AVR8, this->name, "Microchip", this->targetMemoryDescriptorsByType, diff --git a/src/Targets/TargetDescriptor.hpp b/src/Targets/TargetDescriptor.hpp index 02e88f1f..9a907ce1 100644 --- a/src/Targets/TargetDescriptor.hpp +++ b/src/Targets/TargetDescriptor.hpp @@ -14,10 +14,17 @@ namespace Targets { + enum class TargetFamily: std::uint8_t + { + AVR8, + RISC_V, + }; + struct TargetDescriptor { - std::string name; std::string id; + TargetFamily family; + std::string name; std::string vendorName; std::map memoryDescriptorsByType; std::map registerDescriptorsById; @@ -28,6 +35,7 @@ namespace Targets TargetDescriptor( const std::string& id, + TargetFamily family, const std::string& name, const std::string& vendorName, const std::map& memoryDescriptorsByType, @@ -36,8 +44,9 @@ namespace Targets const std::vector& variants, TargetMemoryType programMemoryType ) - : name(name) - , id(id) + : id(id) + , family(family) + , name(name) , vendorName(vendorName) , memoryDescriptorsByType(memoryDescriptorsByType) , registerDescriptorsById(registerDescriptorsById)