Received: from eggs.gnu.org ([2001:4830:134:3::10]:38114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9ZA3-0007eT-GW for qemu-devel@nongnu.org; Sun, 05 Jun 2016 10:36:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9ZA2-0005tZ-6d for qemu-devel@nongnu.org; Sun, 05 Jun 2016 10:36:19 -0400 From: Peter Wu Date: Sun, 5 Jun 2016 16:35:48 +0200 Message-Id: <20160605143548.2331-1-peter@lekensteyn.nl> Subject: [Qemu-devel] [PATCH v2] gdbstub: avoid busy loop while waiting for gdb List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, Peter Maydell While waiting for a gdb response, or while sending an acknowledgement there is not much to do, so do not mark the socket as non-blocking to avoid a busy loop while paused at gdb. This only affects the user-mode emulation (qemu-arm -g 1234 ./a.out). Note that this issue was reported before at https://lists.nongnu.org/archive/html/qemu-devel/2013-02/msg02277.html. While at it, close the gdb client fd on EOF or error while reading. Signed-off-by: Peter Wu Reviewed-by: Peter Maydell --- v2: resent with fixed commit message + R-b from https://patchwork.kernel.org/patch/9008751/ --- gdbstub.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 0e431fd..b126bf5 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -332,7 +332,7 @@ static int get_char(GDBState *s) if (ret < 0) { if (errno == ECONNRESET) s->fd = -1; - if (errno != EINTR && errno != EAGAIN) + if (errno != EINTR) return -1; } else if (ret == 0) { close(s->fd); @@ -393,7 +393,7 @@ static void put_buffer(GDBState *s, const uint8_t *buf, int len) while (len > 0) { ret = send(s->fd, buf, len, 0); if (ret < 0) { - if (errno != EINTR && errno != EAGAIN) + if (errno != EINTR) return; } else { buf += ret; @@ -1542,9 +1542,13 @@ gdb_handlesig(CPUState *cpu, int sig) for (i = 0; i < n; i++) { gdb_read_byte(s, buf[i]); } - } else if (n == 0 || errno != EAGAIN) { + } else { /* XXX: Connection closed. Should probably wait for another connection before continuing. */ + if (n == 0) { + close(s->fd); + } + s->fd = -1; return sig; } } @@ -1599,8 +1603,6 @@ static void gdb_accept(void) gdb_has_xml = false; gdbserver_state = s; - - fcntl(fd, F_SETFL, O_NONBLOCK); } static int gdbserver_open(int port) -- 2.8.3