gdb: pass address_space to target dcache functions

Message ID 20230330144054.20193-1-simon.marchi@efficios.com
State New
Headers
Series gdb: pass address_space to target dcache functions |

Commit Message

Simon Marchi March 30, 2023, 2:40 p.m. UTC
  A simple refactor to make the reference to current_program_space bubble
up one level.  No behavior changes expected.

Change-Id: I237cf2f45ae73c35bcb433ce40e3c03cef6b87e2
---
 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(-)
  

Patch

diff --git a/gdb/dcache.c b/gdb/dcache.c
index c075625cb632..915bc8953641 100644
--- a/gdb/dcache.c
+++ b/gdb/dcache.c
@@ -649,7 +649,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
@@ -661,7 +661,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
@@ -675,7 +675,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 8a8439f6da55..4a84ea5f2712 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -4104,7 +4104,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 ();
@@ -4334,7 +4334,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,
@@ -4895,7 +4895,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 fafd909a714d..58325b716d5a 100644
--- a/gdb/memattr.c
+++ b/gdb/memattr.c
@@ -29,6 +29,7 @@ 
 #include "cli/cli-utils.h"
 #include <algorithm>
 #include "gdbarch.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;
@@ -482,7 +483,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.  */
@@ -520,7 +521,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')
     {
@@ -566,7 +567,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 13c2888e7ea8..4c4fef902c4a 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 1e9e9725f950..4693b388110e 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 0cebecfafc37..648132627992 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -922,7 +922,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);
 }
 
@@ -1493,10 +1493,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.  */
@@ -1579,7 +1579,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);
@@ -2648,7 +2649,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 aa2a6409d98b..8e22c21e65f4 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -474,7 +474,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 c8bac7a01221..62c0fc60d229 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2134,7 +2134,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);