merge from gcc
[deliverable/binutils-gdb.git] / gdb / thread.c
index 1ce514a2d2e1d77c92f1087fb45d643b5eff718c..80d745dc306ad9d5a1eb03e65627a16d1bb1bfbe 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,6 +414,67 @@ prune_threads (void)
     }
 }
 
+static int main_thread_running = 0;
+
+void
+set_running (ptid_t ptid, int running)
+{
+  struct thread_info *tp;
+
+  if (!thread_list)
+    {
+      /* This is one of the targets that does not add main
+        thread to the thread list.  Just use a single
+        global flag to indicate that a thread is running.  
+
+        This problem is unique to ST programs.  For MT programs,
+        the main thread is always present in the thread list.  If it's
+        not, the first call to context_switch will mess up GDB internal
+        state.  */
+      if (running && !main_thread_running && !suppress_resume_observer)
+       observer_notify_target_resumed (ptid);
+      main_thread_running = running;
+      return;
+    }
+
+  /* We try not to notify the observer if no thread has actually changed 
+     the running state -- merely to reduce the number of messages to 
+     frontend.  Frontend is supposed to handle multiple *running just fine.  */
+  if (PIDGET (ptid) == -1)
+    {
+      int any_started = 0;
+      for (tp = thread_list; tp; tp = tp->next)
+       {
+         if (running && !tp->running_)
+           any_started = 1;
+         tp->running_ = running;
+       }
+      if (any_started && !suppress_resume_observer)
+       observer_notify_target_resumed (ptid);      
+    }
+  else
+    {
+      tp = find_thread_pid (ptid);
+      gdb_assert (tp);
+      if (running && !tp->running_ && !suppress_resume_observer)
+       observer_notify_target_resumed (ptid);
+      tp->running_ = running;
+    }  
+}
+
+int
+is_running (ptid_t ptid)
+{
+  struct thread_info *tp;
+
+  if (!thread_list)
+    return main_thread_running;
+
+  tp = find_thread_pid (ptid);
+  gdb_assert (tp);
+  return tp->running_;  
+}
+
 /* Prints the list of threads and their details on UIOUT.
    This is a version of 'info_thread_command' suitable for
    use from MI.  
@@ -478,8 +546,8 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
 
   if (requested_thread == -1)
     {
-      gdb_assert (current_thread != -1);
-      if (ui_out_is_mi_like_p (uiout))
+      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);
     }
 
@@ -562,7 +630,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)
 {
@@ -731,6 +799,7 @@ thread_command (char *tidstr, int from_tty)
       return;
     }
 
+  annotate_thread_changed ();
   gdb_thread_select (uiout, tidstr, NULL);
 }
 
@@ -810,8 +879,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.02542 seconds and 4 git commands to generate.