Simplify target_async hook interface
authorPedro Alves <palves@redhat.com>
Wed, 25 Mar 2015 11:28:31 +0000 (11:28 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 25 Mar 2015 11:28:31 +0000 (11:28 +0000)
All callers of target_async pass it the same callback
(inferior_event_handler).  Since both common code and target backends
need to be able to put the target in and out of target async mode at
any given time, there's really no way that a different callback could
be passed.  This commit simplifies things, and removes the indirection
altogether.  Bonus: with this, gdb's target_async method ends up with
the same signature as gdbserver's.

Tested on x86_64 Fedora 20, native and gdbserver.

gdb/ChangeLog:
2015-03-25  Pedro Alves  <palves@redhat.com>

* target.h <to_async>: Replace 'callback' and 'context' parameters
with boolean 'enable' parameter.
(target_async): Replace CALLBACK and CONTEXT parameters with
boolean ENABLE parameter.
* inf-loop.c (inferior_event_handler): Adjust.
* linux-nat.c (linux_nat_attach, linux_nat_resume)
(linux_nat_resume): Adjust.
(async_client_callback, async_client_context): Delete.
(handle_target_event): Call inferior_event_handler directly.
(linux_nat_async): Replace 'callback' and 'context' parameters
with boolean 'enable' parameter.  Adjust.  Remove references to
async_client_callback and async_client_context.
(linux_nat_close): Adjust.
* record-btrace.c (record_btrace_async): Replace 'callback' and
'context' parameters with boolean 'enable' parameter.  Adjust.
(record_btrace_resume): Adjust.
* record-full.c (record_full_async): Replace 'callback' and
'context' parameters with boolean 'enable' parameter.  Adjust.
(record_full_resume, record_full_core_resume): Adjust.
* remote.c (struct remote_state) <async_client_callback,
async_client_context>: Delete fields.
(remote_start_remote, extended_remote_attach_1, remote_resume)
(extended_remote_create_inferior): Adjust.
(remote_async_serial_handler): Call inferior_event_handler
directly.
(remote_async): Replace 'callback' and 'context' parameters with
boolean 'enable' parameter.  Adjust.
* top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper):
Adjust.
* target-delegates.c: Regenerate.

gdb/ChangeLog
gdb/inf-loop.c
gdb/linux-nat.c
gdb/record-btrace.c
gdb/record-full.c
gdb/remote.c
gdb/target-delegates.c
gdb/target.h
gdb/top.c

index 591a1145406ac3208710af1035645129222cf9e9..febc377a366af532dfd999658d47e1b5f9be3efe 100644 (file)
@@ -1,3 +1,36 @@
+2015-03-25  Pedro Alves  <palves@redhat.com>
+
+       * target.h <to_async>: Replace 'callback' and 'context' parameters
+       with boolean 'enable' parameter.
+       (target_async): Replace CALLBACK and CONTEXT parameters with
+       boolean ENABLE parameter.
+       * inf-loop.c (inferior_event_handler): Adjust.
+       * linux-nat.c (linux_nat_attach, linux_nat_resume)
+       (linux_nat_resume): Adjust.
+       (async_client_callback, async_client_context): Delete.
+       (handle_target_event): Call inferior_event_handler directly.
+       (linux_nat_async): Replace 'callback' and 'context' parameters
+       with boolean 'enable' parameter.  Adjust.  Remove references to
+       async_client_callback and async_client_context.
+       (linux_nat_close): Adjust.
+       * record-btrace.c (record_btrace_async): Replace 'callback' and
+       'context' parameters with boolean 'enable' parameter.  Adjust.
+       (record_btrace_resume): Adjust.
+       * record-full.c (record_full_async): Replace 'callback' and
+       'context' parameters with boolean 'enable' parameter.  Adjust.
+       (record_full_resume, record_full_core_resume): Adjust.
+       * remote.c (struct remote_state) <async_client_callback,
+       async_client_context>: Delete fields.
+       (remote_start_remote, extended_remote_attach_1, remote_resume)
+       (extended_remote_create_inferior): Adjust.
+       (remote_async_serial_handler): Call inferior_event_handler
+       directly.
+       (remote_async): Replace 'callback' and 'context' parameters with
+       boolean 'enable' parameter.  Adjust.
+       * top.c (gdb_readline_wrapper_cleanup, gdb_readline_wrapper):
+       Adjust.
+       * target-delegates.c: Regenerate.
+
 2015-03-25  Gary Benson <gbenson@redhat.com>
            Pedro Alves  <palves@redhat.com>
 
index 429cd73faa2b48950c7efff34837e62b2cf170e9..eed881d5144e6a9a8538689c8576b70ed7a21570 100644 (file)
@@ -74,7 +74,7 @@ inferior_event_handler (enum inferior_event_type event_type,
             so that when the inferior is not running we don't get
             distracted by spurious inferior output.  */
          if (target_has_execution)
-           target_async (NULL, 0);
+           target_async (0);
        }
 
       /* Do all continuations associated with the whole inferior (not
index 660dc8f80f1bad49d7c3a20f1d36a851d0b39e84..0376299fb19a3fd7de9e4e8509f0ddc8c2d509c6 100644 (file)
@@ -1341,7 +1341,7 @@ linux_nat_attach (struct target_ops *ops, const char *args, int from_tty)
                                  attach_proc_task_lwp_callback);
 
   if (target_can_async_p ())
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 }
 
 /* Get pending status of LP.  */
@@ -1789,7 +1789,7 @@ linux_nat_resume (struct target_ops *ops,
 
       if (target_can_async_p ())
        {
-         target_async (inferior_event_handler, 0);
+         target_async (1);
          /* Tell the event loop we have something to process.  */
          async_file_mark ();
        }
@@ -1810,7 +1810,7 @@ linux_nat_resume (struct target_ops *ops,
   linux_resume_one_lwp (lp, step, signo);
 
   if (target_can_async_p ())
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 }
 
 /* Send a signal to an LWP.  */
@@ -4625,10 +4625,6 @@ linux_nat_terminal_ours (struct target_ops *self)
   async_terminal_is_ours = 1;
 }
 
-static void (*async_client_callback) (enum inferior_event_type event_type,
-                                     void *context);
-static void *async_client_context;
-
 /* SIGCHLD handler that serves two purposes: In non-stop/async mode,
    so we notice when any child changes state, and notify the
    event-loop; it allows us to use sigsuspend in linux_nat_wait_1
@@ -4656,7 +4652,7 @@ sigchld_handler (int signo)
 static void
 handle_target_event (int error, gdb_client_data client_data)
 {
-  (*async_client_callback) (INF_REG_EVENT, async_client_context);
+  inferior_event_handler (INF_REG_EVENT, NULL);
 }
 
 /* Create/destroy the target events pipe.  Returns previous state.  */
@@ -4700,15 +4696,10 @@ linux_async_pipe (int enable)
 /* target_async implementation.  */
 
 static void
-linux_nat_async (struct target_ops *ops,
-                void (*callback) (enum inferior_event_type event_type,
-                                  void *context),
-                void *context)
+linux_nat_async (struct target_ops *ops, int enable)
 {
-  if (callback != NULL)
+  if (enable)
     {
-      async_client_callback = callback;
-      async_client_context = context;
       if (!linux_async_pipe (1))
        {
          add_file_handler (linux_nat_event_pipe[0],
@@ -4720,8 +4711,6 @@ linux_nat_async (struct target_ops *ops,
     }
   else
     {
-      async_client_callback = callback;
-      async_client_context = context;
       delete_file_handler (linux_nat_event_pipe[0]);
       linux_async_pipe (0);
     }
@@ -4789,7 +4778,7 @@ linux_nat_close (struct target_ops *self)
 {
   /* Unregister from the event loop.  */
   if (linux_nat_is_async_p (self))
-    linux_nat_async (self, NULL, NULL);
+    linux_nat_async (self, 0);
 
   if (linux_ops->to_close)
     linux_ops->to_close (linux_ops);
index 5eb5cf4f7257f8b9208927064386f29a9288ce52..240a8dc8555f59f6b371f4a6e32729816043b9ae 100644 (file)
@@ -278,17 +278,14 @@ record_btrace_close (struct target_ops *self)
 /* The to_async method of target record-btrace.  */
 
 static void
-record_btrace_async (struct target_ops *ops,
-                    void (*callback) (enum inferior_event_type event_type,
-                                      void *context),
-                    void *context)
+record_btrace_async (struct target_ops *ops, int enable)
 {
-  if (callback != NULL)
+  if (enable)
     mark_async_event_handler (record_btrace_async_inferior_event_handler);
   else
     clear_async_event_handler (record_btrace_async_inferior_event_handler);
 
-  ops->beneath->to_async (ops->beneath, callback, context);
+  ops->beneath->to_async (ops->beneath, enable);
 }
 
 /* Adjusts the size and returns a human readable size suffix.  */
@@ -1789,7 +1786,7 @@ record_btrace_resume (struct target_ops *ops, ptid_t ptid, int step,
   /* Async support.  */
   if (target_can_async_p ())
     {
-      target_async (inferior_event_handler, 0);
+      target_async (1);
       mark_async_event_handler (record_btrace_async_inferior_event_handler);
     }
 }
index 0fbb2646e959c68fdc36bd76ed2b72724f5820d0..43e8be23b6c775618df0e3b8c2e274995002a426 100644 (file)
@@ -914,17 +914,14 @@ record_full_close (struct target_ops *self)
 /* "to_async" target method.  */
 
 static void
-record_full_async (struct target_ops *ops,
-                  void (*callback) (enum inferior_event_type event_type,
-                                    void *context),
-                  void *context)
+record_full_async (struct target_ops *ops, int enable)
 {
-  if (callback != NULL)
+  if (enable)
     mark_async_event_handler (record_full_async_inferior_event_token);
   else
     clear_async_event_handler (record_full_async_inferior_event_token);
 
-  ops->beneath->to_async (ops->beneath, callback, context);
+  ops->beneath->to_async (ops->beneath, enable);
 }
 
 static int record_full_resume_step = 0;
@@ -1006,7 +1003,7 @@ record_full_resume (struct target_ops *ops, ptid_t ptid, int step,
   /* We are about to start executing the inferior (or simulate it),
      let's register it with the event loop.  */
   if (target_can_async_p ())
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 }
 
 static int record_full_get_sig = 0;
@@ -1978,7 +1975,7 @@ record_full_core_resume (struct target_ops *ops, ptid_t ptid, int step,
   /* We are about to start executing the inferior (or simulate it),
      let's register it with the event loop.  */
   if (target_can_async_p ())
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 }
 
 /* "to_kill" method for prec over corefile.  */
index fd677fe22c955c37d53b853a21eb12584d9e27b8..164231c4e21a321162cb2c8cf89d998d0189d02a 100644 (file)
@@ -124,10 +124,7 @@ static int remote_can_async_p (struct target_ops *);
 
 static int remote_is_async_p (struct target_ops *);
 
-static void remote_async (struct target_ops *ops,
-                         void (*callback) (enum inferior_event_type event_type,
-                                           void *context),
-                         void *context);
+static void remote_async (struct target_ops *ops, int enable);
 
 static void sync_remote_interrupt_twice (int signo);
 
@@ -356,10 +353,6 @@ struct remote_state
   int use_threadinfo_query;
   int use_threadextra_query;
 
-  void (*async_client_callback) (enum inferior_event_type event_type,
-                                void *context);
-  void *async_client_context;
-
   /* This is set to the data address of the access causing the target
      to stop for a watchpoint.  */
   CORE_ADDR remote_watch_data_address;
@@ -3661,7 +3654,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
        }
 
       if (target_can_async_p ())
-       target_async (inferior_event_handler, 0);
+       target_async (1);
 
       if (thread_count () == 0)
        {
@@ -4590,7 +4583,7 @@ extended_remote_attach_1 (struct target_ops *target, const char *args,
 
          push_stop_reply ((struct stop_reply *) reply);
 
-         target_async (inferior_event_handler, 0);
+         target_async (1);
        }
       else
        {
@@ -4929,7 +4922,7 @@ remote_resume (struct target_ops *ops,
      into infcmd.c in order to allow inferior function calls to work
      NOT asynchronously.  */
   if (target_can_async_p ())
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 
   /* We've just told the target to resume.  The remote server will
      wait for the inferior to stop, and then send a stop reply.  In
@@ -8112,7 +8105,7 @@ extended_remote_create_inferior (struct target_ops *ops,
   /* If running asynchronously, register the target file descriptor
      with the event loop.  */
   if (target_can_async_p ())
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 
   /* Disable address space randomization if requested (and supported).  */
   if (extended_remote_supports_disable_randomization (ops))
@@ -11962,7 +11955,7 @@ remote_async_serial_handler (struct serial *scb, void *context)
 
   /* Don't propogate error information up to the client.  Instead let
      the client find out about the error by querying the target.  */
-  rs->async_client_callback (INF_REG_EVENT, rs->async_client_context);
+  inferior_event_handler (INF_REG_EVENT, NULL);
 }
 
 static void
@@ -11972,18 +11965,13 @@ remote_async_inferior_event_handler (gdb_client_data data)
 }
 
 static void
-remote_async (struct target_ops *ops,
-             void (*callback) (enum inferior_event_type event_type,
-                               void *context),
-             void *context)
+remote_async (struct target_ops *ops, int enable)
 {
   struct remote_state *rs = get_remote_state ();
 
-  if (callback != NULL)
+  if (enable)
     {
       serial_async (rs->remote_desc, remote_async_serial_handler, rs);
-      rs->async_client_callback = callback;
-      rs->async_client_context = context;
 
       /* If there are pending events in the stop reply queue tell the
         event loop to process them.  */
index 0c1309a9aaf32f89bb832aace5e7bd351d313cc2..b29abaf5b37d76143128ebd49407326d0756cdc4 100644 (file)
@@ -1692,29 +1692,27 @@ debug_is_async_p (struct target_ops *self)
 }
 
 static void
-delegate_async (struct target_ops *self, async_callback_ftype *arg1, void *arg2)
+delegate_async (struct target_ops *self, int arg1)
 {
   self = self->beneath;
-  self->to_async (self, arg1, arg2);
+  self->to_async (self, arg1);
 }
 
 static void
-tdefault_async (struct target_ops *self, async_callback_ftype *arg1, void *arg2)
+tdefault_async (struct target_ops *self, int arg1)
 {
   tcomplain ();
 }
 
 static void
-debug_async (struct target_ops *self, async_callback_ftype *arg1, void *arg2)
+debug_async (struct target_ops *self, int arg1)
 {
   fprintf_unfiltered (gdb_stdlog, "-> %s->to_async (...)\n", debug_target.to_shortname);
-  debug_target.to_async (&debug_target, arg1, arg2);
+  debug_target.to_async (&debug_target, arg1);
   fprintf_unfiltered (gdb_stdlog, "<- %s->to_async (", debug_target.to_shortname);
   target_debug_print_struct_target_ops_p (&debug_target);
   fputs_unfiltered (", ", gdb_stdlog);
-  target_debug_print_async_callback_ftype_p (arg1);
-  fputs_unfiltered (", ", gdb_stdlog);
-  target_debug_print_void_p (arg2);
+  target_debug_print_int (arg1);
   fputs_unfiltered (")\n", gdb_stdlog);
 }
 
index 05dcd9feaead06bfde24c0647e429b59a638da28..19254d66735993781ad4294d4384cddca8dc5d02 100644 (file)
@@ -629,7 +629,7 @@ struct target_ops
       TARGET_DEFAULT_RETURN (0);
     int (*to_is_async_p) (struct target_ops *)
       TARGET_DEFAULT_RETURN (0);
-    void (*to_async) (struct target_ops *, async_callback_ftype *, void *)
+    void (*to_async) (struct target_ops *, int)
       TARGET_DEFAULT_NORETURN (tcomplain ());
     /* This method must be implemented in some situations.  See the
        comment on 'to_can_run'.  */
@@ -1686,9 +1686,9 @@ extern int target_async_permitted;
 /* Is the target in asynchronous execution mode?  */
 #define target_is_async_p() (current_target.to_is_async_p (&current_target))
 
-/* Put the target in async mode with the specified callback function.  */
-#define target_async(CALLBACK,CONTEXT) \
-     (current_target.to_async (&current_target, (CALLBACK), (CONTEXT)))
+/* Enables/disabled async target events.  */
+#define target_async(ENABLE) \
+     (current_target.to_async (&current_target, (ENABLE)))
 
 #define target_execution_direction() \
   (current_target.to_execution_direction (&current_target))
index f746af8ef8b197a54d34a66dda813a0fdcbf1a3f..b15c06b03bab5d7e6a1e99b6129d9d2cdbb02c60 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -806,7 +806,7 @@ gdb_readline_wrapper_cleanup (void *arg)
   saved_after_char_processing_hook = NULL;
 
   if (cleanup->target_is_async_orig)
-    target_async (inferior_event_handler, 0);
+    target_async (1);
 
   xfree (cleanup);
 }
@@ -829,7 +829,7 @@ gdb_readline_wrapper (const char *prompt)
   back_to = make_cleanup (gdb_readline_wrapper_cleanup, cleanup);
 
   if (cleanup->target_is_async_orig)
-    target_async (NULL, NULL);
+    target_async (0);
 
   /* Display our prompt and prevent double prompt display.  */
   display_gdb_prompt (prompt);
This page took 0.071832 seconds and 4 git commands to generate.