target: add to_record_stop_replaying target method
[deliverable/binutils-gdb.git] / gdb / thread.c
index 28e5ef8b5e5ffc6ab7a6309be941a52079fee79a..0f8eded70ffb0441fb6906ae9eae9eefc6e1fde8 100644 (file)
@@ -42,7 +42,7 @@
 #include "cli/cli-decode.h"
 #include "gdb_regex.h"
 #include "cli/cli-utils.h"
-#include "continuations.h"
+#include "thread-fsm.h"
 
 /* Definition of struct thread_info exported to gdbthread.h.  */
 
@@ -158,6 +158,19 @@ thread_has_single_step_breakpoint_here (struct thread_info *tp,
          && breakpoint_has_location_inserted_here (ss_bps, aspace, addr));
 }
 
+/* See gdbthread.h.  */
+
+void
+thread_cancel_execution_command (struct thread_info *thr)
+{
+  if (thr->thread_fsm != NULL)
+    {
+      thread_fsm_clean_up (thr->thread_fsm);
+      thread_fsm_delete (thr->thread_fsm);
+      thr->thread_fsm = NULL;
+    }
+}
+
 static void
 clear_thread_inferior_resources (struct thread_info *tp)
 {
@@ -175,8 +188,7 @@ clear_thread_inferior_resources (struct thread_info *tp)
 
   btrace_teardown (tp);
 
-  do_all_intermediate_continuations_thread (tp, 1);
-  do_all_continuations_thread (tp, 1);
+  thread_cancel_execution_command (tp);
 }
 
 static void
@@ -220,9 +232,7 @@ init_thread_list (void)
 static struct thread_info *
 new_thread (ptid_t ptid)
 {
-  struct thread_info *tp;
-
-  tp = xcalloc (1, sizeof (*tp));
+  struct thread_info *tp = XCNEW (struct thread_info);
 
   tp->ptid = ptid;
   tp->num = ++highest_thread_num;
@@ -232,6 +242,7 @@ new_thread (ptid_t ptid)
   /* Nothing to follow yet.  */
   tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
   tp->state = THREAD_STOPPED;
+  tp->suspend.waitstatus.kind = TARGET_WAITKIND_IGNORE;
 
   return tp;
 }
@@ -764,7 +775,7 @@ enable_thread_stack_temporaries (ptid_t ptid)
 
   tp->stack_temporaries_enabled = 1;
   tp->stack_temporaries = NULL;
-  data = (ptid_t *) xmalloc (sizeof (ptid_t));
+  data = XNEW (ptid_t);
   *data = ptid;
   c = make_cleanup (disable_thread_stack_temporaries, data);
 
@@ -852,44 +863,84 @@ thread_change_ptid (ptid_t old_ptid, ptid_t new_ptid)
   observer_notify_thread_ptid_changed (old_ptid, new_ptid);
 }
 
+/* See gdbthread.h.  */
+
+void
+set_resumed (ptid_t ptid, int resumed)
+{
+  struct thread_info *tp;
+  int all = ptid_equal (ptid, minus_one_ptid);
+
+  if (all || ptid_is_pid (ptid))
+    {
+      for (tp = thread_list; tp; tp = tp->next)
+       if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
+         tp->resumed = resumed;
+    }
+  else
+    {
+      tp = find_thread_ptid (ptid);
+      gdb_assert (tp != NULL);
+      tp->resumed = resumed;
+    }
+}
+
+/* Helper for set_running, that marks one thread either running or
+   stopped.  */
+
+static int
+set_running_thread (struct thread_info *tp, int running)
+{
+  int started = 0;
+
+  if (running && tp->state == THREAD_STOPPED)
+    started = 1;
+  tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
+
+  if (!running)
+    {
+      /* If the thread is now marked stopped, remove it from
+        the step-over queue, so that we don't try to resume
+        it until the user wants it to.  */
+      if (tp->step_over_next != NULL)
+       thread_step_over_chain_remove (tp);
+    }
+
+  return started;
+}
+
 void
 set_running (ptid_t ptid, int running)
 {
   struct thread_info *tp;
   int all = ptid_equal (ptid, minus_one_ptid);
+  int any_started = 0;
 
   /* 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 (all || ptid_is_pid (ptid))
     {
-      int any_started = 0;
-
       for (tp = thread_list; tp; tp = tp->next)
        if (all || ptid_get_pid (tp->ptid) == ptid_get_pid (ptid))
          {
            if (tp->state == THREAD_EXITED)
              continue;
-           if (running && tp->state == THREAD_STOPPED)
+
+           if (set_running_thread (tp, running))
              any_started = 1;
-           tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
          }
-      if (any_started)
-       observer_notify_target_resumed (ptid);
     }
   else
     {
-      int started = 0;
-
       tp = find_thread_ptid (ptid);
-      gdb_assert (tp);
+      gdb_assert (tp != NULL);
       gdb_assert (tp->state != THREAD_EXITED);
-      if (running && tp->state == THREAD_STOPPED)
-       started = 1;
-      tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
-      if (started)
-       observer_notify_target_resumed (ptid);
+      if (set_running_thread (tp, running))
+       any_started = 1;
     }
+  if (any_started)
+    observer_notify_target_resumed (ptid);
 }
 
 static int
@@ -1008,9 +1059,8 @@ finish_thread_state (ptid_t ptid)
            continue;
          if (all || ptid_get_pid (ptid) == ptid_get_pid (tp->ptid))
            {
-             if (tp->executing && tp->state == THREAD_STOPPED)
+             if (set_running_thread (tp, tp->executing))
                any_started = 1;
-             tp->state = tp->executing ? THREAD_RUNNING : THREAD_STOPPED;
            }
        }
     }
@@ -1020,9 +1070,8 @@ finish_thread_state (ptid_t ptid)
       gdb_assert (tp);
       if (tp->state != THREAD_EXITED)
        {
-         if (tp->executing && tp->state == THREAD_STOPPED)
+         if (set_running_thread (tp, tp->executing))
            any_started = 1;
-         tp->state = tp->executing ? THREAD_RUNNING : THREAD_STOPPED;
        }
     }
 
@@ -1472,9 +1521,8 @@ make_cleanup_restore_current_thread (void)
 {
   struct thread_info *tp;
   struct frame_info *frame;
-  struct current_thread_cleanup *old;
+  struct current_thread_cleanup *old = XNEW (struct current_thread_cleanup);
 
-  old = xmalloc (sizeof (struct current_thread_cleanup));
   old->inferior_ptid = inferior_ptid;
   old->inf_id = current_inferior ()->num;
   old->was_removable = current_inferior ()->removable;
@@ -1578,7 +1626,7 @@ thread_apply_all_command (char *cmd, int from_tty)
 
       /* Save a copy of the thread_list in case we execute detach
          command.  */
-      tp_array = xmalloc (sizeof (struct thread_info *) * tc);
+      tp_array = XNEWVEC (struct thread_info *, tc);
       make_cleanup (xfree, tp_array);
 
       ALL_NON_EXITED_THREADS (tp)
This page took 0.026166 seconds and 4 git commands to generate.