gdb, remote, btrace: move switch_to_thread call right before xfer call
authorMarkus Metzger <markus.t.metzger@intel.com>
Thu, 25 Nov 2021 14:22:24 +0000 (15:22 +0100)
committerMarkus Metzger <markus.t.metzger@intel.com>
Thu, 27 Jan 2022 12:31:21 +0000 (13:31 +0100)
In remote_target::remote_btrace_maybe_reopen, we switch to the currently
iterated thread in order to set inferior_ptid for a subsequent xfer.

Move the switch_to_thread call directly before the target_read_stralloc
call to clarify why we need to switch threads.

gdb/remote.c

index 9f2c63b21411fa762e04664a167eaaafb6ae6044..49eeb63445db35644f7a96e1ae3cb0f47de0b3f1 100644 (file)
@@ -14103,12 +14103,15 @@ remote_target::btrace_sync_conf (const btrace_config *conf)
     }
 }
 
-/* Read the current thread's btrace configuration from the target and
-   store it into CONF.  */
+/* Read TP's btrace configuration from the target and store it into CONF.  */
 
 static void
-btrace_read_config (struct btrace_config *conf)
+btrace_read_config (thread_info *tp, struct btrace_config *conf)
 {
+  /* target_read_stralloc relies on INFERIOR_PTID.  */
+  scoped_restore_current_thread restore_thread;
+  switch_to_thread (tp);
+
   gdb::optional<gdb::char_vector> xml
     = target_read_stralloc (current_inferior ()->top_target (),
                            TARGET_OBJECT_BTRACE_CONF, "");
@@ -14132,14 +14135,10 @@ remote_target::remote_btrace_maybe_reopen ()
   if (packet_support (PACKET_qXfer_btrace_conf) != PACKET_ENABLE)
     return;
 
-  scoped_restore_current_thread restore_thread;
-
   for (thread_info *tp : all_non_exited_threads (this))
     {
-      switch_to_thread (tp);
-
       memset (&rs->btrace_config, 0x00, sizeof (struct btrace_config));
-      btrace_read_config (&rs->btrace_config);
+      btrace_read_config (tp, &rs->btrace_config);
 
       if (rs->btrace_config.format == BTRACE_FORMAT_NONE)
        continue;
@@ -14227,7 +14226,7 @@ remote_target::enable_btrace (thread_info *tp,
      tracing itself is not impacted.  */
   try
     {
-      btrace_read_config (&tinfo->conf);
+      btrace_read_config (tp, &tinfo->conf);
     }
   catch (const gdb_exception_error &err)
     {