From 16d01f9cd49f553a958a69ad3c9f781ebd402da8 Mon Sep 17 00:00:00 2001 From: Bernhard Wodok <barto@gmx.net> Date: Tue, 27 Aug 2019 11:40:31 -0400 Subject: Fix PR win32/24284: tcp_auto_retry doesn't work in MinGW This was reported by Bernhard Wodok, along with a patch to fix the issue. I adjusted the patch a bit, and I'm submitting the patch on his behalf. According to Bernhard, the issue can be reproduced by doing: 1. start gdb 2. enter 'target remote :2345' 3. observe that it throws a "connection refused" error immediately instead of waiting and throwing a timeout error I.e., I believe it can be reproduced by our current tests, which is why I'm not proposing any extra tests here (well, I don't use nor have any Windows system to test this, so...). The problem happens because, on ser-tcp:wait_for_connect, we call 'gdb_select' passing 0 as its first argument, which, when using MinGW, ends up using the 'gdb_select' version from mingw-hdep.c, and when the first argument is 0 this means that WaitForMultipleObjects will be called with 0 as its first argument as well. According to the MS API docs, this is forbidden: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitformultipleobjects The proposed fix is simple: we just call Sleep when N == 0 (and when TIMEOUT is non-NULL), and return 0. It makes sense to me. Both Bernhard and Paul Carroll confirmed that the fix works. I'm Cc'ing Bernhard in case you have any questions about the patch. OK? gdb/ChangeLog: 2019-08-29 Bernhard Wodok <barto@gmx.net> Sergio Durigan Junior <sergiodj@redhat.com> PR win32/24284 * mingw-hdep.c (gdb_select): Handle case when 'n' is zero. --- gdb/ChangeLog | 6 ++++++ gdb/mingw-hdep.c | 11 +++++++++++ 2 files changed, 17 insertions(+) (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a82f7c6..fba2f4a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-08-29 Bernhard Wodok <barto@gmx.net> + Sergio Durigan Junior <sergiodj@redhat.com> + + PR win32/24284 + * mingw-hdep.c (gdb_select): Handle case when 'n' is zero. + 2019-08-28 Andrew Burgess <andrew.burgess@embecosm.com> * symtab.c (search_symbols): Don't include MODULE_DOMAIN symbols diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c index 44fb22e..0af1b39 100644 --- a/gdb/mingw-hdep.c +++ b/gdb/mingw-hdep.c @@ -64,6 +64,17 @@ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int num_ready; size_t indx; + if (n == 0) + { + /* The MS API says that the first argument to + WaitForMultipleObjects cannot be zero. That's why we just + use a regular Sleep here. */ + if (timeout != NULL) + Sleep (timeout->tv_sec * 1000 + timeout->tv_usec / 1000); + + return 0; + } + num_ready = 0; num_handles = 0; num_scbs = 0; -- cgit v1.1