[14/58] gdbserver: turn target ops 'read_memory' and 'write_memory' into methods

Message ID f2a037cdef11542c559477b3846d183db39e105d.1581410933.git.tankut.baris.aktemur@intel.com
State Superseded
Headers show
Series
  • Turn gdbserver's process_stratum_target into a class
Related show

Commit Message

Tankut Baris Aktemur Feb. 11, 2020, 9:01 a.m.
gdbserver/ChangeLog:
2020-02-10  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

	Make process_stratum_target's read_memory and write_memory
	ops methods of process_target.

	* target.h (struct process_stratum_target): Remove the target ops.
	(class process_target): Add the target ops.
	(read_inferior_memory): Update the macro.
	(write_inferior_memory): Update the macro.

	Update the derived structs and callers below.

	* linux-aarch32-low.c (arm_breakpoint_at): Update.
	* linux-aarch64-low.c (aarch64_breakpoint_at): Update.
	* linux-arm-low.c (arm_sigreturn_next_pc): Update.
	(arm_get_syscall_trapinfo): Update.
	* linux-cris-low.c (cris_breakpoint_at): Update.
	* linux-crisv32-low.c (cris_breakpoint_at): Update.
	* linux-m32r-low.c (m32r_breakpoint_at): Update.
	* linux-mips-low.c (mips_breakpoint_at): Update.
	* linux-nios2-low.c (nios2_breakpoint_at): Update.
	* linux-ppc-low.c (parse_spufs_run): Update.
	(ppc_get_pc): Update.
	(ppc_set_pc): Update.
	(ppc_breakpoint_at): Update.
	* linux-sh-low.c (sh_breakpoint_at): Update.
	* linux-sparc-low.c (sparc_fill_gregset_to_stack): Update.
	(sparc_store_gregset_from_stack): Update.
	(sparc_breakpoint_at): Update.
	* linux-tic6x-low.c (tic6x_breakpoint_at): Update.
	* linux-tile-low.c (tile_breakpoint_at): Update.
	* linux-x86-low.c (x86_breakpoint_at): Update.
	* linux-xtensa-low.c (xtensa_breakpoint_at): Update.
	* mem-break.c (insert_memory_breakpoint): Update.
	(validate_inserted_breakpoint): Update.
	* target.c (read_inferior_memory): Update.
	(write_inferior_memory): Update.
	* linux-low.c (linux_target_ops): Update.
	(linux_read_memory): Make a wrapper around the read_memory target
	op call.
	(linux_process_target::read_memory): Rename from linux_read_memory.
	(linux_write_memory): Turn into ...
	(linux_process_target::write_memory): ... this.
	* linux-low.h (class linux_process_target): Update.
	* lynx-low.c (lynx_target_ops): Update.
	(lynx_read_memory): Turn into ...
	(lynx_process_target::read_memory): ... this.
	(lynx_write_memory): Turn into ...
	(lynx_process_target::write_memory): ... this.
	* lynx-low.h (class lynx_process_target): Update.
	* nto-low.c (nto_target_ops): Update.
	(nto_read_memory): Turn into ...
	(nto_process_target::read_memory): ... this.
	(nto_write_memory): Turn into ...
	(nto_process_target::write_memory): ... this.
	* nto-low.h (class nto_process_target): Update.
	* win32-low.c (win32_target_ops): Update.
	(win32_read_inferior_memory): Turn into ...
	(win32_process_target::read_memory): ... this.
	(win32_write_inferior_memory): Turn into ...
	(win32_process_target::write_memory): ... this.
	* win32-low.h (class win32_process_target): Update.
---
 gdbserver/linux-aarch32-low.c |  6 +++---
 gdbserver/linux-aarch64-low.c |  4 ++--
 gdbserver/linux-arm-low.c     |  8 ++++----
 gdbserver/linux-cris-low.c    |  4 ++--
 gdbserver/linux-crisv32-low.c |  4 ++--
 gdbserver/linux-low.c         | 20 +++++++++++++------
 gdbserver/linux-low.h         |  6 ++++++
 gdbserver/linux-m32r-low.c    |  4 ++--
 gdbserver/linux-mips-low.c    |  2 +-
 gdbserver/linux-nios2-low.c   |  4 ++--
 gdbserver/linux-ppc-low.c     |  2 +-
 gdbserver/linux-sh-low.c      |  2 +-
 gdbserver/linux-sparc-low.c   |  6 +++---
 gdbserver/linux-tic6x-low.c   |  2 +-
 gdbserver/linux-tile-low.c    |  2 +-
 gdbserver/linux-x86-low.c     |  2 +-
 gdbserver/linux-xtensa-low.c  |  4 ++--
 gdbserver/lynx-low.c          | 14 ++++++-------
 gdbserver/lynx-low.h          |  6 ++++++
 gdbserver/mem-break.c         |  6 +++---
 gdbserver/nto-low.c           | 12 ++++++------
 gdbserver/nto-low.h           |  6 ++++++
 gdbserver/target.c            |  4 ++--
 gdbserver/target.h            | 37 +++++++++++++++++------------------
 gdbserver/win32-low.c         | 13 ++++++------
 gdbserver/win32-low.h         |  6 ++++++
 26 files changed, 108 insertions(+), 78 deletions(-)

-- 
2.17.1

Patch

diff --git a/gdbserver/linux-aarch32-low.c b/gdbserver/linux-aarch32-low.c
index c6a70249d3b..41e018ab528 100644
--- a/gdbserver/linux-aarch32-low.c
+++ b/gdbserver/linux-aarch32-low.c
@@ -192,13 +192,13 @@  arm_breakpoint_at (CORE_ADDR where)
       /* Thumb mode.  */
       unsigned short insn;
 
-      (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+      the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
       if (insn == thumb_breakpoint)
 	return 1;
 
       if (insn == thumb2_breakpoint[0])
 	{
-	  (*the_target->read_memory) (where + 2, (unsigned char *) &insn, 2);
+	  the_target->pt->read_memory (where + 2, (unsigned char *) &insn, 2);
 	  if (insn == thumb2_breakpoint[1])
 	    return 1;
 	}
@@ -208,7 +208,7 @@  arm_breakpoint_at (CORE_ADDR where)
       /* ARM mode.  */
       unsigned long insn;
 
-      (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+      the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
       if (insn == arm_abi_breakpoint)
 	return 1;
 
diff --git a/gdbserver/linux-aarch64-low.c b/gdbserver/linux-aarch64-low.c
index 961fd5b3cc4..97117f05780 100644
--- a/gdbserver/linux-aarch64-low.c
+++ b/gdbserver/linux-aarch64-low.c
@@ -192,8 +192,8 @@  aarch64_breakpoint_at (CORE_ADDR where)
     {
       gdb_byte insn[aarch64_breakpoint_len];
 
-      (*the_target->read_memory) (where, (unsigned char *) &insn,
-				  aarch64_breakpoint_len);
+      the_target->pt->read_memory (where, (unsigned char *) &insn,
+				   aarch64_breakpoint_len);
       if (memcmp (insn, aarch64_breakpoint, aarch64_breakpoint_len) == 0)
 	return 1;
 
diff --git a/gdbserver/linux-arm-low.c b/gdbserver/linux-arm-low.c
index 9f046c098bf..e7cc1196857 100644
--- a/gdbserver/linux-arm-low.c
+++ b/gdbserver/linux-arm-low.c
@@ -779,15 +779,15 @@  arm_sigreturn_next_pc (struct regcache *regcache, int svc_number,
   gdb_assert (svc_number == __NR_sigreturn || svc_number == __NR_rt_sigreturn);
 
   collect_register_by_name (regcache, "sp", &sp);
-  (*the_target->read_memory) (sp, (unsigned char *) &sp_data, 4);
+  the_target->pt->read_memory (sp, (unsigned char *) &sp_data, 4);
 
   pc_offset = arm_linux_sigreturn_next_pc_offset
     (sp, sp_data, svc_number, __NR_sigreturn == svc_number ? 1 : 0);
 
-  (*the_target->read_memory) (sp + pc_offset, (unsigned char *) &next_pc, 4);
+  the_target->pt->read_memory (sp + pc_offset, (unsigned char *) &next_pc, 4);
 
   /* Set IS_THUMB according the CPSR saved on the stack.  */
-  (*the_target->read_memory) (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
+  the_target->pt->read_memory (sp + pc_offset + 4, (unsigned char *) &cpsr, 4);
   *is_thumb = ((cpsr & CPSR_T) != 0);
 
   return next_pc;
@@ -939,7 +939,7 @@  arm_get_syscall_trapinfo (struct regcache *regcache, int *sysno)
 
       collect_register_by_name (regcache, "pc", &pc);
 
-      if ((*the_target->read_memory) (pc - 4, (unsigned char *) &insn, 4))
+      if (the_target->pt->read_memory (pc - 4, (unsigned char *) &insn, 4))
 	*sysno = UNKNOWN_SYSCALL;
       else
 	{
diff --git a/gdbserver/linux-cris-low.c b/gdbserver/linux-cris-low.c
index 8ea5af92e31..6a4e8b1946a 100644
--- a/gdbserver/linux-cris-low.c
+++ b/gdbserver/linux-cris-low.c
@@ -76,8 +76,8 @@  cris_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn,
-			      cris_breakpoint_len);
+  the_target->pt->read_memory (where, (unsigned char *) &insn,
+			       cris_breakpoint_len);
   if (insn == cris_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-crisv32-low.c b/gdbserver/linux-crisv32-low.c
index facb5c5c274..fe12624c3b6 100644
--- a/gdbserver/linux-crisv32-low.c
+++ b/gdbserver/linux-crisv32-low.c
@@ -72,8 +72,8 @@  cris_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn,
-			      cris_breakpoint_len);
+  the_target->pt->read_memory (where, (unsigned char *) &insn,
+			       cris_breakpoint_len);
   if (insn == cris_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-low.c b/gdbserver/linux-low.c
index 1d05e1b9ff0..dad9dcf86fc 100644
--- a/gdbserver/linux-low.c
+++ b/gdbserver/linux-low.c
@@ -5709,11 +5709,20 @@  linux_process_target::store_registers (regcache *regcache, int regno)
 }
 
 
-/* Copy LEN bytes from inferior's memory starting at MEMADDR
-   to debugger memory starting at MYADDR.  */
+/* A wrapper for the read_memory target op.  */
 
 static int
 linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+{
+  return the_target->pt->read_memory (memaddr, myaddr, len);
+}
+
+/* Copy LEN bytes from inferior's memory starting at MEMADDR
+   to debugger memory starting at MYADDR.  */
+
+int
+linux_process_target::read_memory (CORE_ADDR memaddr,
+				   unsigned char *myaddr, int len)
 {
   int pid = lwpid_of (current_thread);
   PTRACE_XFER_TYPE *buffer;
@@ -5801,8 +5810,9 @@  linux_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
    memory at MEMADDR.  On failure (cannot write to the inferior)
    returns the value of errno.  Always succeeds if LEN is zero.  */
 
-static int
-linux_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+linux_process_target::write_memory (CORE_ADDR memaddr,
+				    const unsigned char *myaddr, int len)
 {
   int i;
   /* Round starting address down to longword boundary.  */
@@ -7359,8 +7369,6 @@  linux_get_hwcap2 (int wordsize)
 static linux_process_target the_linux_target;
 
 static process_stratum_target linux_target_ops = {
-  linux_read_memory,
-  linux_write_memory,
   linux_look_up_symbols,
   linux_request_interrupt,
   linux_read_auxv,
diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h
index 51622f6d211..58fd665ba66 100644
--- a/gdbserver/linux-low.h
+++ b/gdbserver/linux-low.h
@@ -298,6 +298,12 @@  public:
   int prepare_to_access_memory () override;
 
   void done_accessing_memory () override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 #define get_thread_lwp(thr) ((struct lwp_info *) (thread_target_data (thr)))
diff --git a/gdbserver/linux-m32r-low.c b/gdbserver/linux-m32r-low.c
index c52e816e341..8fe8389618f 100644
--- a/gdbserver/linux-m32r-low.c
+++ b/gdbserver/linux-m32r-low.c
@@ -70,8 +70,8 @@  m32r_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn,
-			      m32r_breakpoint_len);
+  the_target->pt->read_memory (where, (unsigned char *) &insn,
+			       m32r_breakpoint_len);
   if (insn == m32r_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-mips-low.c b/gdbserver/linux-mips-low.c
index f94e141be79..cb7eb53e3eb 100644
--- a/gdbserver/linux-mips-low.c
+++ b/gdbserver/linux-mips-low.c
@@ -302,7 +302,7 @@  mips_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == mips_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-nios2-low.c b/gdbserver/linux-nios2-low.c
index bfc5aee165d..6e5d3084dad 100644
--- a/gdbserver/linux-nios2-low.c
+++ b/gdbserver/linux-nios2-low.c
@@ -131,12 +131,12 @@  nios2_breakpoint_at (CORE_ADDR where)
 
   /* For R2, first check for the 2-byte CDX trap.n breakpoint encoding.  */
 #if defined(__nios2_arch__) && __nios2_arch__ == 2
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
   if (insn == CDX_BREAKPOINT)
     return 1;
 #endif
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == nios2_breakpoint)
     return 1;
   return 0;
diff --git a/gdbserver/linux-ppc-low.c b/gdbserver/linux-ppc-low.c
index 5d8d67bec2f..93b3511a2e1 100644
--- a/gdbserver/linux-ppc-low.c
+++ b/gdbserver/linux-ppc-low.c
@@ -277,7 +277,7 @@  ppc_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == ppc_breakpoint)
     return 1;
   /* If necessary, recognize more trap instructions here.  GDB only uses
diff --git a/gdbserver/linux-sh-low.c b/gdbserver/linux-sh-low.c
index abe71ff4766..06ce8118ebf 100644
--- a/gdbserver/linux-sh-low.c
+++ b/gdbserver/linux-sh-low.c
@@ -76,7 +76,7 @@  sh_breakpoint_at (CORE_ADDR where)
 {
   unsigned short insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 2);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 2);
   if (insn == sh_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-sparc-low.c b/gdbserver/linux-sparc-low.c
index cfa76c0b8e6..b0b6c96b3de 100644
--- a/gdbserver/linux-sparc-low.c
+++ b/gdbserver/linux-sparc-low.c
@@ -133,7 +133,7 @@  sparc_fill_gregset_to_stack (struct regcache *regcache, const void *buf)
   for (i = l0_regno; i <= i7_regno; i++)
     {
       collect_register (regcache, i, tmp_reg_buf);
-      (*the_target->write_memory) (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
+      the_target->pt->write_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
       addr += sizeof (tmp_reg_buf);
     }
 }
@@ -184,7 +184,7 @@  sparc_store_gregset_from_stack (struct regcache *regcache, const void *buf)
 
   for (i = l0_regno; i <= i7_regno; i++)
     {
-      (*the_target->read_memory) (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
+      the_target->pt->read_memory (addr, tmp_reg_buf, sizeof (tmp_reg_buf));
       supply_register (regcache, i, tmp_reg_buf);
       addr += sizeof (tmp_reg_buf);
     }
@@ -242,7 +242,7 @@  sparc_breakpoint_at (CORE_ADDR where)
 {
   unsigned char insn[INSN_SIZE];
 
-  (*the_target->read_memory) (where, (unsigned char *) insn, sizeof (insn));
+  the_target->pt->read_memory (where, (unsigned char *) insn, sizeof (insn));
 
   if (memcmp (sparc_breakpoint, insn, sizeof (insn)) == 0)
     return 1;
diff --git a/gdbserver/linux-tic6x-low.c b/gdbserver/linux-tic6x-low.c
index 51a31c7876a..b57f8c57710 100644
--- a/gdbserver/linux-tic6x-low.c
+++ b/gdbserver/linux-tic6x-low.c
@@ -241,7 +241,7 @@  tic6x_breakpoint_at (CORE_ADDR where)
 {
   unsigned int insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 4);
   if (insn == tic6x_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-tile-low.c b/gdbserver/linux-tile-low.c
index cd85e945a46..baee93a5c24 100644
--- a/gdbserver/linux-tile-low.c
+++ b/gdbserver/linux-tile-low.c
@@ -85,7 +85,7 @@  tile_breakpoint_at (CORE_ADDR where)
 {
   uint64_t insn;
 
-  (*the_target->read_memory) (where, (unsigned char *) &insn, 8);
+  the_target->pt->read_memory (where, (unsigned char *) &insn, 8);
   if (insn == tile_breakpoint)
     return 1;
 
diff --git a/gdbserver/linux-x86-low.c b/gdbserver/linux-x86-low.c
index 09ec22ff678..cb2d3f59580 100644
--- a/gdbserver/linux-x86-low.c
+++ b/gdbserver/linux-x86-low.c
@@ -515,7 +515,7 @@  x86_breakpoint_at (CORE_ADDR pc)
 {
   unsigned char c;
 
-  (*the_target->read_memory) (pc, &c, 1);
+  the_target->pt->read_memory (pc, &c, 1);
   if (c == 0xCC)
     return 1;
 
diff --git a/gdbserver/linux-xtensa-low.c b/gdbserver/linux-xtensa-low.c
index 83af11e11dc..31e7bad36b8 100644
--- a/gdbserver/linux-xtensa-low.c
+++ b/gdbserver/linux-xtensa-low.c
@@ -207,8 +207,8 @@  xtensa_breakpoint_at (CORE_ADDR where)
 {
     unsigned long insn;
 
-    (*the_target->read_memory) (where, (unsigned char *) &insn,
-				xtensa_breakpoint_len);
+    the_target->pt->read_memory (where, (unsigned char *) &insn,
+				 xtensa_breakpoint_len);
     return memcmp((char *) &insn,
 		  xtensa_breakpoint, xtensa_breakpoint_len) == 0;
 }
diff --git a/gdbserver/lynx-low.c b/gdbserver/lynx-low.c
index 365f82b55ce..fe55f9bcdf3 100644
--- a/gdbserver/lynx-low.c
+++ b/gdbserver/lynx-low.c
@@ -638,8 +638,9 @@  lynx_process_target::store_registers (regcache *regcache, int regno)
 
 /* Implement the read_memory target_ops method.  */
 
-static int
-lynx_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+int
+lynx_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+				  int len)
 {
   /* On LynxOS, memory reads needs to be performed in chunks the size
      of int types, and they should also be aligned accordingly.  */
@@ -671,8 +672,9 @@  lynx_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 
 /* Implement the write_memory target_ops method.  */
 
-static int
-lynx_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+lynx_process_target::write_memory (CORE_ADDR memaddr,
+				   const unsigned char *myaddr, int len)
 {
   /* On LynxOS, memory writes needs to be performed in chunks the size
      of int types, and they should also be aligned accordingly.  */
@@ -694,7 +696,7 @@  lynx_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
 	{
 	  /* We need to read the memory at this address in order to preserve
 	     the data that we are not overwriting.  */
-	  lynx_read_memory (addr, (unsigned char *) &buf, xfer_size);
+	  read_memory (addr, (unsigned char *) &buf, xfer_size);
 	  if (errno)
 	    return errno;
 	}
@@ -727,8 +729,6 @@  static lynx_process_target the_lynx_target;
 /* The LynxOS target_ops vector.  */
 
 static process_stratum_target lynx_target_ops = {
-  lynx_read_memory,
-  lynx_write_memory,
   NULL,  /* look_up_symbols */
   lynx_request_interrupt,
   NULL,  /* read_auxv */
diff --git a/gdbserver/lynx-low.h b/gdbserver/lynx-low.h
index 0d82f86e94e..05223ec9774 100644
--- a/gdbserver/lynx-low.h
+++ b/gdbserver/lynx-low.h
@@ -80,6 +80,12 @@  public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/mem-break.c b/gdbserver/mem-break.c
index 1b6f2365814..43a07c390d1 100644
--- a/gdbserver/mem-break.c
+++ b/gdbserver/mem-break.c
@@ -380,8 +380,8 @@  insert_memory_breakpoint (struct raw_breakpoint *bp)
     {
       memcpy (bp->old_data, buf, bp_size (bp));
 
-      err = (*the_target->write_memory) (bp->pc, bp_opcode (bp),
-					 bp_size (bp));
+      err = the_target->pt->write_memory (bp->pc, bp_opcode (bp),
+					  bp_size (bp));
       if (err != 0)
 	{
 	  if (debug_threads)
@@ -1857,7 +1857,7 @@  validate_inserted_breakpoint (struct raw_breakpoint *bp)
   gdb_assert (bp->raw_type == raw_bkpt_type_sw);
 
   buf = (unsigned char *) alloca (bp_size (bp));
-  err = (*the_target->read_memory) (bp->pc, buf, bp_size (bp));
+  err = the_target->pt->read_memory (bp->pc, buf, bp_size (bp));
   if (err || memcmp (buf, bp_opcode (bp), bp_size (bp)) != 0)
     {
       /* Tag it as gone.  */
diff --git a/gdbserver/nto-low.c b/gdbserver/nto-low.c
index 2e75225b01e..f1c4be09f7f 100644
--- a/gdbserver/nto-low.c
+++ b/gdbserver/nto-low.c
@@ -706,8 +706,9 @@  nto_process_target::store_registers (regcache *regcache, int regno)
 
    Return 0 on success -1 otherwise.  */
 
-static int
-nto_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+int
+nto_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+				 int len)
 {
   TRACE ("%s memaddr:0x%08lx, len:%d\n", __func__, memaddr, len);
 
@@ -725,8 +726,9 @@  nto_read_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 
    Return 0 on success -1 otherwise.  */
 
-static int
-nto_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
+int
+nto_process_target::write_memory (CORE_ADDR memaddr,
+				  const unsigned char *myaddr, int len)
 {
   int len_written;
 
@@ -941,8 +943,6 @@  nto_sw_breakpoint_from_kind (int kind, int *size)
 static nto_process_target the_nto_target;
 
 static process_stratum_target nto_target_ops = {
-  nto_read_memory,
-  nto_write_memory,
   NULL, /* nto_look_up_symbols */
   nto_request_interrupt,
   nto_read_auxv,
diff --git a/gdbserver/nto-low.h b/gdbserver/nto-low.h
index 1fb57f4f73d..6f420219ad4 100644
--- a/gdbserver/nto-low.h
+++ b/gdbserver/nto-low.h
@@ -70,6 +70,12 @@  public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 /* The inferior's target description.  This is a global because the
diff --git a/gdbserver/target.c b/gdbserver/target.c
index f88e9faf191..49302f61dfb 100644
--- a/gdbserver/target.c
+++ b/gdbserver/target.c
@@ -120,7 +120,7 @@  int
 read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
 {
   int res;
-  res = (*the_target->read_memory) (memaddr, myaddr, len);
+  res = the_target->pt->read_memory (memaddr, myaddr, len);
   check_mem_read (memaddr, myaddr, len);
   return res;
 }
@@ -151,7 +151,7 @@  target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
      update it.  */
   gdb::byte_vector buffer (myaddr, myaddr + len);
   check_mem_write (memaddr, buffer.data (), myaddr, len);
-  return (*the_target->write_memory) (memaddr, buffer.data (), len);
+  return the_target->pt->write_memory (memaddr, buffer.data (), len);
 }
 
 ptid_t
diff --git a/gdbserver/target.h b/gdbserver/target.h
index 16ff5ab6baa..5621dc1d60e 100644
--- a/gdbserver/target.h
+++ b/gdbserver/target.h
@@ -70,25 +70,6 @@  class process_target;
    shared code.  */
 struct process_stratum_target
 {
-  /* Read memory from the inferior process.  This should generally be
-     called through read_inferior_memory, which handles breakpoint shadowing.
-
-     Read LEN bytes at MEMADDR into a buffer at MYADDR.
-  
-     Returns 0 on success and errno on failure.  */
-
-  int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
-
-  /* Write memory to the inferior process.  This should generally be
-     called through target_write_memory, which handles breakpoint shadowing.
-
-     Write LEN bytes from the buffer at MYADDR to MEMADDR.
-
-     Returns 0 on success and errno on failure.  */
-
-  int (*write_memory) (CORE_ADDR memaddr, const unsigned char *myaddr,
-		       int len);
-
   /* Query GDB for the values of any symbols we're interested in.
      This function is called whenever we receive a "qSymbols::"
      query, which corresponds to every time more symbols (might)
@@ -477,6 +458,24 @@  public:
 
   /* Undo the effects of prepare_to_access_memory.  */
   virtual void done_accessing_memory ();
+
+  /* Read memory from the inferior process.  This should generally be
+     called through read_inferior_memory, which handles breakpoint shadowing.
+
+     Read LEN bytes at MEMADDR into a buffer at MYADDR.
+
+     Returns 0 on success and errno on failure.  */
+  virtual int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+			   int len) = 0;
+
+  /* Write memory to the inferior process.  This should generally be
+     called through target_write_memory, which handles breakpoint shadowing.
+
+     Write LEN bytes from the buffer at MYADDR to MEMADDR.
+
+     Returns 0 on success and errno on failure.  */
+  virtual int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+			    int len) = 0;
 };
 
 extern process_stratum_target *the_target;
diff --git a/gdbserver/win32-low.c b/gdbserver/win32-low.c
index 6639401b1ae..1a56c9c45a4 100644
--- a/gdbserver/win32-low.c
+++ b/gdbserver/win32-low.c
@@ -1666,8 +1666,9 @@  win32_process_target::store_registers (regcache *regcache, int regno)
 /* Read memory from the inferior process.  This should generally be
    called through read_inferior_memory, which handles breakpoint shadowing.
    Read LEN bytes at MEMADDR into a buffer at MYADDR.  */
-static int
-win32_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
+int
+win32_process_target::read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+				   int len)
 {
   return child_xfer_memory (memaddr, (char *) myaddr, len, 0, 0) != len;
 }
@@ -1676,9 +1677,9 @@  win32_read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len)
    called through write_inferior_memory, which handles breakpoint shadowing.
    Write LEN bytes from the buffer at MYADDR to MEMADDR.
    Returns 0 on success and errno on failure.  */
-static int
-win32_write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
-			     int len)
+int
+win32_process_target::write_memory (CORE_ADDR memaddr,
+				    const unsigned char *myaddr, int len)
 {
   return child_xfer_memory (memaddr, (char *) myaddr, len, 1, 0) != len;
 }
@@ -1827,8 +1828,6 @@  win32_sw_breakpoint_from_kind (int kind, int *size)
 static win32_process_target the_win32_target;
 
 static process_stratum_target win32_target_ops = {
-  win32_read_inferior_memory,
-  win32_write_inferior_memory,
   NULL, /* lookup_symbols */
   win32_request_interrupt,
   NULL, /* read_auxv */
diff --git a/gdbserver/win32-low.h b/gdbserver/win32-low.h
index 451c3f1b17d..27ba64ce916 100644
--- a/gdbserver/win32-low.h
+++ b/gdbserver/win32-low.h
@@ -129,6 +129,12 @@  public:
   void fetch_registers (regcache *regcache, int regno) override;
 
   void store_registers (regcache *regcache, int regno) override;
+
+  int read_memory (CORE_ADDR memaddr, unsigned char *myaddr,
+		   int len) override;
+
+  int write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
+		    int len) override;
 };
 
 /* Retrieve the context for this thread, if not already retrieved.  */