]> Git Repo - binutils.git/blobdiff - gdb/thread.c
Use observers to report stop events in MI.
[binutils.git] / gdb / thread.c
index 97facd2e6b69a5f618d88272348f12cd5efd60ff..446a55ece0309c8cebc3651921e9314a59953fb3 100644 (file)
@@ -40,6 +40,7 @@
 #include <signal.h>
 #include "ui-out.h"
 #include "observer.h"
+#include "annotate.h"
 
 /* Definition of struct thread_info exported to gdbthread.h */
 
@@ -61,8 +62,6 @@ static void info_threads_command (char *, int);
 static void thread_apply_command (char *, int);
 static void restore_current_thread (ptid_t);
 static void prune_threads (void);
-static struct cleanup *make_cleanup_restore_current_thread (ptid_t,
-                                                            struct frame_id);
 
 void
 delete_step_resume_breakpoint (void *arg)
@@ -128,22 +127,32 @@ add_thread_silent (ptid_t ptid)
   tp->num = ++highest_thread_num;
   tp->next = thread_list;
   thread_list = tp;
+
+  observer_notify_new_thread (tp);
+
   return tp;
 }
 
 struct thread_info *
-add_thread (ptid_t ptid)
+add_thread_with_info (ptid_t ptid, struct private_thread_info *private)
 {
   struct thread_info *result = add_thread_silent (ptid);
 
+  result->private = private;
+
   if (print_thread_events)
     printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
 
-  observer_notify_new_thread (result);
-  
+  annotate_new_thread ();
   return result;
 }
 
+struct thread_info *
+add_thread (ptid_t ptid)
+{
+  return add_thread_with_info (ptid, NULL);
+}
+
 void
 delete_thread (ptid_t ptid)
 {
@@ -163,6 +172,8 @@ delete_thread (ptid_t ptid)
   else
     thread_list = tp->next;
 
+  observer_notify_thread_exit (tp);
+
   free_thread (tp);
 }
 
@@ -310,7 +321,6 @@ load_infrun_state (ptid_t ptid,
                   CORE_ADDR *step_range_start,
                   CORE_ADDR *step_range_end,
                   struct frame_id *step_frame_id,
-                  int *handling_longjmp,
                   int *stepping_over_breakpoint,
                   int *stepping_through_solib_after_catch,
                   bpstat *stepping_through_solib_catchpoints,
@@ -331,7 +341,6 @@ load_infrun_state (ptid_t ptid,
   *step_range_start = tp->step_range_start;
   *step_range_end = tp->step_range_end;
   *step_frame_id = tp->step_frame_id;
-  *handling_longjmp = tp->handling_longjmp;
   *stepping_over_breakpoint = tp->stepping_over_breakpoint;
   *stepping_through_solib_after_catch =
     tp->stepping_through_solib_after_catch;
@@ -351,7 +360,6 @@ save_infrun_state (ptid_t ptid,
                   CORE_ADDR step_range_start,
                   CORE_ADDR step_range_end,
                   const struct frame_id *step_frame_id,
-                  int handling_longjmp,
                   int stepping_over_breakpoint,
                   int stepping_through_solib_after_catch,
                   bpstat stepping_through_solib_catchpoints,
@@ -372,7 +380,6 @@ save_infrun_state (ptid_t ptid,
   tp->step_range_start = step_range_start;
   tp->step_range_end = step_range_end;
   tp->step_frame_id = (*step_frame_id);
-  tp->handling_longjmp = handling_longjmp;
   tp->stepping_over_breakpoint = stepping_over_breakpoint;
   tp->stepping_through_solib_after_catch = stepping_through_solib_after_catch;
   tp->stepping_through_solib_catchpoints = stepping_through_solib_catchpoints;
@@ -407,15 +414,14 @@ prune_threads (void)
     }
 }
 
-/* Print information about currently known threads 
-
- * Note: this has the drawback that it _really_ switches
- *       threads, which frees the frame cache.  A no-side
- *       effects info-threads command would be nicer.
- */
-
-static void
-info_threads_command (char *arg, int from_tty)
+/* Prints the list of threads and their details on UIOUT.
+   This is a version of 'info_thread_command' suitable for
+   use from MI.  
+   If REQESTED_THREAD is not -1, it's the GDB id of the thread
+   that should be printed.  Otherwise, all threads are
+   printed.  */
+void
+print_thread_info (struct ui_out *uiout, int requested_thread)
 {
   struct thread_info *tp;
   ptid_t current_ptid;
@@ -423,45 +429,94 @@ info_threads_command (char *arg, int from_tty)
   struct cleanup *old_chain;
   struct frame_id saved_frame_id;
   char *extra_info;
+  int current_thread = -1;
 
   /* Backup current thread and selected frame.  */
   saved_frame_id = get_frame_id (get_selected_frame (NULL));
   old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
 
+  make_cleanup_ui_out_list_begin_end (uiout, "threads");
+
   prune_threads ();
   target_find_new_threads ();
   current_ptid = inferior_ptid;
   for (tp = thread_list; tp; tp = tp->next)
     {
+      struct cleanup *chain2;
+
+      if (requested_thread != -1 && tp->num != requested_thread)
+       continue;
+
+      chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+
       if (ptid_equal (tp->ptid, current_ptid))
-       printf_filtered ("* ");
+       {
+         current_thread = tp->num;
+         ui_out_text (uiout, "* ");
+       }
       else
-       printf_filtered ("  ");
+       ui_out_text (uiout, "  ");
 
-      printf_filtered ("%d %s", tp->num, target_tid_to_str (tp->ptid));
+      ui_out_field_int (uiout, "id", tp->num);
+      ui_out_text (uiout, " ");
+      ui_out_field_string (uiout, "target-id", target_tid_to_str (tp->ptid));
 
       extra_info = target_extra_thread_info (tp);
       if (extra_info)
-       printf_filtered (" (%s)", extra_info);
-      puts_filtered ("  ");
+       {
+         ui_out_text (uiout, " (");
+         ui_out_field_string (uiout, "details", extra_info);
+         ui_out_text (uiout, ")");
+       }
+      ui_out_text (uiout, "  ");
       /* That switch put us at the top of the stack (leaf frame).  */
       switch_to_thread (tp->ptid);
-      print_stack_frame (get_selected_frame (NULL), 0, LOCATION);
+      print_stack_frame (get_selected_frame (NULL), 
+                        /* For MI output, print frame level.  */
+                        ui_out_is_mi_like_p (uiout),
+                        LOCATION);
+
+      do_cleanups (chain2);
     }
 
   /* Restores the current thread and the frame selected before
      the "info threads" command.  */
   do_cleanups (old_chain);
 
+  if (requested_thread == -1)
+    {
+      gdb_assert (current_thread != -1 || !thread_list);
+      if (current_thread != -1 && ui_out_is_mi_like_p (uiout))
+       ui_out_field_int (uiout, "current-thread-id", current_thread);
+    }
+
   /*  If case we were not able to find the original frame, print the
       new selected frame.  */
   if (frame_find_by_id (saved_frame_id) == NULL)
     {
       warning (_("Couldn't restore frame in current thread, at frame 0"));
-      print_stack_frame (get_selected_frame (NULL), 0, LOCATION);
+      /* For MI, we should probably have a notification about
+        current frame change.  But this error is not very likely, so
+        don't bother for now.  */
+      if (!ui_out_is_mi_like_p (uiout))
+       print_stack_frame (get_selected_frame (NULL), 0, LOCATION);
     }
 }
 
+
+/* Print information about currently known threads 
+
+ * Note: this has the drawback that it _really_ switches
+ *       threads, which frees the frame cache.  A no-side
+ *       effects info-threads command would be nicer.
+ */
+
+static void
+info_threads_command (char *arg, int from_tty)
+{
+  print_thread_info (uiout, -1);
+}
+
 /* Switch from one thread to another. */
 
 void
@@ -514,7 +569,7 @@ do_restore_current_thread_cleanup (void *arg)
   xfree (old);
 }
 
-static struct cleanup *
+struct cleanup *
 make_cleanup_restore_current_thread (ptid_t inferior_ptid, 
                                      struct frame_id a_frame_id)
 {
@@ -683,6 +738,7 @@ thread_command (char *tidstr, int from_tty)
       return;
     }
 
+  annotate_thread_changed ();
   gdb_thread_select (uiout, tidstr, NULL);
 }
 
@@ -762,8 +818,8 @@ The new thread ID must be currently known."),
 
   add_setshow_boolean_cmd ("thread-events", no_class,
          &print_thread_events, _("\
-Set printing of thread events (e.g., thread start and exit)."), _("\
-Show printing of thread events (e.g., thread start and exit)."), NULL,
+Set printing of thread events (such as thread start and exit)."), _("\
+Show printing of thread events (such as thread start and exit)."), NULL,
          NULL,
          show_print_thread_events,
          &setprintlist, &showprintlist);
This page took 0.031144 seconds and 4 git commands to generate.