[binutils-gdb] [gdb] Add thread_control_state::step_start_function methods

Tom de Vries via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0e309221ade6ad412d5439fa20f255b213d7539a

commit 0e309221ade6ad412d5439fa20f255b213d7539a
Author: Tom de Vries <[email protected]>
Date:   Tue Apr 14 22:36:09 2026 +0200

    [gdb] Add thread_control_state::step_start_function methods
    
    Factor out all uses of thread_control_state::step_start_function into
    methods, and make the field private.
    
    Tested on x86_64-linux.
    
    Co-Authored-By: Andrew Burgess <[email protected]>
    Approved-By: Andrew Burgess <[email protected]>

Diff:
---
 gdb/gdbthread.h | 36 ++++++++++++++++++++++++++++++++++--
 gdb/infcmd.c    |  2 +-
 gdb/infrun.c    | 13 ++++++-------
 3 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index d64bf6e5a01..224e6e4b657 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -154,8 +154,36 @@ struct thread_control_state
   CORE_ADDR step_range_start = 0;	/* Inclusive */
   CORE_ADDR step_range_end = 0;		/* Exclusive */
 
-  /* Function the thread was in as of last it started stepping.  */
-  struct symbol *step_start_function = nullptr;
+  /* Set m_step_start_function according to PC.  */
+  void set_step_start_function (CORE_ADDR pc)
+  {
+    m_step_start_function = find_symbol_for_pc (pc);
+  }
+
+  /* Reset m_step_start_function.  */
+  void reset_step_start_function ()
+  {
+    m_step_start_function = nullptr;
+  }
+
+  /* Return true if the function symbol for PC matches
+     m_step_start_function.  */
+  bool in_step_start_function (CORE_ADDR pc)
+  {
+    return m_step_start_function == find_symbol_for_pc (pc);
+  }
+
+  /* Return true if m_step_start_function is set.  */
+  bool step_start_function_p ()
+  {
+    return m_step_start_function != nullptr;
+  }
+
+  /* Return m_step_start_function.  */
+  struct symbol *step_start_function ()
+  {
+    return m_step_start_function;
+  }
 
   /* If GDB issues a target step request, and this is nonzero, the
      target should single-step this thread once, and then continue
@@ -208,6 +236,10 @@ struct thread_control_state
 
   /* True if the thread is evaluating a BP condition.  */
   bool in_cond_eval = false;
+
+private:
+  /* Function the thread was in as of last it started stepping.  */
+  struct symbol *m_step_start_function = nullptr;
 };
 
 /* Inferior thread specific part of `struct infcall_suspend_state'.  */
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index fa7b273ae57..a1df59e09f2 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -899,7 +899,7 @@ set_step_frame (thread_info *tp)
   set_step_info (tp, frame, sal);
 
   CORE_ADDR pc = get_frame_pc (frame);
-  tp->control.step_start_function = find_symbol_for_pc (pc);
+  tp->control.set_step_start_function (pc);
 }
 
 /* Step until outside of current statement.  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 2c9a27325af..becd68a21ad 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3098,7 +3098,7 @@ clear_proceed_status_thread (struct thread_info *tp)
   tp->control.step_frame_id = null_frame_id;
   tp->control.step_stack_frame_id = null_frame_id;
   tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
-  tp->control.step_start_function = nullptr;
+  tp->control.reset_step_start_function ();
   tp->stop_requested = false;
 
   tp->control.stop_step = 0;
@@ -7745,9 +7745,9 @@ process_event_stop_test (struct execution_control_state *ecs)
   if (execution_direction != EXEC_REVERSE
       && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
       && in_solib_dynsym_resolve_code (ecs->event_thread->stop_pc ())
-      && (ecs->event_thread->control.step_start_function == nullptr
+      && (!ecs->event_thread->control.step_start_function_p ()
 	  || !in_solib_dynsym_resolve_code (
-	       ecs->event_thread->control.step_start_function->value_block ()
+	       ecs->event_thread->control.step_start_function ()->value_block ()
 		->entry_pc ())))
     {
       CORE_ADDR pc_after_resolver =
@@ -7871,8 +7871,8 @@ process_event_stop_test (struct execution_control_state *ecs)
 	   == ecs->event_thread->control.step_stack_frame_id)
 	  && ((ecs->event_thread->control.step_stack_frame_id
 	       != outer_frame_id)
-	      || (ecs->event_thread->control.step_start_function
-		  != find_symbol_for_pc (ecs->event_thread->stop_pc ())))))
+	      || !ecs->event_thread->control.in_step_start_function
+		    (ecs->event_thread->stop_pc ()))))
     {
       CORE_ADDR stop_pc = ecs->event_thread->stop_pc ();
       CORE_ADDR real_stop_pc;
@@ -9359,8 +9359,7 @@ print_stop_location (const target_waitstatus &ws)
       if (tp->control.stop_step
 	  && (tp->control.step_frame_id
 	      == get_frame_id (get_current_frame ()))
-	  && (tp->control.step_start_function
-	      == find_symbol_for_pc (tp->stop_pc ())))
+	  && tp->control.in_step_start_function (tp->stop_pc ()))
 	{
 	  symtab_and_line sal = find_frame_sal (get_selected_frame (nullptr));
 	  if (sal.symtab != tp->current_symtab)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.