Remove ALL_OBJFILES_SAFE
authorTom Tromey <tom@tromey.com>
Sat, 24 Nov 2018 00:09:34 +0000 (17:09 -0700)
committerTom Tromey <tom@tromey.com>
Thu, 10 Jan 2019 01:28:14 +0000 (18:28 -0700)
This removes the ALL_OBJFILES_SAFE macro, replacing the uses with
ranged for loops.

gdb/ChangeLog
2019-01-09  Tom Tromey  <tom@tromey.com>

* common/next-iterator.h (next_adapter): Add Iterator template
parameter.
* objfiles.h (ALL_OBJFILES_SAFE): Remove.
(class all_objfiles_safe): New.
* jit.c (jit_inferior_exit_hook): Use all_objfiles_safe.
* objfiles.c (put_objfile_before): Update comment.
(add_separate_debug_objfile): Likewise.
(free_all_objfiles): Use all_objfiles_safe.
(objfile_purge_solibs): Likewise.

gdb/ChangeLog
gdb/common/next-iterator.h
gdb/jit.c
gdb/objfiles.c
gdb/objfiles.h

index 00160cf74d441907d5205bf5cceeeffcd53b5047..e51c19c1faae0acd50d5c6606679e2c55f29b26b 100644 (file)
@@ -1,3 +1,15 @@
+2019-01-09  Tom Tromey  <tom@tromey.com>
+
+       * common/next-iterator.h (next_adapter): Add Iterator template
+       parameter.
+       * objfiles.h (ALL_OBJFILES_SAFE): Remove.
+       (class all_objfiles_safe): New.
+       * jit.c (jit_inferior_exit_hook): Use all_objfiles_safe.
+       * objfiles.c (put_objfile_before): Update comment.
+       (add_separate_debug_objfile): Likewise.
+       (free_all_objfiles): Use all_objfiles_safe.
+       (objfile_purge_solibs): Likewise.
+
 2019-01-09  Tom Tromey  <tom@tromey.com>
 
        * symtab.c (iterate_over_symtabs, matching_obj_sections)
index 588ebfd9d1f1433e10524877bccda2524dce1a92..b61b253bd9d6ea69b06a14ee62150a9b21aa677f 100644 (file)
@@ -72,7 +72,7 @@ private:
 
 /* A range adapter that allows iterating over a linked list.  */
 
-template<typename T>
+template<typename T, typename Iterator = next_iterator<T>>
 class next_adapter
 {
 public:
@@ -82,7 +82,7 @@ public:
   {
   }
 
-  using iterator = next_iterator<T>;
+  using iterator = Iterator;
 
   iterator begin () const
   {
index e77c03ad59b649a727426a995053ba5feb45f096..8b7f715824c25308f18a076c6ef6dd0249b9a358 100644 (file)
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -1393,10 +1393,7 @@ jit_breakpoint_re_set (void)
 static void
 jit_inferior_exit_hook (struct inferior *inf)
 {
-  struct objfile *objf;
-  struct objfile *temp;
-
-  ALL_OBJFILES_SAFE (objf, temp)
+  for (objfile *objf : all_objfiles_safe (current_program_space))
     {
       struct jit_objfile_data *objf_data
        = (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data);
index c9a727aff7de06230421c2a97291d86619f3bb8a..5d46e69dc316a3ec63bf84426f5d0b80546a099a 100644 (file)
@@ -514,7 +514,7 @@ objfile_separate_debug_iterate (const struct objfile *parent,
 
 /* Put one object file before a specified on in the global list.
    This can be used to make sure an object file is destroyed before
-   another when using ALL_OBJFILES_SAFE to free all objfiles.  */
+   another when using all_objfiles_safe to free all objfiles.  */
 void
 put_objfile_before (struct objfile *objfile, struct objfile *before_this)
 {
@@ -587,7 +587,7 @@ add_separate_debug_objfile (struct objfile *objfile, struct objfile *parent)
   parent->separate_debug_objfile = objfile;
 
   /* Put the separate debug object before the normal one, this is so that
-     usage of the ALL_OBJFILES_SAFE macro will stay safe.  */
+     usage of all_objfiles_safe will stay safe.  */
   put_objfile_before (objfile, parent);
 }
 
@@ -730,17 +730,14 @@ objfile::~objfile ()
 void
 free_all_objfiles (void)
 {
-  struct objfile *objfile, *temp;
   struct so_list *so;
 
   /* Any objfile referencewould become stale.  */
   for (so = master_so_list (); so; so = so->next)
     gdb_assert (so->objfile == NULL);
 
-  ALL_OBJFILES_SAFE (objfile, temp)
-  {
+  for (objfile *objfile : all_objfiles_safe (current_program_space))
     delete objfile;
-  }
   clear_symtab_users (0);
 }
 \f
@@ -1047,17 +1044,14 @@ have_full_symbols (void)
 void
 objfile_purge_solibs (void)
 {
-  struct objfile *objf;
-  struct objfile *temp;
-
-  ALL_OBJFILES_SAFE (objf, temp)
-  {
-    /* We assume that the solib package has been purged already, or will
-       be soon.  */
+  for (objfile *objf : all_objfiles_safe (current_program_space))
+    {
+      /* We assume that the solib package has been purged already, or will
+        be soon.  */
 
-    if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SHARED))
-      delete objf;
-  }
+      if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SHARED))
+       delete objf;
+    }
 }
 
 
index 512869f214e91c243b1b3a255149c6a26b080859..cb3668aff651f4f2b631d04f0d3202f2d739a557 100644 (file)
@@ -29,6 +29,7 @@
 #include "gdb_bfd.h"
 #include <vector>
 #include "common/next-iterator.h"
+#include "common/safe-iterator.h"
 
 struct bcache;
 struct htab;
@@ -581,21 +582,36 @@ public:
   }
 };
 
+/* An iterarable object that can be used to iterate over all
+   objfiles.  The basic use is in a foreach, like:
 
-/* Traverse all object files in the current program space.
-   ALL_OBJFILES_SAFE works even if you delete the objfile during the
-   traversal.  */
+   for (objfile *objf : all_objfiles_safe (pspace)) { ... }
+
+   This variant uses a basic_safe_iterator so that objfiles can be
+   deleted during iteration.  */
+
+class all_objfiles_safe
+  : public next_adapter<struct objfile,
+                       basic_safe_iterator<next_iterator<objfile>>>
+{
+public:
+
+  explicit all_objfiles_safe (struct program_space *pspace)
+    : next_adapter<struct objfile,
+                  basic_safe_iterator<next_iterator<objfile>>>
+        (pspace->objfiles)
+  {
+  }
+};
+
+
+/* Traverse all object files in the current program space.  */
 
 #define ALL_OBJFILES(obj)                          \
   for ((obj) = current_program_space->objfiles; \
        (obj) != NULL;                              \
        (obj) = (obj)->next)
 
-#define ALL_OBJFILES_SAFE(obj,nxt)                     \
-  for ((obj) = current_program_space->objfiles;        \
-       (obj) != NULL? ((nxt)=(obj)->next,1) :0;        \
-       (obj) = (nxt))
-
 /* Traverse all symtabs in one objfile.  */
 
 #define ALL_OBJFILE_FILETABS(objfile, cu, s) \
This page took 0.028149 seconds and 4 git commands to generate.