public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/12] Merge event loop implementations
@ 2020-03-14 18:51 Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 01/12] Move start_event_loop out of event-loop.c Tom Tromey
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches

Here's v2 of the series to merge the event loop code between gdb and
gdbserver.  I've been meaning to resend this for a while (since Feb I
think) but I forgot about it.

The reviews for v1 are back in September 2019.

I think this version addresses all the review comments; but it's been
a while, so it is best to double check.

Let me know what you think.

Tom



^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 01/12] Move start_event_loop out of event-loop.c
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 02/12] Move event-loop configury to common.m4 Tom Tromey
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

A subsequent patch is going to move event-loop.c to gdbsupport.  In a
review of an earlier version of this series, Pedro pointed out that
the resulting code would be cleaner if start_event_loop were not
shared -- because gdb and gdbserver have some different needs here --
and so this moves start_event_loop to main.c.  Because the only caller
is there, it is also now static.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* event-loop.h (start_event_loop): Don't declare.
	* event-loop.c (start_event_loop): Move...
	* main.c (start_event_loop): ...here.  Now static.
---
 gdb/ChangeLog    |  6 ++++++
 gdb/event-loop.c | 54 ----------------------------------------------
 gdb/event-loop.h |  1 -
 gdb/main.c       | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index af8f80b6a2c..36df4767aa9 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -318,60 +318,6 @@ gdb_do_one_event (void)
   return 1;
 }
 
-/* Start up the event loop.  This is the entry point to the event loop
-   from the command loop.  */
-
-void
-start_event_loop (void)
-{
-  /* Loop until there is nothing to do.  This is the entry point to
-     the event loop engine.  gdb_do_one_event will process one event
-     for each invocation.  It blocks waiting for an event and then
-     processes it.  */
-  while (1)
-    {
-      int result = 0;
-
-      try
-	{
-	  result = gdb_do_one_event ();
-	}
-      catch (const gdb_exception &ex)
-	{
-	  exception_print (gdb_stderr, ex);
-
-	  /* If any exception escaped to here, we better enable
-	     stdin.  Otherwise, any command that calls async_disable_stdin,
-	     and then throws, will leave stdin inoperable.  */
-	  SWITCH_THRU_ALL_UIS ()
-	    {
-	      async_enable_stdin ();
-	    }
-	  /* If we long-jumped out of do_one_event, we probably didn't
-	     get around to resetting the prompt, which leaves readline
-	     in a messed-up state.  Reset it here.  */
-	  current_ui->prompt_state = PROMPT_NEEDED;
-	  gdb::observers::command_error.notify ();
-	  /* This call looks bizarre, but it is required.  If the user
-	     entered a command that caused an error,
-	     after_char_processing_hook won't be called from
-	     rl_callback_read_char_wrapper.  Using a cleanup there
-	     won't work, since we want this function to be called
-	     after a new prompt is printed.  */
-	  if (after_char_processing_hook)
-	    (*after_char_processing_hook) ();
-	  /* Maybe better to set a flag to be checked somewhere as to
-	     whether display the prompt or not.  */
-	}
-
-      if (result < 0)
-	break;
-    }
-
-  /* We are done with the event loop.  There are no more event sources
-     to listen to.  So we exit GDB.  */
-  return;
-}
 \f
 
 /* Wrapper function for create_file_handler, so that the caller
diff --git a/gdb/event-loop.h b/gdb/event-loop.h
index 64f3712786d..52740c3b9af 100644
--- a/gdb/event-loop.h
+++ b/gdb/event-loop.h
@@ -80,7 +80,6 @@ typedef void (timer_handler_func) (gdb_client_data);
 
 /* Exported functions from event-loop.c */
 
-extern void start_event_loop (void);
 extern int gdb_do_one_event (void);
 extern void delete_file_handler (int fd);
 extern void add_file_handler (int fd, handler_func *proc, 
diff --git a/gdb/main.c b/gdb/main.c
index a03ed8117ab..67a3d0027e1 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -53,6 +53,7 @@
 #include "gdbtk/generic/gdbtk.h"
 #endif
 #include "gdbsupport/alt-stack.h"
+#include "observable.h"
 
 /* The selected interpreter.  This will be used as a set command
    variable, so it should always be malloc'ed - since
@@ -336,6 +337,61 @@ get_init_files (std::vector<std::string> *system_gdbinit,
   *local_gdbinit = localinit;
 }
 
+/* Start up the event loop.  This is the entry point to the event loop
+   from the command loop.  */
+
+static void
+start_event_loop ()
+{
+  /* Loop until there is nothing to do.  This is the entry point to
+     the event loop engine.  gdb_do_one_event will process one event
+     for each invocation.  It blocks waiting for an event and then
+     processes it.  */
+  while (1)
+    {
+      int result = 0;
+
+      try
+	{
+	  result = gdb_do_one_event ();
+	}
+      catch (const gdb_exception &ex)
+	{
+	  exception_print (gdb_stderr, ex);
+
+	  /* If any exception escaped to here, we better enable
+	     stdin.  Otherwise, any command that calls async_disable_stdin,
+	     and then throws, will leave stdin inoperable.  */
+	  SWITCH_THRU_ALL_UIS ()
+	    {
+	      async_enable_stdin ();
+	    }
+	  /* If we long-jumped out of do_one_event, we probably didn't
+	     get around to resetting the prompt, which leaves readline
+	     in a messed-up state.  Reset it here.  */
+	  current_ui->prompt_state = PROMPT_NEEDED;
+	  gdb::observers::command_error.notify ();
+	  /* This call looks bizarre, but it is required.  If the user
+	     entered a command that caused an error,
+	     after_char_processing_hook won't be called from
+	     rl_callback_read_char_wrapper.  Using a cleanup there
+	     won't work, since we want this function to be called
+	     after a new prompt is printed.  */
+	  if (after_char_processing_hook)
+	    (*after_char_processing_hook) ();
+	  /* Maybe better to set a flag to be checked somewhere as to
+	     whether display the prompt or not.  */
+	}
+
+      if (result < 0)
+	break;
+    }
+
+  /* We are done with the event loop.  There are no more event sources
+     to listen to.  So we exit GDB.  */
+  return;
+}
+
 /* Call command_loop.  */
 
 /* Prevent inlining this function for the benefit of GDB's selftests
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 02/12] Move event-loop configury to common.m4
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 01/12] Move start_event_loop out of event-loop.c Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 03/12] Move gdb_select.h to gdbsupport/ Tom Tromey
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

gdb_select.h and the event loop require some configure checks, so this
moves the needed checks to common.m4 and updates the configure
scripts.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* configure.ac: Remove checks that are now in GDB_AC_COMMON.

gdbserver/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* configure: Rebuild.
	* config.in: Rebuild.

gdbsupport/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* config.in, configure: Rebuild.
	* common.m4 (GDB_AC_COMMON): Check for poll.h, sys/poll.h,
	sys/select.h, and poll.
---
 gdb/ChangeLog        |  5 +++++
 gdb/configure        | 10 +++++-----
 gdb/configure.ac     |  6 +++---
 gdbserver/ChangeLog  |  5 +++++
 gdbserver/config.in  | 12 ++++++++++++
 gdbserver/configure  |  4 ++--
 gdbsupport/ChangeLog |  6 ++++++
 gdbsupport/common.m4 |  5 +++--
 gdbsupport/config.in | 12 ++++++++++++
 gdbsupport/configure |  4 ++--
 10 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/gdb/configure b/gdb/configure
index 614f3402c3d..a70597e3e17 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -11615,11 +11615,11 @@ $as_echo "#define STDC_HEADERS 1" >>confdefs.h
 fi
 
 # elf_hp.h is for HP/UX 64-bit shared library support.
-for ac_header in nlist.h machine/reg.h poll.h sys/poll.h \
+for ac_header in nlist.h machine/reg.h \
                   thread_db.h \
 		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
 		  sys/resource.h sys/ptrace.h ptrace.h \
-		  sys/reg.h sys/debugreg.h sys/select.h \
+		  sys/reg.h sys/debugreg.h \
 		  termios.h elf_hp.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
@@ -12265,7 +12265,7 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
 # ------------------------------ #
 
 for ac_func in getuid getgid \
-		pipe poll pread pread64 pwrite resize_term \
+		pipe pread pread64 pwrite resize_term \
 		getpgid setsid \
 		sigaction sigsetmask socketpair \
 		ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
@@ -12778,7 +12778,7 @@ $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
   fi
 
 
-  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h 		   dlfcn.h 		   linux/elf.h sys/procfs.h proc_service.h
+  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h 		   dlfcn.h 		   linux/elf.h sys/procfs.h proc_service.h 		   poll.h sys/poll.h sys/select.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -13183,7 +13183,7 @@ $as_echo "#define HAVE_WORKING_FORK 1" >>confdefs.h
 
 fi
 
-  for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \
+  for ac_func in fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
 		  setpgid setpgrp getrusage getauxval
 do :
diff --git a/gdb/configure.ac b/gdb/configure.ac
index b9dbe13232a..f405a0351d7 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -1229,11 +1229,11 @@ AC_SUBST(SRCHIGH_CFLAGS)
 
 AC_HEADER_STDC
 # elf_hp.h is for HP/UX 64-bit shared library support.
-AC_CHECK_HEADERS([nlist.h machine/reg.h poll.h sys/poll.h \
+AC_CHECK_HEADERS([nlist.h machine/reg.h \
                   thread_db.h \
 		  sys/file.h sys/filio.h sys/ioctl.h sys/param.h \
 		  sys/resource.h sys/ptrace.h ptrace.h \
-		  sys/reg.h sys/debugreg.h sys/select.h \
+		  sys/reg.h sys/debugreg.h \
 		  termios.h elf_hp.h])
 AC_CHECK_HEADERS(sys/user.h, [], [],
 [#if HAVE_SYS_PARAM_H
@@ -1279,7 +1279,7 @@ AC_C_BIGENDIAN
 # ------------------------------ #
 
 AC_CHECK_FUNCS([getuid getgid \
-		pipe poll pread pread64 pwrite resize_term \
+		pipe pread pread64 pwrite resize_term \
 		getpgid setsid \
 		sigaction sigsetmask socketpair \
 		ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
diff --git a/gdbserver/config.in b/gdbserver/config.in
index e62795072f2..8376b81d63f 100644
--- a/gdbserver/config.in
+++ b/gdbserver/config.in
@@ -195,6 +195,12 @@
 /* Define to 1 if you have the `pipe2' function. */
 #undef HAVE_PIPE2
 
+/* Define to 1 if you have the `poll' function. */
+#undef HAVE_POLL
+
+/* Define to 1 if you have the <poll.h> header file. */
+#undef HAVE_POLL_H
+
 /* Define to 1 if you have the `pread' function. */
 #undef HAVE_PREAD
 
@@ -319,6 +325,9 @@
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#undef HAVE_SYS_POLL_H
+
 /* Define to 1 if you have the <sys/procfs.h> header file. */
 #undef HAVE_SYS_PROCFS_H
 
@@ -331,6 +340,9 @@
 /* Define to 1 if you have the <sys/resource.h> header file. */
 #undef HAVE_SYS_RESOURCE_H
 
+/* Define to 1 if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
 /* Define to 1 if you have the <sys/socket.h> header file. */
 #undef HAVE_SYS_SOCKET_H
 
diff --git a/gdbserver/configure b/gdbserver/configure
index 55cf2416b56..4ed95baf73f 100755
--- a/gdbserver/configure
+++ b/gdbserver/configure
@@ -6706,7 +6706,7 @@ $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
   fi
 
 
-  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h 		   dlfcn.h 		   linux/elf.h sys/procfs.h proc_service.h
+  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h 		   dlfcn.h 		   linux/elf.h sys/procfs.h proc_service.h 		   poll.h sys/poll.h sys/select.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -7111,7 +7111,7 @@ $as_echo "#define HAVE_WORKING_FORK 1" >>confdefs.h
 
 fi
 
-  for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \
+  for ac_func in fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
 		  setpgid setpgrp getrusage getauxval
 do :
diff --git a/gdbsupport/common.m4 b/gdbsupport/common.m4
index e67058632ca..b461f5f017d 100644
--- a/gdbsupport/common.m4
+++ b/gdbsupport/common.m4
@@ -46,11 +46,12 @@ AC_DEFUN([GDB_AC_COMMON], [
 		   thread_db.h wait.h dnl
 		   termios.h dnl
 		   dlfcn.h dnl
-		   linux/elf.h sys/procfs.h proc_service.h)
+		   linux/elf.h sys/procfs.h proc_service.h dnl
+		   poll.h sys/poll.h sys/select.h)
 
   AC_FUNC_MMAP
   AC_FUNC_VFORK
-  AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 socketpair sigaction \
+  AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
 		  setpgid setpgrp getrusage getauxval])
 
diff --git a/gdbsupport/config.in b/gdbsupport/config.in
index 6a6b0bc74f0..3ba9d521cb2 100644
--- a/gdbsupport/config.in
+++ b/gdbsupport/config.in
@@ -155,6 +155,12 @@
 /* Define to 1 if you have the `pipe2' function. */
 #undef HAVE_PIPE2
 
+/* Define to 1 if you have the `poll' function. */
+#undef HAVE_POLL
+
+/* Define to 1 if you have the <poll.h> header file. */
+#undef HAVE_POLL_H
+
 /* Define if <sys/procfs.h> has prfpregset_t. */
 #undef HAVE_PRFPREGSET_T
 
@@ -245,6 +251,9 @@
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
+/* Define to 1 if you have the <sys/poll.h> header file. */
+#undef HAVE_SYS_POLL_H
+
 /* Define to 1 if you have the <sys/procfs.h> header file. */
 #undef HAVE_SYS_PROCFS_H
 
@@ -254,6 +263,9 @@
 /* Define to 1 if you have the <sys/resource.h> header file. */
 #undef HAVE_SYS_RESOURCE_H
 
+/* Define to 1 if you have the <sys/select.h> header file. */
+#undef HAVE_SYS_SELECT_H
+
 /* Define to 1 if you have the <sys/socket.h> header file. */
 #undef HAVE_SYS_SOCKET_H
 
diff --git a/gdbsupport/configure b/gdbsupport/configure
index 2ffe539eb09..bace202f651 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -8404,7 +8404,7 @@ $as_echo "#define HAVE_LANGINFO_CODESET 1" >>confdefs.h
   fi
 
 
-  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h 		   dlfcn.h 		   linux/elf.h sys/procfs.h proc_service.h
+  for ac_header in linux/perf_event.h locale.h memory.h signal.h 		   sys/resource.h sys/socket.h 		   sys/un.h sys/wait.h 		   thread_db.h wait.h 		   termios.h 		   dlfcn.h 		   linux/elf.h sys/procfs.h proc_service.h 		   poll.h sys/poll.h sys/select.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
 ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
@@ -8809,7 +8809,7 @@ $as_echo "#define HAVE_WORKING_FORK 1" >>confdefs.h
 
 fi
 
-  for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \
+  for ac_func in fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
 		  ptrace64 sbrk setns sigaltstack sigprocmask \
 		  setpgid setpgrp getrusage getauxval
 do :
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 03/12] Move gdb_select.h to gdbsupport/
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 01/12] Move start_event_loop out of event-loop.c Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 02/12] Move event-loop configury to common.m4 Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 04/12] Include <chrono> in event-loop.c Tom Tromey
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves gdb_select.h to gdbsupport/, so it can be used by other
code there.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* gdb_select.h: Move to ../gdbsupport/.
	* event-loop.c: Update include path.
	* top.c: Update include path.
	* ser-base.c: Update include path.
	* ui-file.c: Update include path.
	* ser-tcp.c: Update include path.
	* guile/scm-ports.c: Update include path.
	* posix-hdep.c: Update include path.
	* ser-unix.c: Update include path.
	* gdb_usleep.c: Update include path.
	* mingw-hdep.c: Update include path.
	* inflow.c: Update include path.
	* infrun.c: Update include path.
	* event-top.c: Update include path.

gdbsupport/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* gdb_select.h: Move from ../gdb/.
---
 gdb/ChangeLog                    | 17 +++++++++++++++++
 gdb/event-loop.c                 |  3 +--
 gdb/event-top.c                  |  2 +-
 gdb/guile/scm-ports.c            |  2 +-
 gdb/inflow.c                     |  2 +-
 gdb/infrun.c                     |  2 +-
 gdb/mingw-hdep.c                 |  2 +-
 gdb/posix-hdep.c                 |  2 +-
 gdb/ser-base.c                   |  2 +-
 gdb/ser-tcp.c                    |  2 +-
 gdb/ser-unix.c                   |  2 +-
 gdb/top.c                        |  2 +-
 gdb/ui-file.c                    |  2 +-
 gdbsupport/ChangeLog             |  4 ++++
 {gdb => gdbsupport}/gdb_select.h |  0
 15 files changed, 33 insertions(+), 13 deletions(-)
 rename {gdb => gdbsupport}/gdb_select.h (100%)

diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 36df4767aa9..ae9d27eedd7 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -32,8 +32,7 @@
 
 #include <sys/types.h>
 #include "gdbsupport/gdb_sys_time.h"
-#include "gdb_select.h"
-#include "observable.h"
+#include "gdbsupport/gdb_select.h"
 #include "top.h"
 
 /* Tell create_file_handler what events we are interested in.
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 1bfc28ea099..965ecd536f6 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -39,7 +39,7 @@
 #include "maint.h"
 #include "gdbsupport/buffer.h"
 #include "ser-event.h"
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include "gdbsupport/gdb-sigmask.h"
 
 /* readline include files.  */
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 3f832dc753a..407d1d36f1f 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -22,7 +22,7 @@
    conventions, et.al.  */
 
 #include "defs.h"
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include "top.h"
 #include "target.h"
 #include "guile-internal.h"
diff --git a/gdb/inflow.c b/gdb/inflow.c
index e5e595ed981..1b8e819436a 100644
--- a/gdb/inflow.c
+++ b/gdb/inflow.c
@@ -27,7 +27,7 @@
 #include "observable.h"
 #include <signal.h>
 #include <fcntl.h>
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 
 #include "inflow.h"
 #include "gdbcmd.h"
diff --git a/gdb/infrun.c b/gdb/infrun.c
index d672d1a1609..adde9d7f6d9 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -64,7 +64,7 @@
 #include "arch-utils.h"
 #include "gdbsupport/scope-exit.h"
 #include "gdbsupport/forward-scope-exit.h"
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include <unordered_map>
 
 /* Prototypes for local functions */
diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c
index cc425491dc9..016cf2d2310 100644
--- a/gdb/mingw-hdep.c
+++ b/gdb/mingw-hdep.c
@@ -22,7 +22,7 @@
 #include "serial.h"
 #include "event-loop.h"
 
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 
 #include <windows.h>
 
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c
index cca72418aac..e5754cd701a 100644
--- a/gdb/posix-hdep.c
+++ b/gdb/posix-hdep.c
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "event-loop.h"
 
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 
 /* Wrapper for select.  Nothing special needed on POSIX platforms.  */
 
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 89d9a695c2f..8231ec51543 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -22,7 +22,7 @@
 #include "ser-base.h"
 #include "event-loop.h"
 
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include "gdbsupport/gdb_sys_time.h"
 #ifdef USE_WIN32API
 #include <winsock2.h>
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index c5581744f99..1c6d5a346c6 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -58,7 +58,7 @@
 #endif
 
 #include <signal.h>
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include <algorithm>
 
 #ifndef HAVE_SOCKLEN_T
diff --git a/gdb/ser-unix.c b/gdb/ser-unix.c
index 8000e352a09..9a13acddbc8 100644
--- a/gdb/ser-unix.c
+++ b/gdb/ser-unix.c
@@ -28,7 +28,7 @@
 #include <sys/socket.h>
 #include "gdbsupport/gdb_sys_time.h"
 
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include "gdbcmd.h"
 #include "gdbsupport/filestuff.h"
 #include <termios.h>
diff --git a/gdb/top.c b/gdb/top.c
index e2432489dc8..010aa6fb771 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -51,7 +51,7 @@
 #include "filenames.h"
 #include "frame.h"
 #include "gdbsupport/buffer.h"
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include "gdbsupport/scope-exit.h"
 #include "gdbarch.h"
 #include "gdbsupport/pathstuff.h"
diff --git a/gdb/ui-file.c b/gdb/ui-file.c
index f3adbd014aa..a7b63a494b9 100644
--- a/gdb/ui-file.c
+++ b/gdb/ui-file.c
@@ -22,7 +22,7 @@
 #include "defs.h"
 #include "ui-file.h"
 #include "gdb_obstack.h"
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
 #include "gdbsupport/filestuff.h"
 #include "cli/cli-style.h"
 
diff --git a/gdb/gdb_select.h b/gdbsupport/gdb_select.h
similarity index 100%
rename from gdb/gdb_select.h
rename to gdbsupport/gdb_select.h
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 04/12] Include <chrono> in event-loop.c
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (2 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 03/12] Move gdb_select.h to gdbsupport/ Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 05/12] Use warning in event-loop Tom Tromey
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Include <chrono> in event-loop.c, because it is used there.  Currently
it is included indirectly, but after the subsequent patches this will
no longer be the case.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* event-loop.c: Include <chrono>.
---
 gdb/ChangeLog    | 4 ++++
 gdb/event-loop.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index ae9d27eedd7..880fc30d9d6 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -22,6 +22,8 @@
 #include "event-top.h"
 #include "ser-event.h"
 
+#include <chrono>
+
 #ifdef HAVE_POLL
 #if defined (HAVE_POLL_H)
 #include <poll.h>
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 05/12] Use warning in event-loop
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (3 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 04/12] Include <chrono> in event-loop.c Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 06/12] Introduce and use flush_streams Tom Tromey
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Change event-loop.c to avoid printf_unfiltered in favor of warning.
warning is aleady available to code in gdbsupport/.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* event-loop.c (handle_file_event): Use warning, not
	printf_unfiltered.
---
 gdb/ChangeLog    |  5 +++++
 gdb/event-loop.c | 11 +++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 880fc30d9d6..a5d2f6fa1cc 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -616,11 +616,10 @@ handle_file_event (file_handler *file_ptr, int ready_mask)
 		  /* Work in progress.  We may need to tell somebody
 		     what kind of error we had.  */
 		  if (mask & POLLERR)
-		    printf_unfiltered (_("Error detected on fd %d\n"),
-				       file_ptr->fd);
+		    warning (_("Error detected on fd %d"), file_ptr->fd);
 		  if (mask & POLLNVAL)
-		    printf_unfiltered (_("Invalid or non-`poll'able fd %d\n"),
-				       file_ptr->fd);
+		    warning (_("Invalid or non-`poll'able fd %d"),
+			     file_ptr->fd);
 		  file_ptr->error = 1;
 		}
 	      else
@@ -634,8 +633,8 @@ handle_file_event (file_handler *file_ptr, int ready_mask)
 	    {
 	      if (ready_mask & GDB_EXCEPTION)
 		{
-		  printf_unfiltered (_("Exception condition detected "
-				       "on fd %d\n"), file_ptr->fd);
+		  warning (_("Exception condition detected on fd %d"),
+			   file_ptr->fd);
 		  file_ptr->error = 1;
 		}
 	      else
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 06/12] Introduce and use flush_streams
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (4 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 05/12] Use warning in event-loop Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 07/12] Introduce async-event.[ch] Tom Tromey
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Code in gdbsupport can't call gdb_flush, so this introduces a new
"flush_streams" function that must be supplied by the client.

Note that the similar gdb_flush_out_err exists, but it isn't defined
in quite the same way, so it wasn't clear to me whether the two could
be merged.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* utils.c (flush_streams): New function.
	* event-loop.c (gdb_wait_for_event): Call flush_streams.

gdbsupport/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* errors.h (flush_streams): Declare.
---
 gdb/ChangeLog        | 5 +++++
 gdb/event-loop.c     | 3 +--
 gdb/utils.c          | 9 +++++++++
 gdbsupport/ChangeLog | 4 ++++
 gdbsupport/errors.h  | 4 ++++
 5 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index a5d2f6fa1cc..4ce8899612c 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -663,8 +663,7 @@ gdb_wait_for_event (int block)
   int num_found = 0;
 
   /* Make sure all output is done before getting another event.  */
-  gdb_stdout->flush ();
-  gdb_stderr->flush ();
+  flush_streams ();
 
   if (gdb_notifier.num_fds == 0)
     return -1;
diff --git a/gdb/utils.c b/gdb/utils.c
index 0b470120a22..f9cde46ad8d 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -691,6 +691,15 @@ malloc_failure (long size)
     }
 }
 
+/* See common/errors.h.  */
+
+void
+flush_streams ()
+{
+  gdb_stdout->flush ();
+  gdb_stderr->flush ();
+}
+
 /* My replacement for the read system call.
    Used like `read' but keeps going if `read' returns too soon.  */
 
diff --git a/gdbsupport/errors.h b/gdbsupport/errors.h
index da13482798a..f8f6c157f23 100644
--- a/gdbsupport/errors.h
+++ b/gdbsupport/errors.h
@@ -87,4 +87,8 @@ extern void perror_with_name (const char *string) ATTRIBUTE_NORETURN;
 
 extern void malloc_failure (long size) ATTRIBUTE_NORETURN;
 
+/* Flush stdout and stderr.  Must be provided by the client.  */
+
+extern void flush_streams ();
+
 #endif /* COMMON_ERRORS_H */
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 07/12] Introduce async-event.[ch]
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (5 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 06/12] Introduce and use flush_streams Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 08/12] Move event-loop.[ch] to gdbsupport/ Tom Tromey
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This patch splits out some gdb-specific code from event-loop, into new
files async-event.[ch].  Strictly speaking this code could perhaps be
put into gdbsupport/, but because gdbserver does not currently use it,
it seemed better, for size reasons, to split it out.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* tui/tui-win.c: Include async-event.h.
	* remote.c: Include async-event.h.
	* remote-notif.c: Include async-event.h.
	* record-full.c: Include async-event.h.
	* record-btrace.c: Include async-event.h.
	* infrun.c: Include async-event.h.
	* event-top.c: Include async-event.h.
	* event-loop.h: Move some declarations to async-event.h.
	* event-loop.c: Don't include ser-event.h or top.h.  Move some
	code to async-event.c.
	* async-event.h: New file.
	* async-event.c: New file.
	* Makefile.in (COMMON_SFILES): Add async-event.c.
	(HFILES_NO_SRCDIR): Add async-event.h.
---
 gdb/ChangeLog       |  17 +++
 gdb/Makefile.in     |   2 +
 gdb/async-event.c   | 325 ++++++++++++++++++++++++++++++++++++++++++++
 gdb/async-event.h   |  71 ++++++++++
 gdb/event-loop.c    | 306 -----------------------------------------
 gdb/event-loop.h    |  47 ++-----
 gdb/event-top.c     |   1 +
 gdb/infrun.c        |   1 +
 gdb/record-btrace.c |   1 +
 gdb/record-full.c   |   1 +
 gdb/remote-notif.c  |   1 +
 gdb/remote.c        |   1 +
 gdb/tui/tui-win.c   |   1 +
 13 files changed, 430 insertions(+), 345 deletions(-)
 create mode 100644 gdb/async-event.c
 create mode 100644 gdb/async-event.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 1db02c07ac2..31d443ff12b 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -954,6 +954,7 @@ COMMON_SFILES = \
 	alloc.c \
 	annotate.c \
 	arch-utils.c \
+	async-event.c \
 	auto-load.c \
 	auxv.c \
 	ax-gdb.c \
@@ -1208,6 +1209,7 @@ HFILES_NO_SRCDIR = \
 	arm-linux-tdep.h \
 	arm-nbsd-tdep.h \
 	arm-tdep.h \
+	async-event.h \
 	auto-load.h \
 	auxv.h \
 	ax.h \
diff --git a/gdb/async-event.c b/gdb/async-event.c
new file mode 100644
index 00000000000..dd65c17468b
--- /dev/null
+++ b/gdb/async-event.c
@@ -0,0 +1,325 @@
+/* Async events for the GDB event loop.
+   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "async-event.h"
+
+#include "ser-event.h"
+#include "top.h"
+
+/* PROC is a function to be invoked when the READY flag is set.  This
+   happens when there has been a signal and the corresponding signal
+   handler has 'triggered' this async_signal_handler for execution.
+   The actual work to be done in response to a signal will be carried
+   out by PROC at a later time, within process_event.  This provides a
+   deferred execution of signal handlers.
+
+   Async_init_signals takes care of setting up such an
+   async_signal_handler for each interesting signal.  */
+
+typedef struct async_signal_handler
+  {
+    int ready;			    /* If ready, call this handler
+				       from the main event loop, using
+				       invoke_async_handler.  */
+    struct async_signal_handler *next_handler;	/* Ptr to next handler.  */
+    sig_handler_func *proc;	    /* Function to call to do the work.  */
+    gdb_client_data client_data;    /* Argument to async_handler_func.  */
+  }
+async_signal_handler;
+
+/* PROC is a function to be invoked when the READY flag is set.  This
+   happens when the event has been marked with
+   MARK_ASYNC_EVENT_HANDLER.  The actual work to be done in response
+   to an event will be carried out by PROC at a later time, within
+   process_event.  This provides a deferred execution of event
+   handlers.  */
+typedef struct async_event_handler
+  {
+    /* If ready, call this handler from the main event loop, using
+       invoke_event_handler.  */
+    int ready;
+
+    /* Point to next handler.  */
+    struct async_event_handler *next_handler;
+
+    /* Function to call to do the work.  */
+    async_event_handler_func *proc;
+
+    /* Argument to PROC.  */
+    gdb_client_data client_data;
+  }
+async_event_handler;
+
+/* All the async_signal_handlers gdb is interested in are kept onto
+   this list.  */
+static struct
+  {
+    /* Pointer to first in handler list.  */
+    async_signal_handler *first_handler;
+
+    /* Pointer to last in handler list.  */
+    async_signal_handler *last_handler;
+  }
+sighandler_list;
+
+/* All the async_event_handlers gdb is interested in are kept onto
+   this list.  */
+static struct
+  {
+    /* Pointer to first in handler list.  */
+    async_event_handler *first_handler;
+
+    /* Pointer to last in handler list.  */
+    async_event_handler *last_handler;
+  }
+async_event_handler_list;
+
+
+/* This event is signalled whenever an asynchronous handler needs to
+   defer an action to the event loop.  */
+static struct serial_event *async_signal_handlers_serial_event;
+
+/* Callback registered with ASYNC_SIGNAL_HANDLERS_SERIAL_EVENT.  */
+
+static void
+async_signals_handler (int error, gdb_client_data client_data)
+{
+  /* Do nothing.  Handlers are run by invoke_async_signal_handlers
+     from instead.  */
+}
+
+void
+initialize_async_signal_handlers (void)
+{
+  async_signal_handlers_serial_event = make_serial_event ();
+
+  add_file_handler (serial_event_fd (async_signal_handlers_serial_event),
+		    async_signals_handler, NULL);
+}
+
+\f
+
+/* Create an asynchronous handler, allocating memory for it.
+   Return a pointer to the newly created handler.
+   This pointer will be used to invoke the handler by 
+   invoke_async_signal_handler.
+   PROC is the function to call with CLIENT_DATA argument 
+   whenever the handler is invoked.  */
+async_signal_handler *
+create_async_signal_handler (sig_handler_func * proc,
+			     gdb_client_data client_data)
+{
+  async_signal_handler *async_handler_ptr;
+
+  async_handler_ptr = XNEW (async_signal_handler);
+  async_handler_ptr->ready = 0;
+  async_handler_ptr->next_handler = NULL;
+  async_handler_ptr->proc = proc;
+  async_handler_ptr->client_data = client_data;
+  if (sighandler_list.first_handler == NULL)
+    sighandler_list.first_handler = async_handler_ptr;
+  else
+    sighandler_list.last_handler->next_handler = async_handler_ptr;
+  sighandler_list.last_handler = async_handler_ptr;
+  return async_handler_ptr;
+}
+
+/* Mark the handler (ASYNC_HANDLER_PTR) as ready.  This information
+   will be used when the handlers are invoked, after we have waited
+   for some event.  The caller of this function is the interrupt
+   handler associated with a signal.  */
+void
+mark_async_signal_handler (async_signal_handler * async_handler_ptr)
+{
+  async_handler_ptr->ready = 1;
+  serial_event_set (async_signal_handlers_serial_event);
+}
+
+/* See event-loop.h.  */
+
+void
+clear_async_signal_handler (async_signal_handler *async_handler_ptr)
+{
+  async_handler_ptr->ready = 0;
+}
+
+/* See event-loop.h.  */
+
+int
+async_signal_handler_is_marked (async_signal_handler *async_handler_ptr)
+{
+  return async_handler_ptr->ready;
+}
+
+/* Call all the handlers that are ready.  Returns true if any was
+   indeed ready.  */
+
+int
+invoke_async_signal_handlers (void)
+{
+  async_signal_handler *async_handler_ptr;
+  int any_ready = 0;
+
+  /* We're going to handle all pending signals, so no need to wake up
+     the event loop again the next time around.  Note this must be
+     cleared _before_ calling the callbacks, to avoid races.  */
+  serial_event_clear (async_signal_handlers_serial_event);
+
+  /* Invoke all ready handlers.  */
+
+  while (1)
+    {
+      for (async_handler_ptr = sighandler_list.first_handler;
+	   async_handler_ptr != NULL;
+	   async_handler_ptr = async_handler_ptr->next_handler)
+	{
+	  if (async_handler_ptr->ready)
+	    break;
+	}
+      if (async_handler_ptr == NULL)
+	break;
+      any_ready = 1;
+      async_handler_ptr->ready = 0;
+      /* Async signal handlers have no connection to whichever was the
+	 current UI, and thus always run on the main one.  */
+      current_ui = main_ui;
+      (*async_handler_ptr->proc) (async_handler_ptr->client_data);
+    }
+
+  return any_ready;
+}
+
+/* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
+   Free the space allocated for it.  */
+void
+delete_async_signal_handler (async_signal_handler ** async_handler_ptr)
+{
+  async_signal_handler *prev_ptr;
+
+  if (sighandler_list.first_handler == (*async_handler_ptr))
+    {
+      sighandler_list.first_handler = (*async_handler_ptr)->next_handler;
+      if (sighandler_list.first_handler == NULL)
+	sighandler_list.last_handler = NULL;
+    }
+  else
+    {
+      prev_ptr = sighandler_list.first_handler;
+      while (prev_ptr && prev_ptr->next_handler != (*async_handler_ptr))
+	prev_ptr = prev_ptr->next_handler;
+      gdb_assert (prev_ptr);
+      prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
+      if (sighandler_list.last_handler == (*async_handler_ptr))
+	sighandler_list.last_handler = prev_ptr;
+    }
+  xfree ((*async_handler_ptr));
+  (*async_handler_ptr) = NULL;
+}
+
+/* Create an asynchronous event handler, allocating memory for it.
+   Return a pointer to the newly created handler.  PROC is the
+   function to call with CLIENT_DATA argument whenever the handler is
+   invoked.  */
+async_event_handler *
+create_async_event_handler (async_event_handler_func *proc,
+			    gdb_client_data client_data)
+{
+  async_event_handler *h;
+
+  h = XNEW (struct async_event_handler);
+  h->ready = 0;
+  h->next_handler = NULL;
+  h->proc = proc;
+  h->client_data = client_data;
+  if (async_event_handler_list.first_handler == NULL)
+    async_event_handler_list.first_handler = h;
+  else
+    async_event_handler_list.last_handler->next_handler = h;
+  async_event_handler_list.last_handler = h;
+  return h;
+}
+
+/* Mark the handler (ASYNC_HANDLER_PTR) as ready.  This information
+   will be used by gdb_do_one_event.  The caller will be whoever
+   created the event source, and wants to signal that the event is
+   ready to be handled.  */
+void
+mark_async_event_handler (async_event_handler *async_handler_ptr)
+{
+  async_handler_ptr->ready = 1;
+}
+
+/* See event-loop.h.  */
+
+void
+clear_async_event_handler (async_event_handler *async_handler_ptr)
+{
+  async_handler_ptr->ready = 0;
+}
+
+/* Check if asynchronous event handlers are ready, and call the
+   handler function for one that is.  */
+
+int
+check_async_event_handlers ()
+{
+  async_event_handler *async_handler_ptr;
+
+  for (async_handler_ptr = async_event_handler_list.first_handler;
+       async_handler_ptr != NULL;
+       async_handler_ptr = async_handler_ptr->next_handler)
+    {
+      if (async_handler_ptr->ready)
+	{
+	  async_handler_ptr->ready = 0;
+	  (*async_handler_ptr->proc) (async_handler_ptr->client_data);
+	  return 1;
+	}
+    }
+
+  return 0;
+}
+
+/* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
+   Free the space allocated for it.  */
+void
+delete_async_event_handler (async_event_handler **async_handler_ptr)
+{
+  async_event_handler *prev_ptr;
+
+  if (async_event_handler_list.first_handler == *async_handler_ptr)
+    {
+      async_event_handler_list.first_handler
+	= (*async_handler_ptr)->next_handler;
+      if (async_event_handler_list.first_handler == NULL)
+	async_event_handler_list.last_handler = NULL;
+    }
+  else
+    {
+      prev_ptr = async_event_handler_list.first_handler;
+      while (prev_ptr && prev_ptr->next_handler != *async_handler_ptr)
+	prev_ptr = prev_ptr->next_handler;
+      gdb_assert (prev_ptr);
+      prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
+      if (async_event_handler_list.last_handler == (*async_handler_ptr))
+	async_event_handler_list.last_handler = prev_ptr;
+    }
+  xfree (*async_handler_ptr);
+  *async_handler_ptr = NULL;
+}
diff --git a/gdb/async-event.h b/gdb/async-event.h
new file mode 100644
index 00000000000..408f7764f7c
--- /dev/null
+++ b/gdb/async-event.h
@@ -0,0 +1,71 @@
+/* Async events for the GDB event loop.
+   Copyright (C) 1999-2019 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef ASYNC_EVENT_H
+#define ASYNC_EVENT_H
+
+#include "event-loop.h"
+
+struct async_signal_handler;
+struct async_event_handler;
+typedef void (sig_handler_func) (gdb_client_data);
+typedef void (async_event_handler_func) (gdb_client_data);
+
+extern struct async_signal_handler *
+  create_async_signal_handler (sig_handler_func *proc, 
+			       gdb_client_data client_data);
+extern void delete_async_signal_handler (struct async_signal_handler **);
+
+/* Call the handler from HANDLER the next time through the event
+   loop.  */
+extern void mark_async_signal_handler (struct async_signal_handler *handler);
+
+/* Returns true if HANDLER is marked ready.  */
+
+extern int
+  async_signal_handler_is_marked (struct async_signal_handler *handler);
+
+/* Mark HANDLER as NOT ready.  */
+
+extern void clear_async_signal_handler (struct async_signal_handler *handler);
+
+/* Create and register an asynchronous event source in the event loop,
+   and set PROC as its callback.  CLIENT_DATA is passed as argument to
+   PROC upon its invocation.  Returns a pointer to an opaque structure
+   used to mark as ready and to later delete this event source from
+   the event loop.  */
+extern struct async_event_handler *
+  create_async_event_handler (async_event_handler_func *proc,
+			      gdb_client_data client_data);
+
+/* Remove the event source pointed by HANDLER_PTR created by
+   CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it.  */
+extern void
+  delete_async_event_handler (struct async_event_handler **handler_ptr);
+
+/* Call the handler from HANDLER the next time through the event
+   loop.  */
+extern void mark_async_event_handler (struct async_event_handler *handler);
+
+/* Mark the handler (ASYNC_HANDLER_PTR) as NOT ready.  */
+
+extern void clear_async_event_handler (struct async_event_handler *handler);
+
+extern void initialize_async_signal_handlers (void);
+
+#endif /* ASYNC_EVENT_H */
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 4ce8899612c..e5347d2e3f0 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -19,8 +19,6 @@
 
 #include "defs.h"
 #include "event-loop.h"
-#include "event-top.h"
-#include "ser-event.h"
 
 #include <chrono>
 
@@ -35,7 +33,6 @@
 #include <sys/types.h>
 #include "gdbsupport/gdb_sys_time.h"
 #include "gdbsupport/gdb_select.h"
-#include "top.h"
 
 /* Tell create_file_handler what events we are interested in.
    This is used by the select version of the event loop.  */
@@ -60,50 +57,6 @@ typedef struct file_handler
   }
 file_handler;
 
-/* PROC is a function to be invoked when the READY flag is set.  This
-   happens when there has been a signal and the corresponding signal
-   handler has 'triggered' this async_signal_handler for execution.
-   The actual work to be done in response to a signal will be carried
-   out by PROC at a later time, within process_event.  This provides a
-   deferred execution of signal handlers.
-
-   Async_init_signals takes care of setting up such an
-   async_signal_handler for each interesting signal.  */
-
-typedef struct async_signal_handler
-  {
-    int ready;			    /* If ready, call this handler
-				       from the main event loop, using
-				       invoke_async_handler.  */
-    struct async_signal_handler *next_handler;	/* Ptr to next handler.  */
-    sig_handler_func *proc;	    /* Function to call to do the work.  */
-    gdb_client_data client_data;    /* Argument to async_handler_func.  */
-  }
-async_signal_handler;
-
-/* PROC is a function to be invoked when the READY flag is set.  This
-   happens when the event has been marked with
-   MARK_ASYNC_EVENT_HANDLER.  The actual work to be done in response
-   to an event will be carried out by PROC at a later time, within
-   process_event.  This provides a deferred execution of event
-   handlers.  */
-typedef struct async_event_handler
-  {
-    /* If ready, call this handler from the main event loop, using
-       invoke_event_handler.  */
-    int ready;
-
-    /* Point to next handler.  */
-    struct async_event_handler *next_handler;
-
-    /* Function to call to do the work.  */
-    async_event_handler_func *proc;
-
-    /* Argument to PROC.  */
-    gdb_client_data client_data;
-  }
-async_event_handler;
-
 /* Gdb_notifier is just a list of file descriptors gdb is interested in.
    These are the input file descriptor, and the target file
    descriptor.  We have two flavors of the notifier, one for platforms
@@ -198,61 +151,12 @@ static struct
   }
 timer_list;
 
-/* All the async_signal_handlers gdb is interested in are kept onto
-   this list.  */
-static struct
-  {
-    /* Pointer to first in handler list.  */
-    async_signal_handler *first_handler;
-
-    /* Pointer to last in handler list.  */
-    async_signal_handler *last_handler;
-  }
-sighandler_list;
-
-/* All the async_event_handlers gdb is interested in are kept onto
-   this list.  */
-static struct
-  {
-    /* Pointer to first in handler list.  */
-    async_event_handler *first_handler;
-
-    /* Pointer to last in handler list.  */
-    async_event_handler *last_handler;
-  }
-async_event_handler_list;
-
-static int invoke_async_signal_handlers (void);
 static void create_file_handler (int fd, int mask, handler_func *proc,
 				 gdb_client_data client_data);
-static int check_async_event_handlers (void);
 static int gdb_wait_for_event (int);
 static int update_wait_timeout (void);
 static int poll_timers (void);
 \f
-
-/* This event is signalled whenever an asynchronous handler needs to
-   defer an action to the event loop.  */
-static struct serial_event *async_signal_handlers_serial_event;
-
-/* Callback registered with ASYNC_SIGNAL_HANDLERS_SERIAL_EVENT.  */
-
-static void
-async_signals_handler (int error, gdb_client_data client_data)
-{
-  /* Do nothing.  Handlers are run by invoke_async_signal_handlers
-     from instead.  */
-}
-
-void
-initialize_async_signal_handlers (void)
-{
-  async_signal_handlers_serial_event = make_serial_event ();
-
-  add_file_handler (serial_event_fd (async_signal_handlers_serial_event),
-		    async_signals_handler, NULL);
-}
-
 /* Process one high level event.  If nothing is ready at this time,
    wait for something to happen (via gdb_wait_for_event), then process
    it.  Returns >0 if something was done otherwise returns <0 (this
@@ -800,216 +704,6 @@ gdb_wait_for_event (int block)
   return 0;
 }
 \f
-
-/* Create an asynchronous handler, allocating memory for it.
-   Return a pointer to the newly created handler.
-   This pointer will be used to invoke the handler by 
-   invoke_async_signal_handler.
-   PROC is the function to call with CLIENT_DATA argument 
-   whenever the handler is invoked.  */
-async_signal_handler *
-create_async_signal_handler (sig_handler_func * proc,
-			     gdb_client_data client_data)
-{
-  async_signal_handler *async_handler_ptr;
-
-  async_handler_ptr = XNEW (async_signal_handler);
-  async_handler_ptr->ready = 0;
-  async_handler_ptr->next_handler = NULL;
-  async_handler_ptr->proc = proc;
-  async_handler_ptr->client_data = client_data;
-  if (sighandler_list.first_handler == NULL)
-    sighandler_list.first_handler = async_handler_ptr;
-  else
-    sighandler_list.last_handler->next_handler = async_handler_ptr;
-  sighandler_list.last_handler = async_handler_ptr;
-  return async_handler_ptr;
-}
-
-/* Mark the handler (ASYNC_HANDLER_PTR) as ready.  This information
-   will be used when the handlers are invoked, after we have waited
-   for some event.  The caller of this function is the interrupt
-   handler associated with a signal.  */
-void
-mark_async_signal_handler (async_signal_handler * async_handler_ptr)
-{
-  async_handler_ptr->ready = 1;
-  serial_event_set (async_signal_handlers_serial_event);
-}
-
-/* See event-loop.h.  */
-
-void
-clear_async_signal_handler (async_signal_handler *async_handler_ptr)
-{
-  async_handler_ptr->ready = 0;
-}
-
-/* See event-loop.h.  */
-
-int
-async_signal_handler_is_marked (async_signal_handler *async_handler_ptr)
-{
-  return async_handler_ptr->ready;
-}
-
-/* Call all the handlers that are ready.  Returns true if any was
-   indeed ready.  */
-
-static int
-invoke_async_signal_handlers (void)
-{
-  async_signal_handler *async_handler_ptr;
-  int any_ready = 0;
-
-  /* We're going to handle all pending signals, so no need to wake up
-     the event loop again the next time around.  Note this must be
-     cleared _before_ calling the callbacks, to avoid races.  */
-  serial_event_clear (async_signal_handlers_serial_event);
-
-  /* Invoke all ready handlers.  */
-
-  while (1)
-    {
-      for (async_handler_ptr = sighandler_list.first_handler;
-	   async_handler_ptr != NULL;
-	   async_handler_ptr = async_handler_ptr->next_handler)
-	{
-	  if (async_handler_ptr->ready)
-	    break;
-	}
-      if (async_handler_ptr == NULL)
-	break;
-      any_ready = 1;
-      async_handler_ptr->ready = 0;
-      /* Async signal handlers have no connection to whichever was the
-	 current UI, and thus always run on the main one.  */
-      current_ui = main_ui;
-      (*async_handler_ptr->proc) (async_handler_ptr->client_data);
-    }
-
-  return any_ready;
-}
-
-/* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
-   Free the space allocated for it.  */
-void
-delete_async_signal_handler (async_signal_handler ** async_handler_ptr)
-{
-  async_signal_handler *prev_ptr;
-
-  if (sighandler_list.first_handler == (*async_handler_ptr))
-    {
-      sighandler_list.first_handler = (*async_handler_ptr)->next_handler;
-      if (sighandler_list.first_handler == NULL)
-	sighandler_list.last_handler = NULL;
-    }
-  else
-    {
-      prev_ptr = sighandler_list.first_handler;
-      while (prev_ptr && prev_ptr->next_handler != (*async_handler_ptr))
-	prev_ptr = prev_ptr->next_handler;
-      gdb_assert (prev_ptr);
-      prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
-      if (sighandler_list.last_handler == (*async_handler_ptr))
-	sighandler_list.last_handler = prev_ptr;
-    }
-  xfree ((*async_handler_ptr));
-  (*async_handler_ptr) = NULL;
-}
-
-/* Create an asynchronous event handler, allocating memory for it.
-   Return a pointer to the newly created handler.  PROC is the
-   function to call with CLIENT_DATA argument whenever the handler is
-   invoked.  */
-async_event_handler *
-create_async_event_handler (async_event_handler_func *proc,
-			    gdb_client_data client_data)
-{
-  async_event_handler *h;
-
-  h = XNEW (struct async_event_handler);
-  h->ready = 0;
-  h->next_handler = NULL;
-  h->proc = proc;
-  h->client_data = client_data;
-  if (async_event_handler_list.first_handler == NULL)
-    async_event_handler_list.first_handler = h;
-  else
-    async_event_handler_list.last_handler->next_handler = h;
-  async_event_handler_list.last_handler = h;
-  return h;
-}
-
-/* Mark the handler (ASYNC_HANDLER_PTR) as ready.  This information
-   will be used by gdb_do_one_event.  The caller will be whoever
-   created the event source, and wants to signal that the event is
-   ready to be handled.  */
-void
-mark_async_event_handler (async_event_handler *async_handler_ptr)
-{
-  async_handler_ptr->ready = 1;
-}
-
-/* See event-loop.h.  */
-
-void
-clear_async_event_handler (async_event_handler *async_handler_ptr)
-{
-  async_handler_ptr->ready = 0;
-}
-
-/* Check if asynchronous event handlers are ready, and call the
-   handler function for one that is.  */
-
-static int
-check_async_event_handlers (void)
-{
-  async_event_handler *async_handler_ptr;
-
-  for (async_handler_ptr = async_event_handler_list.first_handler;
-       async_handler_ptr != NULL;
-       async_handler_ptr = async_handler_ptr->next_handler)
-    {
-      if (async_handler_ptr->ready)
-	{
-	  async_handler_ptr->ready = 0;
-	  (*async_handler_ptr->proc) (async_handler_ptr->client_data);
-	  return 1;
-	}
-    }
-
-  return 0;
-}
-
-/* Delete an asynchronous handler (ASYNC_HANDLER_PTR).
-   Free the space allocated for it.  */
-void
-delete_async_event_handler (async_event_handler **async_handler_ptr)
-{
-  async_event_handler *prev_ptr;
-
-  if (async_event_handler_list.first_handler == *async_handler_ptr)
-    {
-      async_event_handler_list.first_handler
-	= (*async_handler_ptr)->next_handler;
-      if (async_event_handler_list.first_handler == NULL)
-	async_event_handler_list.last_handler = NULL;
-    }
-  else
-    {
-      prev_ptr = async_event_handler_list.first_handler;
-      while (prev_ptr && prev_ptr->next_handler != *async_handler_ptr)
-	prev_ptr = prev_ptr->next_handler;
-      gdb_assert (prev_ptr);
-      prev_ptr->next_handler = (*async_handler_ptr)->next_handler;
-      if (async_event_handler_list.last_handler == (*async_handler_ptr))
-	async_event_handler_list.last_handler = prev_ptr;
-    }
-  xfree (*async_handler_ptr);
-  *async_handler_ptr = NULL;
-}
-
 /* Create a timer that will expire in MS milliseconds from now.  When
    the timer is ready, PROC will be executed.  At creation, the timer
    is added to the timers queue.  This queue is kept sorted in order
diff --git a/gdb/event-loop.h b/gdb/event-loop.h
index 52740c3b9af..2eaaa0c8b60 100644
--- a/gdb/event-loop.h
+++ b/gdb/event-loop.h
@@ -71,11 +71,7 @@
    Corollary tasks are the creation and deletion of event sources.  */
 
 typedef void *gdb_client_data;
-struct async_signal_handler;
-struct async_event_handler;
 typedef void (handler_func) (int, gdb_client_data);
-typedef void (sig_handler_func) (gdb_client_data);
-typedef void (async_event_handler_func) (gdb_client_data);
 typedef void (timer_handler_func) (gdb_client_data);
 
 /* Exported functions from event-loop.c */
@@ -84,50 +80,23 @@ extern int gdb_do_one_event (void);
 extern void delete_file_handler (int fd);
 extern void add_file_handler (int fd, handler_func *proc, 
 			      gdb_client_data client_data);
-extern struct async_signal_handler *
-  create_async_signal_handler (sig_handler_func *proc, 
-			       gdb_client_data client_data);
-extern void delete_async_signal_handler (struct async_signal_handler **);
 extern int create_timer (int milliseconds, 
 			 timer_handler_func *proc, 
 			 gdb_client_data client_data);
 extern void delete_timer (int id);
 
-/* Call the handler from HANDLER the next time through the event
-   loop.  */
-extern void mark_async_signal_handler (struct async_signal_handler *handler);
+/* Must be defined by client.  */
 
-/* Returns true if HANDLER is marked ready.  */
+extern void handle_event_loop_exception (const gdb_exception &);
 
-extern int
-  async_signal_handler_is_marked (struct async_signal_handler *handler);
+/* Must be defined by client.  Returns true if any signal handler was
+   ready.  */
 
-/* Mark HANDLER as NOT ready.  */
+extern int invoke_async_signal_handlers ();
 
-extern void clear_async_signal_handler (struct async_signal_handler *handler);
+/* Must be defined by client.  Returns true if any event handler was
+   ready.  */
 
-/* Create and register an asynchronous event source in the event loop,
-   and set PROC as its callback.  CLIENT_DATA is passed as argument to
-   PROC upon its invocation.  Returns a pointer to an opaque structure
-   used to mark as ready and to later delete this event source from
-   the event loop.  */
-extern struct async_event_handler *
-  create_async_event_handler (async_event_handler_func *proc,
-			      gdb_client_data client_data);
-
-/* Remove the event source pointed by HANDLER_PTR created by
-   CREATE_ASYNC_EVENT_HANDLER from the event loop, and release it.  */
-extern void
-  delete_async_event_handler (struct async_event_handler **handler_ptr);
-
-/* Call the handler from HANDLER the next time through the event
-   loop.  */
-extern void mark_async_event_handler (struct async_event_handler *handler);
-
-/* Mark the handler (ASYNC_HANDLER_PTR) as NOT ready.  */
-
-extern void clear_async_event_handler (struct async_event_handler *handler);
-
-extern void initialize_async_signal_handlers (void);
+extern int check_async_event_handlers ();
 
 #endif /* EVENT_LOOP_H */
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 965ecd536f6..5d7a77b5b4b 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -41,6 +41,7 @@
 #include "ser-event.h"
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/gdb-sigmask.h"
+#include "async-event.h"
 
 /* readline include files.  */
 #include "readline/readline.h"
diff --git a/gdb/infrun.c b/gdb/infrun.c
index adde9d7f6d9..4bf2527853a 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -66,6 +66,7 @@
 #include "gdbsupport/forward-scope-exit.h"
 #include "gdbsupport/gdb_select.h"
 #include <unordered_map>
+#include "async-event.h"
 
 /* Prototypes for local functions */
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index d3da8527c5c..acc5f3ba663 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -42,6 +42,7 @@
 #include <algorithm>
 #include "gdbarch.h"
 #include "cli/cli-style.h"
+#include "async-event.h"
 
 static const target_info record_btrace_target_info = {
   "record-btrace",
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 51b7beabf66..4e1961af1bf 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -38,6 +38,7 @@
 #include "infrun.h"
 #include "gdbsupport/gdb_unlinker.h"
 #include "gdbsupport/byte-vector.h"
+#include "async-event.h"
 
 #include <signal.h>
 
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index cc0011f958c..f41ebc3d735 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -40,6 +40,7 @@
 #include "inferior.h"
 #include "infrun.h"
 #include "gdbcmd.h"
+#include "async-event.h"
 
 bool notif_debug = false;
 
diff --git a/gdb/remote.c b/gdb/remote.c
index 0f78b1be1b5..01839d61c6a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -77,6 +77,7 @@
 #include "gdbsupport/byte-vector.h"
 #include <algorithm>
 #include <unordered_map>
+#include "async-event.h"
 
 /* The remote target.  */
 
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index b962e028f8e..df7480fc57c 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -35,6 +35,7 @@
 #include "source.h"
 #include "event-loop.h"
 #include "gdbcmd.h"
+#include "async-event.h"
 
 #include "tui/tui.h"
 #include "tui/tui-io.h"
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 08/12] Move event-loop.[ch] to gdbsupport/
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (6 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 07/12] Introduce async-event.[ch] Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 09/12] Implement event-loop glue for gdbserver Tom Tromey
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves event-loop.[ch] to gdbsupport/ and updates the uses in gdb.

gdb/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* run-on-main-thread.c: Update include.
	* unittests/main-thread-selftests.c: Update include.
	* tui/tui-win.c: Update include.
	* tui/tui-io.c: Update include.
	* tui/tui-interp.c: Update include.
	* tui/tui-hooks.c: Update include.
	* top.h: Update include.
	* top.c: Update include.
	* ser-base.c: Update include.
	* remote.c: Update include.
	* remote-notif.c: Update include.
	* remote-fileio.c: Update include.
	* record-full.c: Update include.
	* record-btrace.c: Update include.
	* python/python.c: Update include.
	* posix-hdep.c: Update include.
	* mingw-hdep.c: Update include.
	* mi/mi-main.c: Update include.
	* mi/mi-interp.c: Update include.
	* main.c: Update include.
	* linux-nat.c: Update include.
	* interps.c: Update include.
	* infrun.c: Update include.
	* inf-loop.c: Update include.
	* event-top.c: Update include.
	* event-loop.c: Move to ../gdbsupport/.
	* event-loop.h: Move to ../gdbsupport/.
	* async-event.h: Update include.
	* Makefile.in (COMMON_SFILES, HFILES_NO_SRCDIR): Update.

gdbsupport/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* event-loop.h: Move from ../gdb/.
	* event-loop.cc: Move from ../gdb/.
---
 gdb/ChangeLog                                | 32 ++++++++++++++++++++
 gdb/Makefile.in                              |  2 --
 gdb/async-event.h                            |  2 +-
 gdb/event-top.c                              |  2 +-
 gdb/inf-loop.c                               |  2 +-
 gdb/infrun.c                                 |  2 +-
 gdb/interps.c                                |  2 +-
 gdb/linux-nat.c                              |  2 +-
 gdb/main.c                                   |  2 +-
 gdb/mi/mi-interp.c                           |  2 +-
 gdb/mi/mi-main.c                             |  2 +-
 gdb/mingw-hdep.c                             |  2 +-
 gdb/posix-hdep.c                             |  2 +-
 gdb/python/python.c                          |  2 +-
 gdb/record-btrace.c                          |  2 +-
 gdb/record-full.c                            |  2 +-
 gdb/remote-fileio.c                          |  2 +-
 gdb/remote-notif.c                           |  2 +-
 gdb/remote.c                                 |  2 +-
 gdb/run-on-main-thread.c                     |  2 +-
 gdb/ser-base.c                               |  2 +-
 gdb/top.c                                    |  2 +-
 gdb/top.h                                    |  2 +-
 gdb/tui/tui-hooks.c                          |  2 +-
 gdb/tui/tui-interp.c                         |  2 +-
 gdb/tui/tui-io.c                             |  2 +-
 gdb/tui/tui-win.c                            |  2 +-
 gdb/unittests/main-thread-selftests.c        |  2 +-
 gdbsupport/ChangeLog                         |  5 +++
 gdbsupport/Makefile.am                       |  1 +
 gdbsupport/Makefile.in                       | 22 ++++++++------
 gdb/event-loop.c => gdbsupport/event-loop.cc |  4 +--
 {gdb => gdbsupport}/event-loop.h             |  0
 33 files changed, 78 insertions(+), 40 deletions(-)
 rename gdb/event-loop.c => gdbsupport/event-loop.cc (99%)
 rename {gdb => gdbsupport}/event-loop.h (100%)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 31d443ff12b..cadd217b5fc 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1015,7 +1015,6 @@ COMMON_SFILES = \
 	dwarf2/read.c \
 	dwarf2/section.c \
 	eval.c \
-	event-loop.c \
 	event-top.c \
 	exceptions.c \
 	exec.c \
@@ -1250,7 +1249,6 @@ HFILES_NO_SRCDIR = \
 	dwarf2/index-common.h \
 	dwarf2/loc.h \
 	dwarf2/read.h \
-	event-loop.h \
 	event-top.h \
 	exceptions.h \
 	exec.h \
diff --git a/gdb/async-event.h b/gdb/async-event.h
index 408f7764f7c..3b3747a2604 100644
--- a/gdb/async-event.h
+++ b/gdb/async-event.h
@@ -19,7 +19,7 @@
 #ifndef ASYNC_EVENT_H
 #define ASYNC_EVENT_H
 
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 
 struct async_signal_handler;
 struct async_event_handler;
diff --git a/gdb/event-top.c b/gdb/event-top.c
index 5d7a77b5b4b..ac0f3701016 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -25,7 +25,7 @@
 #include "infrun.h"
 #include "target.h"
 #include "terminal.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "interps.h"
 #include <signal.h>
diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c
index 987a8ef48fe..c40ae239426 100644
--- a/gdb/inf-loop.c
+++ b/gdb/inf-loop.c
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "inferior.h"
 #include "infrun.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "inf-loop.h"
 #include "remote.h"
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4bf2527853a..18ac3be8307 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -56,7 +56,7 @@
 #include "target-dcache.h"
 #include "terminal.h"
 #include "solist.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "thread-fsm.h"
 #include "gdbsupport/enum-flags.h"
 #include "progspace-and-thread.h"
diff --git a/gdb/interps.c b/gdb/interps.c
index 8c01091e50b..4b2e3fd37b0 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -32,7 +32,7 @@
 #include "defs.h"
 #include "gdbcmd.h"
 #include "ui-out.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "interps.h"
 #include "completer.h"
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 81af83c4ac5..ae83dc10599 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -47,7 +47,7 @@
 #include <sys/stat.h>		/* for struct stat */
 #include <fcntl.h>		/* for O_RDONLY */
 #include "inf-loop.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include <pwd.h>
 #include <sys/types.h>
diff --git a/gdb/main.c b/gdb/main.c
index 67a3d0027e1..59cb14161be 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -28,7 +28,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <ctype.h>
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "ui-out.h"
 
 #include "interps.h"
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index e77093cfa28..7fe901bd68e 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -23,7 +23,7 @@
 
 #include "interps.h"
 #include "event-top.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "inferior.h"
 #include "infrun.h"
 #include "ui-out.h"
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 68cbcdd4fcd..9c6323e52c6 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -33,7 +33,7 @@
 #include "ui-out.h"
 #include "mi-out.h"
 #include "interps.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "gdbcore.h"		/* For write_memory().  */
 #include "value.h"
diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c
index 016cf2d2310..43d99747659 100644
--- a/gdb/mingw-hdep.c
+++ b/gdb/mingw-hdep.c
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "main.h"
 #include "serial.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 
 #include "gdbsupport/gdb_select.h"
 
diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c
index e5754cd701a..dfb230bc749 100644
--- a/gdb/posix-hdep.c
+++ b/gdb/posix-hdep.c
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 
 #include "gdbsupport/gdb_select.h"
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6e243c1a07b..02543aea710 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -27,7 +27,7 @@
 #include "objfiles.h"
 #include "value.h"
 #include "language.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "readline/tilde.h"
 #include "python.h"
 #include "extension-priv.h"
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index acc5f3ba663..2ca9a61457a 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -36,7 +36,7 @@
 #include "frame-unwind.h"
 #include "hashtab.h"
 #include "infrun.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "inf-loop.h"
 #include "inferior.h"
 #include <algorithm>
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 4e1961af1bf..9c8bd18149b 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -31,7 +31,7 @@
 #include "record-full.h"
 #include "elf-bfd.h"
 #include "gcore.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "inf-loop.h"
 #include "gdb_bfd.h"
 #include "observable.h"
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index f2dc9a66ead..df470fd86df 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -25,7 +25,7 @@
 #include "gdbsupport/gdb_wait.h"
 #include <sys/stat.h>
 #include "remote-fileio.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "target.h"
 #include "filenames.h"
 #include "gdbsupport/filestuff.h"
diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index f41ebc3d735..2e5f124284b 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -35,7 +35,7 @@
 #include "remote.h"
 #include "remote-notif.h"
 #include "observable.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "target.h"
 #include "inferior.h"
 #include "infrun.h"
diff --git a/gdb/remote.c b/gdb/remote.c
index 01839d61c6a..8b5f01111ad 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -49,7 +49,7 @@
 
 #include "gdbsupport/gdb_sys_time.h"
 
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "inf-loop.h"
 
diff --git a/gdb/run-on-main-thread.c b/gdb/run-on-main-thread.c
index 74ab1e19a57..2cc93e430d8 100644
--- a/gdb/run-on-main-thread.c
+++ b/gdb/run-on-main-thread.c
@@ -22,7 +22,7 @@
 #if CXX_STD_THREAD
 #include <mutex>
 #endif
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 
 /* The serial event used when posting runnables.  */
 
diff --git a/gdb/ser-base.c b/gdb/ser-base.c
index 8231ec51543..fb6f4e056ad 100644
--- a/gdb/ser-base.c
+++ b/gdb/ser-base.c
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "serial.h"
 #include "ser-base.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 
 #include "gdbsupport/gdb_select.h"
 #include "gdbsupport/gdb_sys_time.h"
diff --git a/gdb/top.c b/gdb/top.c
index 010aa6fb771..8b82bd3c038 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -42,7 +42,7 @@
 #include "gdbsupport/version.h"
 #include "serial.h"
 #include "main.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "gdbthread.h"
 #include "extension.h"
 #include "interps.h"
diff --git a/gdb/top.h b/gdb/top.h
index 638e02cad4c..2147e2d4b48 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -21,7 +21,7 @@
 #define TOP_H
 
 #include "gdbsupport/buffer.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "value.h"
 
 struct tl_interp_info;
diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 0e45e0e7507..793ca0e4469 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -26,7 +26,7 @@
 #include "objfiles.h"
 #include "target.h"
 #include "gdbcore.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "frame.h"
 #include "breakpoint.h"
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 090cf0e0d0c..10118af2741 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -22,7 +22,7 @@
 #include "interps.h"
 #include "top.h"
 #include "event-top.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "ui-out.h"
 #include "cli-out.h"
 #include "tui/tui-data.h"
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index b5ee2a2b6b6..e7a8ac77bce 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -21,7 +21,7 @@
 
 #include "defs.h"
 #include "target.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "event-top.h"
 #include "command.h"
 #include "top.h"
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index df7480fc57c..7cb4aa9bbd4 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -33,7 +33,7 @@
 #include "cli/cli-style.h"
 #include "top.h"
 #include "source.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #include "gdbcmd.h"
 #include "async-event.h"
 
diff --git a/gdb/unittests/main-thread-selftests.c b/gdb/unittests/main-thread-selftests.c
index c51f34ef41d..564a107b354 100644
--- a/gdb/unittests/main-thread-selftests.c
+++ b/gdb/unittests/main-thread-selftests.c
@@ -21,7 +21,7 @@
 #include "gdbsupport/selftest.h"
 #include "gdbsupport/block-signals.h"
 #include "run-on-main-thread.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 #if CXX_STD_THREAD
 #include <thread>
 #endif
diff --git a/gdbsupport/Makefile.am b/gdbsupport/Makefile.am
index ee78a891b3b..e95ee5dbc50 100644
--- a/gdbsupport/Makefile.am
+++ b/gdbsupport/Makefile.am
@@ -46,6 +46,7 @@ libgdbsupport_a_SOURCES = \
     common-utils.cc \
     environ.cc \
     errors.cc \
+    event-loop.cc \
     fileio.cc \
     filestuff.cc \
     format.cc \
diff --git a/gdbsupport/Makefile.in b/gdbsupport/Makefile.in
index 7ed2e6fac23..5051ab31a49 100644
--- a/gdbsupport/Makefile.in
+++ b/gdbsupport/Makefile.in
@@ -149,16 +149,16 @@ am_libgdbsupport_a_OBJECTS = agent.$(OBJEXT) btrace-common.$(OBJEXT) \
 	buffer.$(OBJEXT) cleanups.$(OBJEXT) common-debug.$(OBJEXT) \
 	common-exceptions.$(OBJEXT) common-inferior.$(OBJEXT) \
 	common-regcache.$(OBJEXT) common-utils.$(OBJEXT) \
-	environ.$(OBJEXT) errors.$(OBJEXT) fileio.$(OBJEXT) \
-	filestuff.$(OBJEXT) format.$(OBJEXT) gdb-dlfcn.$(OBJEXT) \
-	gdb_tilde_expand.$(OBJEXT) gdb_wait.$(OBJEXT) \
-	gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) netstuff.$(OBJEXT) \
-	new-op.$(OBJEXT) pathstuff.$(OBJEXT) print-utils.$(OBJEXT) \
-	ptid.$(OBJEXT) rsp-low.$(OBJEXT) run-time-clock.$(OBJEXT) \
-	safe-strerror.$(OBJEXT) scoped_mmap.$(OBJEXT) \
-	signals.$(OBJEXT) signals-state-save-restore.$(OBJEXT) \
-	tdesc.$(OBJEXT) thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) \
-	$(am__objects_1)
+	environ.$(OBJEXT) errors.$(OBJEXT) event-loop.$(OBJEXT) \
+	fileio.$(OBJEXT) filestuff.$(OBJEXT) format.$(OBJEXT) \
+	gdb-dlfcn.$(OBJEXT) gdb_tilde_expand.$(OBJEXT) \
+	gdb_wait.$(OBJEXT) gdb_vecs.$(OBJEXT) job-control.$(OBJEXT) \
+	netstuff.$(OBJEXT) new-op.$(OBJEXT) pathstuff.$(OBJEXT) \
+	print-utils.$(OBJEXT) ptid.$(OBJEXT) rsp-low.$(OBJEXT) \
+	run-time-clock.$(OBJEXT) safe-strerror.$(OBJEXT) \
+	scoped_mmap.$(OBJEXT) signals.$(OBJEXT) \
+	signals-state-save-restore.$(OBJEXT) tdesc.$(OBJEXT) \
+	thread-pool.$(OBJEXT) xml-utils.$(OBJEXT) $(am__objects_1)
 libgdbsupport_a_OBJECTS = $(am_libgdbsupport_a_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -368,6 +368,7 @@ libgdbsupport_a_SOURCES = \
     common-utils.cc \
     environ.cc \
     errors.cc \
+    event-loop.cc \
     fileio.cc \
     filestuff.cc \
     format.cc \
@@ -471,6 +472,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common-utils.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/environ.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/event-loop.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fileio.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filestuff.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/format.Po@am__quote@
diff --git a/gdb/event-loop.c b/gdbsupport/event-loop.cc
similarity index 99%
rename from gdb/event-loop.c
rename to gdbsupport/event-loop.cc
index e5347d2e3f0..f7ccc4eec47 100644
--- a/gdb/event-loop.c
+++ b/gdbsupport/event-loop.cc
@@ -17,8 +17,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "defs.h"
-#include "event-loop.h"
+#include "gdbsupport/common-defs.h"
+#include "gdbsupport/event-loop.h"
 
 #include <chrono>
 
diff --git a/gdb/event-loop.h b/gdbsupport/event-loop.h
similarity index 100%
rename from gdb/event-loop.h
rename to gdbsupport/event-loop.h
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 09/12] Implement event-loop glue for gdbserver
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (7 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 08/12] Move event-loop.[ch] to gdbsupport/ Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 10/12] Switch gdbserver to gdbsupport event loop Tom Tromey
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

event-loop.c requires the client to provide some functions.  This
patch implements these functions for gdbserver.

gdbserver/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* server.c (invoke_async_signal_handlers)
	(check_async_event_handlers, flush_streams, gdb_select): New
	functions.
---
 gdbserver/ChangeLog |  6 ++++++
 gdbserver/server.cc | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index 43962adc86c..ac7a7fd75aa 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -47,6 +47,7 @@
 
 #include "gdbsupport/selftest.h"
 #include "gdbsupport/scope-exit.h"
+#include "gdbsupport/gdb_select.h"
 
 #define require_running_or_return(BUF)		\
   if (!target_running ())			\
@@ -4477,6 +4478,40 @@ handle_target_event (int err, gdb_client_data client_data)
   return 0;
 }
 
+/* See gdbsupport/event-loop.h.  */
+
+int
+invoke_async_signal_handlers ()
+{
+  return 0;
+}
+
+/* See gdbsupport/event-loop.h.  */
+
+int
+check_async_event_handlers ()
+{
+  return 0;
+}
+
+/* See gdbsupport/errors.h  */
+
+void
+flush_streams ()
+{
+  fflush (stdout);
+  fflush (stderr);
+}
+
+/* See gdbsupport/gdb_select.h.  */
+
+int
+gdb_select (int n, fd_set *readfds, fd_set *writefds,
+	    fd_set *exceptfds, struct timeval *timeout)
+{
+  return select (n, readfds, writefds, exceptfds, timeout);
+}
+
 #if GDB_SELF_TEST
 namespace selftests
 {
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 10/12] Switch gdbserver to gdbsupport event loop
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (8 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 09/12] Implement event-loop glue for gdbserver Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 11/12] Move gdb_notifier comment Tom Tromey
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes gdbserver to use the gdbserver event loop, removing the
ancient fork.

gdbserver/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* server.h (handle_serial_event, handle_target_event): Update.
	* server.c: Don't call initialize_event_loop.
	(keep_processing_events): New global.
	(handle_serial_event): Return void.  Set keep_processing_events.
	(handle_target_event): Return void.
	(start_event_loop): Move from event-loop.c.  Rewrite.
	* remote-utils.c (handle_accept_event): Return void.
	(reset_readchar): Use delete_timer.
	(process_remaining): Return void.
	(reschedule): Use create_timer.
	* event-loop.h: Remove.
	* event-loop.cc: Remove.
	* Makefile.in (OBS): Use gdbsupport/event-loop.o, not event-loop.o.
---
 gdbserver/ChangeLog       |  16 ++
 gdbserver/Makefile.in     |   1 -
 gdbserver/event-loop.cc   | 567 --------------------------------------
 gdbserver/event-loop.h    |  36 ---
 gdbserver/remote-utils.cc |  18 +-
 gdbserver/server.cc       |  44 ++-
 gdbserver/server.h        |   6 +-
 7 files changed, 60 insertions(+), 628 deletions(-)
 delete mode 100644 gdbserver/event-loop.cc
 delete mode 100644 gdbserver/event-loop.h

diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in
index 8c35c169d62..417a530e25d 100644
--- a/gdbserver/Makefile.in
+++ b/gdbserver/Makefile.in
@@ -241,7 +241,6 @@ OBS = \
 	ax.o \
 	debug.o \
 	dll.o \
-	event-loop.o \
 	hostio.o \
 	inferiors.o \
 	mem-break.o \
diff --git a/gdbserver/event-loop.cc b/gdbserver/event-loop.cc
deleted file mode 100644
index 8827e8a32eb..00000000000
--- a/gdbserver/event-loop.cc
+++ /dev/null
@@ -1,567 +0,0 @@
-/* Event loop machinery for the remote server for GDB.
-   Copyright (C) 1999-2020 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
-
-/* Based on src/gdb/event-loop.c.  */
-
-#include "server.h"
-
-#include <sys/types.h>
-#include "gdbsupport/gdb_sys_time.h"
-
-#ifdef USE_WIN32API
-#include <windows.h>
-#include <io.h>
-#endif
-
-#include <unistd.h>
-#include <queue>
-
-typedef int (event_handler_func) (gdb_fildes_t);
-
-/* Tell create_file_handler what events we are interested in.  */
-
-#define GDB_READABLE	(1<<1)
-#define GDB_WRITABLE	(1<<2)
-#define GDB_EXCEPTION	(1<<3)
-
-/* Events are queued by on the event_queue and serviced later
-   on by do_one_event.  An event can be, for instance, a file
-   descriptor becoming ready to be read.  Servicing an event simply
-   means that the procedure PROC will be called.  We have 2 queues,
-   one for file handlers that we listen to in the event loop, and one
-   for the file handlers+events that are ready.  The procedure PROC
-   associated with each event is always the same (handle_file_event).
-   Its duty is to invoke the handler associated with the file
-   descriptor whose state change generated the event, plus doing other
-   cleanups and such.  */
-
-struct gdb_event
-  {
-    /* Procedure to call to service this event.  */
-    event_handler_func *proc;
-
-    /* File descriptor that is ready.  */
-    gdb_fildes_t fd;
-  };
-
-/* Information about each file descriptor we register with the event
-   loop.  */
-
-typedef struct file_handler
-  {
-    /* File descriptor.  */
-    gdb_fildes_t fd;
-
-    /* Events we want to monitor.  */
-    int mask;
-
-    /* Events that have been seen since the last time.  */
-    int ready_mask;
-
-    /* Procedure to call when fd is ready.  */
-    handler_func *proc;
-
-    /* Argument to pass to proc.  */
-    gdb_client_data client_data;
-
-    /* Was an error detected on this fd?  */
-    int error;
-
-    /* Next registered file descriptor.  */
-    struct file_handler *next_file;
-  }
-file_handler;
-
-typedef gdb::unique_xmalloc_ptr<gdb_event> gdb_event_up;
-
-static std::queue<gdb_event_up, std::list<gdb_event_up>> event_queue;
-
-/* Gdb_notifier is just a list of file descriptors gdb is interested
-   in.  These are the input file descriptor, and the target file
-   descriptor.  Each of the elements in the gdb_notifier list is
-   basically a description of what kind of events gdb is interested
-   in, for each fd.  */
-
-static struct
-  {
-    /* Ptr to head of file handler list.  */
-    file_handler *first_file_handler;
-
-    /* Masks to be used in the next call to select.  Bits are set in
-       response to calls to create_file_handler.  */
-    fd_set check_masks[3];
-
-    /* What file descriptors were found ready by select.  */
-    fd_set ready_masks[3];
-
-    /* Number of valid bits (highest fd value + 1). (for select) */
-    int num_fds;
-  }
-gdb_notifier;
-
-/* Callbacks are just routines that are executed before waiting for the
-   next event.  In GDB this is struct gdb_timer.  We don't need timers
-   so rather than copy all that complexity in gdbserver, we provide what
-   we need, but we do so in a way that if/when the day comes that we need
-   that complexity, it'll be easier to add - replace callbacks with timers
-   and use a delta of zero (which is all gdb currently uses timers for anyway).
-
-   PROC will be executed before gdbserver goes to sleep to wait for the
-   next event.  */
-
-struct callback_event
-  {
-    int id;
-    callback_handler_func *proc;
-    gdb_client_data data;
-    struct callback_event *next;
-  };
-
-/* Table of registered callbacks.  */
-
-static struct
-  {
-    struct callback_event *first;
-    struct callback_event *last;
-
-    /* Id of the last callback created.  */
-    int num_callbacks;
-  }
-callback_list;
-
-void
-initialize_event_loop (void)
-{
-}
-
-/* Process one event.  If an event was processed, 1 is returned
-   otherwise 0 is returned.  Scan the queue from head to tail,
-   processing therefore the high priority events first, by invoking
-   the associated event handler procedure.  */
-
-static int
-process_event (void)
-{
-  /* Let's get rid of the event from the event queue.  We need to
-     do this now because while processing the event, since the
-     proc function could end up jumping out to the caller of this
-     function.  In that case, we would have on the event queue an
-     event which has been processed, but not deleted.  */
-  if (!event_queue.empty ())
-    {
-      gdb_event_up event_ptr = std::move (event_queue.front ());
-      event_queue.pop ();
-
-      event_handler_func *proc = event_ptr->proc;
-      gdb_fildes_t fd = event_ptr->fd;
-
-      /* Now call the procedure associated with the event.  */
-      if ((*proc) (fd))
-	return -1;
-      return 1;
-    }
-
-  /* This is the case if there are no event on the event queue.  */
-  return 0;
-}
-
-/* Append PROC to the callback list.
-   The result is the "id" of the callback that can be passed back to
-   delete_callback_event.  */
-
-int
-append_callback_event (callback_handler_func *proc, gdb_client_data data)
-{
-  struct callback_event *event_ptr = XNEW (struct callback_event);
-
-  event_ptr->id = callback_list.num_callbacks++;
-  event_ptr->proc = proc;
-  event_ptr->data = data;
-  event_ptr->next = NULL;
-  if (callback_list.first == NULL)
-    callback_list.first = event_ptr;
-  if (callback_list.last != NULL)
-    callback_list.last->next = event_ptr;
-  callback_list.last = event_ptr;
-  return event_ptr->id;
-}
-
-/* Delete callback ID.
-   It is not an error callback ID doesn't exist.  */
-
-void
-delete_callback_event (int id)
-{
-  struct callback_event **p;
-
-  for (p = &callback_list.first; *p != NULL; p = &(*p)->next)
-    {
-      struct callback_event *event_ptr = *p;
-
-      if (event_ptr->id == id)
-	{
-	  *p = event_ptr->next;
-	  if (event_ptr == callback_list.last)
-	    callback_list.last = NULL;
-	  free (event_ptr);
-	  break;
-	}
-    }
-}
-
-/* Run the next callback.
-   The result is 1 if a callback was called and event processing
-   should continue, -1 if the callback wants the event loop to exit,
-   and 0 if there are no more callbacks.  */
-
-static int
-process_callback (void)
-{
-  struct callback_event *event_ptr;
-
-  event_ptr = callback_list.first;
-  if (event_ptr != NULL)
-    {
-      callback_handler_func *proc = event_ptr->proc;
-      gdb_client_data data = event_ptr->data;
-
-      /* Remove the event before calling PROC,
-	 more events may get added by PROC.  */
-      callback_list.first = event_ptr->next;
-      if (callback_list.first == NULL)
-	callback_list.last = NULL;
-      free  (event_ptr);
-      if ((*proc) (data))
-	return -1;
-      return 1;
-    }
-
-  return 0;
-}
-
-/* Add a file handler/descriptor to the list of descriptors we are
-   interested in.  FD is the file descriptor for the file/stream to be
-   listened to.  MASK is a combination of READABLE, WRITABLE,
-   EXCEPTION.  PROC is the procedure that will be called when an event
-   occurs for FD.  CLIENT_DATA is the argument to pass to PROC.  */
-
-static void
-create_file_handler (gdb_fildes_t fd, int mask, handler_func *proc,
-		     gdb_client_data client_data)
-{
-  file_handler *file_ptr;
-
-  /* Do we already have a file handler for this file? (We may be
-     changing its associated procedure).  */
-  for (file_ptr = gdb_notifier.first_file_handler;
-       file_ptr != NULL;
-       file_ptr = file_ptr->next_file)
-    if (file_ptr->fd == fd)
-      break;
-
-  /* It is a new file descriptor.  Add it to the list.  Otherwise,
-     just change the data associated with it.  */
-  if (file_ptr == NULL)
-    {
-      file_ptr = XNEW (struct file_handler);
-      file_ptr->fd = fd;
-      file_ptr->ready_mask = 0;
-      file_ptr->next_file = gdb_notifier.first_file_handler;
-      gdb_notifier.first_file_handler = file_ptr;
-
-      if (mask & GDB_READABLE)
-	FD_SET (fd, &gdb_notifier.check_masks[0]);
-      else
-	FD_CLR (fd, &gdb_notifier.check_masks[0]);
-
-      if (mask & GDB_WRITABLE)
-	FD_SET (fd, &gdb_notifier.check_masks[1]);
-      else
-	FD_CLR (fd, &gdb_notifier.check_masks[1]);
-
-      if (mask & GDB_EXCEPTION)
-	FD_SET (fd, &gdb_notifier.check_masks[2]);
-      else
-	FD_CLR (fd, &gdb_notifier.check_masks[2]);
-
-      if (gdb_notifier.num_fds <= fd)
-	gdb_notifier.num_fds = fd + 1;
-    }
-
-  file_ptr->proc = proc;
-  file_ptr->client_data = client_data;
-  file_ptr->mask = mask;
-}
-
-/* Wrapper function for create_file_handler.  */
-
-void
-add_file_handler (gdb_fildes_t fd,
-		  handler_func *proc, gdb_client_data client_data)
-{
-  create_file_handler (fd, GDB_READABLE | GDB_EXCEPTION, proc, client_data);
-}
-
-/* Remove the file descriptor FD from the list of monitored fd's:
-   i.e. we don't care anymore about events on the FD.  */
-
-void
-delete_file_handler (gdb_fildes_t fd)
-{
-  file_handler *file_ptr, *prev_ptr = NULL;
-  int i;
-
-  /* Find the entry for the given file. */
-
-  for (file_ptr = gdb_notifier.first_file_handler;
-       file_ptr != NULL;
-       file_ptr = file_ptr->next_file)
-    if (file_ptr->fd == fd)
-      break;
-
-  if (file_ptr == NULL)
-    return;
-
-  if (file_ptr->mask & GDB_READABLE)
-    FD_CLR (fd, &gdb_notifier.check_masks[0]);
-  if (file_ptr->mask & GDB_WRITABLE)
-    FD_CLR (fd, &gdb_notifier.check_masks[1]);
-  if (file_ptr->mask & GDB_EXCEPTION)
-    FD_CLR (fd, &gdb_notifier.check_masks[2]);
-
-  /* Find current max fd.  */
-
-  if ((fd + 1) == gdb_notifier.num_fds)
-    {
-      gdb_notifier.num_fds--;
-      for (i = gdb_notifier.num_fds; i; i--)
-	{
-	  if (FD_ISSET (i - 1, &gdb_notifier.check_masks[0])
-	      || FD_ISSET (i - 1, &gdb_notifier.check_masks[1])
-	      || FD_ISSET (i - 1, &gdb_notifier.check_masks[2]))
-	    break;
-	}
-      gdb_notifier.num_fds = i;
-    }
-
-  /* Deactivate the file descriptor, by clearing its mask, so that it
-     will not fire again.  */
-
-  file_ptr->mask = 0;
-
-  /* Get rid of the file handler in the file handler list.  */
-  if (file_ptr == gdb_notifier.first_file_handler)
-    gdb_notifier.first_file_handler = file_ptr->next_file;
-  else
-    {
-      for (prev_ptr = gdb_notifier.first_file_handler;
-	   prev_ptr->next_file != file_ptr;
-	   prev_ptr = prev_ptr->next_file)
-	;
-      prev_ptr->next_file = file_ptr->next_file;
-    }
-  free (file_ptr);
-}
-
-/* Handle the given event by calling the procedure associated to the
-   corresponding file handler.  Called by process_event indirectly,
-   through event_ptr->proc.  EVENT_FILE_DESC is file descriptor of the
-   event in the front of the event queue.  */
-
-static int
-handle_file_event (gdb_fildes_t event_file_desc)
-{
-  file_handler *file_ptr;
-  int mask;
-
-  /* Search the file handler list to find one that matches the fd in
-     the event.  */
-  for (file_ptr = gdb_notifier.first_file_handler; file_ptr != NULL;
-       file_ptr = file_ptr->next_file)
-    {
-      if (file_ptr->fd == event_file_desc)
-	{
-	  /* See if the desired events (mask) match the received
-	     events (ready_mask).  */
-
-	  if (file_ptr->ready_mask & GDB_EXCEPTION)
-	    {
-	      warning ("Exception condition detected on fd %s",
-		       pfildes (file_ptr->fd));
-	      file_ptr->error = 1;
-	    }
-	  else
-	    file_ptr->error = 0;
-	  mask = file_ptr->ready_mask & file_ptr->mask;
-
-	  /* Clear the received events for next time around.  */
-	  file_ptr->ready_mask = 0;
-
-	  /* If there was a match, then call the handler.  */
-	  if (mask != 0)
-	    {
-	      if ((*file_ptr->proc) (file_ptr->error,
-				     file_ptr->client_data) < 0)
-		return -1;
-	    }
-	  break;
-	}
-    }
-
-  return 0;
-}
-
-/* Create a file event, to be enqueued in the event queue for
-   processing.  The procedure associated to this event is always
-   handle_file_event, which will in turn invoke the one that was
-   associated to FD when it was registered with the event loop.  */
-
-static gdb_event *
-create_file_event (gdb_fildes_t fd)
-{
-  gdb_event *file_event_ptr;
-
-  file_event_ptr = XNEW (gdb_event);
-  file_event_ptr->proc = handle_file_event;
-  file_event_ptr->fd = fd;
-
-  return file_event_ptr;
-}
-
-/* Called by 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
-   select.  Return -1 if there are no files descriptors to monitor,
-   otherwise return 0.  */
-
-static int
-wait_for_event (void)
-{
-  file_handler *file_ptr;
-  int num_found = 0;
-
-  /* Make sure all output is done before getting another event.  */
-  fflush (stdout);
-  fflush (stderr);
-
-  if (gdb_notifier.num_fds == 0)
-    return -1;
-
-  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],
-		      NULL);
-
-  /* Clear the masks after an error from select.  */
-  if (num_found == -1)
-    {
-      FD_ZERO (&gdb_notifier.ready_masks[0]);
-      FD_ZERO (&gdb_notifier.ready_masks[1]);
-      FD_ZERO (&gdb_notifier.ready_masks[2]);
-#ifdef EINTR
-      /* Dont print anything if we got a signal, let gdb handle
-	 it.  */
-      if (errno != EINTR)
-	perror_with_name ("select");
-#endif
-    }
-
-  /* Enqueue all detected file events.  */
-
-  for (file_ptr = gdb_notifier.first_file_handler;
-       file_ptr != NULL && num_found > 0;
-       file_ptr = file_ptr->next_file)
-    {
-      int mask = 0;
-
-      if (FD_ISSET (file_ptr->fd, &gdb_notifier.ready_masks[0]))
-	mask |= GDB_READABLE;
-      if (FD_ISSET (file_ptr->fd, &gdb_notifier.ready_masks[1]))
-	mask |= GDB_WRITABLE;
-      if (FD_ISSET (file_ptr->fd, &gdb_notifier.ready_masks[2]))
-	mask |= GDB_EXCEPTION;
-
-      if (!mask)
-	continue;
-      else
-	num_found--;
-
-      /* Enqueue an event only if this is still a new event for this
-	 fd.  */
-
-      if (file_ptr->ready_mask == 0)
-	{
-	  gdb_event *file_event_ptr = create_file_event (file_ptr->fd);
-
-	  event_queue.emplace (file_event_ptr);
-	}
-      file_ptr->ready_mask = mask;
-    }
-
-  return 0;
-}
-
-/* Start up the event loop.  This is the entry point to the event
-   loop.  */
-
-void
-start_event_loop (void)
-{
-  /* Loop until there is nothing to do.  This is the entry point to
-     the event loop engine.  If nothing is ready at this time, wait
-     for something to happen (via wait_for_event), then process it.
-     Return when there are no longer event sources to wait for.  */
-
-  while (1)
-    {
-      /* Any events already waiting in the queue?  */
-      int res = process_event ();
-
-      /* Did the event handler want the event loop to stop?  */
-      if (res == -1)
-	return;
-
-      if (res)
-	continue;
-
-      /* Process any queued callbacks before we go to sleep.  */
-      res = process_callback ();
-
-      /* Did the callback want the event loop to stop?  */
-      if (res == -1)
-	return;
-
-      if (res)
-	continue;
-
-      /* Wait for a new event.  If wait_for_event returns -1, we
-	 should get out because this means that there are no event
-	 sources left.  This will make the event loop stop, and the
-	 application exit.  */
-
-      if (wait_for_event () < 0)
-	return;
-    }
-
-  /* We are done with the event loop.  There are no more event sources
-     to listen to.  So we exit gdbserver.  */
-}
diff --git a/gdbserver/event-loop.h b/gdbserver/event-loop.h
deleted file mode 100644
index a49173e867d..00000000000
--- a/gdbserver/event-loop.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Event loop machinery for the remote server for GDB.
-   Copyright (C) 1993-2020 Free Software Foundation, Inc.
-
-   This file is part of GDB.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-#ifndef GDBSERVER_EVENT_LOOP_H
-#define GDBSERVER_EVENT_LOOP_H
-
-typedef void *gdb_client_data;
-typedef int (handler_func) (int, gdb_client_data);
-typedef int (callback_handler_func) (gdb_client_data);
-
-extern void delete_file_handler (gdb_fildes_t fd);
-extern void add_file_handler (gdb_fildes_t fd, handler_func *proc,
-			      gdb_client_data client_data);
-extern int append_callback_event (callback_handler_func *proc,
-				   gdb_client_data client_data);
-extern void delete_callback_event (int id);
-
-extern void start_event_loop (void);
-extern void initialize_event_loop (void);
-
-#endif /* GDBSERVER_EVENT_LOOP_H */
diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 1c211e25720..6249691954d 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -144,7 +144,7 @@ enable_async_notification (int fd)
 #endif
 }
 
-static int
+static void
 handle_accept_event (int err, gdb_client_data client_data)
 {
   struct sockaddr_storage sockaddr;
@@ -213,8 +213,6 @@ handle_accept_event (int err, gdb_client_data client_data)
      until GDB as selected all-stop/non-stop, and has queried the
      threads' status ('?').  */
   target_async (0);
-
-  return 0;
 }
 
 /* Prepare for a later connection to a remote debugger.
@@ -930,27 +928,21 @@ reset_readchar (void)
   readchar_bufcnt = 0;
   if (readchar_callback != NOT_SCHEDULED)
     {
-      delete_callback_event (readchar_callback);
+      delete_timer (readchar_callback);
       readchar_callback = NOT_SCHEDULED;
     }
 }
 
 /* Process remaining data in readchar_buf.  */
 
-static int
+static void
 process_remaining (void *context)
 {
-  int res;
-
   /* This is a one-shot event.  */
   readchar_callback = NOT_SCHEDULED;
 
   if (readchar_bufcnt > 0)
-    res = handle_serial_event (0, NULL);
-  else
-    res = 0;
-
-  return res;
+    handle_serial_event (0, NULL);
 }
 
 /* If there is still data in the buffer, queue another event to process it,
@@ -960,7 +952,7 @@ static void
 reschedule (void)
 {
   if (readchar_bufcnt > 0 && readchar_callback == NOT_SCHEDULED)
-    readchar_callback = append_callback_event (process_remaining, NULL);
+    readchar_callback = create_timer (0, process_remaining, NULL);
 }
 
 /* Read a packet from the remote machine, with error checking,
diff --git a/gdbserver/server.cc b/gdbserver/server.cc
index ac7a7fd75aa..77175ff74cb 100644
--- a/gdbserver/server.cc
+++ b/gdbserver/server.cc
@@ -83,6 +83,10 @@ bool run_once;
 /* Whether to report TARGET_WAITKIND_NO_RESUMED events.  */
 static bool report_no_resumed;
 
+/* The event loop checks this to decide whether to continue accepting
+   events.  */
+static bool keep_processing_events = true;
+
 bool non_stop;
 
 static struct {
@@ -3463,6 +3467,32 @@ gdbserver_show_disableable (FILE *stream)
 	   "  threads     \tAll of the above\n");
 }
 
+/* Start up the event loop.  This is the entry point to the event
+   loop.  */
+
+static void
+start_event_loop ()
+{
+  /* Loop until there is nothing to do.  This is the entry point to
+     the event loop engine.  If nothing is ready at this time, wait
+     for something to happen (via wait_for_event), then process it.
+     Return when there are no longer event sources to wait for.  */
+
+  keep_processing_events = true;
+  while (keep_processing_events)
+    {
+      /* Any events already waiting in the queue?  */
+      int res = gdb_do_one_event ();
+
+      /* Was there an error?  */
+      if (res == -1)
+	break;
+    }
+
+  /* We are done with the event loop.  There are no more event sources
+     to listen to.  So we exit gdbserver.  */
+}
+
 static void
 kill_inferior_callback (process_info *process)
 {
@@ -3762,7 +3792,6 @@ captured_main (int argc, char *argv[])
   initialize_async_io ();
   initialize_low ();
   have_job_control ();
-  initialize_event_loop ();
   if (target_supports_tracepoints ())
     initialize_tracepoint ();
 
@@ -4365,7 +4394,7 @@ process_serial_event (void)
 
 /* Event-loop callback for serial events.  */
 
-int
+void
 handle_serial_event (int err, gdb_client_data client_data)
 {
   if (debug_threads)
@@ -4373,13 +4402,14 @@ handle_serial_event (int err, gdb_client_data client_data)
 
   /* Really handle it.  */
   if (process_serial_event () < 0)
-    return -1;
+    {
+      keep_processing_events = false;
+      return;
+    }
 
   /* Be sure to not change the selected thread behind GDB's back.
      Important in the non-stop mode asynchronous protocol.  */
   set_desired_thread ();
-
-  return 0;
 }
 
 /* Push a stop notification on the notification queue.  */
@@ -4397,7 +4427,7 @@ push_stop_notification (ptid_t ptid, struct target_waitstatus *status)
 
 /* Event-loop callback for target events.  */
 
-int
+void
 handle_target_event (int err, gdb_client_data client_data)
 {
   client_state &cs = get_client_state ();
@@ -4474,8 +4504,6 @@ handle_target_event (int err, gdb_client_data client_data)
   /* Be sure to not change the selected thread behind GDB's back.
      Important in the non-stop mode asynchronous protocol.  */
   set_desired_thread ();
-
-  return 0;
 }
 
 /* See gdbsupport/event-loop.h.  */
diff --git a/gdbserver/server.h b/gdbserver/server.h
index 5ef48b62c62..039082e2eff 100644
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -88,13 +88,13 @@ typedef SOCKET gdb_fildes_t;
 typedef int gdb_fildes_t;
 #endif
 
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
 
 /* Functions from server.c.  */
 extern void handle_v_requests (char *own_buf, int packet_len,
 			       int *new_packet_len);
-extern int handle_serial_event (int err, gdb_client_data client_data);
-extern int handle_target_event (int err, gdb_client_data client_data);
+extern void handle_serial_event (int err, gdb_client_data client_data);
+extern void handle_target_event (int err, gdb_client_data client_data);
 
 /* Get rid of the currently pending stop replies that match PTID.  */
 extern void discard_queued_stop_replies (ptid_t ptid);
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 11/12] Move gdb_notifier comment
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (9 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 10/12] Switch gdbserver to gdbsupport event loop Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-03-14 18:51 ` [PATCH v2 12/12] Remove gdb_fildes_t Tom Tromey
  2020-04-13 21:08 ` [PATCH v2 00/12] Merge event loop implementations Tom Tromey
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves the gdb_notifier comment a bit lower in event-loop.c, to
where it belongs; and removes an obsolete comment that Pedro pointed
out.

gdbsupport/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* event-loop.c: Move comment.  Remove obsolete 	comment.
---
 gdbsupport/ChangeLog     |  4 ++++
 gdbsupport/event-loop.cc | 19 ++++++++-----------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/gdbsupport/event-loop.cc b/gdbsupport/event-loop.cc
index f7ccc4eec47..e959e1b91b8 100644
--- a/gdbsupport/event-loop.cc
+++ b/gdbsupport/event-loop.cc
@@ -57,17 +57,6 @@ typedef struct file_handler
   }
 file_handler;
 
-/* Gdb_notifier is just a list of file descriptors gdb is interested in.
-   These are the input file descriptor, and the target file
-   descriptor.  We have two flavors of the notifier, one for platforms
-   that have the POLL function, the other for those that don't, and
-   only support SELECT.  Each of the elements in the gdb_notifier list is
-   basically a description of what kind of events gdb is interested
-   in, for each fd.  */
-
-/* As of 1999-04-30 only the input file descriptor is registered with the
-   event loop.  */
-
 /* Do we use poll or select ? */
 #ifdef HAVE_POLL
 #define USE_POLL 1
@@ -82,6 +71,14 @@ static unsigned char use_poll = USE_POLL;
 #include <io.h>
 #endif
 
+/* Gdb_notifier is just a list of file descriptors gdb is interested in.
+   These are the input file descriptor, and the target file
+   descriptor.  We have two flavors of the notifier, one for platforms
+   that have the POLL function, the other for those that don't, and
+   only support SELECT.  Each of the elements in the gdb_notifier list is
+   basically a description of what kind of events gdb is interested
+   in, for each fd.  */
+
 static struct
   {
     /* Ptr to head of file handler list.  */
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 12/12] Remove gdb_fildes_t
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (10 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 11/12] Move gdb_notifier comment Tom Tromey
@ 2020-03-14 18:51 ` Tom Tromey
  2020-04-13 21:08 ` [PATCH v2 00/12] Merge event loop implementations Tom Tromey
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-03-14 18:51 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

gdb_fildes_t and pfildes are no longer used, so remove them.

gdbserver/ChangeLog
2020-03-14  Tom Tromey  <tom@tromey.com>

	* server.h (gdb_fildes_t): Remove typedef.
	* remote-utils.c (remote_desc, list_desc): Now int.
	(INVALID_DESCRIPTOR): Remove.
	(gdb_connected, remote_close)
	(check_remote_input_interrupt_request): Update.
	* utils.h (pfildes): Don't declare.
	* utils.c (pfildes): Remove.
---
 gdbserver/ChangeLog       | 10 ++++++++++
 gdbserver/remote-utils.cc | 16 +++++-----------
 gdbserver/server.h        |  7 -------
 gdbserver/utils.cc        | 12 ------------
 gdbserver/utils.h         |  1 -
 5 files changed, 15 insertions(+), 31 deletions(-)

diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc
index 6249691954d..67c560d1c87 100644
--- a/gdbserver/remote-utils.cc
+++ b/gdbserver/remote-utils.cc
@@ -78,12 +78,6 @@ typedef int socklen_t;
 
 #ifndef IN_PROCESS_AGENT
 
-#if USE_WIN32API
-# define INVALID_DESCRIPTOR INVALID_SOCKET
-#else
-# define INVALID_DESCRIPTOR -1
-#endif
-
 /* Extra value for readchar_callback.  */
 enum {
   /* The callback is currently not scheduled.  */
@@ -108,8 +102,8 @@ struct sym_cache
 
 static int remote_is_stdio = 0;
 
-static gdb_fildes_t remote_desc = INVALID_DESCRIPTOR;
-static gdb_fildes_t listen_desc = INVALID_DESCRIPTOR;
+static int remote_desc = -1;
+static int listen_desc = -1;
 
 #ifdef USE_WIN32API
 # define read(fd, buf, len) recv (fd, (char *) buf, len, 0)
@@ -119,7 +113,7 @@ static gdb_fildes_t listen_desc = INVALID_DESCRIPTOR;
 int
 gdb_connected (void)
 {
-  return remote_desc != INVALID_DESCRIPTOR;
+  return remote_desc != -1;
 }
 
 /* Return true if the remote connection is over stdio.  */
@@ -425,7 +419,7 @@ remote_close (void)
   if (! remote_connection_is_stdio ())
     close (remote_desc);
 #endif
-  remote_desc = INVALID_DESCRIPTOR;
+  remote_desc = -1;
 
   reset_readchar ();
 }
@@ -788,7 +782,7 @@ check_remote_input_interrupt_request (void)
   /* This function may be called before establishing communications,
      therefore we need to validate the remote descriptor.  */
 
-  if (remote_desc == INVALID_DESCRIPTOR)
+  if (remote_desc == -1)
     return;
 
   input_interrupt (0);
diff --git a/gdbserver/server.h b/gdbserver/server.h
index 039082e2eff..09989e46264 100644
--- a/gdbserver/server.h
+++ b/gdbserver/server.h
@@ -81,13 +81,6 @@ extern bool disable_packet_T;
 extern bool run_once;
 extern bool non_stop;
 
-#if USE_WIN32API
-#include <winsock2.h>
-typedef SOCKET gdb_fildes_t;
-#else
-typedef int gdb_fildes_t;
-#endif
-
 #include "gdbsupport/event-loop.h"
 
 /* Functions from server.c.  */
diff --git a/gdbserver/utils.cc b/gdbserver/utils.cc
index d88f4ac5ca7..d52d2ac8736 100644
--- a/gdbserver/utils.cc
+++ b/gdbserver/utils.cc
@@ -113,15 +113,3 @@ paddress (CORE_ADDR addr)
 {
   return phex_nz (addr, sizeof (CORE_ADDR));
 }
-
-/* Convert a file descriptor into a printable string.  */
-
-char *
-pfildes (gdb_fildes_t fd)
-{
-#if USE_WIN32API
-  return phex_nz (fd, sizeof (gdb_fildes_t));
-#else
-  return plongest (fd);
-#endif
-}
diff --git a/gdbserver/utils.h b/gdbserver/utils.h
index fa3ca9bb945..fc56f33f9f3 100644
--- a/gdbserver/utils.h
+++ b/gdbserver/utils.h
@@ -20,6 +20,5 @@
 #define GDBSERVER_UTILS_H
 
 char *paddress (CORE_ADDR addr);
-char *pfildes (gdb_fildes_t fd);
 
 #endif /* GDBSERVER_UTILS_H */
-- 
2.17.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v2 00/12] Merge event loop implementations
  2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
                   ` (11 preceding siblings ...)
  2020-03-14 18:51 ` [PATCH v2 12/12] Remove gdb_fildes_t Tom Tromey
@ 2020-04-13 21:08 ` Tom Tromey
  12 siblings, 0 replies; 14+ messages in thread
From: Tom Tromey @ 2020-04-13 21:08 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> Here's v2 of the series to merge the event loop code between gdb and
Tom> gdbserver.  I've been meaning to resend this for a while (since Feb I
Tom> think) but I forgot about it.

Tom> The reviews for v1 are back in September 2019.

Tom> I think this version addresses all the review comments; but it's been
Tom> a while, so it is best to double check.

I'm checking this in now.

Tom

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-04-13 21:08 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-14 18:51 [PATCH v2 00/12] Merge event loop implementations Tom Tromey
2020-03-14 18:51 ` [PATCH v2 01/12] Move start_event_loop out of event-loop.c Tom Tromey
2020-03-14 18:51 ` [PATCH v2 02/12] Move event-loop configury to common.m4 Tom Tromey
2020-03-14 18:51 ` [PATCH v2 03/12] Move gdb_select.h to gdbsupport/ Tom Tromey
2020-03-14 18:51 ` [PATCH v2 04/12] Include <chrono> in event-loop.c Tom Tromey
2020-03-14 18:51 ` [PATCH v2 05/12] Use warning in event-loop Tom Tromey
2020-03-14 18:51 ` [PATCH v2 06/12] Introduce and use flush_streams Tom Tromey
2020-03-14 18:51 ` [PATCH v2 07/12] Introduce async-event.[ch] Tom Tromey
2020-03-14 18:51 ` [PATCH v2 08/12] Move event-loop.[ch] to gdbsupport/ Tom Tromey
2020-03-14 18:51 ` [PATCH v2 09/12] Implement event-loop glue for gdbserver Tom Tromey
2020-03-14 18:51 ` [PATCH v2 10/12] Switch gdbserver to gdbsupport event loop Tom Tromey
2020-03-14 18:51 ` [PATCH v2 11/12] Move gdb_notifier comment Tom Tromey
2020-03-14 18:51 ` [PATCH v2 12/12] Remove gdb_fildes_t Tom Tromey
2020-04-13 21:08 ` [PATCH v2 00/12] Merge event loop implementations Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).