gdb: print thread names in thread apply command output
[deliverable/binutils-gdb.git] / gdb / thread.c
index 54b59e22448a260e4190ffe5438b8b5c799a1cd9..c6e3d356a5a352de4bb07e5a3eab38a4b39b2fc9 100644 (file)
@@ -1563,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
@@ -1570,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 ());
        }
     }
@@ -1581,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.024701 seconds and 4 git commands to generate.