merge from gcc
[deliverable/binutils-gdb.git] / gdb / thread.c
index beab381fad1bac844ff608c34b2205b9fb8d8b59..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 */
 
@@ -141,7 +142,8 @@ add_thread_with_info (ptid_t ptid, struct private_thread_info *private)
 
   if (print_thread_events)
     printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
-  
+
+  annotate_new_thread ();
   return result;
 }
 
@@ -412,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.  
@@ -736,6 +799,7 @@ thread_command (char *tidstr, int from_tty)
       return;
     }
 
+  annotate_thread_changed ();
   gdb_thread_select (uiout, tidstr, NULL);
 }
 
This page took 0.025134 seconds and 4 git commands to generate.