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-24 19:17:41 +00:00
|
|
|
|
2022-03-31 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/SupportedFeaturesResponse.hpp"
|
|
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
#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
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace DebugServer::Gdb::CommandPackets
|
2022-02-05 15:32:08 +00:00
|
|
|
{
|
2022-12-26 21:27:19 +00:00
|
|
|
using Services::TargetControllerService;
|
2022-04-09 15:57:24 +01:00
|
|
|
|
2022-03-24 19:17:41 +00:00
|
|
|
using ResponsePackets::SupportedFeaturesResponse;
|
|
|
|
|
using ResponsePackets::ErrorResponsePacket;
|
|
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
using Exceptions::ClientNotSupported;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-10-01 21:01:37 +01:00
|
|
|
SupportedFeaturesQuery::SupportedFeaturesQuery(const RawPacket& rawPacket)
|
2022-04-03 17:25:21 +01:00
|
|
|
: CommandPacket(rawPacket)
|
|
|
|
|
{
|
2022-02-05 15:32:08 +00:00
|
|
|
/*
|
2022-04-03 17:25:21 +01:00
|
|
|
* For qSupported packets, supported and unsupported GDB features are reported in the packet data, where each
|
|
|
|
|
* GDB feature is separated by a semicolon.
|
2022-02-05 15:32:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// The "qSupported:" prefix occupies 11 bytes
|
2022-04-03 16:59:14 +01:00
|
|
|
if (this->data.size() > 11) {
|
|
|
|
|
const auto packetData = QString::fromLocal8Bit(
|
2022-02-05 15:32:08 +00:00
|
|
|
reinterpret_cast<const char*>(this->data.data() + 11),
|
|
|
|
|
static_cast<int>(this->data.size() - 11)
|
|
|
|
|
);
|
|
|
|
|
|
2022-04-03 16:59:14 +01:00
|
|
|
const auto featureList = packetData.split(";");
|
|
|
|
|
static const auto gdbFeatureMapping = getGdbFeatureToNameMapping();
|
2022-02-05 15:32:08 +00:00
|
|
|
|
2022-04-03 16:59:14 +01:00
|
|
|
for (auto featureName : featureList) {
|
2022-02-05 15:32:08 +00:00
|
|
|
// We only care about supported features. Supported features will precede a '+' character.
|
2022-04-03 16:59:14 +01:00
|
|
|
if (featureName[featureName.size() - 1] == '+') {
|
|
|
|
|
featureName.remove('+');
|
2022-02-05 15:32:08 +00:00
|
|
|
|
2022-04-03 16:59:14 +01:00
|
|
|
const auto feature = gdbFeatureMapping.valueAt(featureName.toStdString());
|
2022-02-05 15:32:08 +00:00
|
|
|
if (feature.has_value()) {
|
2022-04-03 16:59:14 +01:00
|
|
|
this->supportedFeatures.insert(feature.value());
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2022-12-26 21:27:19 +00:00
|
|
|
void SupportedFeaturesQuery::handle(DebugSession& debugSession, TargetControllerService& targetControllerService) {
|
2023-05-07 20:17:33 +01:00
|
|
|
Logger::info("Handling QuerySupport packet");
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
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
|
2022-05-14 22:38:49 +01:00
|
|
|
debugSession.connection.writePacket(SupportedFeaturesResponse(debugSession.supportedFeatures));
|
2022-03-24 19:17:41 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|