+2020-02-20 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
+
+ Turn process_stratum_target's read_memory and write_memory
+ ops into methods of process_target.
+
+ * target.h (struct process_stratum_target): Remove the target ops.
+ (class process_target): Add the target ops.
+
+ Update the derived classes and callers below.
+
+ * linux-aarch32-low.cc (arm_breakpoint_at): Update.
+ * linux-aarch64-low.cc (aarch64_breakpoint_at): Update.
+ * linux-arm-low.cc (arm_sigreturn_next_pc): Update.
+ (arm_get_syscall_trapinfo): Update.
+ * linux-cris-low.cc (cris_breakpoint_at): Update.
+ * linux-crisv32-low.cc (cris_breakpoint_at): Update.
+ * linux-m32r-low.cc (m32r_breakpoint_at): Update.
+ * linux-mips-low.cc (mips_breakpoint_at): Update.
+ * linux-nios2-low.cc (nios2_breakpoint_at): Update.
+ * linux-ppc-low.cc (ppc_breakpoint_at): Update.
+ * linux-sh-low.cc (sh_breakpoint_at): Update.
+ * linux-sparc-low.cc (sparc_fill_gregset_to_stack): Update.
+ (sparc_store_gregset_from_stack): Update.
+ (sparc_breakpoint_at): Update.
+ * linux-tic6x-low.cc (tic6x_breakpoint_at): Update.
+ * linux-tile-low.cc (tile_breakpoint_at): Update.
+ * linux-x86-low.cc (x86_breakpoint_at): Update.
+ * linux-xtensa-low.cc (xtensa_breakpoint_at): Update.
+ * mem-brea.cc (insert_memory_breakpoint): Update.
+ (validate_inserted_breakpoint): Update.
+ * target.cc (read_inferior_memory): Update.
+ (target_write_memory): Update.
+ * linux-low.cc (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.cc (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.cc (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.cc (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.
+
2020-02-20 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Turn process_stratum_target's prepare_to_access_memory and
/* 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;
}
/* 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;
{
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;
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;
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
{
{
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;
{
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;
}
-/* 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;
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. */
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,
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)))
{
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;
{
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;
/* 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;
{
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
{
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;
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);
}
}
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);
}
{
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;
{
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;
{
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;
{
unsigned char c;
- (*the_target->read_memory) (pc, &c, 1);
+ the_target->pt->read_memory (pc, &c, 1);
if (c == 0xCC)
return 1;
{
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;
}
/* 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. */
/* 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. */
{
/* 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;
}
/* 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 */
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
{
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)
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. */
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);
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;
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,
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
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;
}
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
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)
/* 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;
/* 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;
}
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;
}
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 */
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. */