This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Avoid premature serial timeouts
- From: Michael Daniels <mdaniels at blackberry dot com>
- To: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Fri, 18 Nov 2016 21:36:53 +0000
- Subject: [PATCH] Avoid premature serial timeouts
- Authentication-results: sourceware.org; auth=none
I noticed that when calling serial_readchar() with a large timeout
(or -1), and there is no data to read for > 1s then it will prematurely
return SERIAL_TIMEOUT.
I narrowed it down to do_hardwire_readchar() calling wait_for() with a
timeout of 1, and returning immediately if there was an error/timeout.
I have moved some lines around to capture what I believe was the original
intent.
Thoughts?
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 2e7b1b4..9bd45f6 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -549,32 +549,23 @@ do_hardwire_readchar (struct serial *scb, int timeout)
scb->timeout_remaining = (timeout < 0 ? timeout : timeout - delta);
status = wait_for (scb, delta);
- if (status < 0)
+ if (status == SERIAL_TIMEOUT) {
+ if (scb->timeout_remaining > 0) {
+ timeout = scb->timeout_remaining;
+ continue;
+ } else if (scb->timeout_remaining < 0)
+ continue;
+ else
+ return SERIAL_TIMEOUT;
+ } else if (status < 0)
return status;
status = read (scb->fd, scb->buf, BUFSIZ);
- if (status <= 0)
- {
- if (status == 0)
- {
- /* Zero characters means timeout (it could also be EOF, but
- we don't (yet at least) distinguish). */
- if (scb->timeout_remaining > 0)
- {
- timeout = scb->timeout_remaining;
- continue;
- }
- else if (scb->timeout_remaining < 0)
- continue;
- else
- return SERIAL_TIMEOUT;
- }
- else if (errno == EINTR)
- continue;
- else
- return SERIAL_ERROR; /* Got an error from read. */
- }
+ if (status < 0 && errno == EINTR)
+ continue;
+ else if (status <= 0)
+ return SERIAL_ERROR; /* Got an error from read. */
scb->bufcnt = status;
scb->bufcnt--;