From: Peter Wu <peter@lekensteyn.nl>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org
Subject: [Qemu-devel] [PATCH] gdbstub: avoid busy loop while waiting for gdb
Date: Wed, 4 May 2016 00:58:39 +0200 [thread overview]
Message-ID: <1462316319-4308-1-git-send-email-peter@lekensteyn.nl> (raw)
While waiting for a gdb response, or while sending an acknowledgement
there is not much to do, so just 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 <peter@lekensteyn.nl>
---
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.0
next reply other threads:[~2016-05-03 22:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-03 22:58 Peter Wu [this message]
2016-05-05 15:37 ` [Qemu-devel] [PATCH] gdbstub: avoid busy loop while waiting for gdb Peter Maydell
2016-05-05 16:08 ` Peter Wu
2016-05-05 16:23 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462316319-4308-1-git-send-email-peter@lekensteyn.nl \
--to=peter@lekensteyn.nl \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).