]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: make progspace::exec_filename private, add getter / setter
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 30 May 2024 18:53:53 +0000 (14:53 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 8 Jun 2024 03:09:03 +0000 (23:09 -0400)
Just like the title says... I think this makes things a bit clearer, for
instance where the exec filename is set.  It also makes the read call
sites a bit nicer, avoiding the `.get ()`.

Change-Id: If8b58ae8f6270c8a34b868f6ca06128c6671ea3c
Approved-By: Tom Tromey <tom@tromey.com>
gdb/corefile.c
gdb/exec.c
gdb/inferior.c
gdb/mi/mi-main.c
gdb/progspace.c
gdb/progspace.h
gdb/python/py-progspace.c

index 044c084ab6f3949f5e22ab1ab4af916fb3bda469..3ae3fc7b633720f4a8e6b1ba7a642e88951dd1c0 100644 (file)
@@ -81,8 +81,9 @@ validate_files (void)
 const char *
 get_exec_file (int err)
 {
-  if (current_program_space->exec_filename != nullptr)
-    return current_program_space->exec_filename.get ();
+  if (current_program_space->exec_filename () != nullptr)
+    return current_program_space->exec_filename ();
+
   if (!err)
     return NULL;
 
index 88915260d609114fdba306eb6d989b0500b8edb6..4fe4d3bb50adbb0a42943055df1d8c2c16942a88 100644 (file)
@@ -456,15 +456,15 @@ exec_file_attach (const char *filename, int from_tty)
 
       /* 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_assert (current_program_space->exec_filename () == nullptr);
       if (load_via_target)
-       current_program_space->exec_filename
-         (make_unique_xstrdup
+       current_program_space->set_exec_filename
+         (make_unique_xstrdup
             (bfd_get_filename (current_program_space->exec_bfd ())));
       else
-       current_program_space->exec_filename
-         make_unique_xstrdup (gdb_realpath_keepfile
-                                  (scratch_pathname).c_str ());
+       current_program_space->set_exec_filename
+         (make_unique_xstrdup (gdb_realpath_keepfile
+                                 (scratch_pathname).c_str ()));
 
       if (!bfd_check_format_matches (current_program_space->exec_bfd (),
                                     bfd_object, &matching))
index 0522cb5c14d5fd1d87cee73d0ddeb075231e273b..6a197679902bd8cb303889f2edfd1906bfef7446 100644 (file)
@@ -519,7 +519,7 @@ void
 print_selected_inferior (struct ui_out *uiout)
 {
   struct inferior *inf = current_inferior ();
-  const char *filename = inf->pspace->exec_filename.get ();
+  const char *filename = inf->pspace->exec_filename ();
 
   if (filename == NULL)
     filename = _("<noexec>");
@@ -613,8 +613,8 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
       std::string conn = uiout_field_connection (inf->process_target ());
       uiout->field_string ("connection-id", conn);
 
-      if (inf->pspace->exec_filename != nullptr)
-       uiout->field_string ("exec", inf->pspace->exec_filename.get (),
+      if (inf->pspace->exec_filename () != nullptr)
+       uiout->field_string ("exec", inf->pspace->exec_filename (),
                             file_name_style.style ());
       else
        uiout->field_skip ("exec");
@@ -750,7 +750,7 @@ inferior_command (const char *args, int from_tty)
     {
       inf = current_inferior ();
       gdb_assert (inf != nullptr);
-      const char *filename = inf->pspace->exec_filename.get ();
+      const char *filename = inf->pspace->exec_filename ();
 
       if (filename == nullptr)
        filename = _("<noexec>");
index a758b689ae722e1264c667e83809e1fde94e7a5b..5bcb5f7ee8ceba27618fed1b5d4eaac9230c23ef 100644 (file)
@@ -651,11 +651,8 @@ print_one_inferior (struct inferior *inferior, bool recurse,
       if (inferior->pid != 0)
        uiout->field_signed ("pid", inferior->pid);
 
-      if (inferior->pspace->exec_filename != nullptr)
-       {
-         uiout->field_string ("executable",
-                              inferior->pspace->exec_filename.get ());
-       }
+      if (inferior->pspace->exec_filename () != nullptr)
+       uiout->field_string ("executable", inferior->pspace->exec_filename ());
 
       if (inferior->pid != 0)
        {
index 5be514d45b0dad32c1ac9bd8d6d94228b58d166a..d5b5ef20023bc8544b910cf2a3433a6fcd5e15a5 100644 (file)
@@ -209,7 +209,7 @@ program_space::exec_close ()
 
       remove_target_sections (saved_ebfd);
 
-      exec_filename.reset (nullptr);
+      m_exec_filename.reset ();
     }
 }
 
@@ -223,8 +223,8 @@ clone_program_space (struct program_space *dest, struct program_space *src)
 
   set_current_program_space (dest);
 
-  if (src->exec_filename != NULL)
-    exec_file_attach (src->exec_filename.get (), 0);
+  if (src->exec_filename () != nullptr)
+    exec_file_attach (src->exec_filename (), 0);
 
   if (src->symfile_object_file != NULL)
     symbol_file_add_main (objfile_name (src->symfile_object_file),
@@ -277,8 +277,8 @@ print_program_space (struct ui_out *uiout, int requested)
       if (requested != -1 && pspace->num != requested)
        continue;
 
-      if (pspace->exec_filename != nullptr)
-       longest_exec_name = std::max (strlen (pspace->exec_filename.get ()),
+      if (pspace->exec_filename () != nullptr)
+       longest_exec_name = std::max (strlen (pspace->exec_filename ()),
                                      longest_exec_name);
 
       ++count;
@@ -310,8 +310,8 @@ print_program_space (struct ui_out *uiout, int requested)
 
       uiout->field_signed ("id", pspace->num);
 
-      if (pspace->exec_filename != nullptr)
-       uiout->field_string ("exec", pspace->exec_filename.get (),
+      if (pspace->exec_filename () != nullptr)
+       uiout->field_string ("exec", pspace->exec_filename (),
                             file_name_style.style ());
       else
        uiout->field_skip ("exec");
index bc24ef93733c7a2df7850f6778a27425c214ab4b..82c0a743f3265ee7152fa95f3ed01c3ba49d058f 100644 (file)
@@ -292,6 +292,15 @@ struct program_space
   intrusive_list<solib> &solibs ()
   { return so_list; }
 
+  /* Similar to `bfd_get_filename (exec_bfd ())` but in original form given
+     by user, without symbolic links and pathname resolved.  It is not nullptr
+     iff `exec_bfd ()` is not nullptr.  */
+  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 ();
@@ -352,10 +361,6 @@ struct program_space
   gdb_bfd_ref_ptr ebfd;
   /* The last-modified time, from when the exec was brought in.  */
   long ebfd_mtime = 0;
-  /* Similar to bfd_get_filename (exec_bfd) but in original form given
-     by user, without symbolic links and pathname resolved.  It is not
-     NULL iff EBFD is not NULL.  */
-  gdb::unique_xmalloc_ptr<char> exec_filename;
 
   /* Binary file diddling handle for the core file.  */
   gdb_bfd_ref_ptr cbfd;
@@ -414,6 +419,9 @@ private:
   /* The set of target sections matching the sections mapped into
      this program space.  Managed by both exec_ops and solib.c.  */
   std::vector<target_section> m_target_sections;
+
+  /* See `exec_filename`.  */
+  gdb::unique_xmalloc_ptr<char> m_exec_filename;
 };
 
 /* The list of all program spaces.  There's always at least one.  */
index a5b22ce9d5c8025dc749357e3784cbc2832193be..5bc0015d7288dbe3e1abb5ece6fb2320882ca4ca 100644 (file)
@@ -148,7 +148,7 @@ pspy_get_exec_file (PyObject *self, void *closure)
 
   PSPY_REQUIRE_VALID (obj);
 
-  const char *filename = obj->pspace->exec_filename.get ();
+  const char *filename = obj->pspace->exec_filename ();
   if (filename != nullptr)
     return host_string_to_python_string (filename).release ();