From: Mark Mitchell <mark@codesourcery.com>
To: Daniel Jacobowitz <drow@false.org>
Cc: Christopher Faylor <me@cgf.cx>, gdb-patches@sources.redhat.com
Subject: Re: PATCH: Support Windows in event-loop.c
Date: Mon, 25 Apr 2005 20:23:00 -0000 [thread overview]
Message-ID: <426D5178.6010502@codesourcery.com> (raw)
In-Reply-To: <20050425153549.GA15967@nevyn.them.org>
[-- Attachment #1: Type: text/plain, Size: 585 bytes --]
Daniel Jacobowitz wrote:
> No idea. I think in GDB is OK. In that case it should probably be
> encapsulated as "gdb_select".
Here is the revised patch. As per previous discussion, this version
still has the limitation that it only works with consoles -- but it
would be possible to use threads within gdb_select to extend it to work
with a wider variety of handles. In any case, this patch provides
useful functionality on Windows, and does not impose the Windows API on
generic code.
OK to commit?
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
[-- Attachment #2: gdb.event.patch --]
[-- Type: text/plain, Size: 7124 bytes --]
2005-04-25 Mark Mitchell <mark@codesourcery.com>
* event-loop.c (gdb_assert.h): Include.
(<windows.h>): Include under Windows.
(<io.h>): Likeiwse.
(gdb_select): New function.
(gdb_wait_for_event): Use it.
* Makefile.in (event-loop.o): Depend on $(gdb_assert_h).
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.707
diff -c -5 -p -r1.707 Makefile.in
*** Makefile.in 18 Mar 2005 21:03:38 -0000 1.707
--- Makefile.in 25 Apr 2005 20:09:04 -0000
*************** environ.o: environ.c $(defs_h) $(environ
*** 1907,1917 ****
eval.o: eval.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
$(value_h) $(expression_h) $(target_h) $(frame_h) $(language_h) \
$(f_lang_h) $(cp_abi_h) $(infcall_h) $(objc_lang_h) $(block_h) \
$(parser_defs_h) $(cp_support_h)
event-loop.o: event-loop.c $(defs_h) $(event_loop_h) $(event_top_h) \
! $(gdb_string_h) $(exceptions_h)
event-top.o: event-top.c $(defs_h) $(top_h) $(inferior_h) $(target_h) \
$(terminal_h) $(event_loop_h) $(event_top_h) $(interps_h) \
$(exceptions_h) $(gdbcmd_h) $(readline_h) $(readline_history_h)
exceptions.o: exceptions.c $(defs_h) $(exceptions_h) $(breakpoint_h) \
$(target_h) $(inferior_h) $(annotate_h) $(ui_out_h) $(gdb_assert_h) \
--- 1910,1920 ----
eval.o: eval.c $(defs_h) $(gdb_string_h) $(symtab_h) $(gdbtypes_h) \
$(value_h) $(expression_h) $(target_h) $(frame_h) $(language_h) \
$(f_lang_h) $(cp_abi_h) $(infcall_h) $(objc_lang_h) $(block_h) \
$(parser_defs_h) $(cp_support_h)
event-loop.o: event-loop.c $(defs_h) $(event_loop_h) $(event_top_h) \
! $(gdb_string_h) $(exceptions_h) $(gdb_assert_h)
event-top.o: event-top.c $(defs_h) $(top_h) $(inferior_h) $(target_h) \
$(terminal_h) $(event_loop_h) $(event_top_h) $(interps_h) \
$(exceptions_h) $(gdbcmd_h) $(readline_h) $(readline_history_h)
exceptions.o: exceptions.c $(defs_h) $(exceptions_h) $(breakpoint_h) \
$(target_h) $(inferior_h) $(annotate_h) $(ui_out_h) $(gdb_assert_h) \
Index: event-loop.c
===================================================================
RCS file: /cvs/src/src/gdb/event-loop.c,v
retrieving revision 1.24
diff -c -5 -p -r1.24 event-loop.c
*** event-loop.c 12 Feb 2005 00:39:18 -0000 1.24
--- event-loop.c 25 Apr 2005 20:20:34 -0000
***************
*** 34,43 ****
--- 34,44 ----
#include <sys/types.h>
#include "gdb_string.h"
#include <errno.h>
#include <sys/time.h>
#include "exceptions.h"
+ #include "gdb_assert.h"
typedef struct gdb_event gdb_event;
typedef void (event_handler_func) (int);
/* Event for the GDB event system. Events are queued by calling
*************** event_queue;
*** 131,140 ****
--- 132,146 ----
#define USE_POLL 0
#endif /* HAVE_POLL */
static unsigned char use_poll = USE_POLL;
+ #ifdef USE_WIN32API
+ #include <windows.h>
+ #include <io.h>
+ #endif
+
static struct
{
/* Ptr to head of file handler list. */
file_handler *first_file_handler;
*************** handle_file_event (int event_file_desc)
*** 723,732 ****
--- 729,806 ----
break;
}
}
}
+ /* Wrapper for select. This function is not yet exported from this
+ file because it is not sufficiently general. For example,
+ ser-base.c uses select to check for socket activity, and this
+ function does not support sockets under Windows, so we do not want
+ to use gdb_select in ser-base.c. */
+
+ static int
+ gdb_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
+ struct timeval *timeout)
+ {
+ #ifdef USE_WIN32API
+ HANDLE handles[MAXIMUM_WAIT_OBJECTS];
+ HANDLE h;
+ DWORD event;
+ DWORD num_handles;
+ int fd;
+
+ num_handles = 0;
+ for (fd = 0; fd < n; ++fd)
+ {
+ /* EXCEPTFDS is silently ignored. GDB always sets GDB_EXCEPTION
+ when calling add_file_handler, but there is no natural analog
+ under Windows. */
+ /* There is no support yet for WRITEFDS. At present, this isn't
+ used by GDB -- but we do not want to silently ignore WRITEFDS
+ if something starts using it. */
+ gdb_assert (!FD_ISSET (fd, writefds));
+ if (FD_ISSET (fd, readfds))
+ handles[num_handles++] = (HANDLE) _get_osfhandle (fd);
+ }
+ event = WaitForMultipleObjects (num_handles,
+ handles,
+ FALSE,
+ timeout
+ ? (timeout->tv_sec * 1000 + timeout->tv_usec)
+ : INFINITE);
+ /* EVENT can only be a value in the WAIT_ABANDONED_0 range if the
+ HANDLES included an abandoned mutex. Since GDB doesn't use
+ mutexes, that should never occur. */
+ gdb_assert (!(WAIT_ABANDONED_0 <= event
+ && event < WAIT_ABANDONED_0 + num_handles));
+ if (event == WAIT_FAILED)
+ return -1;
+ if (event == WAIT_TIMEOUT)
+ return 0;
+ /* Run through the READFDS, clearing bits corresponding to descriptors
+ for which input is unavailable. */
+ h = handles[event - WAIT_OBJECT_0];
+ for (fd = 0; fd < n; ++fd)
+ {
+ HANDLE fd_h = (HANDLE) _get_osfhandle (fd);
+ /* This handle might be ready, even though it wasn't the handle
+ returned by WaitForMultipleObjects. */
+ if (FD_ISSET (fd, readfds) && fd_h != h
+ && WaitForSingleObject (fd_h, 0) == WAIT_OBJECT_0)
+ FD_CLR (fd, readfds);
+ }
+ /* We never report any descriptors available for writing or with
+ exceptional conditions. */
+ FD_ZERO (writefds);
+ FD_ZERO (exceptfds);
+
+ return 1;
+ #else
+ return select (n, readfds, writefds, exceptfds, timeout);
+ #endif
+ }
+
/* Called by gdb_do_one_event to wait for new events on the
monitored file descriptors. Queue file events as they are
detected by the poll.
If there are no events, this function will block in the
call to poll.
*************** gdb_wait_for_event (void)
*** 767,782 ****
else
{
gdb_notifier.ready_masks[0] = gdb_notifier.check_masks[0];
gdb_notifier.ready_masks[1] = gdb_notifier.check_masks[1];
gdb_notifier.ready_masks[2] = gdb_notifier.check_masks[2];
! num_found = select (gdb_notifier.num_fds,
! &gdb_notifier.ready_masks[0],
! &gdb_notifier.ready_masks[1],
! &gdb_notifier.ready_masks[2],
! gdb_notifier.timeout_valid
! ? &gdb_notifier.select_timeout : NULL);
/* Clear the masks after an error from select. */
if (num_found == -1)
{
FD_ZERO (&gdb_notifier.ready_masks[0]);
--- 841,856 ----
else
{
gdb_notifier.ready_masks[0] = gdb_notifier.check_masks[0];
gdb_notifier.ready_masks[1] = gdb_notifier.check_masks[1];
gdb_notifier.ready_masks[2] = gdb_notifier.check_masks[2];
! num_found = gdb_select (gdb_notifier.num_fds,
! &gdb_notifier.ready_masks[0],
! &gdb_notifier.ready_masks[1],
! &gdb_notifier.ready_masks[2],
! gdb_notifier.timeout_valid
! ? &gdb_notifier.select_timeout : NULL);
/* Clear the masks after an error from select. */
if (num_found == -1)
{
FD_ZERO (&gdb_notifier.ready_masks[0]);
next prev parent reply other threads:[~2005-04-25 20:23 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-21 5:53 Mark Mitchell
2005-04-21 18:46 ` Eli Zaretskii
2005-04-21 18:49 ` Daniel Jacobowitz
2005-04-21 18:56 ` Mark Mitchell
2005-04-21 20:30 ` Eli Zaretskii
2005-04-21 20:56 ` Daniel Jacobowitz
2005-04-21 21:15 ` Mark Mitchell
2005-04-22 8:26 ` Eli Zaretskii
2005-04-22 12:08 ` Christopher Faylor
2005-04-22 13:23 ` Eli Zaretskii
2005-04-22 15:04 ` Christopher Faylor
2005-04-22 15:14 ` Ian Lance Taylor
2005-04-22 15:28 ` Christopher Faylor
2005-04-22 15:52 ` Mark Mitchell
2005-04-22 8:16 ` Eli Zaretskii
2005-04-24 22:18 ` Daniel Jacobowitz
2005-04-24 22:30 ` Mark Kettenis
2005-04-25 0:04 ` Mark Mitchell
2005-04-24 23:57 ` Mark Mitchell
2005-04-25 4:25 ` Christopher Faylor
2005-04-25 13:16 ` Daniel Jacobowitz
2005-04-25 14:50 ` Christopher Faylor
2005-04-25 14:59 ` Mark Mitchell
2005-04-25 15:04 ` Daniel Jacobowitz
2005-04-25 15:18 ` Mark Mitchell
2005-04-25 15:23 ` Daniel Jacobowitz
2005-04-25 15:26 ` Mark Mitchell
2005-04-25 15:36 ` Daniel Jacobowitz
2005-04-25 16:44 ` Eli Zaretskii
2005-04-25 20:23 ` Mark Mitchell [this message]
2005-04-25 21:07 ` Eli Zaretskii
2005-04-25 21:49 ` Mark Mitchell
2005-04-25 22:00 ` Mark Kettenis
2005-04-25 22:09 ` Mark Mitchell
2005-04-25 22:29 ` Mark Kettenis
2005-04-25 22:47 ` Mark Mitchell
2005-04-26 3:55 ` Eli Zaretskii
2005-04-25 23:16 ` Christopher Faylor
2005-04-25 23:20 ` Mark Mitchell
2005-04-25 23:33 ` Christopher Faylor
2005-04-26 0:21 ` Mark Mitchell
2005-04-26 3:58 ` Eli Zaretskii
2005-04-26 3:59 ` Mark Mitchell
2005-04-25 15:50 ` Ian Lance Taylor
2005-04-26 3:49 ` Eli Zaretskii
2005-04-26 13:17 ` Daniel Jacobowitz
2005-04-25 15:52 ` M.M. Kettenis
2005-04-25 16:00 ` Daniel Jacobowitz
2005-04-25 16:08 ` Ian Lance Taylor
2005-04-25 16:24 ` Christopher Faylor
2005-04-25 17:08 ` Mark Mitchell
2005-04-25 21:04 ` Eli Zaretskii
2005-04-25 16:42 ` Eli Zaretskii
2005-04-21 21:01 ` Christopher Faylor
2005-04-21 21:03 ` Christopher Faylor
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=426D5178.6010502@codesourcery.com \
--to=mark@codesourcery.com \
--cc=drow@false.org \
--cc=gdb-patches@sources.redhat.com \
--cc=me@cgf.cx \
/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