Files
BloomPatched/src/DebugServer/GdbRsp/CommandPackets/RemoveBreakpoint.cpp

65 lines
2.2 KiB
C++
Raw Normal View History

2021-10-02 17:39:27 +01:00
#include "RemoveBreakpoint.hpp"
2021-04-04 21:04:12 +01:00
#include <QtCore/QString>
#include "src/DebugServer/GdbRsp/ResponsePackets/OkResponsePacket.hpp"
#include "src/DebugServer/GdbRsp/ResponsePackets/ErrorResponsePacket.hpp"
#include "src/Targets/TargetBreakpoint.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom::DebugServer::Gdb::CommandPackets
{
using Targets::TargetBreakpoint;
2021-04-04 21:04:12 +01:00
using ResponsePackets::OkResponsePacket;
using ResponsePackets::ErrorResponsePacket;
using Exceptions::Exception;
2021-04-04 21:04:12 +01:00
void RemoveBreakpoint::init() {
if (data.size() < 6) {
throw Exception("Unexpected RemoveBreakpoint packet size");
}
2021-04-04 21:04:12 +01:00
// z0 = SW breakpoint, z1 = HW breakpoint
this->type = (data[1] == 0) ? BreakpointType::SOFTWARE_BREAKPOINT : (data[1] == 1) ?
BreakpointType::HARDWARE_BREAKPOINT : BreakpointType::UNKNOWN;
2021-04-04 21:04:12 +01:00
auto packetData = QString::fromLocal8Bit(
reinterpret_cast<const char*>(this->data.data() + 2),
static_cast<int>(this->data.size() - 2)
);
auto packetSegments = packetData.split(",");
if (packetSegments.size() < 3) {
throw Exception("Unexpected number of packet segments in RemoveBreakpoint packet");
}
2021-04-04 21:04:12 +01:00
bool conversionStatus = true;
this->address = packetSegments.at(1).toUInt(&conversionStatus, 16);
2021-04-04 21:04:12 +01:00
if (!conversionStatus) {
throw Exception("Failed to convert address hex value from RemoveBreakpoint packet.");
}
2021-04-04 21:04:12 +01:00
}
void RemoveBreakpoint::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) {
Logger::debug("Removing breakpoint at address " + std::to_string(this->address));
try {
auto breakpoint = TargetBreakpoint();
breakpoint.address = this->address;
targetControllerConsole.removeBreakpoint(breakpoint);
debugSession.connection.writePacket(OkResponsePacket());
} catch (const Exception& exception) {
Logger::error("Failed to remove breakpoint on target - " + exception.getMessage());
debugSession.connection.writePacket(ErrorResponsePacket());
}
}
2021-04-04 21:04:12 +01:00
}