Files
BloomPatched/src/DebugServers/GdbRsp/CommandPackets/WriteRegister.cpp

32 lines
1.1 KiB
C++
Raw Normal View History

#include "WriteRegister.hpp"
2021-10-02 17:39:27 +01:00
2021-04-04 21:04:12 +01:00
#include "src/DebugServers/GdbRsp/GdbRspDebugServer.hpp"
#include "src/Exceptions/Exception.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom::DebugServers::Gdb::CommandPackets
{
using namespace Bloom::Exceptions;
2021-04-04 21:04:12 +01:00
void WriteRegister::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) {
gdbRspDebugServer.handleGdbPacket(*this);
}
void WriteRegister::init() {
// The P packet updates a single register
auto packet = std::string(this->data.begin(), this->data.end());
2021-04-04 21:04:12 +01:00
if (packet.size() < 4) {
throw Exception("Invalid P command packet - insufficient data in packet.");
}
2021-04-04 21:04:12 +01:00
if (packet.find('=') == std::string::npos) {
throw Exception("Invalid P command packet - unexpected format");
}
2021-04-04 21:04:12 +01:00
auto packetSegments = QString::fromStdString(packet).split("=");
this->registerNumber = static_cast<int>(packetSegments.front().mid(1).toUInt(nullptr, 16));
this->registerValue = Packet::hexToData(packetSegments.back().toStdString());
std::reverse(this->registerValue.begin(), this->registerValue.end());
}
2021-04-04 21:04:12 +01:00
}