2021-04-04 21:04:12 +01:00
|
|
|
#include "CommandPacket.hpp"
|
2021-10-02 17:39:27 +01:00
|
|
|
|
2022-03-31 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
|
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/OkResponsePacket.hpp"
|
|
|
|
|
#include "src/DebugServer/Gdb/ResponsePackets/TargetStopped.hpp"
|
2022-04-08 22:17:03 +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
|
|
|
|
2022-03-31 21:52:46 +01:00
|
|
|
#include "src/DebugServer/Gdb/Signal.hpp"
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
#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-04-09 15:57:24 +01:00
|
|
|
using TargetController::TargetControllerConsole;
|
|
|
|
|
|
2022-03-24 19:17:41 +00:00
|
|
|
using ResponsePackets::ResponsePacket;
|
|
|
|
|
using ResponsePackets::OkResponsePacket;
|
|
|
|
|
using ResponsePackets::TargetStopped;
|
2022-04-08 22:17:03 +01:00
|
|
|
using ResponsePackets::EmptyResponsePacket;
|
2022-03-24 19:17:41 +00:00
|
|
|
using ResponsePackets::ErrorResponsePacket;
|
|
|
|
|
|
|
|
|
|
using Exceptions::Exception;
|
|
|
|
|
|
|
|
|
|
void CommandPacket::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) {
|
2022-04-03 02:22:49 +01:00
|
|
|
const auto packetString = std::string(this->data.begin(), this->data.end());
|
|
|
|
|
|
|
|
|
|
if (packetString.empty()) {
|
|
|
|
|
Logger::error("Empty GDB RSP packet received.");
|
|
|
|
|
debugSession.connection.writePacket(ErrorResponsePacket());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
|
|
|
|
if (packetString[0] == '?') {
|
|
|
|
|
// Status report
|
|
|
|
|
debugSession.connection.writePacket(TargetStopped(Signal::TRAP));
|
2022-04-03 02:22:49 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2022-04-03 02:22:49 +01:00
|
|
|
if (packetString[0] == 'D') {
|
2022-03-24 19:17:41 +00:00
|
|
|
// Detach packet - there's not really anything we need to do here, so just respond with an OK
|
|
|
|
|
debugSession.connection.writePacket(OkResponsePacket());
|
2022-04-03 02:22:49 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2022-04-08 22:17:22 +01:00
|
|
|
if (packetString.find("vMustReplyEmpty") == 0) {
|
|
|
|
|
Logger::debug("Handling vMustReplyEmpty");
|
|
|
|
|
debugSession.connection.writePacket(EmptyResponsePacket());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-03 02:22:49 +01:00
|
|
|
if (packetString.find("qAttached") == 0) {
|
2022-03-24 19:17:41 +00:00
|
|
|
Logger::debug("Handling qAttached");
|
2022-04-06 17:10:57 +01:00
|
|
|
debugSession.connection.writePacket(ResponsePacket(std::vector<unsigned char>({1})));
|
2022-04-03 02:22:49 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2022-04-03 02:22:49 +01:00
|
|
|
Logger::debug("Unknown GDB RSP packet: " + packetString + " - returning empty response");
|
2022-03-24 19:17:41 +00:00
|
|
|
|
2022-04-03 02:22:49 +01:00
|
|
|
// Respond with an empty packet
|
2022-04-08 22:17:03 +01:00
|
|
|
debugSession.connection.writePacket(EmptyResponsePacket());
|
2022-02-05 15:32:08 +00:00
|
|
|
}
|
2021-10-02 17:39:27 +01:00
|
|
|
}
|