Files
BloomPatched/src/DebugServer/Gdb/CommandPackets/SetBreakpoint.cpp

77 lines
2.7 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#include "SetBreakpoint.hpp"
2021-10-02 17:39:27 +01:00
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/EmptyResponsePacket.hpp"
2022-03-31 21:52:46 +01:00
#include "src/DebugServer/Gdb/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 DebugServer::Gdb::CommandPackets
{
using Services::TargetControllerService;
using Targets::TargetBreakpoint;
2021-04-04 21:04:12 +01:00
using ResponsePackets::OkResponsePacket;
using ResponsePackets::ErrorResponsePacket;
using ResponsePackets::EmptyResponsePacket;
using ::Exceptions::Exception;
2021-04-04 21:04:12 +01:00
2022-10-01 21:01:37 +01:00
SetBreakpoint::SetBreakpoint(const RawPacket& rawPacket)
: CommandPacket(rawPacket)
{
if (this->data.size() < 6) {
throw Exception("Unexpected SetBreakpoint packet size");
}
2021-04-04 21:04:12 +01:00
// Z0 = SW breakpoint, Z1 = HW breakpoint
this->type = (this->data[1] == '0') ? BreakpointType::SOFTWARE_BREAKPOINT : (this->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 SetBreakpoint 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 SetBreakpoint packet.");
}
2021-04-04 21:04:12 +01:00
}
void SetBreakpoint::handle(DebugSession& debugSession, TargetControllerService& targetControllerService) {
Logger::info("Handling SetBreakpoint packet");
try {
if (this->type == BreakpointType::UNKNOWN) {
Logger::debug(
"Rejecting breakpoint at address " + std::to_string(this->address)
+ " - unsupported breakpoint type"
);
debugSession.connection.writePacket(EmptyResponsePacket());
return;
}
debugSession.setExternalBreakpoint(TargetBreakpoint(this->address), targetControllerService);
debugSession.connection.writePacket(OkResponsePacket());
} catch (const Exception& exception) {
Logger::error("Failed to set breakpoint on target - " + exception.getMessage());
debugSession.connection.writePacket(ErrorResponsePacket());
}
}
2021-04-04 21:04:12 +01:00
}