[binutils-gdb] gdb: pass address_space to target dcache functions

Simon Marchi simark@sourceware.org
Fri Nov 17 20:59:51 GMT 2023


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=413366203156a0483d06a97b3f02b64ba6a215cc

commit 413366203156a0483d06a97b3f02b64ba6a215cc
Author: Simon Marchi <simon.marchi@efficios.com>
Date:   Sun Nov 5 04:52:39 2023 +0000

    gdb: pass address_space to target dcache functions
    
    A simple refactor to make the reference to current_program_space bubble
    up one level.  No behavior changes expected.
    
    Change-Id: I237cf2f45ae73c35bcb433ce40e3c03cef6b87e2

Diff:
---
 gdb/dcache.c        |  6 +++---
 gdb/infrun.c        |  6 +++---
 gdb/memattr.c       |  7 ++++---
 gdb/target-dcache.c | 24 ++++++++++++------------
 gdb/target-dcache.h | 10 ++++++----
 gdb/target.c        | 11 ++++++-----
 gdb/top.c           |  2 +-
 gdb/tracepoint.c    |  2 +-
 8 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/gdb/dcache.c b/gdb/dcache.c
index 8a5fb13acf5..229c13f8b5f 100644
--- a/gdb/dcache.c
+++ b/gdb/dcache.c
@@ -651,7 +651,7 @@ dcache_info_1 (DCACHE *dcache, const char *exp)
 static void
 info_dcache_command (const char *exp, int tty)
 {
-  dcache_info_1 (target_dcache_get (), exp);
+  dcache_info_1 (target_dcache_get (current_program_space->aspace), exp);
 }
 
 static void
@@ -663,7 +663,7 @@ set_dcache_size (const char *args, int from_tty,
       dcache_size = DCACHE_DEFAULT_SIZE;
       error (_("Dcache size must be greater than 0."));
     }
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 }
 
 static void
@@ -677,7 +677,7 @@ set_dcache_line_size (const char *args, int from_tty,
       dcache_line_size = DCACHE_DEFAULT_LINE_SIZE;
       error (_("Invalid dcache line size: %u (must be power of 2)."), d);
     }
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 }
 
 void _initialize_dcache ();
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 4138d00b0f4..08c39eb76f3 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4356,7 +4356,7 @@ wait_for_inferior (inferior *inf)
 	 Target was running and cache could be stale.  This is just a
 	 heuristic.  Running threads may modify target memory, but we
 	 don't get any event.  */
-      target_dcache_invalidate ();
+      target_dcache_invalidate (current_program_space->aspace);
 
       ecs.ptid = do_target_wait_1 (inf, minus_one_ptid, &ecs.ws, 0);
       ecs.target = inf->process_target ();
@@ -4605,7 +4605,7 @@ fetch_inferior_event ()
        was running and cache could be stale.  This is just a heuristic.
        Running threads may modify target memory, but we don't get any
        event.  */
-    target_dcache_invalidate ();
+    target_dcache_invalidate (current_program_space->aspace);
 
     scoped_restore save_exec_dir
       = make_scoped_restore (&execution_direction,
@@ -5184,7 +5184,7 @@ poll_one_curr_target (struct target_waitstatus *ws)
      Target was running and cache could be stale.  This is just a
      heuristic.  Running threads may modify target memory, but we
      don't get any event.  */
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 
   event_ptid = target_wait (minus_one_ptid, ws, TARGET_WNOHANG);
 
diff --git a/gdb/memattr.c b/gdb/memattr.c
index 8b0e3ef7b7e..44ccd9f6cd1 100644
--- a/gdb/memattr.c
+++ b/gdb/memattr.c
@@ -30,6 +30,7 @@
 #include <algorithm>
 #include "gdbarch.h"
 #include "inferior.h"
+#include "progspace.h"
 
 static std::vector<mem_region> user_mem_region_list, target_mem_region_list;
 static std::vector<mem_region> *mem_region_list = &target_mem_region_list;
@@ -483,7 +484,7 @@ enable_mem_command (const char *args, int from_tty)
 {
   require_user_regions (from_tty);
 
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 
   if (args == NULL || *args == '\0')
     { /* Enable all mem regions.  */
@@ -521,7 +522,7 @@ disable_mem_command (const char *args, int from_tty)
 {
   require_user_regions (from_tty);
 
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 
   if (args == NULL || *args == '\0')
     {
@@ -567,7 +568,7 @@ delete_mem_command (const char *args, int from_tty)
 {
   require_user_regions (from_tty);
 
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 
   if (args == NULL || *args == '\0')
     {
diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c
index 13c2888e7ea..4c4fef902c4 100644
--- a/gdb/target-dcache.c
+++ b/gdb/target-dcache.c
@@ -30,10 +30,10 @@ static const registry<address_space>::key<DCACHE, dcache_deleter>
 /* Target dcache is initialized or not.  */
 
 int
-target_dcache_init_p (void)
+target_dcache_init_p (address_space *aspace)
 {
   DCACHE *dcache
-    = target_dcache_aspace_key.get (current_program_space->aspace);
+    = target_dcache_aspace_key.get (aspace);
 
   return (dcache != NULL);
 }
@@ -41,10 +41,10 @@ target_dcache_init_p (void)
 /* Invalidate the target dcache.  */
 
 void
-target_dcache_invalidate (void)
+target_dcache_invalidate (address_space *aspace)
 {
   DCACHE *dcache
-    = target_dcache_aspace_key.get (current_program_space->aspace);
+    = target_dcache_aspace_key.get (aspace);
 
   if (dcache != NULL)
     dcache_invalidate (dcache);
@@ -54,24 +54,24 @@ target_dcache_invalidate (void)
    initialized yet.  */
 
 DCACHE *
-target_dcache_get (void)
+target_dcache_get (address_space *aspace)
 {
-  return target_dcache_aspace_key.get (current_program_space->aspace);
+  return target_dcache_aspace_key.get (aspace);
 }
 
 /* Return the target dcache.  If it is not initialized yet, initialize
    it.  */
 
 DCACHE *
-target_dcache_get_or_init (void)
+target_dcache_get_or_init (address_space *aspace)
 {
   DCACHE *dcache
-    = target_dcache_aspace_key.get (current_program_space->aspace);
+    = target_dcache_aspace_key.get (aspace);
 
   if (dcache == NULL)
     {
       dcache = dcache_init ();
-      target_dcache_aspace_key.set (current_program_space->aspace, dcache);
+      target_dcache_aspace_key.set (aspace, dcache);
     }
 
   return dcache;
@@ -93,7 +93,7 @@ static void
 set_stack_cache (const char *args, int from_tty, struct cmd_list_element *c)
 {
   if (stack_cache_enabled != stack_cache_enabled_1)
-    target_dcache_invalidate ();
+    target_dcache_invalidate (current_program_space->aspace);
 
   stack_cache_enabled = stack_cache_enabled_1;
 }
@@ -131,7 +131,7 @@ static void
 set_code_cache (const char *args, int from_tty, struct cmd_list_element *c)
 {
   if (code_cache_enabled != code_cache_enabled_1)
-    target_dcache_invalidate ();
+    target_dcache_invalidate (current_program_space->aspace);
 
   code_cache_enabled = code_cache_enabled_1;
 }
@@ -158,7 +158,7 @@ code_cache_enabled_p (void)
 static void
 maint_flush_dcache_command (const char *command, int from_tty)
 {
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
   if (from_tty)
     gdb_printf (_("The dcache was flushed.\n"));
 }
diff --git a/gdb/target-dcache.h b/gdb/target-dcache.h
index 1e9e9725f95..4693b388110 100644
--- a/gdb/target-dcache.h
+++ b/gdb/target-dcache.h
@@ -20,13 +20,15 @@
 
 #include "dcache.h"
 
-extern void target_dcache_invalidate (void);
+struct address_space;
 
-extern DCACHE *target_dcache_get (void);
+extern void target_dcache_invalidate (address_space *aspace);
 
-extern DCACHE *target_dcache_get_or_init (void);
+extern DCACHE *target_dcache_get (address_space *aspace);
 
-extern int target_dcache_init_p (void);
+extern DCACHE *target_dcache_get_or_init (address_space *aspace);
+
+extern int target_dcache_init_p (address_space *aspace);
 
 extern int stack_cache_enabled_p (void);
 
diff --git a/gdb/target.c b/gdb/target.c
index a93740bbbdd..8e5c934b457 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -893,7 +893,7 @@ target_kill (void)
 void
 target_load (const char *arg, int from_tty)
 {
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
   current_inferior ()->top_target ()->load (arg, from_tty);
 }
 
@@ -1473,10 +1473,10 @@ raw_memory_xfer_partial (struct target_ops *ops, gdb_byte *readbuf,
      that never made it to the target.  */
   if (writebuf != NULL
       && inferior_ptid != null_ptid
-      && target_dcache_init_p ()
+      && target_dcache_init_p (current_program_space->aspace)
       && (stack_cache_enabled_p () || code_cache_enabled_p ()))
     {
-      DCACHE *dcache = target_dcache_get ();
+      DCACHE *dcache = target_dcache_get (current_program_space->aspace);
 
       /* Note that writing to an area of memory which wasn't present
 	 in the cache doesn't cause it to be loaded in.  */
@@ -1559,7 +1559,8 @@ memory_xfer_partial_1 (struct target_ops *ops, enum target_object object,
 	  || (stack_cache_enabled_p () && object == TARGET_OBJECT_STACK_MEMORY)
 	  || (code_cache_enabled_p () && object == TARGET_OBJECT_CODE_MEMORY)))
     {
-      DCACHE *dcache = target_dcache_get_or_init ();
+      DCACHE *dcache
+	= target_dcache_get_or_init (current_program_space->aspace);
 
       return dcache_read_memory_partial (ops, dcache, memaddr, readbuf,
 					 reg_len, xfered_len);
@@ -2632,7 +2633,7 @@ target_resume (ptid_t scope_ptid, int step, enum gdb_signal signal)
   gdb_assert (inferior_ptid != null_ptid);
   gdb_assert (inferior_ptid.matches (scope_ptid));
 
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 
   current_inferior ()->top_target ()->resume (scope_ptid, step, signal);
 
diff --git a/gdb/top.c b/gdb/top.c
index 5028440b671..d211f1b08be 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -360,7 +360,7 @@ prepare_execute_command ()
      it.  For the duration of the command, though, use the dcache to
      help things like backtrace.  */
   if (non_stop)
-    target_dcache_invalidate ();
+    target_dcache_invalidate (current_program_space->aspace);
 
   return scoped_value_mark ();
 }
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index d5f29eb8b10..750185341ea 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2131,7 +2131,7 @@ tfind_1 (enum trace_find_type type, int num,
   tp = get_tracepoint_by_number_on_target (target_tracept);
 
   reinit_frame_cache ();
-  target_dcache_invalidate ();
+  target_dcache_invalidate (current_program_space->aspace);
 
   set_tracepoint_num (tp ? tp->number : target_tracept);


More information about the Gdb-cvs mailing list