Change exec_close to be a method on program_space
authorTom Tromey <tom@tromey.com>
Thu, 29 Oct 2020 21:04:33 +0000 (15:04 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 29 Oct 2020 21:04:34 +0000 (15:04 -0600)
exec_close uses the current program space, so it seemed cleaner to
change it to be a method on program_space.  This patch makes this
change.

gdb/ChangeLog
2020-10-29  Tom Tromey  <tom@tromey.com>

* progspace.c (program_space::exec_close): New method, from
exec_close in exec.c.
* exec.c (exec_close): Move to progspace.c.
(exec_target::close, exec_file_attach): Update.
* progspace.h (struct program_space) <exec_close>: Declare
method.

gdb/ChangeLog
gdb/exec.c
gdb/exec.h
gdb/progspace.c
gdb/progspace.h

index 357c57f3497aa1029ba7a3c3a228161a2263c6ce..d06ea4760971dd4fc0f0fc730d31ad6e46e3a267 100644 (file)
@@ -1,3 +1,12 @@
+2020-10-29  Tom Tromey  <tom@tromey.com>
+
+       * progspace.c (program_space::exec_close): New method, from
+       exec_close in exec.c.
+       * exec.c (exec_close): Move to progspace.c.
+       (exec_target::close, exec_file_attach): Update.
+       * progspace.h (struct program_space) <exec_close>: Declare
+       method.
+
 2020-10-29  Tom Tromey  <tom@tromey.com>
 
        * progspace.h (struct program_space) <exec_filename>: Rename from
index d27949c609f45663449be03741268cfa667411fa..6459688ad6d929fce092c0a92295572c14cc2200 100644 (file)
@@ -148,29 +148,6 @@ exec_target_open (const char *args, int from_tty)
   exec_file_attach (args, from_tty);
 }
 
-/* Close and clear exec_bfd.  If we end up with no target sections to
-   read memory from, this unpushes the exec_ops target.  */
-
-void
-exec_close (void)
-{
-  if (exec_bfd)
-    {
-      bfd *abfd = exec_bfd;
-
-      gdb_bfd_unref (abfd);
-
-      /* Removing target sections may close the exec_ops target.
-        Clear exec_bfd before doing so to prevent recursion.  */
-      exec_bfd = NULL;
-      exec_bfd_mtime = 0;
-
-      remove_target_sections (&exec_bfd);
-
-      current_program_space->exec_filename.reset (nullptr);
-    }
-}
-
 /* This is the target_close implementation.  Clears all target
    sections and closes all executable bfds from all program spaces.  */
 
@@ -183,7 +160,7 @@ exec_target::close ()
     {
       set_current_program_space (ss);
       current_target_sections->clear ();
-      exec_close ();
+      ss->exec_close ();
     }
 }
 
@@ -396,7 +373,7 @@ exec_file_attach (const char *filename, int from_tty)
   gdb_bfd_ref_ptr exec_bfd_holder = gdb_bfd_ref_ptr::new_reference (exec_bfd);
 
   /* Remove any previous exec file.  */
-  exec_close ();
+  current_program_space->exec_close ();
 
   /* Now open and digest the file the user requested, if any.  */
 
@@ -497,7 +474,7 @@ exec_file_attach (const char *filename, int from_tty)
        {
          /* Make sure to close exec_bfd, or else "run" might try to use
             it.  */
-         exec_close ();
+         current_program_space->exec_close ();
          error (_("\"%ps\": not in executable format: %s"),
                 styled_string (file_name_style.style (), scratch_pathname),
                 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
index b2f51509bcf7489f6c85288a7240316729d9d6d6..f98dd83da215812285ec67b645b3f5554f109233 100644 (file)
@@ -117,8 +117,6 @@ extern void add_target_sections_of_objfile (struct objfile *objfile);
 extern void print_section_info (target_section_table *table,
                                bfd *abfd);
 
-extern void exec_close (void);
-
 /* Helper function that attempts to open the symbol file at EXEC_FILE_HOST.
    If successful, it proceeds to add the symbol file as the main symbol file.
 
index 76001234255035a4f255f1118a0d9096e5434181..8a15c402c28e66d529f637ba0841439a5a90e2cc 100644 (file)
@@ -223,6 +223,26 @@ program_space::solibs () const
   return next_adapter<struct so_list> (this->so_list);
 }
 
+/* See progspace.h.  */
+
+void
+program_space::exec_close ()
+{
+  if (ebfd)
+    {
+      gdb_bfd_unref (ebfd);
+
+      /* Removing target sections may close the exec_ops target.
+        Clear exec_bfd before doing so to prevent recursion.  */
+      ebfd = NULL;
+      ebfd_mtime = 0;
+
+      remove_target_sections (&ebfd);
+
+      exec_filename.reset (nullptr);
+    }
+}
+
 /* Copies program space SRC to DEST.  Copies the main executable file,
    and the main symbol file.  Returns DEST.  */
 
index 3acce50b32fb6940b9002aafd8b5cc683acac0bf..6dcec9c96f7728b25227de383728b254e8b3c7c8 100644 (file)
@@ -272,6 +272,9 @@ struct program_space
      for (so_list *so : pspace->solibs ()) { ... }  */
   next_adapter<struct so_list> solibs () const;
 
+  /* Close and clear exec_bfd.  If we end up with no target sections
+     to read memory from, this unpushes the exec_ops target.  */
+  void exec_close ();
 
   /* Unique ID number.  */
   int num = 0;
This page took 0.03352 seconds and 4 git commands to generate.