2021-10-02 17:39:27 +01:00
|
|
|
#include "RemoveBreakpoint.hpp"
|
|
|
|
|
|
2021-04-04 21:04:12 +01:00
|
|
|
#include <QtCore/QString>
|
|
|
|
|
|
2022-03-31 16:13:44 +01:00
|
|
|
#include "src/DebugServer/GdbRsp/ResponsePackets/OkResponsePacket.hpp"
|
|
|
|
|
#include "src/DebugServer/GdbRsp/ResponsePackets/ErrorResponsePacket.hpp"
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
#include "src/Targets/TargetBreakpoint.hpp"
|
|
|
|
|
|
|
|
|
|
#include "src/Logger/Logger.hpp"
|
|
|
|
|
#include "src/Exceptions/Exception.hpp"
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-03-31 16:05:39 +01:00
|
|
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
2022-02-05 15:32:08 +00:00
|
|
|
{
|
2022-03-24 19:17:41 +00:00
|
|
|
using Targets::TargetBreakpoint;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-03-24 19:17:41 +00:00
|
|
|
using ResponsePackets::OkResponsePacket;
|
|
|
|
|
using ResponsePackets::ErrorResponsePacket;
|
|
|
|
|
|
|
|
|
|
using Exceptions::Exception;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
void RemoveBreakpoint::init() {
|
|
|
|
|
if (data.size() < 6) {
|
|
|
|
|
throw Exception("Unexpected RemoveBreakpoint packet size");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00: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
|
|
|
|
2022-02-05 15:32:08 +00: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
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
bool conversionStatus = true;
|
|
|
|
|
this->address = packetSegments.at(1).toUInt(&conversionStatus, 16);
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
if (!conversionStatus) {
|
|
|
|
|
throw Exception("Failed to convert address hex value from RemoveBreakpoint packet.");
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2022-03-24 19:17:41 +00: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
|
|
|
}
|