Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: gdb-patches@sourceware.org
Subject: Re: RFA: Various Windows (mingw32) additions, mostly relating to select or serial ports
Date: Sat, 04 Feb 2006 15:11:00 -0000	[thread overview]
Message-ID: <20060204151124.GD17011@nevyn.them.org> (raw)
In-Reply-To: <uzml7mh7j.fsf@gnu.org>

On Sat, Feb 04, 2006 at 02:38:56PM +0200, Eli Zaretskii wrote:
> > Date: Fri, 3 Feb 2006 17:05:29 -0500
> > From: Daniel Jacobowitz <drow@false.org>
> > 
> > The primary ugly bit of this patch is the select wrapper.  Windows has
> > interfaces for all these things which map to Unix file descriptors, but
> > while the Unix interfaces are actually compatible, the Windows interfaces
> > are just designed along similar principles.  So you can handle a serial port
> > in roughly the same way you handle a console window.... but only roughly.
> > In fact you need to know what sort of device is behind each "file
> > descriptor", in order to handle it appropriately.
> 
> Could you elaborate a bit?  I cannot easily see where that device
> knowledge is present in the patch; it all looks to me like several
> instances of the same code with almost identical flow.
> 
> In particular, I thought WaitForMultipleObjects could handle any kind
> of handle, be it a pipe, a socket, a console, a process, or a file.
> 
> Even if the code is slightly different in that it calls different OS
> API functions, cannot it all be expressed as the same code that uses a
> function table indexed by the interface type?

Nope.  Well, in a sense, that is what I've done - the
serial_wait_handle interface feeds back to a central loop using
WaitForMultipleObjects.

The problem is that, yes, all these objects are HANDLEs, and
WaitForMultipleObjects can wait for many kinds of HANDLEs.  But there's
different things that "waiting for a handle" might mean, and it doesn't
happen to pick the right one.  So what I'm doing is using other
handles, controlled by threads or async I/O functions, to signal the
conditions we're interested in.

The four I implemented are:

- Serial.  Yes, I confess this is more different from the others than
it has to be; the most elegant way was to open the file in "overlapped"
mode, and then issue an overlapped (similar to non-blocking) wait for
EV_RXCHAR.  It could be reworked to use a thread, like the other three,
but it would still need to use WaitCommEvent.  I did this one first.
As far as I can tell you can't wait directly on a serial handle at all,
or if you can, the MSDN documentation doesn't tell you what will
cause it to become signalled.

- Console.  You can wait on a console handle, and Mark's previous code
did so.  However, it turns out, this signals for any event in the
input queue - including key release events!  But reading from the
console will block since that only fetches keypress events.  So,
we need to explicitly look for keypress events and discard other
things.

- Pipes.  There's just no wait function.  You can wait on a connected
pipe, but it's always signalled as far as I've been able to determine
(and it's undocumented).  You can wait on a named pipe, but that
only waits for a connection to be available, not data.

- Sockets.  They're pretty easy actually; you can associate the
socket with an arbitrary event object.  But afterwards you need
to make a socket-specific call to figure out whether you got
a read or an error; otherwise GDB doesn't detect hangups.

> I'd like an explanation about this paradigm:
> 
> > +      wait_events[0] = state->stop_select;
> > +      wait_events[1] = h;
> > +
> > +      event_index = WaitForMultipleObjects (2, wait_events, FALSE, INFINITE);
> > +
> > +      if (event_index == WAIT_OBJECT_0
> > +	  || WaitForSingleObject (state->stop_select, 0) == WAIT_OBJECT_0)
> > +	{
> > +	  CloseHandle (state->stop_select);
> > +	  return 0;
> > +	}
> 
> (You have similar code in gdb_select and elsewhere.)  Why do you need
> to wait for an object again with WaitForSingleObject, after you've
> just waited for it in WaitForMultipleObjects?

WaitForMultipleObjects returns a single result.  However, both of the
input objects could have been signalled before we woke.  The case this
is trying to handle is WaitForMultipleObjects returning
WAIT_OBJECT_0 + 1, and then stop_select being signalled; if someone has
asked for the thread to exit, we should do so immediately, because
the other handles we rely on will have been closed.

(Yes, this isn't 100% perfect on race conditions.  However, it is as
close as I was able to come up with.  I suppose I could kill and
restart the threads for every select...)

> >  - Windows serial support.  This definitely deserves a NEWS entry,
> >    included.
> 
> ...I don't think you included this entry.

Oops.  I added it while I was writing that bullet point.

+* Improved Windows host support
+
+GDB now builds as a cross debugger hosted on i686-mingw32, including
+native console support, and remote communications using either
+network sockets or serial ports.
+


-- 
Daniel Jacobowitz
CodeSourcery


  reply	other threads:[~2006-02-04 15:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-03 22:05 Daniel Jacobowitz
2006-02-03 22:08 ` Daniel Jacobowitz
2006-02-04 12:43   ` Eli Zaretskii
2006-02-04 15:13     ` Daniel Jacobowitz
2006-02-04  6:28 ` Ian Lance Taylor
2006-02-04 10:30   ` Eli Zaretskii
2006-02-04 17:06     ` Ian Lance Taylor
2006-02-04 17:45       ` Eli Zaretskii
2006-02-04 15:00   ` Daniel Jacobowitz
2006-02-05  0:01     ` Ian Lance Taylor
2006-02-05 22:00       ` Daniel Jacobowitz
2006-02-06  3:27         ` Ian Lance Taylor
2006-02-06  4:03           ` Daniel Jacobowitz
2006-02-04 12:38 ` Eli Zaretskii
2006-02-04 15:11   ` Daniel Jacobowitz [this message]
2006-02-04 15:23     ` Eli Zaretskii
2006-02-04 15:30       ` Daniel Jacobowitz
2006-02-06 21:02 ` Daniel Jacobowitz
2006-02-06 23:02   ` Mark Kettenis
2006-02-06 23:17     ` Daniel Jacobowitz
2006-02-06 23:21     ` Christopher Faylor
2006-02-09 22:38     ` Daniel Jacobowitz
2006-02-10  7:53       ` Eli Zaretskii
2006-02-10 20:46       ` Mark Kettenis
2006-02-10 22:02         ` Daniel Jacobowitz
2006-02-07  4:41   ` Eli Zaretskii

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=20060204151124.GD17011@nevyn.them.org \
    --to=drow@false.org \
    --cc=gdb-patches@sourceware.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