Change all_objfiles_safe adapter to be a method on program_space

This changes the all_objfiles_safe range adapter to be a method on the
program space, and fixes up all the users.

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

	* progspace.h (program_space) <objfiles_safe_range>: New
	typedef.
	<objfiles_safe>: New method.
	* objfiles.h (class all_objfiles_safe): Remove.
	* objfiles.c (free_all_objfiles, objfile_purge_solibs): Update.
	* jit.c (jit_inferior_exit_hook): Update.
This commit is contained in:
Tom Tromey 2019-01-15 17:06:38 -07:00
parent 2030c07971
commit 7e955d83c4
5 changed files with 33 additions and 28 deletions

View File

@ -1,3 +1,12 @@
2019-01-15 Tom Tromey <tom@tromey.com>
* progspace.h (program_space) <objfiles_safe_range>: New
typedef.
<objfiles_safe>: New method.
* objfiles.h (class all_objfiles_safe): Remove.
* objfiles.c (free_all_objfiles, objfile_purge_solibs): Update.
* jit.c (jit_inferior_exit_hook): Update.
2019-01-17 Tom Tromey <tom@tromey.com> 2019-01-17 Tom Tromey <tom@tromey.com>
* progspace.h (program_space) <objfiles_range>: New typedef. * progspace.h (program_space) <objfiles_range>: New typedef.
@ -1114,7 +1123,7 @@
Update copyright year range in all GDB files. Update copyright year range in all GDB files.
2019-01-01 Joel Brobecker <brobecker@adacore.com> 2019-01-01, 19 Joel Brobecker <brobecker@adacore.com>
* config/djgpp/fnchange.lst: Add entry for gdb/ChangeLog-2018. * config/djgpp/fnchange.lst: Add entry for gdb/ChangeLog-2018.

View File

@ -1391,7 +1391,7 @@ jit_breakpoint_re_set (void)
static void static void
jit_inferior_exit_hook (struct inferior *inf) jit_inferior_exit_hook (struct inferior *inf)
{ {
for (objfile *objf : all_objfiles_safe (current_program_space)) for (objfile *objf : current_program_space->objfiles_safe ())
{ {
struct jit_objfile_data *objf_data struct jit_objfile_data *objf_data
= (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data); = (struct jit_objfile_data *) objfile_data (objf, jit_objfile_data);

View 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. /* 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 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 objfiles_safe to free all objfiles. */
void void
put_objfile_before (struct objfile *objfile, struct objfile *before_this) 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; parent->separate_debug_objfile = objfile;
/* Put the separate debug object before the normal one, this is so that /* Put the separate debug object before the normal one, this is so that
usage of all_objfiles_safe will stay safe. */ usage of objfiles_safe will stay safe. */
put_objfile_before (objfile, parent); put_objfile_before (objfile, parent);
} }
@ -735,7 +735,7 @@ free_all_objfiles (void)
for (so = master_so_list (); so; so = so->next) for (so = master_so_list (); so; so = so->next)
gdb_assert (so->objfile == NULL); gdb_assert (so->objfile == NULL);
for (objfile *objfile : all_objfiles_safe (current_program_space)) for (objfile *objfile : current_program_space->objfiles_safe ())
delete objfile; delete objfile;
clear_symtab_users (0); clear_symtab_users (0);
} }
@ -1044,7 +1044,7 @@ have_full_symbols (void)
void void
objfile_purge_solibs (void) objfile_purge_solibs (void)
{ {
for (objfile *objf : all_objfiles_safe (current_program_space)) for (objfile *objf : current_program_space->objfiles_safe ())
{ {
/* We assume that the solib package has been purged already, or will /* We assume that the solib package has been purged already, or will
be soon. */ be soon. */

View File

@ -553,28 +553,6 @@ extern void default_iterate_over_objfiles_in_search_order
void *cb_data, struct objfile *current_objfile); void *cb_data, struct objfile *current_objfile);
/* An iterarable object that can be used to iterate over all
objfiles. The basic use is in a foreach, like:
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_head)
{
}
};
/* A range adapter that makes it possible to iterate over all /* A range adapter that makes it possible to iterate over all
compunits in one objfile. */ compunits in one objfile. */

View File

@ -26,6 +26,8 @@
#include "gdb_bfd.h" #include "gdb_bfd.h"
#include "gdb_vecs.h" #include "gdb_vecs.h"
#include "registry.h" #include "registry.h"
#include "common/next-iterator.h"
#include "common/safe-iterator.h"
struct target_ops; struct target_ops;
struct bfd; struct bfd;
@ -148,6 +150,22 @@ struct program_space
return objfiles_range (objfiles_head); return objfiles_range (objfiles_head);
} }
typedef next_adapter<struct objfile,
basic_safe_iterator<next_iterator<objfile>>>
objfiles_safe_range;
/* An iterable object that can be used to iterate over all objfiles.
The basic use is in a foreach, like:
for (objfile *objf : pspace->objfiles_safe ()) { ... }
This variant uses a basic_safe_iterator so that objfiles can be
deleted during iteration. */
objfiles_safe_range objfiles_safe ()
{
return objfiles_safe_range (objfiles_head);
}
/* Pointer to next in linked list. */ /* Pointer to next in linked list. */
struct program_space *next = NULL; struct program_space *next = NULL;