--- gdb/ser-base.c (revision 3592) +++ gdb/ser-base.c (local) @@ -361,6 +361,9 @@ generic_readchar (struct serial *scb, in if (num_bytes != -1) to_read = (num_bytes < to_read) ? num_bytes : to_read; + if (to_read == 0) + break; + s = read (scb->error_fd, &buf, to_read); if (s == -1) break; --- gdb/ser-mingw.c (revision 3592) +++ gdb/ser-mingw.c (local) @@ -875,7 +875,7 @@ pipe_done_wait_handle (struct serial *sc static int pipe_avail (struct serial *scb, int fd) { - HANDLE h = (HANDLE) _get_osfhandle (scb->error_fd); + HANDLE h = (HANDLE) _get_osfhandle (fd); DWORD numBytes; BOOL r = PeekNamedPipe (h, NULL, 0, NULL, &numBytes, NULL); if (r == FALSE) --- gdb/serial.h (revision 3592) +++ gdb/serial.h (local) @@ -255,7 +255,7 @@ struct serial_ops without blocking. Return value of -1 means that the the read will not block even if less that requested bytes are available. */ - int (*avail)(struct serial *scb); + int (*avail)(struct serial *scb, int fd); #ifdef USE_WIN32API /* Return a handle to wait on, indicating available data from SCB