From 374f3192efb699d9ed381a4aadb5db7d560c572f Mon Sep 17 00:00:00 2001 From: ALTracer Date: Sun, 19 Nov 2023 22:39:33 +0300 Subject: [PATCH] gdb_hostio: Expect other packets from GDB, leading to F-reply * Add a reduced loop like the one in bmp_poll_loop(), allowing BMP to service GDB accessing syscall buffers in target memory; * Use both F-reply and Detach as exit conditions, passing a corresponding result code for the target to see when we resume it --- src/gdb_hostio.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gdb_hostio.c b/src/gdb_hostio.c index c21c56c70ea..09b46d57a79 100644 --- a/src/gdb_hostio.c +++ b/src/gdb_hostio.c @@ -73,8 +73,18 @@ int hostio_reply(target_controller_s *const tc, char *const pbuf, const int len) static int hostio_get_response(target_controller_s *const tc) { char *const packet_buffer = gdb_packet_buffer(); - const size_t size = gdb_getpacket(packet_buffer, GDB_PACKET_BUFFER_SIZE); - return gdb_main_loop(tc, packet_buffer, GDB_PACKET_BUFFER_SIZE, size, true); + /* Still have to service normal 'X'/'m'-packets */ + while (true) { + /* Get back the next packet to process and have the main loop handle it */ + const size_t size = gdb_getpacket(packet_buffer, GDB_PACKET_BUFFER_SIZE); + /* If this was an escape packet (or gdb_if reports link closed), fail the call */ + if (size == 1U && packet_buffer[0] == '\x04') + return -1; + const int result = gdb_main_loop(tc, packet_buffer, GDB_PACKET_BUFFER_SIZE, size, true); + /* If this was an F-packet, we're done */ + if (packet_buffer[0] == 'F') + return result; + } } /* Interface to host system calls */