[5/5] gdb: add inferior parameter to target_clear_description

Message ID 20221124160428.83804-6-simon.marchi@efficios.com
State New
Headers
Series Make some functions independent of current inferior |

Commit Message

Simon Marchi Nov. 24, 2022, 4:04 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

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

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

Change-Id: I85e4c500fceee9fc037f209d188e608536ed3f13
---
 gdb/infrun.c              |  2 +-
 gdb/remote.c              |  2 +-
 gdb/target-descriptions.c | 13 ++++++-------
 gdb/target-descriptions.h |  2 +-
 gdb/target.c              |  2 +-
 5 files changed, 10 insertions(+), 11 deletions(-)
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index c678d5accce..02ca137f545 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1252,7 +1252,7 @@  follow_exec (ptid_t ptid, const char *exec_file_target)
 	 this on "follow-exec-mode new", as the old inferior stays
 	 around (its description is later cleared/refetched on
 	 restart).  */
-      target_clear_description ();
+      target_clear_description (inf);
       target_follow_exec (inf, ptid, exec_file_target);
     }
 
diff --git a/gdb/remote.c b/gdb/remote.c
index ca6fd535a54..cf3b2c92d36 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4962,7 +4962,7 @@  remote_target::start_remote_1 (int from_tty, int extended_p)
       if (remote_read_description_p (this)
 	  && gdbarch_target_desc (target_gdbarch ()) == NULL)
 	{
-	  target_clear_description ();
+	  target_clear_description (current_inferior ());
 	  target_find_description (current_inferior ());
 	}
 
diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c
index 40c04e0770f..1abe5c8ead6 100644
--- a/gdb/target-descriptions.c
+++ b/gdb/target-descriptions.c
@@ -588,13 +588,12 @@  target_find_description (inferior *inf)
   tdesc_info->fetched = true;
 }
 
-/* Discard any description fetched from the current target, and switch
-   the current architecture to one with no target description.  */
+/* See target-descriptions.h.  */
 
 void
-target_clear_description (void)
+target_clear_description (inferior *inf)
 {
-  target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
+  target_desc_info *tdesc_info = get_tdesc_info (inf);
 
   if (!tdesc_info->fetched)
     return;
@@ -603,7 +602,7 @@  target_clear_description (void)
   tdesc_info->tdesc = nullptr;
 
   gdbarch_info info;
-  if (!gdbarch_update_p (current_inferior (), info))
+  if (!gdbarch_update_p (inf, info))
     internal_error (_("Could not remove target-supplied description"));
 }
 
@@ -1293,7 +1292,7 @@  set_tdesc_filename_cmd (const char *args, int from_tty,
 
   tdesc_info->filename = tdesc_filename_cmd_string;
 
-  target_clear_description ();
+  target_clear_description (current_inferior ());
   target_find_description (current_inferior ());
 }
 
@@ -1320,7 +1319,7 @@  unset_tdesc_filename_cmd (const char *args, int from_tty)
   target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
 
   tdesc_info->filename.clear ();
-  target_clear_description ();
+  target_clear_description (current_inferior ());
   target_find_description (current_inferior ());
 }
 
diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h
index ab534488d65..5f89e933b6d 100644
--- a/gdb/target-descriptions.h
+++ b/gdb/target-descriptions.h
@@ -40,7 +40,7 @@  void target_find_description (inferior *inf);
    inferior, and switch the current architecture to one with no target
    description.  */
 
-void target_clear_description (void);
+void target_clear_description (inferior *inf);
 
 /* Return the current inferior's target description.  This should only
    be used by gdbarch initialization code; most access should be
diff --git a/gdb/target.c b/gdb/target.c
index 74925e139dc..bd3b6c98a57 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2484,7 +2484,7 @@  target_pre_inferior (int from_tty)
 
       invalidate_target_mem_regions ();
 
-      target_clear_description ();
+      target_clear_description (current_inferior ());
     }
 
   /* attach_flag may be set if the previous process associated with