From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11540 invoked by alias); 25 Apr 2005 20:23:52 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 9182 invoked from network); 25 Apr 2005 20:22:26 -0000 Received: from unknown (HELO mail.codesourcery.com) (65.74.133.9) by sourceware.org with SMTP; 25 Apr 2005 20:22:26 -0000 Received: (qmail 22402 invoked from network); 25 Apr 2005 20:22:25 -0000 Received: from localhost (HELO ?147.11.233.46?) (mitchell@127.0.0.1) by mail.codesourcery.com with SMTP; 25 Apr 2005 20:22:25 -0000 Message-ID: <426D5178.6010502@codesourcery.com> Date: Mon, 25 Apr 2005 20:23:00 -0000 From: Mark Mitchell Organization: CodeSourcery, LLC User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: Daniel Jacobowitz CC: Christopher Faylor , gdb-patches@sources.redhat.com Subject: Re: PATCH: Support Windows in event-loop.c References: <20050424221806.GA13942@nevyn.them.org> <426C3270.4050608@codesourcery.com> <20050425042414.GA7322@trixie.casa.cgf.cx> <20050425131611.GA7821@nevyn.them.org> <20050425145023.GD6543@trixie.casa.cgf.cx> <426D05D6.8010903@codesourcery.com> <20050425150422.GA13753@nevyn.them.org> <426D0A11.4060604@codesourcery.com> <20050425152324.GA15521@nevyn.them.org> <426D0C1D.8040600@codesourcery.com> <20050425153549.GA15967@nevyn.them.org> In-Reply-To: <20050425153549.GA15967@nevyn.them.org> Content-Type: multipart/mixed; boundary="------------020608000903050300090601" X-SW-Source: 2005-04/txt/msg00321.txt.bz2 This is a multi-part message in MIME format. --------------020608000903050300090601 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 585 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 --------------020608000903050300090601 Content-Type: text/plain; name="gdb.event.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="gdb.event.patch" Content-length: 7124 2005-04-25 Mark Mitchell * event-loop.c (gdb_assert.h): Include. (): Include under Windows. (): 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 #include "gdb_string.h" #include #include #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 + #include + #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]); --------------020608000903050300090601--