int last_program_space_num = 0;
/* The head of the program spaces list. */
-struct program_space *program_spaces;
+std::vector<struct program_space *> program_spaces;
/* Pointer to the current program space. */
struct program_space *current_program_space;
if (shared_aspace)
{
/* Just return the first in the list. */
- return program_spaces->aspace;
+ return program_spaces[0]->aspace;
}
return new_address_space ();
\f
-/* Add a program space from the program spaces list. */
-
-static void
-add_program_space (program_space *pspace)
-{
- if (program_spaces == NULL)
- program_spaces = pspace;
- else
- {
- program_space *last;
-
- for (last = program_spaces; last->next != NULL; last = last->next)
- ;
- last->next = pspace;
- }
-}
-
/* Remove a program space from the program spaces list. */
static void
remove_program_space (program_space *pspace)
{
- program_space *ss, **ss_link;
gdb_assert (pspace != NULL);
- ss = program_spaces;
- ss_link = &program_spaces;
- while (ss != NULL)
- {
- if (ss == pspace)
- {
- *ss_link = ss->next;
- return;
- }
-
- ss_link = &ss->next;
- ss = *ss_link;
- }
+ auto iter = std::find (program_spaces.begin (), program_spaces.end (),
+ pspace);
+ gdb_assert (iter != program_spaces.end ());
+ program_spaces.erase (iter);
}
/* See progspace.h. */
{
program_space_alloc_data (this);
- add_program_space (this);
+ program_spaces.push_back (this);
}
/* See progspace.h. */
void
program_space::free_all_objfiles ()
{
- struct so_list *so;
-
/* Any objfile reference would become stale. */
- for (so = master_so_list (); so; so = so->next)
+ for (struct so_list *so : current_program_space->solibs ())
gdb_assert (so->objfile == NULL);
while (!objfiles_list.empty ())
symfile_object_file = NULL;
}
+/* See progspace.h. */
+
+next_adapter<struct so_list>
+program_space::solibs () const
+{
+ return next_adapter<struct so_list> (this->so_list);
+}
+
/* Copies program space SRC to DEST. Copies the main executable file,
and the main symbol file. Returns DEST. */
static void
print_program_space (struct ui_out *uiout, int requested)
{
- struct program_space *pspace;
int count = 0;
/* Compute number of pspaces we will print. */
- ALL_PSPACES (pspace)
+ for (struct program_space *pspace : program_spaces)
{
if (requested != -1 && pspace->num != requested)
continue;
uiout->table_header (17, ui_left, "exec", "Executable");
uiout->table_body ();
- ALL_PSPACES (pspace)
+ for (struct program_space *pspace : program_spaces)
{
struct inferior *inf;
int printed_header;
static int
valid_program_space_id (int num)
{
- struct program_space *pspace;
-
- ALL_PSPACES (pspace)
+ for (struct program_space *pspace : program_spaces)
if (pspace->num == num)
return 1;
print_program_space (current_uiout, requested);
}
-/* Simply returns the count of program spaces. */
-
-int
-number_of_program_spaces (void)
-{
- struct program_space *pspace;
- int count = 0;
-
- ALL_PSPACES (pspace)
- count++;
-
- return count;
-}
-
/* Update all program spaces matching to address spaces. The user may
have created several program spaces, and loaded executables into
them before connecting to the target interface that will create the
update_address_spaces (void)
{
int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ());
- struct program_space *pspace;
struct inferior *inf;
init_address_spaces ();
struct address_space *aspace = new_address_space ();
free_address_space (current_program_space->aspace);
- ALL_PSPACES (pspace)
+ for (struct program_space *pspace : program_spaces)
pspace->aspace = aspace;
}
else
- ALL_PSPACES (pspace)
+ for (struct program_space *pspace : program_spaces)
{
free_address_space (pspace->aspace);
pspace->aspace = new_address_space ();