Remove exec_filename macro
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)
This removes the exec_filename macro, replacing it with uses of the
member of current_program_space.  This also renames that member, and
changes it to be a unique pointer.

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

* progspace.h (struct program_space) <exec_filename>: Rename from
pspace_exec_filename.  Now a unique_xmalloc_ptr.
* inferior.c (print_selected_inferior): Update.
(print_inferior): Update.
* mi/mi-main.c (print_one_inferior): Update.
* exec.h (exec_filename): Remove macro.
* corefile.c (get_exec_file): Update.
* exec.c (exec_close): Update.
(exec_file_attach): Update.
* progspace.c (clone_program_space): Update.
(print_program_space): Update.

gdb/ChangeLog
gdb/corefile.c
gdb/exec.c
gdb/exec.h
gdb/inferior.c
gdb/mi/mi-main.c
gdb/progspace.c
gdb/progspace.h

index e282ea7f6042c55cacc8e5d8b61aed266da4f1d2..357c57f3497aa1029ba7a3c3a228161a2263c6ce 100644 (file)
@@ -1,3 +1,17 @@
+2020-10-29  Tom Tromey  <tom@tromey.com>
+
+       * progspace.h (struct program_space) <exec_filename>: Rename from
+       pspace_exec_filename.  Now a unique_xmalloc_ptr.
+       * inferior.c (print_selected_inferior): Update.
+       (print_inferior): Update.
+       * mi/mi-main.c (print_one_inferior): Update.
+       * exec.h (exec_filename): Remove macro.
+       * corefile.c (get_exec_file): Update.
+       * exec.c (exec_close): Update.
+       (exec_file_attach): Update.
+       * progspace.c (clone_program_space): Update.
+       (print_program_space): Update.
+
 2020-10-29  Tom Tromey  <tom@tromey.com>
 
        * target-section.h (struct target_section): Add constructor.
index fed0e4fe8ade8cb4d28eeebc2c3845fd29552595..c1eec199342adc3afe50981b5820e34572029b13 100644 (file)
@@ -144,8 +144,8 @@ validate_files (void)
 const char *
 get_exec_file (int err)
 {
-  if (exec_filename)
-    return exec_filename;
+  if (current_program_space->exec_filename != nullptr)
+    return current_program_space->exec_filename.get ();
   if (!err)
     return NULL;
 
index 9bdd87d0eaacefcf22ba40da7868dbbebbec350e..d27949c609f45663449be03741268cfa667411fa 100644 (file)
@@ -167,8 +167,7 @@ exec_close (void)
 
       remove_target_sections (&exec_bfd);
 
-      xfree (exec_filename);
-      exec_filename = NULL;
+      current_program_space->exec_filename.reset (nullptr);
     }
 }
 
@@ -486,11 +485,13 @@ 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 (exec_filename == NULL);
+      gdb_assert (current_program_space->exec_filename == nullptr);
       if (load_via_target)
-       exec_filename = xstrdup (bfd_get_filename (exec_bfd));
+       current_program_space->exec_filename
+         = make_unique_xstrdup (bfd_get_filename (exec_bfd));
       else
-       exec_filename = gdb_realpath_keepfile (scratch_pathname).release ();
+       current_program_space->exec_filename
+         = gdb_realpath_keepfile (scratch_pathname);
 
       if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
        {
index 24489654ddc87ef3e238994311234ad7fc17e230..b2f51509bcf7489f6c85288a7240316729d9d6d6 100644 (file)
@@ -32,7 +32,6 @@ struct objfile;
 
 #define exec_bfd current_program_space->ebfd
 #define exec_bfd_mtime current_program_space->ebfd_mtime
-#define exec_filename current_program_space->pspace_exec_filename
 
 /* Builds a section table, given args BFD.  */
 
index f06c13bbca448ab88cae4d5f33429542673cee65..fc21241a3744f55da3a625cffef74717d3640c42 100644 (file)
@@ -415,7 +415,7 @@ void
 print_selected_inferior (struct ui_out *uiout)
 {
   struct inferior *inf = current_inferior ();
-  const char *filename = inf->pspace->pspace_exec_filename;
+  const char *filename = inf->pspace->exec_filename.get ();
 
   if (filename == NULL)
     filename = _("<noexec>");
@@ -518,8 +518,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.c_str ());
 
-      if (inf->pspace->pspace_exec_filename != NULL)
-       uiout->field_string ("exec", inf->pspace->pspace_exec_filename);
+      if (inf->pspace->exec_filename != nullptr)
+       uiout->field_string ("exec", inf->pspace->exec_filename.get ());
       else
        uiout->field_skip ("exec");
 
index c5c7be7246a820d7051b88762e7430825fac79ba..41bafd2f70d1a166b7c6acf325cafed664449b4d 100644 (file)
@@ -649,10 +649,10 @@ print_one_inferior (struct inferior *inferior, bool recurse,
       if (inferior->pid != 0)
        uiout->field_signed ("pid", inferior->pid);
 
-      if (inferior->pspace->pspace_exec_filename != NULL)
+      if (inferior->pspace->exec_filename != nullptr)
        {
          uiout->field_string ("executable",
-                              inferior->pspace->pspace_exec_filename);
+                              inferior->pspace->exec_filename.get ());
        }
 
       if (inferior->pid != 0)
index 67ea8bdb9e9a1407aecb0f5ce8e5a488586d0df5..76001234255035a4f255f1118a0d9096e5434181 100644 (file)
@@ -233,8 +233,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),
@@ -315,8 +315,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");
 
index 6a0e90363995e8c950b0acf6eece9cbea99cba0d..3acce50b32fb6940b9002aafd8b5cc683acac0bf 100644 (file)
@@ -284,9 +284,9 @@ struct program_space
   /* 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 needs to be freed by xfree.  It is not NULL iff EBFD is not NULL.  */
-  char *pspace_exec_filename = NULL;
+     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;