[gdb/testsuite] Accept new complex print style in mixed-lang-stack.exp
[deliverable/binutils-gdb.git] / gdb / thread.c
index 001fdd42c5e929462f8d8f9bc97e2081a1b58e5b..c6e3d356a5a352de4bb07e5a3eab38a4b39b2fc9 100644 (file)
@@ -823,13 +823,13 @@ set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed)
 /* Helper for set_running, that marks one thread either running or
    stopped.  */
 
-static int
-set_running_thread (struct thread_info *tp, int running)
+static bool
+set_running_thread (struct thread_info *tp, bool running)
 {
-  int started = 0;
+  bool started = false;
 
   if (running && tp->state == THREAD_STOPPED)
-    started = 1;
+    started = true;
   tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
 
   if (!running)
@@ -1429,10 +1429,7 @@ scoped_restore_current_thread::restore ()
       && m_inf->pid != 0)
     switch_to_thread (m_thread);
   else
-    {
-      switch_to_no_thread ();
-      set_current_inferior (m_inf);
-    }
+    switch_to_inferior_no_thread (m_inf);
 
   /* The running state of the originally selected thread may have
      changed, so we have to recheck it here.  */
@@ -1566,6 +1563,14 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
                   const qcs_flags &flags)
 {
   switch_to_thread (thr);
+
+  /* The thread header is computed before running the command since
+     the command can change the inferior, which is not permitted
+     by thread_target_id_str.  */
+  std::string thr_header =
+    string_printf (_("\nThread %s (%s):\n"), print_thread_id (thr),
+                  thread_target_id_str (thr).c_str ());
+
   try
     {
       std::string cmd_result = execute_command_to_string
@@ -1573,9 +1578,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
       if (!flags.silent || cmd_result.length () > 0)
        {
          if (!flags.quiet)
-           printf_filtered (_("\nThread %s (%s):\n"),
-                            print_thread_id (thr),
-                            target_pid_to_str (inferior_ptid).c_str ());
+           printf_filtered ("%s", thr_header.c_str ());
          printf_filtered ("%s", cmd_result.c_str ());
        }
     }
@@ -1584,9 +1587,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
       if (!flags.silent)
        {
          if (!flags.quiet)
-           printf_filtered (_("\nThread %s (%s):\n"),
-                            print_thread_id (thr),
-                            target_pid_to_str (inferior_ptid).c_str ());
+           printf_filtered ("%s", thr_header.c_str ());
          if (flags.cont)
            printf_filtered ("%s\n", ex.what ());
          else
This page took 0.02481 seconds and 4 git commands to generate.