* fork-child.c (fork_inferior): Only reset the thread list if this
[deliverable/binutils-gdb.git] / gdb / thread.c
index fc3df6106b0f18bde268b93f34caf0e246f33295..95f265a7fcbb9799e41f6ad7db7e1fa267768365 100644 (file)
@@ -72,7 +72,7 @@ enum thread_state
   THREAD_EXITED,
 };
 
-extern struct thread_info*
+struct thread_info*
 inferior_thread (void)
 {
   struct thread_info *tp = find_thread_pid (inferior_ptid);
@@ -247,8 +247,7 @@ delete_thread_1 (ptid_t ptid, int silent)
     {
       if (tp->state_ != THREAD_EXITED)
        {
-         if (!silent)
-           observer_notify_thread_exit (tp);
+         observer_notify_thread_exit (tp, silent);
 
          /* Tag it as exited.  */
          tp->state_ = THREAD_EXITED;
@@ -267,8 +266,8 @@ delete_thread_1 (ptid_t ptid, int silent)
     thread_list = tp->next;
 
   /* Notify thread exit, but only if we haven't already.  */
-  if (!silent && tp->state_ != THREAD_EXITED)
-    observer_notify_thread_exit (tp);
+  if (tp->state_ != THREAD_EXITED)
+    observer_notify_thread_exit (tp, silent);
 
   free_thread (tp);
 }
@@ -402,6 +401,22 @@ in_thread_list (ptid_t ptid)
   return 0;                    /* Never heard of 'im */
 }
 
+/* Finds the first thread of the inferior given by PID.  If PID is -1,
+   return the first thread in the list.  */
+
+struct thread_info *
+first_thread_of_process (int pid)
+{
+  struct thread_info *tp, *ret = NULL;
+
+  for (tp = thread_list; tp; tp = tp->next)
+    if (pid == -1 || ptid_get_pid (tp->ptid) == pid)
+      if (ret == NULL || tp->num < ret->num)
+       ret = tp;
+
+  return ret;
+}
+
 /* Print a list of thread ids currently known, and the total number of
    threads. To be used from within catch_errors. */
 static int
@@ -494,21 +509,23 @@ void
 set_running (ptid_t ptid, int running)
 {
   struct thread_info *tp;
+  int all = ptid_equal (ptid, minus_one_ptid);
 
   /* 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)
+  if (all || ptid_is_pid (ptid))
     {
       int any_started = 0;
       for (tp = thread_list; tp; tp = tp->next)
-       {
-         if (tp->state_ == THREAD_EXITED)
-           continue;
-         if (running && tp->state_ == THREAD_STOPPED)
-           any_started = 1;
-         tp->state_ = running ? THREAD_RUNNING : THREAD_STOPPED;
-       }
+       if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
+         {
+           if (tp->state_ == THREAD_EXITED)
+             continue;
+           if (running && tp->state_ == THREAD_STOPPED)
+             any_started = 1;
+           tp->state_ = running ? THREAD_RUNNING : THREAD_STOPPED;
+         }
       if (any_started)
        observer_notify_target_resumed (ptid);
     }
@@ -601,11 +618,13 @@ void
 set_executing (ptid_t ptid, int executing)
 {
   struct thread_info *tp;
+  int all = ptid_equal (ptid, minus_one_ptid);
 
-  if (PIDGET (ptid) == -1)
+  if (all || ptid_is_pid (ptid))
     {
       for (tp = thread_list; tp; tp = tp->next)
-       tp->executing_ = executing;
+       if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
+         tp->executing_ = executing;
     }
   else
     {
@@ -837,7 +856,7 @@ switch_to_thread (ptid_t ptid)
   if (!ptid_equal (inferior_ptid, null_ptid)
       && !is_exited (ptid)
       && !is_executing (ptid))
-    stop_pc = read_pc ();
+    stop_pc = regcache_read_pc (get_thread_regcache (ptid));
   else
     stop_pc = ~(CORE_ADDR) 0;
 }
@@ -925,11 +944,10 @@ do_restore_current_thread_cleanup (void *arg)
      then don't revert back to it, but instead simply drop back to no
      thread selected.  */
   if (tp
-      && is_exited (tp->ptid)
-      && find_inferior_pid (ptid_get_pid (tp->ptid)) == NULL)
-    restore_current_thread (null_ptid);
-  else
+      && find_inferior_pid (ptid_get_pid (tp->ptid)) != NULL)
     restore_current_thread (old->inferior_ptid);
+  else
+    restore_current_thread (null_ptid);
 
   /* The running state of the originally selected thread may have
      changed, so we have to recheck it here.  */
This page took 0.038768 seconds and 4 git commands to generate.