[1/2] gdb: remove call to get_current_regcache in keep_going_pass_signal

Message ID 20250107041920.1694163-1-simark@simark.ca
State New
Headers
Series [1/2] gdb: remove call to get_current_regcache in keep_going_pass_signal |

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-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Simon Marchi Jan. 7, 2025, 4:19 a.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

In keep_going_pass_signal, we call

  get_thread_regcache (ecs->event_thread)

near the top and

  get_current_regcache ()

later.  We also assert that:

  gdb_assert (ecs->event_thread->ptid == inferior_ptid);

Meaning that the event_thread will always be the current thread
(inferior_ptid and current_thread_ are always supposed to be
synchronized).  Since get_current_regcache is implemented as:

  return get_thread_regcache (inferior_thread ());

... and inferior_thread returns the current thread, it seems clear to me
that the two calls will always return the same regcache.  Remove the
call to get_current_regcache in favor of just fetching the regcache once
at the top.

Change-Id: I41b773d8529129a552a8afb3c9d65d9dd28c97ea
---
 gdb/infrun.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


base-commit: d4efbce75f1f98db0837f3791a65d9cb433f7861
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 8a10119487c4..c7a10db125a7 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -9027,9 +9027,10 @@  keep_going_pass_signal (struct execution_control_state *ecs)
   gdb_assert (ecs->event_thread->ptid == inferior_ptid);
   gdb_assert (!ecs->event_thread->resumed ());
 
+  regcache *regcache = get_thread_regcache (ecs->event_thread);
+
   /* Save the pc before execution, to compare with pc after stop.  */
-  ecs->event_thread->prev_pc
-    = regcache_read_pc_protected (get_thread_regcache (ecs->event_thread));
+  ecs->event_thread->prev_pc = regcache_read_pc_protected (regcache);
 
   if (ecs->event_thread->control.trap_expected)
     {
@@ -9066,7 +9067,6 @@  keep_going_pass_signal (struct execution_control_state *ecs)
     }
   else
     {
-      regcache *regcache = get_thread_regcache (ecs->event_thread);
       int remove_bp;
       int remove_wps;
       step_over_what step_what;