Remove ALL_PSPACES

This removes the ALL_PSPACES macro.  In this case it seemed cleanest
to change how program spaces are stored -- instead of using a linked
list, they are now stored in a std::vector.

gdb/ChangeLog
2020-05-08  Tom Tromey  <tom@tromey.com>

	* symtab.c (set_symbol_cache_size)
	(maintenance_print_symbol_cache, maintenance_flush_symbol_cache)
	(maintenance_print_symbol_cache_statistics): Update.
	* symmisc.c (print_symbol_bcache_statistics)
	(print_objfile_statistics, maintenance_print_objfiles)
	(maintenance_info_symtabs, maintenance_check_symtabs)
	(maintenance_expand_symtabs, maintenance_info_line_tables):
	Update.
	* symfile-debug.c (set_debug_symfile): Update.
	* source.c (forget_cached_source_info): Update.
	* python/python.c (gdbpy_progspaces): Update.
	* psymtab.c (maintenance_info_psymtabs): Update.
	* probe.c (parse_probes): Update.
	* linespec.c (iterate_over_all_matching_symtabs)
	(collect_symtabs_from_filename, search_minsyms_for_name): Update.
	* guile/scm-progspace.c (gdbscm_progspaces): Update.
	* exec.c (exec_target::close): Update.
	* ada-tasks.c (ada_tasks_new_objfile_observer): Update.
	* breakpoint.c (print_one_breakpoint_location)
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint): Update.
	* progspace.c (program_spaces): Now a std::vector.
	(maybe_new_address_space): Update.
	(add_program_space): Remove.
	(program_space::program_space): Update.
	(remove_program_space): Update.
	(number_of_program_spaces): Remove.
	(print_program_space, update_address_spaces): Update.
	* progspace.h (program_spaces): Change type.
	(ALL_PSPACES): Remove.
	(number_of_program_spaces): Don't declare.
	(struct program_space) <next>: Remove.
This commit is contained in:
Tom Tromey 2020-05-08 14:21:22 -06:00 committed by Tom Tromey
parent a1fd1ac9de
commit 94c93c35b5
15 changed files with 308 additions and 368 deletions

View file

@ -1,3 +1,38 @@
2020-05-08 Tom Tromey <tom@tromey.com>
* symtab.c (set_symbol_cache_size)
(maintenance_print_symbol_cache, maintenance_flush_symbol_cache)
(maintenance_print_symbol_cache_statistics): Update.
* symmisc.c (print_symbol_bcache_statistics)
(print_objfile_statistics, maintenance_print_objfiles)
(maintenance_info_symtabs, maintenance_check_symtabs)
(maintenance_expand_symtabs, maintenance_info_line_tables):
Update.
* symfile-debug.c (set_debug_symfile): Update.
* source.c (forget_cached_source_info): Update.
* python/python.c (gdbpy_progspaces): Update.
* psymtab.c (maintenance_info_psymtabs): Update.
* probe.c (parse_probes): Update.
* linespec.c (iterate_over_all_matching_symtabs)
(collect_symtabs_from_filename, search_minsyms_for_name): Update.
* guile/scm-progspace.c (gdbscm_progspaces): Update.
* exec.c (exec_target::close): Update.
* ada-tasks.c (ada_tasks_new_objfile_observer): Update.
* breakpoint.c (print_one_breakpoint_location)
(create_longjmp_master_breakpoint)
(create_std_terminate_master_breakpoint): Update.
* progspace.c (program_spaces): Now a std::vector.
(maybe_new_address_space): Update.
(add_program_space): Remove.
(program_space::program_space): Update.
(remove_program_space): Update.
(number_of_program_spaces): Remove.
(print_program_space, update_address_spaces): Update.
* progspace.h (program_spaces): Change type.
(ALL_PSPACES): Remove.
(number_of_program_spaces): Don't declare.
(struct program_space) <next>: Remove.
2020-05-08 Tom Tromey <tom@tromey.com> 2020-05-08 Tom Tromey <tom@tromey.com>
* mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Update. * mi/mi-cmd-file.c (mi_cmd_file_list_shared_libraries): Update.

View file

@ -1433,9 +1433,7 @@ ada_tasks_new_objfile_observer (struct objfile *objfile)
{ {
/* All objfiles are being cleared, so we should clear all /* All objfiles are being cleared, so we should clear all
our caches for all program spaces. */ our caches for all program spaces. */
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
for (pspace = program_spaces; pspace != NULL; pspace = pspace->next)
ada_tasks_invalidate_pspace_data (pspace); ada_tasks_invalidate_pspace_data (pspace);
} }
else else

View file

@ -3224,153 +3224,151 @@ create_overlay_event_breakpoint (void)
static void static void
create_longjmp_master_breakpoint (void) create_longjmp_master_breakpoint (void)
{ {
struct program_space *pspace;
scoped_restore_current_program_space restore_pspace; scoped_restore_current_program_space restore_pspace;
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
{ {
set_current_program_space (pspace); set_current_program_space (pspace);
for (objfile *objfile : current_program_space->objfiles ()) for (objfile *objfile : current_program_space->objfiles ())
{ {
int i; int i;
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
struct breakpoint_objfile_data *bp_objfile_data; struct breakpoint_objfile_data *bp_objfile_data;
gdbarch = objfile->arch (); gdbarch = objfile->arch ();
bp_objfile_data = get_breakpoint_objfile_data (objfile); bp_objfile_data = get_breakpoint_objfile_data (objfile);
if (!bp_objfile_data->longjmp_searched) if (!bp_objfile_data->longjmp_searched)
{ {
std::vector<probe *> ret std::vector<probe *> ret
= find_probes_in_objfile (objfile, "libc", "longjmp"); = find_probes_in_objfile (objfile, "libc", "longjmp");
if (!ret.empty ()) if (!ret.empty ())
{ {
/* We are only interested in checking one element. */ /* We are only interested in checking one element. */
probe *p = ret[0]; probe *p = ret[0];
if (!p->can_evaluate_arguments ()) if (!p->can_evaluate_arguments ())
{ {
/* We cannot use the probe interface here, because it does /* We cannot use the probe interface here,
not know how to evaluate arguments. */ because it does not know how to evaluate
ret.clear (); arguments. */
} ret.clear ();
} }
bp_objfile_data->longjmp_probes = ret; }
bp_objfile_data->longjmp_searched = 1; bp_objfile_data->longjmp_probes = ret;
} bp_objfile_data->longjmp_searched = 1;
}
if (!bp_objfile_data->longjmp_probes.empty ()) if (!bp_objfile_data->longjmp_probes.empty ())
{ {
for (probe *p : bp_objfile_data->longjmp_probes) for (probe *p : bp_objfile_data->longjmp_probes)
{ {
struct breakpoint *b; struct breakpoint *b;
b = create_internal_breakpoint (gdbarch, b = create_internal_breakpoint (gdbarch,
p->get_relocated_address (objfile), p->get_relocated_address (objfile),
bp_longjmp_master, bp_longjmp_master,
&internal_breakpoint_ops); &internal_breakpoint_ops);
b->location = new_probe_location ("-probe-stap libc:longjmp"); b->location = new_probe_location ("-probe-stap libc:longjmp");
b->enable_state = bp_disabled; b->enable_state = bp_disabled;
} }
continue;
}
if (!gdbarch_get_longjmp_target_p (gdbarch))
continue;
for (i = 0; i < NUM_LONGJMP_NAMES; i++)
{
struct breakpoint *b;
const char *func_name;
CORE_ADDR addr;
struct explicit_location explicit_loc;
if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
continue; continue;
}
func_name = longjmp_names[i]; if (!gdbarch_get_longjmp_target_p (gdbarch))
if (bp_objfile_data->longjmp_msym[i].minsym == NULL) continue;
{
struct bound_minimal_symbol m;
m = lookup_minimal_symbol_text (func_name, objfile); for (i = 0; i < NUM_LONGJMP_NAMES; i++)
if (m.minsym == NULL) {
{ struct breakpoint *b;
/* Prevent future lookups in this objfile. */ const char *func_name;
bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; CORE_ADDR addr;
continue; struct explicit_location explicit_loc;
}
bp_objfile_data->longjmp_msym[i] = m;
}
addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym))
b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, continue;
&internal_breakpoint_ops);
initialize_explicit_location (&explicit_loc); func_name = longjmp_names[i];
explicit_loc.function_name = ASTRDUP (func_name); if (bp_objfile_data->longjmp_msym[i].minsym == NULL)
b->location = new_explicit_location (&explicit_loc); {
b->enable_state = bp_disabled; struct bound_minimal_symbol m;
}
} m = lookup_minimal_symbol_text (func_name, objfile);
} if (m.minsym == NULL)
{
/* Prevent future lookups in this objfile. */
bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found;
continue;
}
bp_objfile_data->longjmp_msym[i] = m;
}
addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]);
b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master,
&internal_breakpoint_ops);
initialize_explicit_location (&explicit_loc);
explicit_loc.function_name = ASTRDUP (func_name);
b->location = new_explicit_location (&explicit_loc);
b->enable_state = bp_disabled;
}
}
}
} }
/* Create a master std::terminate breakpoint. */ /* Create a master std::terminate breakpoint. */
static void static void
create_std_terminate_master_breakpoint (void) create_std_terminate_master_breakpoint (void)
{ {
struct program_space *pspace;
const char *const func_name = "std::terminate()"; const char *const func_name = "std::terminate()";
scoped_restore_current_program_space restore_pspace; scoped_restore_current_program_space restore_pspace;
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
{ {
CORE_ADDR addr; CORE_ADDR addr;
set_current_program_space (pspace); set_current_program_space (pspace);
for (objfile *objfile : current_program_space->objfiles ()) for (objfile *objfile : current_program_space->objfiles ())
{ {
struct breakpoint *b; struct breakpoint *b;
struct breakpoint_objfile_data *bp_objfile_data; struct breakpoint_objfile_data *bp_objfile_data;
struct explicit_location explicit_loc; struct explicit_location explicit_loc;
bp_objfile_data = get_breakpoint_objfile_data (objfile); bp_objfile_data = get_breakpoint_objfile_data (objfile);
if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym))
continue; continue;
if (bp_objfile_data->terminate_msym.minsym == NULL) if (bp_objfile_data->terminate_msym.minsym == NULL)
{ {
struct bound_minimal_symbol m; struct bound_minimal_symbol m;
m = lookup_minimal_symbol (func_name, NULL, objfile); m = lookup_minimal_symbol (func_name, NULL, objfile);
if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text
&& MSYMBOL_TYPE (m.minsym) != mst_file_text)) && MSYMBOL_TYPE (m.minsym) != mst_file_text))
{ {
/* Prevent future lookups in this objfile. */ /* Prevent future lookups in this objfile. */
bp_objfile_data->terminate_msym.minsym = &msym_not_found; bp_objfile_data->terminate_msym.minsym = &msym_not_found;
continue; continue;
} }
bp_objfile_data->terminate_msym = m; bp_objfile_data->terminate_msym = m;
} }
addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
b = create_internal_breakpoint (objfile->arch (), addr, b = create_internal_breakpoint (objfile->arch (), addr,
bp_std_terminate_master, bp_std_terminate_master,
&internal_breakpoint_ops); &internal_breakpoint_ops);
initialize_explicit_location (&explicit_loc); initialize_explicit_location (&explicit_loc);
explicit_loc.function_name = ASTRDUP (func_name); explicit_loc.function_name = ASTRDUP (func_name);
b->location = new_explicit_location (&explicit_loc); b->location = new_explicit_location (&explicit_loc);
b->enable_state = bp_disabled; b->enable_state = bp_disabled;
} }
} }
} }
/* Install a master breakpoint on the unwinder's debug hook. */ /* Install a master breakpoint on the unwinder's debug hook. */
@ -6088,7 +6086,7 @@ print_one_breakpoint_location (struct breakpoint *b,
there are several. Always display for MI. */ there are several. Always display for MI. */
if (allflag if (allflag
|| (!gdbarch_has_global_breakpoints (target_gdbarch ()) || (!gdbarch_has_global_breakpoints (target_gdbarch ())
&& (number_of_program_spaces () > 1 && (program_spaces.size () > 1
|| number_of_inferiors () > 1) || number_of_inferiors () > 1)
/* LOC is for existing B, it cannot be in /* LOC is for existing B, it cannot be in
moribund_locations and thus having NULL OWNER. */ moribund_locations and thus having NULL OWNER. */

View file

@ -177,10 +177,9 @@ exec_close (void)
void void
exec_target::close () exec_target::close ()
{ {
struct program_space *ss;
scoped_restore_current_program_space restore_pspace; scoped_restore_current_program_space restore_pspace;
ALL_PSPACES (ss) for (struct program_space *ss : program_spaces)
{ {
set_current_program_space (ss); set_current_program_space (ss);
clear_section_table (current_target_sections); clear_section_table (current_target_sections);

View file

@ -353,17 +353,16 @@ gdbscm_current_progspace (void)
static SCM static SCM
gdbscm_progspaces (void) gdbscm_progspaces (void)
{ {
struct program_space *ps;
SCM result; SCM result;
result = SCM_EOL; result = SCM_EOL;
ALL_PSPACES (ps) for (struct program_space *ps : program_spaces)
{ {
SCM item = psscm_scm_from_pspace (ps); SCM item = psscm_scm_from_pspace (ps);
result = scm_cons (item, result); result = scm_cons (item, result);
} }
return scm_reverse_x (result, SCM_EOL); return scm_reverse_x (result, SCM_EOL);
} }

View file

@ -1133,58 +1133,56 @@ iterate_over_all_matching_symtabs
struct program_space *search_pspace, bool include_inline, struct program_space *search_pspace, bool include_inline,
gdb::function_view<symbol_found_callback_ftype> callback) gdb::function_view<symbol_found_callback_ftype> callback)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
{
if (search_pspace != NULL && search_pspace != pspace)
continue;
if (pspace->executing_startup)
continue;
ALL_PSPACES (pspace) set_current_program_space (pspace);
{
if (search_pspace != NULL && search_pspace != pspace)
continue;
if (pspace->executing_startup)
continue;
set_current_program_space (pspace); for (objfile *objfile : current_program_space->objfiles ())
{
if (objfile->sf)
objfile->sf->qf->expand_symtabs_matching (objfile,
NULL,
&lookup_name,
NULL, NULL,
search_domain);
for (objfile *objfile : current_program_space->objfiles ()) for (compunit_symtab *cu : objfile->compunits ())
{ {
if (objfile->sf) struct symtab *symtab = COMPUNIT_FILETABS (cu);
objfile->sf->qf->expand_symtabs_matching (objfile,
NULL,
&lookup_name,
NULL, NULL,
search_domain);
for (compunit_symtab *cu : objfile->compunits ()) iterate_over_file_blocks (symtab, lookup_name, name_domain,
{ callback);
struct symtab *symtab = COMPUNIT_FILETABS (cu);
iterate_over_file_blocks (symtab, lookup_name, name_domain, if (include_inline)
callback); {
const struct block *block;
int i;
if (include_inline) for (i = FIRST_LOCAL_BLOCK;
{ i < BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab));
const struct block *block; i++)
int i; {
block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i);
for (i = FIRST_LOCAL_BLOCK; state->language->la_iterate_over_symbols
i < BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab)); (block, lookup_name, name_domain,
i++) [&] (block_symbol *bsym)
{ {
block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i); /* Restrict calls to CALLBACK to symbols
state->language->la_iterate_over_symbols representing inline symbols only. */
(block, lookup_name, name_domain, if (SYMBOL_INLINED (bsym->symbol))
[&] (block_symbol *bsym) return callback (bsym);
{ return true;
/* Restrict calls to CALLBACK to symbols });
representing inline symbols only. */ }
if (SYMBOL_INLINED (bsym->symbol)) }
return callback (bsym); }
return true; }
}); }
}
}
}
}
}
} }
/* Returns the block to be used for symbol searches from /* Returns the block to be used for symbol searches from
@ -3786,9 +3784,7 @@ collect_symtabs_from_filename (const char *file,
/* Find that file's data. */ /* Find that file's data. */
if (search_pspace == NULL) if (search_pspace == NULL)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
{ {
if (pspace->executing_startup) if (pspace->executing_startup)
continue; continue;
@ -4335,29 +4331,27 @@ search_minsyms_for_name (struct collect_info *info,
if (symtab == NULL) if (symtab == NULL)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
{
if (search_pspace != NULL && search_pspace != pspace)
continue;
if (pspace->executing_startup)
continue;
ALL_PSPACES (pspace) set_current_program_space (pspace);
{
if (search_pspace != NULL && search_pspace != pspace)
continue;
if (pspace->executing_startup)
continue;
set_current_program_space (pspace); for (objfile *objfile : current_program_space->objfiles ())
{
for (objfile *objfile : current_program_space->objfiles ()) iterate_over_minimal_symbols (objfile, name,
{ [&] (struct minimal_symbol *msym)
iterate_over_minimal_symbols (objfile, name, {
[&] (struct minimal_symbol *msym) add_minsym (msym, objfile, nullptr,
{ info->state->list_mode,
add_minsym (msym, objfile, nullptr, &minsyms);
info->state->list_mode, return false;
&minsyms); });
return false; }
}); }
}
}
} }
else else
{ {

View file

@ -185,9 +185,7 @@ parse_probes (const struct event_location *location,
} }
else else
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
parse_probes_in_pspace (spops, pspace, objfile_namestr, parse_probes_in_pspace (spops, pspace, objfile_namestr,
provider, name, &result); provider, name, &result);
} }

View file

@ -32,7 +32,7 @@
int last_program_space_num = 0; int last_program_space_num = 0;
/* The head of the program spaces list. */ /* 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. */ /* Pointer to the current program space. */
struct program_space *current_program_space; struct program_space *current_program_space;
@ -80,7 +80,7 @@ maybe_new_address_space (void)
if (shared_aspace) if (shared_aspace)
{ {
/* Just return the first in the list. */ /* Just return the first in the list. */
return program_spaces->aspace; return program_spaces[0]->aspace;
} }
return new_address_space (); return new_address_space ();
@ -109,44 +109,17 @@ init_address_spaces (void)
/* 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. */ /* Remove a program space from the program spaces list. */
static void static void
remove_program_space (program_space *pspace) remove_program_space (program_space *pspace)
{ {
program_space *ss, **ss_link;
gdb_assert (pspace != NULL); gdb_assert (pspace != NULL);
ss = program_spaces; auto iter = std::find (program_spaces.begin (), program_spaces.end (),
ss_link = &program_spaces; pspace);
while (ss != NULL) gdb_assert (iter != program_spaces.end ());
{ program_spaces.erase (iter);
if (ss == pspace)
{
*ss_link = ss->next;
return;
}
ss_link = &ss->next;
ss = *ss_link;
}
} }
/* See progspace.h. */ /* See progspace.h. */
@ -157,7 +130,7 @@ program_space::program_space (address_space *aspace_)
{ {
program_space_alloc_data (this); program_space_alloc_data (this);
add_program_space (this); program_spaces.push_back (this);
} }
/* See progspace.h. */ /* See progspace.h. */
@ -301,11 +274,10 @@ program_space_empty_p (struct program_space *pspace)
static void static void
print_program_space (struct ui_out *uiout, int requested) print_program_space (struct ui_out *uiout, int requested)
{ {
struct program_space *pspace;
int count = 0; int count = 0;
/* Compute number of pspaces we will print. */ /* Compute number of pspaces we will print. */
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
{ {
if (requested != -1 && pspace->num != requested) if (requested != -1 && pspace->num != requested)
continue; continue;
@ -322,7 +294,7 @@ print_program_space (struct ui_out *uiout, int requested)
uiout->table_header (17, ui_left, "exec", "Executable"); uiout->table_header (17, ui_left, "exec", "Executable");
uiout->table_body (); uiout->table_body ();
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
{ {
struct inferior *inf; struct inferior *inf;
int printed_header; int printed_header;
@ -375,9 +347,7 @@ print_program_space (struct ui_out *uiout, int requested)
static int static int
valid_program_space_id (int num) valid_program_space_id (int num)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
if (pspace->num == num) if (pspace->num == num)
return 1; return 1;
@ -403,20 +373,6 @@ maintenance_info_program_spaces_command (const char *args, int from_tty)
print_program_space (current_uiout, requested); 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 /* Update all program spaces matching to address spaces. The user may
have created several program spaces, and loaded executables into have created several program spaces, and loaded executables into
them before connecting to the target interface that will create the them before connecting to the target interface that will create the
@ -432,7 +388,6 @@ void
update_address_spaces (void) update_address_spaces (void)
{ {
int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ()); int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ());
struct program_space *pspace;
struct inferior *inf; struct inferior *inf;
init_address_spaces (); init_address_spaces ();
@ -442,11 +397,11 @@ update_address_spaces (void)
struct address_space *aspace = new_address_space (); struct address_space *aspace = new_address_space ();
free_address_space (current_program_space->aspace); free_address_space (current_program_space->aspace);
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
pspace->aspace = aspace; pspace->aspace = aspace;
} }
else else
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
{ {
free_address_space (pspace->aspace); free_address_space (pspace->aspace);
pspace->aspace = new_address_space (); pspace->aspace = new_address_space ();

View file

@ -28,6 +28,7 @@
#include "gdbsupport/next-iterator.h" #include "gdbsupport/next-iterator.h"
#include "gdbsupport/safe-iterator.h" #include "gdbsupport/safe-iterator.h"
#include <list> #include <list>
#include <vector>
struct target_ops; struct target_ops;
struct bfd; struct bfd;
@ -272,9 +273,6 @@ struct program_space
next_adapter<struct so_list> solibs () const; next_adapter<struct so_list> solibs () const;
/* Pointer to next in linked list. */
struct program_space *next = NULL;
/* Unique ID number. */ /* Unique ID number. */
int num = 0; int num = 0;
@ -369,17 +367,11 @@ struct address_space
#define current_target_sections (&current_program_space->target_sections) #define current_target_sections (&current_program_space->target_sections)
/* The list of all program spaces. There's always at least one. */ /* The list of all program spaces. There's always at least one. */
extern struct program_space *program_spaces; extern std::vector<struct program_space *>program_spaces;
/* The current program space. This is always non-null. */ /* The current program space. This is always non-null. */
extern struct program_space *current_program_space; extern struct program_space *current_program_space;
#define ALL_PSPACES(pspace) \
for ((pspace) = program_spaces; (pspace) != NULL; (pspace) = (pspace)->next)
/* Returns the number of program spaces listed. */
extern int number_of_program_spaces (void);
/* Returns true iff there's no inferior bound to PSPACE. */ /* Returns true iff there's no inferior bound to PSPACE. */
extern int program_space_empty_p (struct program_space *pspace); extern int program_space_empty_p (struct program_space *pspace);

View file

@ -1994,12 +1994,10 @@ maintenance_print_psymbols (const char *args, int from_tty)
static void static void
maintenance_info_psymtabs (const char *regexp, int from_tty) maintenance_info_psymtabs (const char *regexp, int from_tty)
{ {
struct program_space *pspace;
if (regexp) if (regexp)
re_comp (regexp); re_comp (regexp);
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
struct gdbarch *gdbarch = objfile->arch (); struct gdbarch *gdbarch = objfile->arch ();

View file

@ -1350,19 +1350,17 @@ gdbpy_print_stack_or_quit ()
static PyObject * static PyObject *
gdbpy_progspaces (PyObject *unused1, PyObject *unused2) gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
{ {
struct program_space *ps;
gdbpy_ref<> list (PyList_New (0)); gdbpy_ref<> list (PyList_New (0));
if (list == NULL) if (list == NULL)
return NULL; return NULL;
ALL_PSPACES (ps) for (struct program_space *ps : program_spaces)
{ {
gdbpy_ref<> item = pspace_to_pspace_object (ps); gdbpy_ref<> item = pspace_to_pspace_object (ps);
if (item == NULL || PyList_Append (list.get (), item.get ()) == -1) if (item == NULL || PyList_Append (list.get (), item.get ()) == -1)
return NULL; return NULL;
} }
return list.release (); return list.release ();
} }

View file

@ -421,9 +421,7 @@ forget_cached_source_info_for_objfile (struct objfile *objfile)
void void
forget_cached_source_info (void) forget_cached_source_info (void)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
forget_cached_source_info_for_objfile (objfile); forget_cached_source_info_for_objfile (objfile);

View file

@ -621,9 +621,7 @@ objfile_set_sym_fns (struct objfile *objfile, const struct sym_fns *sf)
static void static void
set_debug_symfile (const char *args, int from_tty, struct cmd_list_element *c) set_debug_symfile (const char *args, int from_tty, struct cmd_list_element *c)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
if (debug_symfile) if (debug_symfile)

View file

@ -61,9 +61,7 @@ static void print_symbol (struct gdbarch *gdbarch, struct symbol *symbol,
void void
print_symbol_bcache_statistics (void) print_symbol_bcache_statistics (void)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
QUIT; QUIT;
@ -78,64 +76,63 @@ print_symbol_bcache_statistics (void)
void void
print_objfile_statistics (void) print_objfile_statistics (void)
{ {
struct program_space *pspace;
int i, linetables, blockvectors; int i, linetables, blockvectors;
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
QUIT; QUIT;
printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile)); printf_filtered (_("Statistics for '%s':\n"), objfile_name (objfile));
if (OBJSTAT (objfile, n_stabs) > 0) if (OBJSTAT (objfile, n_stabs) > 0)
printf_filtered (_(" Number of \"stab\" symbols read: %d\n"), printf_filtered (_(" Number of \"stab\" symbols read: %d\n"),
OBJSTAT (objfile, n_stabs)); OBJSTAT (objfile, n_stabs));
if (objfile->per_bfd->n_minsyms > 0) if (objfile->per_bfd->n_minsyms > 0)
printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"), printf_filtered (_(" Number of \"minimal\" symbols read: %d\n"),
objfile->per_bfd->n_minsyms); objfile->per_bfd->n_minsyms);
if (OBJSTAT (objfile, n_psyms) > 0) if (OBJSTAT (objfile, n_psyms) > 0)
printf_filtered (_(" Number of \"partial\" symbols read: %d\n"), printf_filtered (_(" Number of \"partial\" symbols read: %d\n"),
OBJSTAT (objfile, n_psyms)); OBJSTAT (objfile, n_psyms));
if (OBJSTAT (objfile, n_syms) > 0) if (OBJSTAT (objfile, n_syms) > 0)
printf_filtered (_(" Number of \"full\" symbols read: %d\n"), printf_filtered (_(" Number of \"full\" symbols read: %d\n"),
OBJSTAT (objfile, n_syms)); OBJSTAT (objfile, n_syms));
if (OBJSTAT (objfile, n_types) > 0) if (OBJSTAT (objfile, n_types) > 0)
printf_filtered (_(" Number of \"types\" defined: %d\n"), printf_filtered (_(" Number of \"types\" defined: %d\n"),
OBJSTAT (objfile, n_types)); OBJSTAT (objfile, n_types));
if (objfile->sf) if (objfile->sf)
objfile->sf->qf->print_stats (objfile); objfile->sf->qf->print_stats (objfile);
i = linetables = 0; i = linetables = 0;
for (compunit_symtab *cu : objfile->compunits ()) for (compunit_symtab *cu : objfile->compunits ())
{ {
for (symtab *s : compunit_filetabs (cu)) for (symtab *s : compunit_filetabs (cu))
{ {
i++; i++;
if (SYMTAB_LINETABLE (s) != NULL) if (SYMTAB_LINETABLE (s) != NULL)
linetables++; linetables++;
} }
} }
blockvectors = std::distance (objfile->compunits ().begin (), blockvectors = std::distance (objfile->compunits ().begin (),
objfile->compunits ().end ()); objfile->compunits ().end ());
printf_filtered (_(" Number of symbol tables: %d\n"), i); printf_filtered (_(" Number of symbol tables: %d\n"), i);
printf_filtered (_(" Number of symbol tables with line tables: %d\n"), printf_filtered (_(" Number of symbol tables with line tables: %d\n"),
linetables); linetables);
printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"), printf_filtered (_(" Number of symbol tables with blockvectors: %d\n"),
blockvectors); blockvectors);
if (OBJSTAT (objfile, sz_strtab) > 0) if (OBJSTAT (objfile, sz_strtab) > 0)
printf_filtered (_(" Space used by string tables: %d\n"), printf_filtered (_(" Space used by string tables: %d\n"),
OBJSTAT (objfile, sz_strtab)); OBJSTAT (objfile, sz_strtab));
printf_filtered (_(" Total memory used for objfile obstack: %s\n"), printf_filtered (_(" Total memory used for objfile obstack: %s\n"),
pulongest (obstack_memory_used (&objfile pulongest (obstack_memory_used (&objfile
->objfile_obstack))); ->objfile_obstack)));
printf_filtered (_(" Total memory used for BFD obstack: %s\n"), printf_filtered (_(" Total memory used for BFD obstack: %s\n"),
pulongest (obstack_memory_used (&objfile->per_bfd pulongest (obstack_memory_used (&objfile->per_bfd
->storage_obstack))); ->storage_obstack)));
printf_filtered printf_filtered
(_(" Total memory used for psymbol cache: %d\n"), (_(" Total memory used for psymbol cache: %d\n"),
objfile->partial_symtabs->psymbol_cache.memory_used ()); objfile->partial_symtabs->psymbol_cache.memory_used ());
printf_filtered (_(" Total memory used for string cache: %d\n"), printf_filtered (_(" Total memory used for string cache: %d\n"),
objfile->per_bfd->string_cache.memory_used ()); objfile->per_bfd->string_cache.memory_used ());
} }
} }
static void static void
@ -762,14 +759,12 @@ maintenance_print_msymbols (const char *args, int from_tty)
static void static void
maintenance_print_objfiles (const char *regexp, int from_tty) maintenance_print_objfiles (const char *regexp, int from_tty)
{ {
struct program_space *pspace;
dont_repeat (); dont_repeat ();
if (regexp) if (regexp)
re_comp (regexp); re_comp (regexp);
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
QUIT; QUIT;
@ -784,14 +779,12 @@ maintenance_print_objfiles (const char *regexp, int from_tty)
static void static void
maintenance_info_symtabs (const char *regexp, int from_tty) maintenance_info_symtabs (const char *regexp, int from_tty)
{ {
struct program_space *pspace;
dont_repeat (); dont_repeat ();
if (regexp) if (regexp)
re_comp (regexp); re_comp (regexp);
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
/* We don't want to print anything for this objfile until we /* We don't want to print anything for this objfile until we
@ -896,9 +889,7 @@ maintenance_info_symtabs (const char *regexp, int from_tty)
static void static void
maintenance_check_symtabs (const char *ignore, int from_tty) maintenance_check_symtabs (const char *ignore, int from_tty)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
/* We don't want to print anything for this objfile until we /* We don't want to print anything for this objfile until we
@ -944,7 +935,6 @@ maintenance_check_symtabs (const char *ignore, int from_tty)
static void static void
maintenance_expand_symtabs (const char *args, int from_tty) maintenance_expand_symtabs (const char *args, int from_tty)
{ {
struct program_space *pspace;
char *regexp = NULL; char *regexp = NULL;
/* We use buildargv here so that we handle spaces in the regexp /* We use buildargv here so that we handle spaces in the regexp
@ -964,7 +954,7 @@ maintenance_expand_symtabs (const char *args, int from_tty)
if (regexp) if (regexp)
re_comp (regexp); re_comp (regexp);
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
if (objfile->sf) if (objfile->sf)
@ -1065,14 +1055,12 @@ maintenance_print_one_line_table (struct symtab *symtab, void *data)
static void static void
maintenance_info_line_tables (const char *regexp, int from_tty) maintenance_info_line_tables (const char *regexp, int from_tty)
{ {
struct program_space *pspace;
dont_repeat (); dont_repeat ();
if (regexp != NULL) if (regexp != NULL)
re_comp (regexp); re_comp (regexp);
ALL_PSPACES (pspace) for (struct program_space *pspace : program_spaces)
for (objfile *objfile : pspace->objfiles ()) for (objfile *objfile : pspace->objfiles ())
{ {
for (compunit_symtab *cust : objfile->compunits ()) for (compunit_symtab *cust : objfile->compunits ())

View file

@ -1276,9 +1276,7 @@ get_symbol_cache (struct program_space *pspace)
static void static void
set_symbol_cache_size (unsigned int new_size) set_symbol_cache_size (unsigned int new_size)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
{ {
struct symbol_cache *cache = symbol_cache_key.get (pspace); struct symbol_cache *cache = symbol_cache_key.get (pspace);
@ -1526,9 +1524,7 @@ symbol_cache_dump (const struct symbol_cache *cache)
static void static void
maintenance_print_symbol_cache (const char *args, int from_tty) maintenance_print_symbol_cache (const char *args, int from_tty)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
{ {
struct symbol_cache *cache; struct symbol_cache *cache;
@ -1552,9 +1548,7 @@ maintenance_print_symbol_cache (const char *args, int from_tty)
static void static void
maintenance_flush_symbol_cache (const char *args, int from_tty) maintenance_flush_symbol_cache (const char *args, int from_tty)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
{ {
symbol_cache_flush (pspace); symbol_cache_flush (pspace);
} }
@ -1597,9 +1591,7 @@ symbol_cache_stats (struct symbol_cache *cache)
static void static void
maintenance_print_symbol_cache_statistics (const char *args, int from_tty) maintenance_print_symbol_cache_statistics (const char *args, int from_tty)
{ {
struct program_space *pspace; for (struct program_space *pspace : program_spaces)
ALL_PSPACES (pspace)
{ {
struct symbol_cache *cache; struct symbol_cache *cache;