/* Program and address space management, for GDB, the GNU debugger.
- Copyright (C) 2009-2020 Free Software Foundation, Inc.
+ Copyright (C) 2009-2021 Free Software Foundation, Inc.
This file is part of GDB.
#include <algorithm>
/* The last program space number assigned. */
-int last_program_space_num = 0;
+static int last_program_space_num = 0;
/* The head of the program spaces list. */
std::vector<struct program_space *> program_spaces;
breakpoint_program_space_exit (this);
no_shared_libraries (NULL, 0);
- exec_close ();
free_all_objfiles ();
/* Defer breakpoint re-set because we don't want to create new
locations for this pspace which we're tearing down. */
clear_symtab_users (SYMFILE_DEFER_BP_RESET);
if (!gdbarch_has_shared_address_space (target_gdbarch ()))
free_address_space (this->aspace);
- clear_section_table (&this->target_sections);
- clear_program_space_solib_cache (this);
/* Discard any data modules have associated with the PSPACE. */
program_space_free_data (this);
}
void
program_space::remove_objfile (struct objfile *objfile)
{
+ /* Removing an objfile from the objfile list invalidates any frame
+ that was built using frame info found in the objfile. Reinit the
+ frame cache to get rid of any frame that might otherwise
+ reference stale info. */
+ reinit_frame_cache ();
+
auto iter = std::find_if (objfiles_list.begin (), objfiles_list.end (),
[=] (const std::shared_ptr<::objfile> &objf)
{
/* See progspace.h. */
-next_adapter<struct so_list>
-program_space::solibs () const
+void
+program_space::exec_close ()
{
- return next_adapter<struct so_list> (this->so_list);
+ if (ebfd != nullptr)
+ {
+ /* Removing target sections may close the exec_ops target.
+ Clear ebfd before doing so to prevent recursion. */
+ ebfd.reset (nullptr);
+ ebfd_mtime = 0;
+
+ remove_target_sections (&ebfd);
+
+ exec_filename.reset (nullptr);
+ }
}
/* Copies program space SRC to DEST. Copies the main executable file,
set_current_program_space (dest);
- if (src->pspace_exec_filename != NULL)
- exec_file_attach (src->pspace_exec_filename, 0);
+ if (src->exec_filename != NULL)
+ exec_file_attach (src->exec_filename.get (), 0);
if (src->symfile_object_file != NULL)
symbol_file_add_main (objfile_name (src->symfile_object_file),
/* Returns true iff there's no inferior bound to PSPACE. */
-int
-program_space_empty_p (struct program_space *pspace)
+bool
+program_space::empty ()
{
- if (find_inferior_for_program_space (pspace) != NULL)
- return 0;
-
- return 1;
+ return find_inferior_for_program_space (this) == nullptr;
}
/* Prints the list of program spaces and their details on UIOUT. If
for (struct program_space *pspace : program_spaces)
{
- struct inferior *inf;
int printed_header;
if (requested != -1 && requested != pspace->num)
uiout->field_signed ("id", pspace->num);
- if (pspace->pspace_exec_filename)
- uiout->field_string ("exec", pspace->pspace_exec_filename);
+ if (pspace->exec_filename != nullptr)
+ uiout->field_string ("exec", pspace->exec_filename.get ());
else
uiout->field_skip ("exec");
e.g., both parent/child inferiors in a vfork, or, on targets
that share pspaces between inferiors. */
printed_header = 0;
- for (inf = inferior_list; inf; inf = inf->next)
+
+ /* We're going to switch inferiors. */
+ scoped_restore_current_thread restore_thread;
+
+ for (inferior *inf : all_inferiors ())
if (inf->pspace == pspace)
{
+ /* Switch to inferior in order to call target methods. */
+ switch_to_inferior_no_thread (inf);
+
if (!printed_header)
{
printed_header = 1;
update_address_spaces (void)
{
int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ());
- struct inferior *inf;
init_address_spaces ();
pspace->aspace = new_address_space ();
}
- for (inf = inferior_list; inf; inf = inf->next)
+ for (inferior *inf : all_inferiors ())
if (gdbarch_has_global_solist (target_gdbarch ()))
inf->aspace = maybe_new_address_space ();
else
/* See progspace.h. */
void
-clear_program_space_solib_cache (struct program_space *pspace)
+program_space::clear_solib_cache ()
{
- pspace->added_solibs.clear ();
- pspace->deleted_solibs.clear ();
+ added_solibs.clear ();
+ deleted_solibs.clear ();
}
\f
_initialize_foo routines may need to install their per-pspace
data keys. We can only allocate a progspace when all those
modules have done that. Do this before
- initialize_current_architecture, because that accesses exec_bfd,
- which in turn dereferences current_program_space. */
+ initialize_current_architecture, because that accesses the ebfd
+ of current_program_space. */
current_program_space = new program_space (new_address_space ());
}