Files
BloomPatched/src/DebugServer/Gdb/TargetDescriptor.hpp

93 lines
3.7 KiB
C++
Raw Normal View History

2022-03-24 19:04:18 +00:00
#pragma once
#include <cstdint>
#include <optional>
#include <vector>
#include <set>
#include <map>
2022-03-24 19:04:18 +00:00
#include "src/Helpers/BiMap.hpp"
2022-03-24 19:04:18 +00:00
#include "src/Targets/TargetDescriptor.hpp"
#include "src/Targets/TargetRegister.hpp"
#include "src/Targets/TargetMemory.hpp"
2022-03-24 19:04:18 +00:00
2022-03-25 00:19:32 +00:00
#include "RegisterDescriptor.hpp"
namespace Bloom::DebugServer::Gdb
2022-03-24 19:04:18 +00:00
{
2022-04-03 17:00:40 +01:00
/**
* GDB target descriptor.
*/
class TargetDescriptor
2022-03-24 19:04:18 +00:00
{
public:
Targets::TargetDescriptor targetDescriptor;
std::map<GdbRegisterId, RegisterDescriptor> gdbRegisterDescriptorsById;
2022-03-24 19:04:18 +00:00
explicit TargetDescriptor(
const Targets::TargetDescriptor& targetDescriptor,
const BiMap<Targets::TargetMemoryType, std::uint32_t>& memoryOffsetsByType,
std::map<GdbRegisterId, RegisterDescriptor> gdbRegisterDescriptorsById,
std::map<Targets::TargetRegisterDescriptorId, GdbRegisterId> gdbRegisterIdsByTargetRegisterDescriptorId,
std::map<GdbRegisterId, Targets::TargetRegisterDescriptorId> targetRegisterDescriptorIdsByGdbRegisterId
);
2022-03-24 19:04:18 +00:00
virtual ~TargetDescriptor() = default;
std::uint32_t getMemoryOffset(Targets::TargetMemoryType memoryType) const;
2022-10-25 19:13:02 +01:00
/**
* Helper method to extract the target memory type (Flash, RAM, etc) from a GDB memory address.
*
* @param address
* @return
*/
Targets::TargetMemoryType getMemoryTypeFromGdbAddress(std::uint32_t address) const;
2022-03-24 19:04:18 +00:00
/**
* Should retrieve the GDB register ID, given a target register descriptor ID. Or std::nullopt if the
* target register descriptor ID isn't mapped to any GDB register.
2022-03-24 19:04:18 +00:00
*
* @param registerDescriptorId
2022-03-24 19:04:18 +00:00
* @return
*/
std::optional<GdbRegisterId> getGdbRegisterIdFromTargetRegisterDescriptorId(
Targets::TargetRegisterDescriptorId targetRegisterDescriptorId
) const;
2022-03-24 19:04:18 +00:00
/**
* Should retrieve the mapped target register descriptor ID for a given GDB register ID.
2022-03-24 19:04:18 +00:00
*
* This function may return std::nullopt if the GDB register ID maps to something that isn't considered a
* register on our end. For example, for AVR targets, the GDB register ID 34 maps to the program counter. But
* the program counter is not treated like any other register in Bloom (there's no TargetRegisterDescriptor for
* it). So in that case, the GDB register ID is not mapped to any target register descriptor ID.
2022-03-24 19:04:18 +00:00
*
* @param gdbRegisterId
2022-03-24 19:04:18 +00:00
* @return
*/
std::optional<Targets::TargetRegisterDescriptorId> getTargetRegisterDescriptorIdFromGdbRegisterId(
GdbRegisterId gdbRegisterId
) const;
protected:
2022-10-25 19:13:02 +01:00
/**
* When GDB sends us a memory address, the memory type (Flash, RAM, EEPROM, etc) is embedded within. This is
* done by ORing the address with some constant. For example, for AVR targets, RAM addresses are ORed with
* 0x00800000. Flash addresses are left unchanged. EEPROM addressing is not supported in GDB (for AVR targets).
*
* memoryOffsetsByType is a mapping of memory types to these known constants (which we're calling offsets).
* Because these offsets vary by target, the mapping lives here, in the GDB target descriptor.
*/
BiMap<Targets::TargetMemoryType, std::uint32_t> memoryOffsetsByType;
2022-10-25 19:13:02 +01:00
/**
* Sorted set of the known memory offsets (see memoryOffsetsByType).
*/
std::set<std::uint32_t> memoryOffsets;
std::map<Targets::TargetRegisterDescriptorId, GdbRegisterId> gdbRegisterIdsByTargetRegisterDescriptorId;
std::map<GdbRegisterId, Targets::TargetRegisterDescriptorId> targetRegisterDescriptorIdsByGdbRegisterId;
2022-03-24 19:04:18 +00:00
};
}