Remove iterate_over_inferiors
authorTom Tromey <tom@tromey.com>
Thu, 23 Apr 2020 12:26:31 +0000 (06:26 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 23 Apr 2020 12:26:31 +0000 (06:26 -0600)
The last caller of iterate_over_inferiors is darwin-nat.c.  This patch
removes the calls from this file, and then remove
iterate_over_inferiors.

In general I think "external iteration" is to be preferred in gdb, the
main benefit being that the code is easier to read.

I rebuilt this on Darwin.  I seem to only have access to Darwin
systems where gdb does not yet work :-(, so I can't run the test
suite.

gdb/ChangeLog
2020-04-23  Tom Tromey  <tom@tromey.com>

* inferior.h (iterate_over_inferiors): Don't declare.
* inferior.c (iterate_over_inferiors): Remove.
* darwin-nat.c (find_inferior_task_it, find_inferior_pid_it):
Remove.
(darwin_find_inferior_by_task, darwin_find_inferior_by_pid): Don't
use iterate_over_inferiors.
(darwin_resume_inferior_it)
(struct resume_inferior_threads_param)
(darwin_resume_inferior_threads_it): Remove.
(darwin_nat_target::resume): Don't use iterate_over_inferiors.

Change-Id: Ib2fdf2c98e40f13156ff869ed3173d5f1fdae7ea

gdb/ChangeLog
gdb/darwin-nat.c
gdb/inferior.c
gdb/inferior.h

index 571ca4b2120d824ad481008e355d1a3123de24ae..f5b4095083bcdc10de000434679bb9997dd42c5d 100644 (file)
@@ -1,3 +1,16 @@
+2020-04-23  Tom Tromey  <tom@tromey.com>
+
+       * inferior.h (iterate_over_inferiors): Don't declare.
+       * inferior.c (iterate_over_inferiors): Remove.
+       * darwin-nat.c (find_inferior_task_it, find_inferior_pid_it):
+       Remove.
+       (darwin_find_inferior_by_task, darwin_find_inferior_by_pid): Don't
+       use iterate_over_inferiors.
+       (darwin_resume_inferior_it)
+       (struct resume_inferior_threads_param)
+       (darwin_resume_inferior_threads_it): Remove.
+       (darwin_nat_target::resume): Don't use iterate_over_inferiors.
+
 2020-04-23  Tom de Vries  <tdevries@suse.de>
 
        * blockframe.c (find_pc_partial_function): Use
index 3bd8d8ce003d57b3ef22ec6e649d0ba31b61259e..2d74bc010c35e29a3048b880355b3be5d55d9706 100644 (file)
@@ -378,32 +378,30 @@ darwin_nat_target::check_new_threads (inferior *inf)
   MACH_CHECK_ERROR (kret);
 }
 
-static int
-find_inferior_task_it (struct inferior *inf, void *port_ptr)
-{
-  darwin_inferior *priv = get_darwin_inferior (inf);
-
-  return priv != nullptr && priv->task == *(task_t *)port_ptr;
-}
-
-static int
-find_inferior_pid_it (struct inferior *inf, void *pid_ptr)
-{
-  return inf->pid == *(int *)pid_ptr;
-}
-
 /* Return an inferior by task port.  */
 static struct inferior *
 darwin_find_inferior_by_task (task_t port)
 {
-  return iterate_over_inferiors (&find_inferior_task_it, &port);
+  for (inferior *inf : all_inferiors ())
+    {
+      darwin_inferior *priv = get_darwin_inferior (inf);
+
+      if (priv != nullptr && priv->task == port)
+       return inf;
+    }
+  return nullptr;
 }
 
 /* Return an inferior by pid port.  */
 static struct inferior *
 darwin_find_inferior_by_pid (int pid)
 {
-  return iterate_over_inferiors (&find_inferior_pid_it, &pid);
+  for (inferior *inf : all_inferiors ())
+    {
+      if (inf->pid == pid)
+       return inf;
+    }
+  return nullptr;
 }
 
 /* Return a thread by port.  */
@@ -458,15 +456,6 @@ darwin_resume_inferior (struct inferior *inf)
     }
 }
 
-/* Iterator functions.  */
-
-static int
-darwin_resume_inferior_it (struct inferior *inf, void *arg)
-{
-  darwin_resume_inferior (inf);
-  return 0;
-}
-
 static void
 darwin_dump_message (mach_msg_header_t *hdr, int disp_body)
 {
@@ -886,23 +875,6 @@ darwin_resume_inferior_threads (struct inferior *inf, int step, int nsignal)
       darwin_resume_thread (inf, thread, step, nsignal);
 }
 
-struct resume_inferior_threads_param
-{
-  int step;
-  int nsignal;
-};
-
-static int
-darwin_resume_inferior_threads_it (struct inferior *inf, void *param)
-{
-  int step = ((struct resume_inferior_threads_param *)param)->step;
-  int nsignal = ((struct resume_inferior_threads_param *)param)->nsignal;
-
-  darwin_resume_inferior_threads (inf, step, nsignal);
-
-  return 0;
-}
-
 /* Suspend all threads of INF.  */
 
 static void
@@ -951,15 +923,13 @@ darwin_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signal)
   /* minus_one_ptid is RESUME_ALL.  */
   if (ptid == minus_one_ptid)
     {
-      struct resume_inferior_threads_param param;
-
-      param.nsignal = nsignal;
-      param.step = step;
-
       /* Resume threads.  */
-      iterate_over_inferiors (darwin_resume_inferior_threads_it, &param);
+      for (inferior *inf : all_inferiors ())
+       darwin_resume_inferior_threads (inf, step, nsignal);
+
       /* Resume tasks.  */
-      iterate_over_inferiors (darwin_resume_inferior_it, NULL);
+      for (inferior *inf : all_inferiors ())
+       darwin_resume_inferior (inf);
     }
   else
     {
index ceee00e9eed5d6a780442f59ab31225fcc6b23d0..2f4ced0788d5cb32260bf51c8112925401c128f0 100644 (file)
@@ -310,17 +310,6 @@ find_inferior_for_program_space (struct program_space *pspace)
   return NULL;
 }
 
-struct inferior *
-iterate_over_inferiors (int (*callback) (struct inferior *, void *),
-                       void *data)
-{
-  for (inferior *inf : all_inferiors_safe ())
-    if ((*callback) (inf, data))
-      return inf;
-
-  return NULL;
-}
-
 int
 have_inferiors (void)
 {
index 4229c6017d92eb9742ef83e1b83688ed6a9e6b30..1ac51369dff26a24a6cf68b97a8775fece6492c2 100644 (file)
@@ -589,20 +589,6 @@ extern struct inferior *find_inferior_id (int num);
 extern struct inferior *
   find_inferior_for_program_space (struct program_space *pspace);
 
-/* Inferior iterator function.
-
-   Calls a callback function once for each inferior, so long as the
-   callback function returns false.  If the callback function returns
-   true, the iteration will end and the current inferior will be
-   returned.  This can be useful for implementing a search for a
-   inferior with arbitrary attributes, or for applying some operation
-   to every inferior.
-
-   It is safe to delete the iterated inferior from the callback.  */
-extern struct inferior *iterate_over_inferiors (int (*) (struct inferior *,
-                                                        void *),
-                                               void *);
-
 /* Returns true if the inferior list is not empty.  */
 extern int have_inferiors (void);
 
This page took 0.030426 seconds and 4 git commands to generate.