Tidied GDB response packet classes
This commit is contained in:
@@ -10,10 +10,8 @@ namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
class ErrorResponsePacket: public ResponsePacket
|
||||
{
|
||||
public:
|
||||
ErrorResponsePacket() = default;
|
||||
|
||||
[[nodiscard]] std::vector<unsigned char> getData() const override {
|
||||
return {'E', '0', '1'};
|
||||
}
|
||||
ErrorResponsePacket()
|
||||
: ResponsePacket(std::vector<unsigned char>{'E', '0', '1'})
|
||||
{};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
class OkResponsePacket: public ResponsePacket
|
||||
{
|
||||
public:
|
||||
OkResponsePacket() = default;
|
||||
|
||||
[[nodiscard]] std::vector<unsigned char> getData() const override {
|
||||
return {'O', 'K'};
|
||||
}
|
||||
OkResponsePacket()
|
||||
: ResponsePacket(std::vector<unsigned char>{'O', 'K'})
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "src/DebugServer/Gdb/Packet.hpp"
|
||||
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
{
|
||||
std::vector<unsigned char> SupportedFeaturesResponse::getData() const {
|
||||
std::string output = "qSupported:";
|
||||
auto gdbFeatureMapping = getGdbFeatureToNameMapping();
|
||||
SupportedFeaturesResponse::SupportedFeaturesResponse(
|
||||
const std::set<std::pair<Feature, std::optional<std::string>>>& supportedFeatures
|
||||
)
|
||||
: supportedFeatures(supportedFeatures)
|
||||
{
|
||||
auto output = std::string("qSupported:");
|
||||
static const auto gdbFeatureMapping = getGdbFeatureToNameMapping();
|
||||
|
||||
for (const auto& supportedFeature : this->supportedFeatures) {
|
||||
auto featureString = gdbFeatureMapping.valueAt(supportedFeature.first);
|
||||
const auto featureString = gdbFeatureMapping.valueAt(supportedFeature.first);
|
||||
|
||||
if (featureString.has_value()) {
|
||||
if (supportedFeature.second.has_value()) {
|
||||
@@ -20,6 +24,6 @@ namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
}
|
||||
}
|
||||
|
||||
return std::vector<unsigned char>(output.begin(), output.end());
|
||||
this->data = {output.begin(), output.end()};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
#include <utility>
|
||||
|
||||
#include "ResponsePacket.hpp"
|
||||
#include "../Feature.hpp"
|
||||
|
||||
#include "src/DebugServer/Gdb/Feature.hpp"
|
||||
|
||||
namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
{
|
||||
@@ -14,13 +15,11 @@ namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
class SupportedFeaturesResponse: public ResponsePacket
|
||||
{
|
||||
public:
|
||||
SupportedFeaturesResponse() = default;
|
||||
explicit SupportedFeaturesResponse(std::set<std::pair<Feature, std::optional<std::string>>> supportedFeatures)
|
||||
: supportedFeatures(std::move(supportedFeatures)) {};
|
||||
explicit SupportedFeaturesResponse(
|
||||
const std::set<std::pair<Feature, std::optional<std::string>>>& supportedFeatures
|
||||
);
|
||||
|
||||
[[nodiscard]] std::vector<unsigned char> getData() const override;
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::set<std::pair<Feature, std::optional<std::string>>> supportedFeatures;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "ResponsePacket.hpp"
|
||||
#include "../Signal.hpp"
|
||||
#include "../StopReason.hpp"
|
||||
#include "src/Targets/TargetRegister.hpp"
|
||||
|
||||
#include "src/DebugServer/Gdb/Signal.hpp"
|
||||
#include "src/DebugServer/Gdb/StopReason.hpp"
|
||||
|
||||
namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
{
|
||||
@@ -17,21 +17,22 @@ namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||
Signal signal;
|
||||
std::optional<StopReason> stopReason;
|
||||
|
||||
explicit TargetStopped(Signal signal): signal(signal) {}
|
||||
|
||||
[[nodiscard]] std::vector<unsigned char> getData() const override {
|
||||
std::string output = "T" + Packet::toHex(std::vector({static_cast<unsigned char>(this->signal)}));
|
||||
explicit TargetStopped(Signal signal, const std::optional<StopReason>& stopReason = std::nullopt)
|
||||
: signal(signal)
|
||||
, stopReason(stopReason)
|
||||
{
|
||||
std::string packetData = "T" + Packet::toHex(std::vector({static_cast<unsigned char>(this->signal)}));
|
||||
|
||||
if (this->stopReason.has_value()) {
|
||||
auto stopReasonMapping = getStopReasonToNameMapping();
|
||||
auto stopReasonName = stopReasonMapping.valueAt(this->stopReason.value());
|
||||
static const auto stopReasonMapping = getStopReasonToNameMapping();
|
||||
const auto stopReasonName = stopReasonMapping.valueAt(this->stopReason.value());
|
||||
|
||||
if (stopReasonName.has_value()) {
|
||||
output += stopReasonName.value() + ":;";
|
||||
packetData += stopReasonName.value() + ":;";
|
||||
}
|
||||
}
|
||||
|
||||
return std::vector<unsigned char>(output.begin(), output.end());
|
||||
this->data = {packetData.begin(), packetData.end()};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user