gdb: add target_ops::supports_displaced_step
[deliverable/binutils-gdb.git] / gdb / thread.c
index 302a49e9845eeca251240ac42dabb01abe8752e3..7496da4e571b87d9d47e1f99ffcb0c1077cdbf07 100644 (file)
@@ -198,7 +198,7 @@ set_thread_exited (thread_info *tp, int silent)
 {
   /* Dead threads don't need to step-over.  Remove from queue.  */
   if (tp->step_over_next != NULL)
-    thread_step_over_chain_remove (tp);
+    global_thread_step_over_chain_remove (tp);
 
   if (tp->state != THREAD_EXITED)
     {
@@ -367,6 +367,20 @@ thread_info::deletable () const
   return refcount () == 0 && !is_current_thread (this);
 }
 
+/* See gdbthread.h.  */
+regcache *
+thread_info::regcache ()
+{
+  return get_thread_regcache (this);
+}
+
+/* See gdbthread.h.  */
+gdbarch *
+thread_info::arch ()
+{
+  return this->regcache ()-> arch ();
+}
+
 /* Add TP to the end of the step-over chain LIST_P.  */
 
 static void
@@ -392,10 +406,10 @@ step_over_chain_enqueue (struct thread_info **list_p, struct thread_info *tp)
     }
 }
 
-/* Remove TP from step-over chain LIST_P.  */
+/* See gdbthread.h.  */
 
-static void
-step_over_chain_remove (struct thread_info **list_p, struct thread_info *tp)
+void
+thread_step_over_chain_remove (thread_info **list_p, thread_info *tp)
 {
   gdb_assert (tp->step_over_next != NULL);
   gdb_assert (tp->step_over_prev != NULL);
@@ -415,12 +429,28 @@ step_over_chain_remove (struct thread_info **list_p, struct thread_info *tp)
 
 /* See gdbthread.h.  */
 
-struct thread_info *
-thread_step_over_chain_next (struct thread_info *tp)
+void
+global_thread_step_over_chain_remove (thread_info *tp)
 {
-  struct thread_info *next = tp->step_over_next;
+  thread_step_over_chain_remove (&global_thread_step_over_chain_head, tp);
+}
+
+/* See gdbthread.h.  */
 
-  return (next == step_over_queue_head ? NULL : next);
+thread_info *
+thread_step_over_chain_next (thread_info *chain_head, thread_info *tp)
+{
+  thread_info *next = tp->step_over_next;
+
+  return next == chain_head ? NULL : next;
+}
+
+/* See gdbthread.h.  */
+
+thread_info *
+global_thread_step_over_chain_next (thread_info *tp)
+{
+  return thread_step_over_chain_next (global_thread_step_over_chain_head, tp);
 }
 
 /* See gdbthread.h.  */
@@ -433,18 +463,33 @@ thread_is_in_step_over_chain (struct thread_info *tp)
 
 /* See gdbthread.h.  */
 
-void
-thread_step_over_chain_enqueue (struct thread_info *tp)
+int thread_step_over_chain_length (thread_info *tp)
 {
-  step_over_chain_enqueue (&step_over_queue_head, tp);
+  if (tp == nullptr)
+    return 0;
+
+  int num = 1;
+  thread_info *iter = tp->step_over_next;
+
+  while (iter != tp)
+    {
+      num++;
+      iter = iter->step_over_next;
+    }
+
+  return num;
+
+
 }
 
 /* See gdbthread.h.  */
 
 void
-thread_step_over_chain_remove (struct thread_info *tp)
+global_thread_step_over_chain_enqueue (struct thread_info *tp)
 {
-  step_over_chain_remove (&step_over_queue_head, tp);
+  if (debug_infrun)
+    fprintf_unfiltered (gdb_stdlog, "enqueueing thread %ld in global step over chain\n", tp->ptid.lwp());
+  step_over_chain_enqueue (&global_thread_step_over_chain_head, tp);
 }
 
 /* Delete the thread referenced by THR.  If SILENT, don't notify
@@ -823,13 +868,13 @@ set_resumed (process_stratum_target *targ, ptid_t ptid, bool resumed)
 /* Helper for set_running, that marks one thread either running or
    stopped.  */
 
-static int
-set_running_thread (struct thread_info *tp, int running)
+static bool
+set_running_thread (struct thread_info *tp, bool running)
 {
-  int started = 0;
+  bool started = false;
 
   if (running && tp->state == THREAD_STOPPED)
-    started = 1;
+    started = true;
   tp->state = running ? THREAD_RUNNING : THREAD_STOPPED;
 
   if (!running)
@@ -838,7 +883,7 @@ set_running_thread (struct thread_info *tp, int running)
         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);
+       global_thread_step_over_chain_remove (tp);
     }
 
   return started;
@@ -1488,8 +1533,16 @@ scoped_restore_current_thread::scoped_restore_current_thread ()
       else
        frame = NULL;
 
-      m_selected_frame_id = get_frame_id (frame);
-      m_selected_frame_level = frame_relative_level (frame);
+      try
+       {
+         m_selected_frame_id = get_frame_id (frame);
+         m_selected_frame_level = frame_relative_level (frame);
+       }
+      catch (const gdb_exception_error &ex)
+       {
+         m_selected_frame_id = null_frame_id;
+         m_selected_frame_level = -1;
+       }
 
       tp->incref ();
       m_thread = tp;
@@ -1563,6 +1616,14 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
                   const qcs_flags &flags)
 {
   switch_to_thread (thr);
+
+  /* The thread header is computed before running the command since
+     the command can change the inferior, which is not permitted
+     by thread_target_id_str.  */
+  std::string thr_header =
+    string_printf (_("\nThread %s (%s):\n"), print_thread_id (thr),
+                  thread_target_id_str (thr).c_str ());
+
   try
     {
       std::string cmd_result = execute_command_to_string
@@ -1570,9 +1631,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
       if (!flags.silent || cmd_result.length () > 0)
        {
          if (!flags.quiet)
-           printf_filtered (_("\nThread %s (%s):\n"),
-                            print_thread_id (thr),
-                            target_pid_to_str (inferior_ptid).c_str ());
+           printf_filtered ("%s", thr_header.c_str ());
          printf_filtered ("%s", cmd_result.c_str ());
        }
     }
@@ -1581,9 +1640,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
       if (!flags.silent)
        {
          if (!flags.quiet)
-           printf_filtered (_("\nThread %s (%s):\n"),
-                            print_thread_id (thr),
-                            target_pid_to_str (inferior_ptid).c_str ());
+           printf_filtered ("%s", thr_header.c_str ());
          if (flags.cont)
            printf_filtered ("%s\n", ex.what ());
          else
@@ -2031,7 +2088,7 @@ thread_select (const char *tidstr, thread_info *tp)
 
   /* Since the current thread may have changed, see if there is any
      exited thread we can now delete.  */
-  prune_threads ();
+  delete_exited_threads ();
 }
 
 /* Print thread and frame switch command response.  */
This page took 0.026785 seconds and 4 git commands to generate.