From 2f6d17fde65a93d34a150c330de6439064f9e7f2 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 17 Jan 2025 18:21:23 +0100 Subject: [PATCH] Process more commands --- src/gdb-stub/connection_handler.cpp | 5 ++++ src/gdb-stub/connection_handler.hpp | 2 ++ src/gdb-stub/gdb_stub.cpp | 42 ++++++++++++++++------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/gdb-stub/connection_handler.cpp b/src/gdb-stub/connection_handler.cpp index 664ef59f..f3c50311 100644 --- a/src/gdb-stub/connection_handler.cpp +++ b/src/gdb-stub/connection_handler.cpp @@ -56,4 +56,9 @@ namespace gdb_stub { (void)this->client_.send(data); } + + void connection_handler::close() const + { + this->client_.close(); + } } diff --git a/src/gdb-stub/connection_handler.hpp b/src/gdb-stub/connection_handler.hpp index 1e9c2f9e..bd1f13af 100644 --- a/src/gdb-stub/connection_handler.hpp +++ b/src/gdb-stub/connection_handler.hpp @@ -14,6 +14,8 @@ namespace gdb_stub void send_packet(std::string_view data) const; void send_raw_data(std::string_view data) const; + void close() const; + private: network::tcp_client_socket& client_; stream_processor processor_{}; diff --git a/src/gdb-stub/gdb_stub.cpp b/src/gdb-stub/gdb_stub.cpp index 38040ead..859c8a24 100644 --- a/src/gdb-stub/gdb_stub.cpp +++ b/src/gdb-stub/gdb_stub.cpp @@ -12,14 +12,6 @@ namespace gdb_stub { namespace { - enum class continuation_event - { - none, - cont, - detach, - step, - }; - network::tcp_client_socket accept_client(const network::address& bind_address) { network::tcp_server_socket server{bind_address.get_family()}; @@ -66,13 +58,29 @@ namespace gdb_stub } } - continuation_event handle_command(const connection_handler& connection, const uint8_t command, - const std::string_view data) + void process_action(const connection_handler& connection, const gdb_action action) { - auto event = continuation_event::none; + if (action == gdb_action::shutdown) + { + connection.close(); + } + } + void handle_command(const connection_handler& connection, async_handler& async, gdb_stub_handler& handler, + const uint8_t command, const std::string_view data) + { switch (command) { + case 'c': + async.run(); + process_action(connection, handler.cont()); + async.pause(); + break; + + case 's': + process_action(connection, handler.stepi()); + break; + case 'q': process_query(connection, data); break; @@ -81,13 +89,12 @@ namespace gdb_stub connection.send_packet({}); break; } - - return event; } - void process_packet(const connection_handler& connection, const std::string_view packet) + void process_packet(const connection_handler& connection, async_handler& async, gdb_stub_handler& handler, + const std::string_view packet) { - (void)connection.send_raw_data("+"); + connection.send_raw_data("+"); if (packet.empty()) { @@ -95,8 +102,7 @@ namespace gdb_stub } const auto command = packet.front(); - const auto event = handle_command(connection, command, packet.substr(1)); - (void)event; + handle_command(connection, async, handler, command, packet.substr(1)); } bool is_interrupt_packet(const std::optional& data) @@ -138,7 +144,7 @@ namespace gdb_stub break; } - process_packet(connection, *packet); + process_packet(connection, async, handler, *packet); } return true;