GDB register descriptor

This commit is contained in:
Nav
2021-12-28 00:00:45 +00:00
parent 7e76503969
commit ca0bcdeda4
5 changed files with 72 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
#include <cstdint>
#include "src/DebugServers/GdbRsp/GdbRspDebugServer.hpp"
#include "src/DebugServers/GdbRsp/Register.hpp"
#include "src/DebugServers/GdbRsp/RegisterDescriptor.hpp"
#include "src/Helpers/BiMap.hpp"
namespace Bloom::DebugServers::Gdb

View File

@@ -4,6 +4,8 @@
#include "CommandPacket.hpp"
#include "src/DebugServers/GdbRsp/RegisterDescriptor.hpp"
namespace Bloom::DebugServers::Gdb::CommandPackets
{
/**
@@ -21,7 +23,7 @@ namespace Bloom::DebugServers::Gdb::CommandPackets
* If the register number is not supplied (as is the case with "g" packets), the server is expected to respond
* with values for all registers.
*/
std::optional<int> registerNumber;
std::optional<GdbRegisterNumberType> registerNumber;
explicit ReadRegisters(const std::vector<unsigned char>& rawPacket): CommandPacket(rawPacket) {
init();

View File

@@ -9,7 +9,7 @@
#include "../DebugServer.hpp"
#include "Connection.hpp"
#include "Signal.hpp"
#include "Register.hpp"
#include "RegisterDescriptor.hpp"
#include "Feature.hpp"
#include "src/Helpers/EventNotifier.hpp"
#include "src/Helpers/BiMap.hpp"

View File

@@ -1,6 +0,0 @@
#pragma once
namespace Bloom::DebugServers::Gdb
{
using GdbRegisterNumber = int;
}

View File

@@ -0,0 +1,67 @@
#pragma once
#include <cstdint>
#include <string>
namespace Bloom::DebugServers::Gdb
{
using GdbRegisterNumberType = int;
/*
* GDB defines a set of registers for each target architecture.
*
* Each register in the set is assigned a register number, which is used to identify the register.
*/
struct RegisterDescriptor
{
GdbRegisterNumberType number;
std::uint16_t size;
std::string name;
RegisterDescriptor(GdbRegisterNumberType number, std::uint16_t size, const std::string& name)
: number(number), size(size), name(name) {};
bool operator == (const RegisterDescriptor& other) const {
return this->number == other.number;
}
bool operator != (const RegisterDescriptor& other) const {
return !(*this == other);
}
bool operator < (const RegisterDescriptor& rhs) const {
return this->number < rhs.number;
}
bool operator > (const RegisterDescriptor& rhs) const {
return rhs < *this;
}
bool operator <= (const RegisterDescriptor& rhs) const {
return !(rhs < *this);
}
bool operator >= (const RegisterDescriptor& rhs) const {
return !(*this < rhs);
}
};
}
namespace std
{
/**
* Hashing function for RegisterDescriptor type.
*
* This is required in order to use RegisterDescriptor as a key in an std::unordered_map (see the BiMap
* class).
*/
template<>
class hash<Bloom::DebugServers::Gdb::RegisterDescriptor>
{
public:
std::size_t operator () (const Bloom::DebugServers::Gdb::RegisterDescriptor& descriptor) const {
// We use the GDB register number as the hash, as it is unique to the register.
return static_cast<size_t>(descriptor.number);
}
};
}