+ This assume that PTID is a valid ptid_t. Otherwise, a gdb_assert
+ will be triggered. */
+
+static int
+ravenscar_get_thread_base_cpu (ptid_t ptid)
+{
+ int base_cpu;
+
+ if (is_ravenscar_task (ptid))
+ {
+ struct ada_task_info *task_info = ada_get_task_info_from_ptid (ptid);
+
+ gdb_assert (task_info != NULL);
+ base_cpu = task_info->base_cpu;
+ }
+ else
+ {
+ /* We assume that the LWP of the PTID is equal to the CPU number. */
+ base_cpu = ptid.lwp ();
+ }
+
+ return base_cpu;
+}
+
+/* Given a ravenscar task (identified by its ptid_t PTID), return true
+ if this task is the currently active task on the cpu that task is
+ running on.
+
+ In other words, this function determine which CPU this task is
+ currently running on, and then return nonzero if the CPU in question
+ is executing the code for that task. If that's the case, then
+ that task's registers are in the CPU bank. Otherwise, the task
+ is currently suspended, and its registers have been saved in memory. */
+
+bool
+ravenscar_thread_target::task_is_currently_active (ptid_t ptid)
+{
+ ptid_t active_task_ptid
+ = active_task (ravenscar_get_thread_base_cpu (ptid));
+
+ return ptid == active_task_ptid;
+}
+
+/* Return the CPU thread (as a ptid_t) on which the given ravenscar
+ task is running.
+
+ This is the thread that corresponds to the CPU on which the task
+ is running. */
+
+static ptid_t
+get_base_thread_from_ravenscar_task (ptid_t ptid)
+{
+ int base_cpu;
+
+ if (!is_ravenscar_task (ptid))
+ return ptid;
+
+ base_cpu = ravenscar_get_thread_base_cpu (ptid);
+ return ptid_t (ptid.pid (), base_cpu, 0);
+}
+
+/* Fetch the ravenscar running thread from target memory, make sure
+ there's a corresponding thread in the thread list, and return it.
+ If the runtime is not initialized, return NULL. */
+
+thread_info *
+ravenscar_thread_target::add_active_thread ()
+{
+ process_stratum_target *proc_target
+ = as_process_stratum_target (this->beneath ());
+
+ int base_cpu;
+
+ gdb_assert (!is_ravenscar_task (m_base_ptid));
+ base_cpu = ravenscar_get_thread_base_cpu (m_base_ptid);
+
+ if (!runtime_initialized ())
+ return nullptr;
+
+ /* Make sure we set m_base_ptid before calling active_task