gas: Update commit 4780e5e4933
[binutils-gdb.git] / gdb / progspace.c
index a0b14a6d2eb7cfec0af972e0343a57c11d3f3201..7080bf8ee2707f0aacd3a7db6d620703e18b6ab4 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -29,7 +29,7 @@
 #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;
@@ -147,15 +147,12 @@ program_space::~program_space ()
 
   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);
 }
@@ -198,6 +195,12 @@ program_space::add_objfile (std::shared_ptr<objfile> &&objfile,
 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)
                            {
@@ -212,10 +215,20 @@ program_space::remove_objfile (struct objfile *objfile)
 
 /* 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,
@@ -228,8 +241,8 @@ clone_program_space (struct program_space *dest, struct program_space *src)
 
   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),
@@ -258,13 +271,10 @@ set_current_program_space (struct program_space *pspace)
 
 /* 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
@@ -296,7 +306,6 @@ print_program_space (struct ui_out *uiout, int requested)
 
   for (struct program_space *pspace : program_spaces)
     {
-      struct inferior *inf;
       int printed_header;
 
       if (requested != -1 && requested != pspace->num)
@@ -311,8 +320,8 @@ print_program_space (struct ui_out *uiout, int requested)
 
       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");
 
@@ -322,9 +331,16 @@ print_program_space (struct ui_out *uiout, int requested)
         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;
@@ -388,7 +404,6 @@ void
 update_address_spaces (void)
 {
   int shared_aspace = gdbarch_has_shared_address_space (target_gdbarch ());
-  struct inferior *inf;
 
   init_address_spaces ();
 
@@ -407,7 +422,7 @@ update_address_spaces (void)
        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
@@ -419,10 +434,10 @@ update_address_spaces (void)
 /* 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
@@ -440,7 +455,7 @@ initialize_progspace (void)
      _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 ());
 }