2021-08-07 17:07:04 +01:00
|
|
|
#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"
|
2021-05-24 20:58:49 +01:00
|
|
|
#include "src/Exceptions/Exception.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
|
|
|
|
using namespace Bloom::DebugServers::Gdb::CommandPackets;
|
2021-05-24 20:58:49 +01:00
|
|
|
using namespace Bloom::Exceptions;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2021-10-06 21:12:31 +01:00
|
|
|
void WriteRegister::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) {
|
|
|
|
|
gdbRspDebugServer.handleGdbPacket(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-07 17:07:04 +01:00
|
|
|
void WriteRegister::init() {
|
2021-04-04 21:04:12 +01:00
|
|
|
// The P packet updates a single register
|
|
|
|
|
auto packet = std::string(this->data.begin(), this->data.end());
|
|
|
|
|
|
2021-06-26 03:39:48 +01:00
|
|
|
if (packet.size() < 4) {
|
2021-04-04 21:04:12 +01:00
|
|
|
throw Exception("Invalid P command packet - insufficient data in packet.");
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-22 23:52:31 +01:00
|
|
|
if (packet.find('=') == std::string::npos) {
|
2021-04-04 21:04:12 +01:00
|
|
|
throw Exception("Invalid P command packet - unexpected format");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto packetSegments = QString::fromStdString(packet).split("=");
|
2021-08-18 22:51:15 +01:00
|
|
|
this->registerNumber = static_cast<int>(packetSegments.front().mid(1).toUInt(nullptr, 16));
|
2021-06-22 23:52:31 +01:00
|
|
|
this->registerValue = Packet::hexToData(packetSegments.back().toStdString());
|
2021-04-04 21:04:12 +01:00
|
|
|
std::reverse(this->registerValue.begin(), this->registerValue.end());
|
|
|
|
|
}
|