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

49 lines
1.5 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#include "ReadMemory.hpp"
2021-10-02 17:39:27 +01:00
2021-04-04 21:04:12 +01:00
#include "src/DebugServers/GdbRsp/GdbRspDebugServer.hpp"
namespace Bloom::DebugServers::Gdb::CommandPackets
{
using namespace Bloom::Exceptions;
2021-04-04 21:04:12 +01:00
void ReadMemory::dispatchToHandler(Gdb::GdbRspDebugServer& gdbRspDebugServer) {
gdbRspDebugServer.handleGdbPacket(*this);
2021-04-04 21:04:12 +01:00
}
void ReadMemory::init() {
if (this->data.size() < 4) {
throw Exception("Invalid packet length");
}
2021-04-04 21:04:12 +01:00
auto packetString = QString::fromLocal8Bit(
reinterpret_cast<const char*>(this->data.data() + 1),
static_cast<int>(this->data.size() - 1)
);
2021-04-04 21:04:12 +01:00
/*
* The read memory ('m') packet consists of two segments, an address and a number of bytes to read.
* These are separated by a comma character.
*/
auto packetSegments = packetString.split(",");
2021-04-04 21:04:12 +01:00
if (packetSegments.size() != 2) {
throw Exception(
"Unexpected number of segments in packet data: " + std::to_string(packetSegments.size())
);
}
2021-04-04 21:04:12 +01:00
bool conversionStatus = false;
this->startAddress = packetSegments.at(0).toUInt(&conversionStatus, 16);
if (!conversionStatus) {
throw Exception("Failed to parse start address from read memory packet data");
}
2021-04-04 21:04:12 +01:00
this->bytes = packetSegments.at(1).toUInt(&conversionStatus, 16);
2021-04-04 21:04:12 +01:00
if (!conversionStatus) {
throw Exception("Failed to parse read length from read memory packet data");
}
2021-04-04 21:04:12 +01:00
}
}