[v7,1/6] gdb: use schedlock_applies in user_visible_resume_ptid.

Message ID 20260325134328.550990-2-klaus.gerlicher@intel.com
State New
Headers
Series gdb: refine scheduler locking settings |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Klaus Gerlicher March 25, 2026, 1:43 p.m. UTC
  From: Natalia Saiapova <natalia.saiapova@intel.com>

This is a refactoring.  The logic in user_visible_resume_ptid is very
similar to schedlock_applies, but uses `step` and `record_will_replay`
parameter instead of `tp->control.stepping_command`.

Refactor schedlock_applies logic into the following two overloaded methods:
  bool schedlock_applies (thread_info *tp)
and
  bool schedlock_applies (bool step, bool record_will_replay)
such that they share the logic.

Update the call-sites accordingly, where we have only the thread, use
the former, and where we have the bool step or record_will_replay use the
latter.

Approved-By: Tom Tromey <tom@tromey.com>
---
 gdb/infrun.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 9864b5bbdec..ba57a82c83e 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -108,6 +108,7 @@  static bool start_step_over (void);
 static bool step_over_info_valid_p (void);
 
 static bool schedlock_applies (struct thread_info *tp);
+static bool schedlock_applies (bool step, bool record_will_replay);
 
 /* Asynchronous signal handler registered as event loop source for
    when we have pending events ready to be passed to the core.  */
@@ -2391,20 +2392,14 @@  user_visible_resume_ptid (int step)
 	 individually.  */
       resume_ptid = inferior_ptid;
     }
-  else if ((scheduler_mode == schedlock_on)
-	   || (scheduler_mode == schedlock_step && step))
+  else if (schedlock_applies (step,
+			      target_record_will_replay (inferior_ptid,
+							 execution_direction)))
     {
       /* User-settable 'scheduler' mode requires solo thread
 	 resume.  */
       resume_ptid = inferior_ptid;
     }
-  else if ((scheduler_mode == schedlock_replay)
-	   && target_record_will_replay (inferior_ptid, execution_direction))
-    {
-      /* User-settable 'scheduler' mode requires solo thread resume in replay
-	 mode.  */
-      resume_ptid = inferior_ptid;
-    }
   else if (inferior_ptid != null_ptid
 	   && inferior_thread ()->control.in_cond_eval)
     {
@@ -3193,17 +3188,32 @@  thread_still_needs_step_over (struct thread_info *tp)
   return what;
 }
 
+/* Returns true if scheduler locking applies to TP.  */
+
+static bool
+schedlock_applies (thread_info *tp)
+{
+  bool step = false;
+  bool record_will_replay = false;
+  if (tp != nullptr)
+    {
+      step = tp->control.stepping_command;
+      record_will_replay
+	= target_record_will_replay (tp->ptid, execution_direction);
+    }
+  return schedlock_applies (step, record_will_replay);
+}
+
 /* Returns true if scheduler locking applies.  STEP indicates whether
-   we're about to do a step/next-like command to a thread.  */
+   we're about to do a step/next-like command and RECORD_WILL_REPLAY
+   indicates whether we're about to replay.  */
 
 static bool
-schedlock_applies (struct thread_info *tp)
+schedlock_applies (bool step, bool record_will_replay)
 {
   return (scheduler_mode == schedlock_on
-	  || (scheduler_mode == schedlock_step
-	      && tp->control.stepping_command)
-	  || (scheduler_mode == schedlock_replay
-	      && target_record_will_replay (tp->ptid, execution_direction)));
+	  || (scheduler_mode == schedlock_step && step)
+	  || (scheduler_mode == schedlock_replay && record_will_replay));
 }
 
 /* When FORCE_P is false, set process_stratum_target::COMMIT_RESUMED_STATE