Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/2] gdb/remote: replace use of std::pair with an actual struct
Date: Wed, 19 Nov 2025 10:32:38 +0000	[thread overview]
Message-ID: <d9d94257e854d1b4d2566876c9c72189095937b8.1760189398.git.aburgess@redhat.com> (raw)
Message-ID: <20251119103238.uJ90QOpqJJcxGXNjIuaw30BKGHt8oBE0uxmSSmKry-M@z> (raw)
In-Reply-To: <cover.1760189398.git.aburgess@redhat.com>

Commit:

  commit 5edcbe2277db05b77ebf53f9c30b6c889a8729bc
  Date:   Mon Jul 24 17:35:54 2023 +0100

      gdb: detect when gdbserver has no default executable set

Introduced a use of std::pair as a data structure to hold some per
program space information within the program space registry.

It was pointed out during review of a later patch that the code would
be easier to understand if the std::pair was replaced with a struct
with named fields.

That is what this commit does.  Replace the std::pair with a struct,
and update all accesses to use the named fields.

There should be no user visible changes after this commit.
---
 gdb/remote.c | 60 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index 2e706e2d45b..143835ad503 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1640,15 +1640,22 @@ enum class remote_exec_source
   UNSET_VALUE,
 };
 
-/* Data held per program-space to represent the remote exec-file path.  The
-   first item in the pair is the exec-file path, this is set either by the
-   user with 'set remote exec-file', or automatically by GDB when
-   connecting to a remote target.
+/* Data held per program-space to represent the remote exec-file path.
+   This holds the 'remote exec-file' value and an enum to indicate where
+   the exec-file value came from, or what an empty exec-file value means.
+   See show_remote_exec_file for details.  */
 
-   The second item in the pair is an enum flag that indicates where the
-   path value came from, or, when the path is the empty string, what this
-   actually means.  See show_remote_exec_file for details.  */
-using remote_exec_file_info = std::pair<std::string, remote_exec_source>;
+struct remote_exec_file_info
+{
+  /* The 'remote exec-file' value.  This will be empty before being set.
+     This is set either with the 'set remote exec-file' command, or
+     automatically by GDB when connecting to a remote target.  */
+  std::string filename;
+
+  /* An enum that indicates where VALUE came from, or what an empty VALUE
+     means.  */
+  remote_exec_source source = remote_exec_source::DEFAULT_VALUE;
+};
 
 /* Per-program-space data key.  */
 static const registry<program_space>::key<remote_exec_file_info>
@@ -1662,8 +1669,7 @@ get_remote_exec_file_info (program_space *pspace)
 {
   remote_exec_file_info *info = remote_pspace_data.get (pspace);
   if (info == nullptr)
-    info = remote_pspace_data.emplace (pspace, "",
-				       remote_exec_source::DEFAULT_VALUE);
+    info = remote_pspace_data.emplace (pspace);
   gdb_assert (info != nullptr);
   return *info;
 }
@@ -2001,7 +2007,7 @@ get_remote_exec_file ()
 {
   const remote_exec_file_info &info
     = get_remote_exec_file_info (current_program_space);
-  return info.first;
+  return info.filename;
 }
 
 /* Set the remote exec file for PSPACE.  */
@@ -2012,8 +2018,8 @@ set_pspace_remote_exec_file (struct program_space *pspace,
 			     remote_exec_source source)
 {
   remote_exec_file_info &info = get_remote_exec_file_info (pspace);
-  info.first = filename;
-  info.second = source;
+  info.filename = filename;
+  info.source = source;
 }
 
 /* The "set remote exec-file" callback.  */
@@ -2034,16 +2040,16 @@ show_remote_exec_file (struct ui_file *file, int from_tty,
   const remote_exec_file_info &info
     = get_remote_exec_file_info (current_program_space);
 
-  if (info.second == remote_exec_source::DEFAULT_VALUE)
+  if (info.source == remote_exec_source::DEFAULT_VALUE)
     gdb_printf (file, _("The remote exec-file is unset, the default "
 			"remote executable will be used.\n"));
-  else if (info.second == remote_exec_source::UNSET_VALUE)
+  else if (info.source == remote_exec_source::UNSET_VALUE)
     gdb_printf (file, _("The remote exec-file is unset, the remote has "
 			"no default executable set.\n"));
   else
     gdb_printf (file, _("The remote exec-file is \"%ps\".\n"),
 		styled_string (file_name_style.style (),
-			       info.first.c_str ()));
+			       info.filename.c_str ()));
 }
 
 static int
@@ -5483,25 +5489,25 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
 	{
 	  remote_exec_file_info &info
 	    = get_remote_exec_file_info (current_program_space);
-	  if (info.second == remote_exec_source::VALUE_FROM_GDB
-	      && info.first != exec_and_args.exec ())
+	  if (info.source == remote_exec_source::VALUE_FROM_GDB
+	      && info.filename != exec_and_args.exec ())
 	    warning (_("updating 'remote exec-file' to '%ps' to match "
 		       "remote target"),
 		     styled_string (file_name_style.style (),
 				    exec_and_args.exec ().c_str ()));
-	  info.first = exec_and_args.exec ();
-	  info.second = remote_exec_source::VALUE_FROM_REMOTE;
+	  info.filename = exec_and_args.exec ();
+	  info.source = remote_exec_source::VALUE_FROM_REMOTE;
 	}
     }
   else if (exec_and_args.is_unset ())
     {
       remote_exec_file_info &info
 	= get_remote_exec_file_info (current_program_space);
-      if (info.second == remote_exec_source::DEFAULT_VALUE
-	  || info.second == remote_exec_source::VALUE_FROM_REMOTE)
+      if (info.source == remote_exec_source::DEFAULT_VALUE
+	  || info.source == remote_exec_source::VALUE_FROM_REMOTE)
 	{
-	  info.first.clear ();
-	  info.second = remote_exec_source::UNSET_VALUE;
+	  info.filename.clear ();
+	  info.source = remote_exec_source::UNSET_VALUE;
 	}
     }
 
@@ -6492,10 +6498,10 @@ remote_unpush_target (remote_target *target)
 	 would be unhelpful.  */
       remote_exec_file_info &exec_info
 	= get_remote_exec_file_info (inf->pspace);
-      if (exec_info.second == remote_exec_source::UNSET_VALUE)
+      if (exec_info.source == remote_exec_source::UNSET_VALUE)
 	{
-	  gdb_assert (exec_info.first.empty ());
-	  exec_info.second = remote_exec_source::DEFAULT_VALUE;
+	  gdb_assert (exec_info.filename.empty ());
+	  exec_info.source = remote_exec_source::DEFAULT_VALUE;
 	}
 
       inf->pop_all_targets_at_and_above (process_stratum);
-- 
2.47.1


  reply	other threads:[~2025-11-19 10:35 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 15:07 [PATCH] gdb: use current executable for 'remote exec-file' in some cases Andrew Burgess
2025-10-06 15:43 ` Eli Zaretskii
2025-10-09 16:17 ` Simon Marchi
2025-10-11 13:34 ` [PATCH 0/2] Auto setting of 'remote exec-file' Andrew Burgess
2025-10-11 13:34   ` Andrew Burgess [this message]
2025-10-11 13:46     ` [PATCH 1/2] gdb/remote: replace use of std::pair with an actual struct Simon Marchi
2025-10-12  8:57       ` Andrew Burgess
2025-10-12 12:05         ` Simon Marchi
2025-10-12 13:13           ` Andrew Burgess
2025-11-19 10:32     ` Andrew Burgess
2025-10-11 13:34   ` [PATCH 2/2] gdb: use current executable for 'remote exec-file' in some cases Andrew Burgess
2025-10-11 14:45     ` Eli Zaretskii
2025-11-07 20:46     ` Simon Marchi
2025-11-11 15:59       ` Andrew Burgess
2026-01-14  1:17         ` Simon Marchi
2026-01-14 16:48           ` Andrew Burgess
2026-01-14 20:01           ` [PATCH] gdb/testsuite: fix failure in gdb.server/fetch-exec-and-args.exp Andrew Burgess
2026-01-15 21:13             ` Simon Marchi
2026-01-22 15:31               ` Andrew Burgess
2025-11-19 10:32     ` [PATCH 2/2] gdb: use current executable for 'remote exec-file' in some cases Andrew Burgess

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=d9d94257e854d1b4d2566876c9c72189095937b8.1760189398.git.aburgess@redhat.com \
    --to=aburgess@redhat.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