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"
|
2023-04-02 00:22:11 +01:00
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/EmptyResponsePacket.hpp"
|
2022-03-31 21:52:46 +01:00
|
|
|
#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
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
namespace 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;
|
2023-04-02 00:22:11 +01:00
|
|
|
using ResponsePackets::EmptyResponsePacket;
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2023-08-13 15:47:51 +01:00
|
|
|
using ::Exceptions::Exception;
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-10-01 21:01:37 +01:00
|
|
|
SetBreakpoint::SetBreakpoint(const RawPacket& rawPacket)
|
2022-04-03 17:25:21 +01:00
|
|
|
: CommandPacket(rawPacket)
|
|
|
|
|
{
|
2022-04-01 19:41:04 +01:00
|
|
|
if (this->data.size() < 6) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exception{"Unexpected SetBreakpoint packet size"};
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
|
2022-02-05 15:32:08 +00:00
|
|
|
// Z0 = SW breakpoint, Z1 = HW breakpoint
|
2024-07-23 21:14:22 +01:00
|
|
|
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
|
|
|
|
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) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exception{"Unexpected number of packet segments in SetBreakpoint packet"};
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
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) {
|
2024-07-23 21:14:22 +01:00
|
|
|
throw Exception{"Failed to convert address hex value from SetBreakpoint packet."};
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2024-07-23 21:14:22 +01:00
|
|
|
void SetBreakpoint::handle(
|
|
|
|
|
DebugSession& debugSession,
|
|
|
|
|
const TargetDescriptor& gdbTargetDescriptor,
|
|
|
|
|
const Targets::TargetDescriptor&,
|
|
|
|
|
TargetControllerService& targetControllerService
|
|
|
|
|
) {
|
2023-05-07 20:17:33 +01:00
|
|
|
Logger::info("Handling SetBreakpoint packet");
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
try {
|
2023-04-02 00:22:11 +01:00
|
|
|
if (this->type == BreakpointType::UNKNOWN) {
|
|
|
|
|
Logger::debug(
|
|
|
|
|
"Rejecting breakpoint at address " + std::to_string(this->address)
|
2024-07-23 21:14:22 +01:00
|
|
|
+ " - unsupported breakpoint type"
|
2023-04-02 00:22:11 +01:00
|
|
|
);
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.connection.writePacket(EmptyResponsePacket{});
|
2023-04-02 00:22:11 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2023-04-01 14:30:33 +01:00
|
|
|
|
2023-09-20 23:37:54 +01:00
|
|
|
debugSession.setExternalBreakpoint(this->address, targetControllerService);
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.connection.writePacket(OkResponsePacket{});
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
} catch (const Exception& exception) {
|
|
|
|
|
Logger::error("Failed to set breakpoint on target - " + exception.getMessage());
|
2024-07-23 21:14:22 +01:00
|
|
|
debugSession.connection.writePacket(ErrorResponsePacket{});
|
2022-03-24 19:17:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-04-04 21:04:12 +01:00
|
|
|
}
|