Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/9] Change exec_close to be a method on program_space
Date: Tue, 21 Jul 2020 21:34:37 -0600	[thread overview]
Message-ID: <20200722033444.18522-3-tom@tromey.com> (raw)
In-Reply-To: <20200722033444.18522-1-tom@tromey.com>

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-07-21  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   |  9 +++++++++
 gdb/exec.c      | 31 ++++---------------------------
 gdb/exec.h      |  2 --
 gdb/progspace.c | 20 ++++++++++++++++++++
 gdb/progspace.h |  3 +++
 5 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index 8ce7a567df1..a395b58da82 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -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);
       clear_section_table (current_target_sections);
-      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.  */
 
@@ -498,7 +475,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 ());
@@ -508,7 +485,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\": can't find the file sections: %s"),
 		 styled_string (file_name_style.style (), scratch_pathname),
 		 bfd_errmsg (bfd_get_error ()));
diff --git a/gdb/exec.h b/gdb/exec.h
index 66fcb1624a4..daaf0d0d4a7 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -118,8 +118,6 @@ extern void add_target_sections_of_objfile (struct objfile *objfile);
 extern void print_section_info (struct 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.
 
diff --git a/gdb/progspace.c b/gdb/progspace.c
index 9cd83e55b75..ca32a0a1b8d 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -218,6 +218,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.  */
 
diff --git a/gdb/progspace.h b/gdb/progspace.h
index afccebbc00b..777bef2e38e 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -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;
-- 
2.17.2



  parent reply	other threads:[~2020-07-22  3:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-22  3:34 [PATCH 0/9] Remove some macros from exec.h and progspace.h Tom Tromey
2020-07-22  3:34 ` [PATCH 1/9] Remove exec_filename macro Tom Tromey
2020-07-22  3:34 ` Tom Tromey [this message]
2020-07-22  3:34 ` [PATCH 3/9] Remove commented-out code from gcore.c Tom Tromey
2020-07-22  3:34 ` [PATCH 4/9] Remove exec_bfd_mtime define Tom Tromey
2020-07-22  3:34 ` [PATCH 5/9] Remove current_target_sections macro Tom Tromey
2020-07-22 12:20   ` Simon Marchi
2020-07-22 12:39     ` Simon Marchi
2020-07-22 14:11       ` Tom Tromey
2020-07-22  3:34 ` [PATCH 6/9] Don't change current program space in exec_target::close Tom Tromey
2020-07-22 12:22   ` Simon Marchi
2020-07-22  3:34 ` [PATCH 7/9] Remove the exec_bfd macro Tom Tromey
2020-07-22  3:34 ` [PATCH 8/9] Change program_space::ebfd to a gdb_bfd_ref_ptr Tom Tromey
2020-07-22  3:34 ` [PATCH 9/9] Remove symfile_objfile macro Tom Tromey
2020-07-22 12:38 ` [PATCH 0/9] Remove some macros from exec.h and progspace.h Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200722033444.18522-3-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox