[v2,12/12] Fix remaining Ravenscar regressions

Message ID 20200805190841.2506771-13-tromey@adacore.com
State New
Headers show
Series
  • Fix Ravenscar regressions
Related show

Commit Message

Tom Tromey Aug. 5, 2020, 7:08 p.m.
Testing showed a few more Ravenscar regressions arising from upstream.
In particular, gdb now uses the current thread in some places where
inferior_ptid was previously used.  This patch fixes the problem by
arranging to save and restore the thread now.

gdb/ChangeLog
2020-08-05  Tom Tromey  <tromey@adacore.com>

	* ravenscar-thread.c
	(ravenscar_thread_target::set_base_thread_from_ravenscar_task):
	New method.
	(ravenscar_thread_target::wait): Check
	runtime_initialized.
	(ravenscar_thread_target::prepare_to_store)
	(ravenscar_thread_target::stopped_by_sw_breakpoint)
	(ravenscar_thread_target::stopped_by_hw_breakpoint)
	(ravenscar_thread_target::stopped_by_watchpoint)
	(ravenscar_thread_target::stopped_data_address)
	(ravenscar_thread_target::core_of_thread): Use
	scoped_restore_current_thread and
	set_base_thread_from_ravenscar_task.
---
 gdb/ChangeLog          | 16 ++++++++++++++++
 gdb/ravenscar-thread.c | 29 +++++++++++++++++++----------
 2 files changed, 35 insertions(+), 10 deletions(-)

-- 
2.26.2

Patch

diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c
index 37df2188cf3..387ebcb32e9 100644
--- a/gdb/ravenscar-thread.c
+++ b/gdb/ravenscar-thread.c
@@ -151,6 +151,15 @@  struct ravenscar_thread_target final : public target_ops
   ptid_t get_base_thread_from_ravenscar_task (ptid_t ptid);
   void add_thread (struct ada_task_info *task);
 
+  /* Like switch_to_thread, but uses the base ptid for the thread.  */
+  void set_base_thread_from_ravenscar_task (ptid_t ptid)
+  {
+    process_stratum_target *proc_target
+      = as_process_stratum_target (this->beneath ());
+    ptid_t underlying = get_base_thread_from_ravenscar_task (ptid);
+    switch_to_thread (find_thread_ptid (proc_target, underlying));
+  }
+
   /* This maps a TID to the CPU on which it was running.  This is
      needed because sometimes the runtime will report an active task
      that hasn't yet been put on the list of tasks that is read by
@@ -571,8 +580,8 @@  ravenscar_thread_target::prepare_to_store (struct regcache *regcache)
 bool
 ravenscar_thread_target::stopped_by_sw_breakpoint ()
 {
-  scoped_restore save_ptid = make_scoped_restore (&inferior_ptid);
-  inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid);
+  scoped_restore_current_thread saver;
+  set_base_thread_from_ravenscar_task (inferior_ptid);
   return beneath ()->stopped_by_sw_breakpoint ();
 }
 
@@ -581,8 +590,8 @@  ravenscar_thread_target::stopped_by_sw_breakpoint ()
 bool
 ravenscar_thread_target::stopped_by_hw_breakpoint ()
 {
-  scoped_restore save_ptid = make_scoped_restore (&inferior_ptid);
-  inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid);
+  scoped_restore_current_thread saver;
+  set_base_thread_from_ravenscar_task (inferior_ptid);
   return beneath ()->stopped_by_hw_breakpoint ();
 }
 
@@ -591,8 +600,8 @@  ravenscar_thread_target::stopped_by_hw_breakpoint ()
 bool
 ravenscar_thread_target::stopped_by_watchpoint ()
 {
-  scoped_restore save_ptid = make_scoped_restore (&inferior_ptid);
-  inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid);
+  scoped_restore_current_thread saver;
+  set_base_thread_from_ravenscar_task (inferior_ptid);
   return beneath ()->stopped_by_watchpoint ();
 }
 
@@ -601,8 +610,8 @@  ravenscar_thread_target::stopped_by_watchpoint ()
 bool
 ravenscar_thread_target::stopped_data_address (CORE_ADDR *addr_p)
 {
-  scoped_restore save_ptid = make_scoped_restore (&inferior_ptid);
-  inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid);
+  scoped_restore_current_thread saver;
+  set_base_thread_from_ravenscar_task (inferior_ptid);
   return beneath ()->stopped_data_address (addr_p);
 }
 
@@ -620,8 +629,8 @@  ravenscar_thread_target::mourn_inferior ()
 int
 ravenscar_thread_target::core_of_thread (ptid_t ptid)
 {
-  scoped_restore save_ptid = make_scoped_restore (&inferior_ptid);
-  inferior_ptid = get_base_thread_from_ravenscar_task (inferior_ptid);
+  scoped_restore_current_thread saver;
+  set_base_thread_from_ravenscar_task (inferior_ptid);
   return beneath ()->core_of_thread (inferior_ptid);
 }