Integrate new gdb stub

This commit is contained in:
momo5502
2025-01-17 17:23:05 +01:00
parent 7d62d1e20e
commit 0253592ae9
9 changed files with 58 additions and 207 deletions

View File

@@ -3,8 +3,11 @@
#include <network/tcp_server_socket.hpp>
#include "stream_processor.hpp"
#include "async_handler.hpp"
#include "checksum.hpp"
using namespace std::literals;
namespace gdb_stub
{
namespace
@@ -111,10 +114,16 @@ namespace gdb_stub
const auto command = packet.front();
const auto event = handle_command(client, command, packet.substr(1));
(void)event;
}
bool is_interrupt_packet(const std::optional<std::string>& data)
{
return data && data->size() == 1 && data->front() == '\x03';
}
}
bool run_gdb_stub(const network::address& bind_address)
bool run_gdb_stub(const network::address& bind_address, gdb_stub_handler& handler)
{
stream_processor processor{};
@@ -124,6 +133,21 @@ namespace gdb_stub
return false;
}
async_handler async{[&](std::atomic_bool& can_run) {
while (can_run)
{
std::this_thread::sleep_for(10ms);
const auto data = client.receive(1);
if (is_interrupt_packet(data) || !client.is_valid())
{
handler.on_interrupt();
can_run = false;
}
}
}};
client.set_blocking(false);
while (client.is_valid())