Files
BloomPatched/src/DebugServer/Gdb/CommandPackets/SupportedFeaturesQuery.cpp

74 lines
2.7 KiB
C++
Raw Normal View History

2021-10-02 17:39:27 +01:00
#include "SupportedFeaturesQuery.hpp"
2021-04-04 21:04:12 +01:00
#include <QtCore/QString>
2022-03-31 21:52:46 +01:00
#include "src/DebugServer/Gdb/Feature.hpp"
2022-03-31 21:52:46 +01:00
#include "src/DebugServer/Gdb/ResponsePackets/SupportedFeaturesResponse.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/Logger/Logger.hpp"
2022-03-31 21:52:46 +01:00
#include "src/DebugServer/Gdb/Exceptions/ClientNotSupported.hpp"
2021-04-04 21:04:12 +01:00
namespace DebugServer::Gdb::CommandPackets
{
using Services::TargetControllerService;
using ResponsePackets::SupportedFeaturesResponse;
using ResponsePackets::ErrorResponsePacket;
using Exceptions::ClientNotSupported;
2021-04-04 21:04:12 +01:00
2022-10-01 21:01:37 +01:00
SupportedFeaturesQuery::SupportedFeaturesQuery(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
{
/*
* For qSupported packets, supported and unsupported GDB features are reported in the packet data, where each
* GDB feature is separated by a semicolon.
*/
// The "qSupported:" prefix occupies 11 bytes
if (this->data.size() > 11) {
const auto packetData = QString::fromLocal8Bit(
reinterpret_cast<const char*>(this->data.data() + 11),
static_cast<int>(this->data.size() - 11)
);
const auto featureList = packetData.split(";");
static const auto gdbFeatureMapping = getGdbFeatureToNameMapping();
for (auto featureName : featureList) {
// We only care about supported features. Supported features will precede a '+' character.
if (featureName[featureName.size() - 1] == '+') {
featureName.remove('+');
const auto feature = gdbFeatureMapping.valueAt(featureName.toStdString());
if (feature.has_value()) {
this->supportedFeatures.insert(feature.value());
}
2021-04-04 21:04:12 +01:00
}
}
}
}
void SupportedFeaturesQuery::handle(
DebugSession& debugSession,
const TargetDescriptor&,
const Targets::TargetDescriptor&,
TargetControllerService& targetControllerService
) {
Logger::info("Handling QuerySupport packet");
if (
!this->isFeatureSupported(Feature::HARDWARE_BREAKPOINTS)
&& !this->isFeatureSupported(Feature::SOFTWARE_BREAKPOINTS)
) {
// All GDB clients are expected to support breakpoints!
throw ClientNotSupported{"GDB client does not support HW or SW breakpoints"};
}
// Respond with a SupportedFeaturesResponse packet, listing all supported GDB features by Bloom
debugSession.connection.writePacket(SupportedFeaturesResponse{debugSession.supportedFeatures});
}
2021-04-04 21:04:12 +01:00
}