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

55 lines
1.9 KiB
C++
Raw Normal View History

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"
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
2022-03-31 21:52:46 +01:00
#include "src/DebugServer/Gdb/Signal.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
2021-04-04 21:04:12 +01:00
namespace Bloom::DebugServer::Gdb::CommandPackets
{
using ResponsePackets::ResponsePacket;
using ResponsePackets::OkResponsePacket;
using ResponsePackets::TargetStopped;
using ResponsePackets::ErrorResponsePacket;
using Exceptions::Exception;
void CommandPacket::handle(DebugSession& debugSession, TargetControllerConsole& targetControllerConsole) {
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;
}
if (packetString[0] == '?') {
// Status report
debugSession.connection.writePacket(TargetStopped(Signal::TRAP));
return;
}
if (packetString[0] == 'D') {
// Detach packet - there's not really anything we need to do here, so just respond with an OK
debugSession.connection.writePacket(OkResponsePacket());
return;
}
if (packetString.find("qAttached") == 0) {
Logger::debug("Handling qAttached");
debugSession.connection.writePacket(ResponsePacket(std::vector<unsigned char>({1})));
return;
}
Logger::debug("Unknown GDB RSP packet: " + packetString + " - returning empty response");
// Respond with an empty packet
debugSession.connection.writePacket(ResponsePacket(std::vector<unsigned char>({0})));
}
2021-10-02 17:39:27 +01:00
}