From 1db70be31edaed3716c33124148e2a46424d859b Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 26 Oct 2024 17:18:42 +0100 Subject: [PATCH] Move AVR-specific GDB memory address translation to `AvrGdbTargetDescriptor` --- .../Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp | 37 ++++++++++++++--- src/DebugServer/Gdb/TargetDescriptor.hpp | 41 +------------------ 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp b/src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp index c3c9a865..9c1e5456 100644 --- a/src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp +++ b/src/DebugServer/Gdb/AvrGdb/AvrGdbTargetDescriptor.hpp @@ -3,6 +3,7 @@ #include "src/DebugServer/Gdb/TargetDescriptor.hpp" #include "src/Targets/TargetDescriptor.hpp" +#include "src/Targets/TargetMemory.hpp" #include "src/Targets/TargetAddressSpaceDescriptor.hpp" #include "src/Targets/TargetMemorySegmentDescriptor.hpp" #include "src/Targets/TargetPeripheralDescriptor.hpp" @@ -35,15 +36,41 @@ namespace DebugServer::Gdb::AvrGdb explicit AvrGdbTargetDescriptor(const Targets::TargetDescriptor& targetDescriptor); - const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptorFromGdbAddress( + /** + * For AVR targets, GDB encodes address space information into memory addresses, by applying a mask. + * + * This function identifies the encoded address space within the given GDB memory address, and returns the + * relevant address space descriptor. + * + * @param address + * @return + */ + [[nodiscard]] const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptorFromGdbAddress( GdbMemoryAddress address - ) const override; + ) const; - Targets::TargetMemoryAddress translateGdbAddress(GdbMemoryAddress address) const override; - GdbMemoryAddress translateTargetMemoryAddress( + /** + * This function translates a GDB memory address to a target memory address. It will strip away any + * GDB-specific masks and return an address that can be used within Bloom. + * + * @param address + * @return + */ + [[nodiscard]] Targets::TargetMemoryAddress translateGdbAddress(GdbMemoryAddress address) const; + + /** + * This function translates a target memory address to a GDB memory address. It will encode address space + * information into the address, as expected by GDB. + * + * @param address + * @param addressSpaceDescriptor + * @param memorySegmentDescriptor + * @return + */ + [[nodiscard]] GdbMemoryAddress translateTargetMemoryAddress( Targets::TargetMemoryAddress address, const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor - ) const override; + ) const; }; } diff --git a/src/DebugServer/Gdb/TargetDescriptor.hpp b/src/DebugServer/Gdb/TargetDescriptor.hpp index 413d1d89..bbd276db 100644 --- a/src/DebugServer/Gdb/TargetDescriptor.hpp +++ b/src/DebugServer/Gdb/TargetDescriptor.hpp @@ -6,7 +6,6 @@ #include #include -#include "src/Helpers/BiMap.hpp" #include "src/Targets/TargetDescriptor.hpp" #include "src/Targets/TargetRegisterDescriptor.hpp" #include "src/Targets/TargetMemory.hpp" @@ -18,7 +17,7 @@ namespace DebugServer::Gdb using GdbMemoryAddress = std::uint32_t; /** - * GDB target descriptor. + * Generic GDB target descriptor. */ class TargetDescriptor { @@ -27,43 +26,5 @@ namespace DebugServer::Gdb std::map targetRegisterDescriptorsByGdbId; virtual ~TargetDescriptor() = default; - - /** - * For targets with multiple address spaces (e.g. AVR), GDB encodes address space information into memory - * addresses, by applying a mask. - * - * This function should identify the encoded address space within a GDB memory address, and return the - * relevant address space descriptor. - * - * @param address - * @return - */ - virtual const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptorFromGdbAddress( - GdbMemoryAddress address - ) const = 0; - - /** - * This function should translate a GDB memory address to a target memory address. This should strip any - * GDB-specific masks and return an address that can be used within Bloom. - * - * @param address - * @return - */ - virtual Targets::TargetMemoryAddress translateGdbAddress(GdbMemoryAddress address) const = 0; - - /** - * This function should translate a target memory address to a GDB memory address. It should encode any - * additional data expected by GDB. - * - * @param address - * @param addressSpaceDescriptor - * @param memorySegmentDescriptor - * @return - */ - virtual GdbMemoryAddress translateTargetMemoryAddress( - Targets::TargetMemoryAddress address, - const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor, - const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor - ) const = 0; }; }