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 3/5] Have program_space::set_exec_bfd do more work
Date: Tue, 10 Nov 2026 19:06:57 -0700	[thread overview]
Message-ID: <20261110-minor-assert-v1-3-bb33660ca557@tromey.com> (raw)
In-Reply-To: <20261110-minor-assert-v1-0-bb33660ca557@tromey.com>

This changes program_space::set_exec_bfd to also set the exec
filename, and to compute the exec BFD mtime.  This is better because
these things really ought to all be set at the same time.

program_space::set_exec_filename is not needed any more -- and should
not be needed in the future.
---
 gdb/exec.c      | 20 +++++++-------------
 gdb/progspace.c | 14 ++++++++++++++
 gdb/progspace.h | 14 ++++----------
 3 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/gdb/exec.c b/gdb/exec.c
index aa6fc42ebe7..125ba9d2c44 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -477,26 +477,20 @@ exec_file_attach (const char *filename, int from_tty)
 	       styled_string (file_name_style.style (), scratch_pathname),
 	       gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
 
-      current_program_space->set_exec_bfd (std::move (new_exec_bfd));
-
-      /* gdb_realpath_keepfile resolves symlinks on the local
-	 filesystem and so cannot be used for "target:" files.  */
-      gdb_assert (current_program_space->exec_filename () == nullptr);
+      gdb::unique_xmalloc_ptr<char> new_exec_filename;
       if (load_via_target)
-	current_program_space->set_exec_filename
-	  (make_unique_xstrdup
-	     (bfd_get_filename (current_program_space->exec_bfd ())));
+	new_exec_filename
+	  = make_unique_xstrdup (bfd_get_filename (new_exec_bfd.get ()));
       else
-	current_program_space->set_exec_filename
-	  (make_unique_xstrdup (gdb_realpath_keepfile
+	new_exec_filename
+	  = (make_unique_xstrdup (gdb_realpath_keepfile
 				  (scratch_pathname).c_str ()));
+      current_program_space->set_exec_bfd (std::move (new_exec_bfd),
+					   std::move (new_exec_filename));
 
       std::vector<target_section> sections
 	= build_section_table (current_program_space->exec_bfd ());
 
-      current_program_space->ebfd_mtime
-	= gdb_bfd_get_mtime (current_program_space->exec_bfd ());
-
       validate_files ();
 
       set_gdbarch_from_file (current_program_space->exec_bfd ());
diff --git a/gdb/progspace.c b/gdb/progspace.c
index a9d13c91598..430629c57b3 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -277,6 +277,20 @@ program_space::objfile_for_address (CORE_ADDR address)
 
 /* See progspace.h.  */
 
+void
+program_space::set_exec_bfd (gdb_bfd_ref_ptr &&abfd,
+			     gdb::unique_xmalloc_ptr<char> new_filename)
+{
+  gdb_assert (ebfd == nullptr);
+  gdb_assert (abfd != nullptr);
+  ebfd = std::move (abfd);
+  gdb_assert (m_exec_filename = nullptr);
+  m_exec_filename = std::move (new_filename);
+  ebfd_mtime = gdb_bfd_get_mtime (ebfd.get ());
+}
+
+/* See progspace.h.  */
+
 void
 program_space::exec_close ()
 {
diff --git a/gdb/progspace.h b/gdb/progspace.h
index d0d8466a8e5..f55444ce88c 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -298,9 +298,6 @@ struct program_space
   const char *exec_filename () const
   { return m_exec_filename.get (); }
 
-  void set_exec_filename (gdb::unique_xmalloc_ptr<char> filename)
-  { m_exec_filename = std::move (filename); }
-
   /* 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 ();
@@ -309,13 +306,10 @@ struct program_space
   bfd *exec_bfd () const
   { return ebfd.get (); }
 
-  /* Set the exec BFD for this program space to ABFD.  */
-  void set_exec_bfd (gdb_bfd_ref_ptr &&abfd)
-  {
-    gdb_assert (ebfd == nullptr);
-    gdb_assert (abfd != nullptr);
-    ebfd = std::move (abfd);
-  }
+  /* Set the exec BFD for this program space to ABFD.  This also
+     updates the ebfd_mtime and set the exec filename.  */
+  void set_exec_bfd (gdb_bfd_ref_ptr &&abfd,
+		     gdb::unique_xmalloc_ptr<char> new_filename);
 
   /* Reset saved solib data at the start of an solib event.  This lets
      us properly collect the data when calling solib_add, so it can then

-- 
2.49.0


  parent reply	other threads:[~2026-11-11  2:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  2:06 [PATCH 0/5] Minor updates to program space and setting the exec file Tom Tromey
2026-11-11  2:06 ` [PATCH 1/5] Reject null pointers in program_space::set_exec_bfd Tom Tromey
2026-11-11  2:06 ` [PATCH 2/5] Hoist call to gdb_bfd_check_format_matches in exec.c Tom Tromey
2026-11-11  2:06 ` Tom Tromey [this message]
2026-11-11  2:06 ` [PATCH 4/5] Mark two program_space fields as private Tom Tromey
2026-11-11  2:06 ` [PATCH 5/5] Add some uses of bool to progspace and exec_file_attach Tom Tromey

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=20261110-minor-assert-v1-3-bb33660ca557@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