* infrun.c (normal_stop): Don't call
[deliverable/binutils-gdb.git] / gdb / thread.c
index 02fb845abf545a9dfd78fd184698a923d01d7aa5..8a98b8ec4b6af57b6f57cd55c4ba94ccf6a7babc 100644 (file)
@@ -1,7 +1,8 @@
 /* Multi-process/thread control for GDB, the GNU debugger.
 
    Copyright (C) 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2007, 2008, 2009
+   Free Software Foundation, Inc.
 
    Contributed by Lynx Real-Time Systems, Inc.  Los Gatos, CA.
 
@@ -631,14 +632,68 @@ set_stop_requested (ptid_t ptid, int stop)
     observer_notify_thread_stop_requested (ptid);
 }
 
+void
+finish_thread_state (ptid_t ptid)
+{
+  struct thread_info *tp;
+  int all;
+  int any_started = 0;
+
+  all = ptid_equal (ptid, minus_one_ptid);
+
+  if (all || ptid_is_pid (ptid))
+    {
+      for (tp = thread_list; tp; tp = tp->next)
+       {
+         if (tp->state_ == THREAD_EXITED)
+           continue;
+         if (all || ptid_get_pid (ptid) == ptid_get_pid (tp->ptid))
+           {
+             if (tp->executing_ && tp->state_ == THREAD_STOPPED)
+               any_started = 1;
+             tp->state_ = tp->executing_ ? THREAD_RUNNING : THREAD_STOPPED;
+           }
+       }
+    }
+  else
+    {
+      tp = find_thread_pid (ptid);
+      gdb_assert (tp);
+      if (tp->state_ != THREAD_EXITED)
+       {
+         if (tp->executing_ && tp->state_ == THREAD_STOPPED)
+           any_started = 1;
+         tp->state_ = tp->executing_ ? THREAD_RUNNING : THREAD_STOPPED;
+       }
+    }
+
+  if (any_started)
+    observer_notify_target_resumed (ptid);
+}
+
+void
+finish_thread_state_cleanup (void *arg)
+{
+  ptid_t *ptid_p = arg;
+
+  gdb_assert (arg);
+
+  finish_thread_state (*ptid_p);
+}
+
 /* Prints the list of threads and their details on UIOUT.
    This is a version of 'info_thread_command' suitable for
    use from MI.  
    If REQUESTED_THREAD is not -1, it's the GDB id of the thread
    that should be printed.  Otherwise, all threads are
-   printed.  */
+   printed.  
+   If PID is not -1, only print threads from the process PID.
+   Otherwise, threads from all attached PIDs are printed.   
+   If both REQUESTED_THREAD and PID are not -1, then the thread
+   is printed if it belongs to the specified process.  Otherwise,
+   an error is raised.  */
 void
-print_thread_info (struct ui_out *uiout, int requested_thread)
+print_thread_info (struct ui_out *uiout, int requested_thread, int pid)
 {
   struct thread_info *tp;
   ptid_t current_ptid;
@@ -661,6 +716,13 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
       if (requested_thread != -1 && tp->num != requested_thread)
        continue;
 
+      if (pid != -1 && PIDGET (tp->ptid) != pid)
+       {
+         if (requested_thread != -1)
+           error (_("Requested thread not found in requested process"));
+         continue;
+       }
+
       if (ptid_equal (tp->ptid, current_ptid))
        current_thread = tp->num;
 
@@ -678,17 +740,14 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
       ui_out_text (uiout, " ");
       ui_out_field_string (uiout, "target-id", target_tid_to_str (tp->ptid));
 
-      if (tp->state_ != THREAD_EXITED)
+      extra_info = target_extra_thread_info (tp);
+      if (extra_info)
        {
-         extra_info = target_extra_thread_info (tp);
-         if (extra_info)
-           {
-             ui_out_text (uiout, " (");
-             ui_out_field_string (uiout, "details", extra_info);
-             ui_out_text (uiout, ")");
-           }
-         ui_out_text (uiout, "  ");
+         ui_out_text (uiout, " (");
+         ui_out_field_string (uiout, "details", extra_info);
+         ui_out_text (uiout, ")");
        }
+      ui_out_text (uiout, "  ");
 
       if (tp->state_ == THREAD_RUNNING)
        ui_out_text (uiout, "(running)\n");
@@ -706,9 +765,7 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
       if (ui_out_is_mi_like_p (uiout))
        {
          char *state = "stopped";
-         if (tp->state_ == THREAD_EXITED)
-           state = "exited";
-         else if (tp->state_ == THREAD_RUNNING)
+         if (tp->state_ == THREAD_RUNNING)
            state = "running";
          ui_out_field_string (uiout, "state", state);
        }
@@ -720,7 +777,7 @@ print_thread_info (struct ui_out *uiout, int requested_thread)
      the "info threads" command.  */
   do_cleanups (old_chain);
 
-  if (requested_thread == -1)
+  if (pid == -1 && requested_thread == -1 )
     {
       gdb_assert (current_thread != -1
                  || !thread_list);
@@ -745,7 +802,7 @@ The current thread <Thread ID %d> has terminated.  See `help thread'.\n",
 static void
 info_threads_command (char *arg, int from_tty)
 {
-  print_thread_info (uiout, -1);
+  print_thread_info (uiout, -1, -1);
 }
 
 /* Switch from one thread to another. */
@@ -1037,7 +1094,6 @@ thread_command (char *tidstr, int from_tty)
       return;
     }
 
-  annotate_thread_changed ();
   gdb_thread_select (uiout, tidstr, NULL);
 }
 
@@ -1070,6 +1126,8 @@ do_captured_thread_select (struct ui_out *uiout, void *tidstr)
 
   switch_to_thread (tp->ptid);
 
+  annotate_thread_changed ();
+
   ui_out_text (uiout, "[Switching to thread ");
   ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid));
   ui_out_text (uiout, " (");
This page took 0.030981 seconds and 4 git commands to generate.