This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Crashed cross gdb/MinGW host
- From: Daniel Jacobowitz <drow at false dot org>
- To: Masaki Muranaka <monaka at monami-software dot com>, gdb-patches at sourceware dot org
- Date: Sat, 10 Jun 2006 14:25:07 -0400
- Subject: Re: [patch] Crashed cross gdb/MinGW host
- References: <0494AFF8-AB9B-40E8-A4D2-C119DEEC5248@monami-software.com> <20060519185257.GA2667@trixie.casa.cgf.cx>
On Fri, May 19, 2006 at 02:52:57PM -0400, Christopher Faylor wrote:
> On Fri, May 19, 2006 at 06:47:04PM +0900, Masaki Muranaka wrote:
> >My sh-elf-gdb on MinGW host was crashed when I tried to debug using the
> >serial connection. Here is a patch.
> >
> >It's possible the another plan to remove writefds check. There is no
> >support yet for writefds.
>
> If this is truly supposed to be an emulation of the system select(), I
> think it would make sense to check both !readfds and !writefds.
Sorry for letting this sit so long. I just encountered this bug today.
I think I tested console and pipe when I last touched this code
but failed to test ser-base.
The underlying problem is actually different. The code looks like
this:
if (!FD_ISSET (fd, readfds) && !FD_ISSET (fd, writefds))
continue;
if (FD_ISSET (fd, readfds))
...
if (FD_ISSET (fd, exceptfds))
...
See the mismatch? :-(
I have committed the attached patch as obvious. It adds the missing
NULL checks, and also corrects the loop check for exceptfds.
--
Daniel Jacobowitz
CodeSourcery
2006-06-10 Daniel Jacobowitz <dan@codesourcery.com>
* mingw-hdep.c (gdb_select): Always check for NULL fd sets
before calling FD_ISSET. Correct check for exceptfds which
previously tested writefds.
Index: mingw-hdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mingw-hdep.c,v
retrieving revision 1.3
diff -u -p -r1.3 mingw-hdep.c
--- mingw-hdep.c 24 Apr 2006 21:00:13 -0000 1.3
+++ mingw-hdep.c 10 Jun 2006 16:37:55 -0000
@@ -105,8 +105,8 @@ gdb_select (int n, fd_set *readfds, fd_s
if something starts using it. */
gdb_assert (!writefds || !FD_ISSET (fd, writefds));
- if (!FD_ISSET (fd, readfds)
- && !FD_ISSET (fd, exceptfds))
+ if ((!readfds || !FD_ISSET (fd, readfds))
+ && (!exceptfds || !FD_ISSET (fd, exceptfds)))
continue;
h = (HANDLE) _get_osfhandle (fd);
@@ -124,13 +124,13 @@ gdb_select (int n, fd_set *readfds, fd_s
except = never_handle;
}
- if (FD_ISSET (fd, readfds))
+ if (readfds && FD_ISSET (fd, readfds))
{
gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
handles[num_handles++] = read;
}
- if (FD_ISSET (fd, exceptfds))
+ if (exceptfds && FD_ISSET (fd, exceptfds))
{
gdb_assert (num_handles < MAXIMUM_WAIT_OBJECTS);
handles[num_handles++] = except;
@@ -169,10 +169,11 @@ gdb_select (int n, fd_set *readfds, fd_s
HANDLE fd_h;
struct serial *scb;
- if (!FD_ISSET (fd, readfds) && !FD_ISSET (fd, writefds))
+ if ((!readfds || !FD_ISSET (fd, readfds))
+ && (!exceptfds || !FD_ISSET (fd, exceptfds)))
continue;
- if (FD_ISSET (fd, readfds))
+ if (readfds && FD_ISSET (fd, readfds))
{
fd_h = handles[indx++];
/* This handle might be ready, even though it wasn't the handle
@@ -183,7 +184,7 @@ gdb_select (int n, fd_set *readfds, fd_s
num_ready++;
}
- if (FD_ISSET (fd, exceptfds))
+ if (exceptfds && FD_ISSET (fd, exceptfds))
{
fd_h = handles[indx++];
/* This handle might be ready, even though it wasn't the handle