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 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"
|
|
|
|
|
#include "src/DebugServer/Gdb/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-12-26 21:27:19 +00:00
|
|
|
using Services::TargetControllerService;
|
2022-04-09 15:57:24 +01: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-10-01 21:01:37 +01:00
|
|
|
RemoveBreakpoint::RemoveBreakpoint(const RawPacket& rawPacket)
|
2022-04-03 17:25:21 +01:00
|
|
|
: CommandPacket(rawPacket)
|
|
|
|
|
{
|
2022-04-03 16:59:14 +01:00
|
|
|
if (this->data.size() < 6) {
|
2022-02-05 15:32:08 +00:00
|
|
|
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
|
2023-04-01 19:07:25 +01:00
|
|
|
this->type = (this->data[1] == '0') ? BreakpointType::SOFTWARE_BREAKPOINT : (this->data[1] == '1') ?
|
2022-02-05 15:32:08 +00:00
|
|
|
BreakpointType::HARDWARE_BREAKPOINT : BreakpointType::UNKNOWN;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-04-03 16:59:14 +01:00
|
|
|
const auto packetData = QString::fromLocal8Bit(
|
2022-02-05 15:32:08 +00:00
|
|
|
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
|
|
|
|
2022-12-26 21:27:19 +00:00
|
|
|
void RemoveBreakpoint::handle(DebugSession& debugSession, TargetControllerService& targetControllerService) {
|
2023-05-07 20:17:33 +01:00
|
|
|
Logger::info("Handling RemoveBreakpoint packet");
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
try {
|
2023-04-01 14:30:33 +01:00
|
|
|
Logger::debug("Removing breakpoint at address " + std::to_string(this->address));
|
|
|
|
|
|
2022-12-26 21:27:19 +00:00
|
|
|
targetControllerService.removeBreakpoint(TargetBreakpoint(this->address));
|
2022-03-24 19:17:41 +00:00
|
|
|
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
|
|
|
}
|