More tidying in GDB command packet classes

This commit is contained in:
Nav
2022-04-03 16:59:14 +01:00
parent 2febc27805
commit 81ff76a1a3
5 changed files with 20 additions and 25 deletions

View File

@@ -17,10 +17,10 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
{
public:
/**
* The "c" packet can contain an address which defines the point from which the execution should be resumed on
* The "c" packet can contain an address which specifies the point from which the execution should be resumed on
* the target.
*
* Although the packet *can* contain this address, it is not required, hence the optional.
* Although the packet *can* contain this address, it is not required, hence the std::optional type.
*/
std::optional<std::uint32_t> fromProgramCounter;

View File

@@ -1,6 +1,5 @@
#include "ReadRegisters.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/TargetStopped.hpp"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/Targets/TargetRegister.hpp"

View File

@@ -20,15 +20,15 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
using Exceptions::Exception;
void RemoveBreakpoint::init() {
if (data.size() < 6) {
if (this->data.size() < 6) {
throw Exception("Unexpected RemoveBreakpoint packet size");
}
// z0 = SW breakpoint, z1 = HW breakpoint
this->type = (data[1] == 0) ? BreakpointType::SOFTWARE_BREAKPOINT : (data[1] == 1) ?
this->type = (this->data[1] == 0) ? BreakpointType::SOFTWARE_BREAKPOINT : (this->data[1] == 1) ?
BreakpointType::HARDWARE_BREAKPOINT : BreakpointType::UNKNOWN;
auto packetData = QString::fromLocal8Bit(
const auto packetData = QString::fromLocal8Bit(
reinterpret_cast<const char*>(this->data.data() + 2),
static_cast<int>(this->data.size() - 2)
);
@@ -50,10 +50,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
Logger::debug("Removing breakpoint at address " + std::to_string(this->address));
try {
auto breakpoint = TargetBreakpoint();
breakpoint.address = this->address;
targetControllerConsole.removeBreakpoint(breakpoint);
targetControllerConsole.removeBreakpoint(TargetBreakpoint(this->address));
debugSession.connection.writePacket(OkResponsePacket());
} catch (const Exception& exception) {

View File

@@ -26,25 +26,23 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
*/
// The "qSupported:" prefix occupies 11 bytes
if (data.size() > 11) {
auto packetData = QString::fromLocal8Bit(
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)
);
auto featureList = packetData.split(";");
auto gdbFeatureMapping = getGdbFeatureToNameMapping();
for (int i = 0; i < featureList.size(); i++) {
auto featureString = featureList.at(i);
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 (featureString[featureString.size() - 1] == '+') {
featureString.remove('+');
if (featureName[featureName.size() - 1] == '+') {
featureName.remove('+');
auto feature = gdbFeatureMapping.valueAt(featureString.toStdString());
const auto feature = gdbFeatureMapping.valueAt(featureName.toStdString());
if (feature.has_value()) {
this->supportedFeatures.insert(static_cast<decltype(feature)::value_type>(feature.value()));
this->supportedFeatures.insert(feature.value());
}
}
}
@@ -62,11 +60,9 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
}
// Respond with a SupportedFeaturesResponse packet, listing all supported GDB features by Bloom
auto response = SupportedFeaturesResponse({
debugSession.connection.writePacket(SupportedFeaturesResponse({
{Feature::SOFTWARE_BREAKPOINTS, std::nullopt},
{Feature::PACKET_SIZE, std::to_string(debugSession.connection.getMaxPacketSize())},
});
debugSession.connection.writePacket(response);
}));
}
}

View File

@@ -20,5 +20,8 @@ namespace Bloom::Targets
TargetBreakpointAddress address = 0;
bool disabled = false;
TargetBreakpoint() = default;
explicit TargetBreakpoint(TargetBreakpointAddress address): address(address) {};
};
}