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"
|
|
|
|
|
#include "src/Exceptions/Exception.hpp"
|
2022-03-31 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/Exceptions/ClientNotSupported.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-03-31 16:05:39 +01:00
|
|
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
2022-02-05 15:32:08 +00:00
|
|
|
{
|
2022-04-09 15:57:24 +01:00
|
|
|
using TargetController::TargetControllerConsole;
|
|
|
|
|
|
2022-03-24 19:17:41 +00:00
|
|
|
using ResponsePackets::SupportedFeaturesResponse;
|
|
|
|
|
using ResponsePackets::ErrorResponsePacket;
|
|
|
|
|
|
|
|
|
|
using Bloom::Exceptions::Exception;
|
|
|
|
|
using Gdb::Exceptions::ClientNotSupported;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-04-08 23:39:51 +01:00
|
|
|
SupportedFeaturesQuery::SupportedFeaturesQuery(const RawPacketType& 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
|
|
|
|
|
|
|
|
void SupportedFeaturesQuery::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) {
|
|
|
|
|
Logger::debug("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
|
2022-04-03 16:59:14 +01:00
|
|
|
debugSession.connection.writePacket(SupportedFeaturesResponse({
|
2022-03-24 19:17:41 +00:00
|
|
|
{Feature::SOFTWARE_BREAKPOINTS, std::nullopt},
|
|
|
|
|
{Feature::PACKET_SIZE, std::to_string(debugSession.connection.getMaxPacketSize())},
|
2022-04-03 16:59:14 +01:00
|
|
|
}));
|
2022-03-24 19:17:41 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|