aboutsummaryrefslogtreecommitdiff
path: root/gdb/objfiles.h
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-11-23 17:09:34 -0700
committerTom Tromey <tom@tromey.com>2019-01-09 18:28:14 -0700
commitcac85af2467c9bac326b397b150274d95d2916a5 (patch)
tree1e9c3722cd2e1592218f8dc5c7e31a154d848a3e /gdb/objfiles.h
parentaed57c537116ae91f553ac835b3f96d1f87b3bb0 (diff)
downloadgdb-cac85af2467c9bac326b397b150274d95d2916a5.zip
gdb-cac85af2467c9bac326b397b150274d95d2916a5.tar.gz
gdb-cac85af2467c9bac326b397b150274d95d2916a5.tar.bz2
Remove ALL_OBJFILES_SAFE
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.
Diffstat (limited to 'gdb/objfiles.h')
-rw-r--r--gdb/objfiles.h32
1 files changed, 24 insertions, 8 deletions
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 512869f..cb3668a 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -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) \