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 1/9] Remove exec_filename macro
Date: Tue, 21 Jul 2020 21:34:36 -0600	[thread overview]
Message-ID: <20200722033444.18522-2-tom@tromey.com> (raw)
In-Reply-To: <20200722033444.18522-1-tom@tromey.com>

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-07-21  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    | 14 ++++++++++++++
 gdb/corefile.c   |  4 ++--
 gdb/exec.c       | 11 ++++++-----
 gdb/exec.h       |  1 -
 gdb/inferior.c   |  6 +++---
 gdb/mi/mi-main.c |  4 ++--
 gdb/progspace.c  |  8 ++++----
 gdb/progspace.h  |  6 +++---
 8 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/gdb/corefile.c b/gdb/corefile.c
index fed0e4fe8ad..c1eec199342 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -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;
 
diff --git a/gdb/exec.c b/gdb/exec.c
index 2ff5846c0e7..8ce7a567df1 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -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);
     }
 }
 
@@ -487,11 +486,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))
 	{
diff --git a/gdb/exec.h b/gdb/exec.h
index 54e6ff4d9ba..66fcb1624a4 100644
--- a/gdb/exec.h
+++ b/gdb/exec.h
@@ -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, SECTABLE_PTR, SECEND_PTR.
    Returns 0 if OK, 1 on error.  */
diff --git a/gdb/inferior.c b/gdb/inferior.c
index f775938721d..5c63dfa0bf1 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -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");
 
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 55bb777ef77..8d4bff47938 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -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)
diff --git a/gdb/progspace.c b/gdb/progspace.c
index a0b14a6d2eb..9cd83e55b75 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -228,8 +228,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),
@@ -311,8 +311,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");
 
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 099b4dc0b3a..afccebbc00b 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -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;
-- 
2.17.2



  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 ` Tom Tromey [this message]
2020-07-22  3:34 ` [PATCH 2/9] Change exec_close to be a method on program_space Tom Tromey
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-2-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