public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 4/5] gdb: add inferior parameter to target_find_description
Date: Thu, 24 Nov 2022 11:04:27 -0500	[thread overview]
Message-ID: <20221124160428.83804-5-simon.marchi@efficios.com> (raw)
In-Reply-To: <20221124160428.83804-1-simon.marchi@efficios.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

Make target_find_description not dependent on the current inferior on
entry.  Add an inferior parameter, and make it switch the current
inferior temporarily where needed.

Make callers pass the current inferior, no change in behavior is
expected.

Change-Id: I6fbe03a91e812c003b7946ba7ccc807a8b7369e6
---
 gdb/infcmd.c              |  2 +-
 gdb/infrun.c              |  2 +-
 gdb/remote.c              |  6 +++---
 gdb/target-descriptions.c | 31 ++++++++++++++++++-------------
 gdb/target-descriptions.h |  6 +++---
 gdb/tracefile-tfile.c     |  2 +-
 6 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index f7bce0d0399..f281914ce54 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -251,7 +251,7 @@ post_create_inferior (int from_tty)
      Targets which need to access registers during to_open,
      to_create_inferior, or to_attach should do it earlier; but many
      don't need to.  */
-  target_find_description ();
+  target_find_description (current_inferior ());
 
   /* Now that we know the register layout, retrieve current PC.  But
      if the PC is unavailable (e.g., we're opening a core file with
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 96346e1f25b..c678d5accce 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1272,7 +1272,7 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
      architecture, and the old executable may e.g., be 32-bit, while
      the new one 64-bit), and before anything involving memory or
      registers.  */
-  target_find_description ();
+  target_find_description (inf);
 
   gdb::observers::inferior_execd.notify (inf);
 
diff --git a/gdb/remote.c b/gdb/remote.c
index 5118ecd0a31..ca6fd535a54 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4826,7 +4826,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
 
   /* Next, if the target can specify a description, read it.  We do
      this before anything involving memory or registers.  */
-  target_find_description ();
+  target_find_description (current_inferior ());
 
   /* Next, now that we know something about the target, update the
      address spaces in the program spaces.  */
@@ -4963,7 +4963,7 @@ remote_target::start_remote_1 (int from_tty, int extended_p)
 	  && gdbarch_target_desc (target_gdbarch ()) == NULL)
 	{
 	  target_clear_description ();
-	  target_find_description ();
+	  target_find_description (current_inferior ());
 	}
 
       /* Use the previously fetched status.  */
@@ -6187,7 +6187,7 @@ extended_remote_target::attach (const char *args, int from_tty)
 
   /* Next, if the target can specify a description, read it.  We do
      this before anything involving memory or registers.  */
-  target_find_description ();
+  target_find_description (current_inferior ());
 
   if (!target_is_non_stop_p ())
     {
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 57d23747f26..40c04e0770f 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -520,13 +520,12 @@ target_desc_info_free (struct target_desc_info *tdesc_info)
 
 static std::string tdesc_filename_cmd_string;
 
-/* Fetch the current target's description, and switch the current
-   architecture to one which incorporates that description.  */
+/* See target-descriptions.h.  */
 
 void
-target_find_description (void)
+target_find_description (inferior *inf)
 {
-  target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
+  target_desc_info *tdesc_info = get_tdesc_info (inf);
 
   /* If we've already fetched a description from the target, don't do
      it again.  This allows a target to fetch the description early,
@@ -538,7 +537,7 @@ target_find_description (void)
   /* The current architecture should not have any target description
      specified.  It should have been cleared, e.g. when we
      disconnected from the previous target.  */
-  gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL);
+  gdb_assert (gdbarch_target_desc (inf->gdbarch) == nullptr);
 
   /* First try to fetch an XML description from the user-specified
      file.  */
@@ -546,16 +545,22 @@ target_find_description (void)
   if (!tdesc_info->filename.empty ())
     tdesc_info->tdesc = file_read_description_xml (tdesc_info->filename.data ());
 
+  /* The calls that get the target description from the target depend on INF
+     being the current inferior, and some targets need a specific thread to
+     be selected.  */
+  scoped_restore_current_thread restore_thread;
+  thread_info *thread = any_thread_of_inferior (inf);
+  gdb_assert (thread != nullptr);
+  switch_to_thread (thread);
+
   /* Next try to read the description from the current target using
      target objects.  */
   if (tdesc_info->tdesc == nullptr)
-    tdesc_info->tdesc = target_read_description_xml
-      (current_inferior ()->top_target ());
+    tdesc_info->tdesc = target_read_description_xml (inf->top_target ());
 
   /* If that failed try a target-specific hook.  */
   if (tdesc_info->tdesc == nullptr)
-    tdesc_info->tdesc = target_read_description
-      (current_inferior ()->top_target ());
+    tdesc_info->tdesc = target_read_description (inf->top_target ());
 
   /* If a non-NULL description was returned, then update the current
      architecture.  */
@@ -564,13 +569,13 @@ target_find_description (void)
       struct gdbarch_info info;
 
       info.target_desc = tdesc_info->tdesc;
-      if (!gdbarch_update_p (current_inferior (), info))
+      if (!gdbarch_update_p (inf, info))
 	warning (_("Architecture rejected target-supplied description"));
       else
 	{
 	  struct tdesc_arch_data *data;
 
-	  data = get_arch_data (target_gdbarch ());
+	  data = get_arch_data (inf->gdbarch);
 	  if (tdesc_has_registers (tdesc_info->tdesc)
 	      && data->arch_regs.empty ())
 	    warning (_("Target-supplied registers are not supported "
@@ -1289,7 +1294,7 @@ set_tdesc_filename_cmd (const char *args, int from_tty,
   tdesc_info->filename = tdesc_filename_cmd_string;
 
   target_clear_description ();
-  target_find_description ();
+  target_find_description (current_inferior ());
 }
 
 static void
@@ -1316,7 +1321,7 @@ unset_tdesc_filename_cmd (const char *args, int from_tty)
 
   tdesc_info->filename.clear ();
   target_clear_description ();
-  target_find_description ();
+  target_find_description (current_inferior ());
 }
 
 /* Print target description in C.  */
diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h
index 3049b783e2f..ab534488d65 100644
--- a/gdb/target-descriptions.h
+++ b/gdb/target-descriptions.h
@@ -31,10 +31,10 @@ struct target_ops;
 struct target_desc_info;
 struct inferior;
 
-/* Fetch the current inferior's description, and switch its current
-   architecture to one which incorporates that description.  */
+/* Fetch INFERIOR's target description, and switch its architecture to one which
+   incorporates that description.  */
 
-void target_find_description (void);
+void target_find_description (inferior *inf);
 
 /* Discard any description fetched from the target for the current
    inferior, and switch the current architecture to one with no target
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 3266f357a27..b8302902af4 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -538,7 +538,7 @@ tfile_target_open (const char *arg, int from_tty)
 	}
 
       /* By now, tdesc lines have been read from tfile - let's parse them.  */
-      target_find_description ();
+      target_find_description (current_inferior ());
 
       /* Record the starting offset of the binary trace data.  */
       trace_frames_offset = bytes;
-- 
2.37.3


  parent reply	other threads:[~2022-11-24 16:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-24 16:04 [PATCH 0/5] Make some functions independent of current inferior Simon Marchi
2022-11-24 16:04 ` [PATCH 1/5] gdb: add inferior parameter to target_current_description Simon Marchi
2022-11-24 16:04 ` [PATCH 2/5] gdb: add inferior parameter to set_target_gdbarch, rename to set_inferior_gdbarch Simon Marchi
2022-11-24 16:42   ` Lancelot SIX
2022-11-24 16:47     ` Simon Marchi
2022-11-24 16:04 ` [PATCH 3/5] gdb: add inferior parameter to gdbarch_update_p Simon Marchi
2022-11-24 16:04 ` Simon Marchi [this message]
2022-11-24 16:25   ` [PATCH 4/5] gdb: add inferior parameter to target_find_description Simon Marchi
2022-11-24 16:04 ` [PATCH 5/5] gdb: add inferior parameter to target_clear_description 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=20221124160428.83804-5-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).