Replace write_inferior_memory with target_write_memory

target_write_memory is just a simple wrapper for
write_inferior_memory.  Because target_write_memory is needed for
gdbsupport, and because gdb uses the name "target_write_memory"
everywhere, this patch renames write_inferior_memory and removes the
wrapper.  I think this brings gdb and gdbserver slightly more in sync.

gdb/gdbserver/ChangeLog
2019-08-15  Tom Tromey  <tromey@adacore.com>

	* tracepoint.c (write_inferior_data_pointer)
	(write_inferior_integer, write_inferior_int8)
	(write_inferior_uinteger, m_tracepoint_action_download)
	(r_tracepoint_action_download, x_tracepoint_action_download)
	(l_tracepoint_action_download, clear_inferior_trace_buffer)
	(download_agent_expr, download_tracepoint_1)
	(download_trace_state_variables, upload_fast_traceframes): Update.
	* server.c (gdb_write_memory): Update.
	* remote-utils.c (relocate_instruction): Update.
	* proc-service.c (ps_pdwrite): Update.
	* mem-break.c (remove_memory_breakpoint)
	(delete_fast_tracepoint_jump, set_fast_tracepoint_jump)
	(uninsert_fast_tracepoint_jumps_at)
	(reinsert_fast_tracepoint_jumps_at): Update.
	* linux-x86-low.c (append_insns)
	(i386_install_fast_tracepoint_jump_pad)
	(amd64_write_goto_address, i386_write_goto_address): Update.
	* linux-s390-low.c (append_insns, s390_write_goto_address):
	Update.
	* linux-ppc-low.c (ppc_relocate_instruction)
	(ppc_install_fast_tracepoint_jump_pad, emit_insns)
	(ppc_write_goto_address): Update.
	* linux-aarch64-low.c (append_insns): Update.
	* target.h (struct target_ops): Update.
	(write_inferior_memory): Don't declare.
	* target.c (target_write_memory): Rename from
	write_inferior_memory.  Remove old target_write_memory.
This commit is contained in:
Tom Tromey 2019-08-14 09:18:21 -06:00
parent c6778d00df
commit 4196ab2a6d
12 changed files with 89 additions and 68 deletions

View File

@ -1,3 +1,33 @@
2019-08-15 Tom Tromey <tromey@adacore.com>
* tracepoint.c (write_inferior_data_pointer)
(write_inferior_integer, write_inferior_int8)
(write_inferior_uinteger, m_tracepoint_action_download)
(r_tracepoint_action_download, x_tracepoint_action_download)
(l_tracepoint_action_download, clear_inferior_trace_buffer)
(download_agent_expr, download_tracepoint_1)
(download_trace_state_variables, upload_fast_traceframes): Update.
* server.c (gdb_write_memory): Update.
* remote-utils.c (relocate_instruction): Update.
* proc-service.c (ps_pdwrite): Update.
* mem-break.c (remove_memory_breakpoint)
(delete_fast_tracepoint_jump, set_fast_tracepoint_jump)
(uninsert_fast_tracepoint_jumps_at)
(reinsert_fast_tracepoint_jumps_at): Update.
* linux-x86-low.c (append_insns)
(i386_install_fast_tracepoint_jump_pad)
(amd64_write_goto_address, i386_write_goto_address): Update.
* linux-s390-low.c (append_insns, s390_write_goto_address):
Update.
* linux-ppc-low.c (ppc_relocate_instruction)
(ppc_install_fast_tracepoint_jump_pad, emit_insns)
(ppc_write_goto_address): Update.
* linux-aarch64-low.c (append_insns): Update.
* target.h (struct target_ops): Update.
(write_inferior_memory): Don't declare.
* target.c (target_write_memory): Rename from
write_inferior_memory. Remove old target_write_memory.
2019-08-15 Tom Tromey <tromey@adacore.com>
* target.c (write_inferior_memory): Use std::vector.

View File

@ -1626,11 +1626,11 @@ append_insns (CORE_ADDR *to, size_t len, const uint32_t *buf)
for (i = 0; i < len; i++)
le_buf[i] = htole32 (buf[i]);
write_inferior_memory (*to, (const unsigned char *) le_buf, byte_len);
target_write_memory (*to, (const unsigned char *) le_buf, byte_len);
xfree (le_buf);
#else
write_inferior_memory (*to, (const unsigned char *) buf, byte_len);
target_write_memory (*to, (const unsigned char *) buf, byte_len);
#endif
*to += byte_len;

View File

@ -1535,12 +1535,12 @@ ppc_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
/* Jump over the unconditional branch. */
insn = (insn & ~0xfffc) | 0x8;
write_inferior_memory (*to, (unsigned char *) &insn, 4);
target_write_memory (*to, (unsigned char *) &insn, 4);
*to += 4;
/* Build a unconditional branch and copy LK bit. */
insn = (18 << 26) | (0x3fffffc & newrel) | (insn & 0x3);
write_inferior_memory (*to, (unsigned char *) &insn, 4);
target_write_memory (*to, (unsigned char *) &insn, 4);
*to += 4;
return;
@ -1563,14 +1563,14 @@ ppc_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
bdnz_insn |= (insn ^ (1 << 22)) & (1 << 22);
bf_insn |= (insn ^ (1 << 24)) & (1 << 24);
write_inferior_memory (*to, (unsigned char *) &bdnz_insn, 4);
target_write_memory (*to, (unsigned char *) &bdnz_insn, 4);
*to += 4;
write_inferior_memory (*to, (unsigned char *) &bf_insn, 4);
target_write_memory (*to, (unsigned char *) &bf_insn, 4);
*to += 4;
/* Build a unconditional branch and copy LK bit. */
insn = (18 << 26) | (0x3fffffc & newrel) | (insn & 0x3);
write_inferior_memory (*to, (unsigned char *) &insn, 4);
target_write_memory (*to, (unsigned char *) &insn, 4);
*to += 4;
return;
@ -1583,14 +1583,14 @@ ppc_relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
/* Build a unconditional branch and copy LK bit. */
insn = (18 << 26) | (0x3fffffc & newrel) | (insn & 0x3);
write_inferior_memory (*to, (unsigned char *) &insn, 4);
target_write_memory (*to, (unsigned char *) &insn, 4);
*to += 4;
return;
}
}
write_inferior_memory (*to, (unsigned char *) &insn, 4);
target_write_memory (*to, (unsigned char *) &insn, 4);
*to += 4;
}
@ -1750,7 +1750,7 @@ ppc_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
p += GEN_ADDI (p, 1, 1, frame_size);
/* Flush instructions to inferior memory. */
write_inferior_memory (buildaddr, (unsigned char *) buf, (p - buf) * 4);
target_write_memory (buildaddr, (unsigned char *) buf, (p - buf) * 4);
/* Now, insert the original instruction to execute in the jump pad. */
*adjusted_insn_addr = buildaddr + (p - buf) * 4;
@ -1780,7 +1780,7 @@ ppc_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
}
/* b <tpaddr+4> */
p += GEN_B (p, offset);
write_inferior_memory (buildaddr, (unsigned char *) buf, (p - buf) * 4);
target_write_memory (buildaddr, (unsigned char *) buf, (p - buf) * 4);
*jump_entry = buildaddr + (p - buf) * 4;
/* The jump pad is now built. Wire in a jump to our jump pad. This
@ -1816,7 +1816,7 @@ static void
emit_insns (uint32_t *buf, int n)
{
n = n * sizeof (uint32_t);
write_inferior_memory (current_insn_ptr, (unsigned char *) buf, n);
target_write_memory (current_insn_ptr, (unsigned char *) buf, n);
current_insn_ptr += n;
}
@ -2604,7 +2604,7 @@ ppc_write_goto_address (CORE_ADDR from, CORE_ADDR to, int size)
}
if (!emit_error)
write_inferior_memory (from, (unsigned char *) &insn, 4);
target_write_memory (from, (unsigned char *) &insn, 4);
}
/* Table of emit ops for 32-bit. */

View File

@ -1036,7 +1036,7 @@ static const unsigned char s390_ft_exit_gpr_zarch[] = {
static void
append_insns (CORE_ADDR *to, size_t len, const unsigned char *buf)
{
write_inferior_memory (*to, buf, len);
target_write_memory (*to, buf, len);
*to += len;
}
@ -1793,7 +1793,7 @@ s390_write_goto_address (CORE_ADDR from, CORE_ADDR to, int size)
}
memcpy (buf, &sdiff, sizeof sdiff);
write_inferior_memory (from, buf, sizeof sdiff);
target_write_memory (from, buf, sizeof sdiff);
}
/* Preparation for emitting a literal pool of given size. Loads the address

View File

@ -1007,7 +1007,7 @@ x86_supports_tracepoints (void)
static void
append_insns (CORE_ADDR *to, size_t len, const unsigned char *buf)
{
write_inferior_memory (*to, buf, len);
target_write_memory (*to, buf, len);
*to += len;
}
@ -1385,7 +1385,7 @@ i386_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint, CORE_ADDR tpaddr,
offset = *jump_entry - (*trampoline + sizeof (jump_insn));
memcpy (buf, jump_insn, sizeof (jump_insn));
memcpy (buf + 1, &offset, 4);
write_inferior_memory (*trampoline, buf, sizeof (jump_insn));
target_write_memory (*trampoline, buf, sizeof (jump_insn));
/* Use a 16-bit relative jump instruction to jump to the trampoline. */
offset = (*trampoline - (tpaddr + sizeof (small_jump_insn))) & 0xffff;
@ -1780,7 +1780,7 @@ amd64_write_goto_address (CORE_ADDR from, CORE_ADDR to, int size)
}
memcpy (buf, &diff, sizeof (int));
write_inferior_memory (from, buf, sizeof (int));
target_write_memory (from, buf, sizeof (int));
}
static void
@ -2398,7 +2398,7 @@ i386_write_goto_address (CORE_ADDR from, CORE_ADDR to, int size)
}
memcpy (buf, &diff, sizeof (int));
write_inferior_memory (from, buf, sizeof (int));
target_write_memory (from, buf, sizeof (int));
}
static void

View File

@ -401,15 +401,15 @@ remove_memory_breakpoint (struct raw_breakpoint *bp)
int err;
/* Since there can be trap breakpoints inserted in the same address
range, we use `write_inferior_memory', which takes care of
range, we use `target_write_memory', which takes care of
layering breakpoints on top of fast tracepoints, and on top of
the buffer we pass it. This works because the caller has already
either unlinked the breakpoint or marked it uninserted. Also
note that we need to pass the current shadow contents, because
write_inferior_memory updates any shadow memory with what we pass
target_write_memory updates any shadow memory with what we pass
here, and we want that to be a nop. */
memcpy (buf, bp->old_data, bp_size (bp));
err = write_inferior_memory (bp->pc, buf, bp_size (bp));
err = target_write_memory (bp->pc, buf, bp_size (bp));
if (err != 0)
{
if (debug_threads)
@ -578,17 +578,17 @@ delete_fast_tracepoint_jump (struct fast_tracepoint_jump *todel)
*bp_link = bp->next;
/* Since there can be breakpoints inserted in the same
address range, we use `write_inferior_memory', which
address range, we use `target_write_memory', which
takes care of layering breakpoints on top of fast
tracepoints, and on top of the buffer we pass it.
This works because we've already unlinked the fast
tracepoint jump above. Also note that we need to
pass the current shadow contents, because
write_inferior_memory updates any shadow memory with
target_write_memory updates any shadow memory with
what we pass here, and we want that to be a nop. */
buf = (unsigned char *) alloca (bp->length);
memcpy (buf, fast_tracepoint_jump_shadow (bp), bp->length);
ret = write_inferior_memory (bp->pc, buf, bp->length);
ret = target_write_memory (bp->pc, buf, bp->length);
if (ret != 0)
{
/* Something went wrong, relink the jump. */
@ -672,14 +672,14 @@ set_fast_tracepoint_jump (CORE_ADDR where,
proc->fast_tracepoint_jumps = jp;
/* Since there can be trap breakpoints inserted in the same address
range, we use use `write_inferior_memory', which takes care of
range, we use use `target_write_memory', which takes care of
layering breakpoints on top of fast tracepoints, on top of the
buffer we pass it. This works because we've already linked in
the fast tracepoint jump above. Also note that we need to pass
the current shadow contents, because write_inferior_memory
the current shadow contents, because target_write_memory
updates any shadow memory with what we pass here, and we want
that to be a nop. */
err = write_inferior_memory (where, buf, length);
err = target_write_memory (where, buf, length);
if (err != 0)
{
if (debug_threads)
@ -721,17 +721,17 @@ uninsert_fast_tracepoint_jumps_at (CORE_ADDR pc)
jp->inserted = 0;
/* Since there can be trap breakpoints inserted in the same
address range, we use use `write_inferior_memory', which
address range, we use use `target_write_memory', which
takes care of layering breakpoints on top of fast
tracepoints, and on top of the buffer we pass it. This works
because we've already marked the fast tracepoint fast
tracepoint jump uninserted above. Also note that we need to
pass the current shadow contents, because
write_inferior_memory updates any shadow memory with what we
target_write_memory updates any shadow memory with what we
pass here, and we want that to be a nop. */
buf = (unsigned char *) alloca (jp->length);
memcpy (buf, fast_tracepoint_jump_shadow (jp), jp->length);
err = write_inferior_memory (jp->pc, buf, jp->length);
err = target_write_memory (jp->pc, buf, jp->length);
if (err != 0)
{
jp->inserted = 1;
@ -769,16 +769,16 @@ reinsert_fast_tracepoint_jumps_at (CORE_ADDR where)
jp->inserted = 1;
/* Since there can be trap breakpoints inserted in the same address
range, we use `write_inferior_memory', which takes care of
range, we use `target_write_memory', which takes care of
layering breakpoints on top of fast tracepoints, and on top of
the buffer we pass it. This works because we've already marked
the fast tracepoint jump inserted above. Also note that we need
to pass the current shadow contents, because
write_inferior_memory updates any shadow memory with what we pass
target_write_memory updates any shadow memory with what we pass
here, and we want that to be a nop. */
buf = (unsigned char *) alloca (jp->length);
memcpy (buf, fast_tracepoint_jump_shadow (jp), jp->length);
err = write_inferior_memory (where, buf, jp->length);
err = target_write_memory (where, buf, jp->length);
if (err != 0)
{
jp->inserted = 0;

View File

@ -91,7 +91,7 @@ ps_err_e
ps_pdwrite (gdb_ps_prochandle_t ph, psaddr_t addr,
gdb_ps_write_buf_t buf, gdb_ps_size_t size)
{
if (write_inferior_memory ((uintptr_t) addr, (const gdb_byte *) buf, size)
if (target_write_memory ((uintptr_t) addr, (const gdb_byte *) buf, size)
!= 0)
return PS_ERR;
return PS_OK;

View File

@ -1636,7 +1636,7 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
{
if (decode_X_packet (&cs.own_buf[1], len - 1, &mem_addr,
&mem_len, &mem_buf) < 0
|| write_inferior_memory (mem_addr, mem_buf, mem_len) != 0)
|| target_write_memory (mem_addr, mem_buf, mem_len) != 0)
write_enn (cs.own_buf);
else
write_ok (cs.own_buf);
@ -1644,7 +1644,7 @@ relocate_instruction (CORE_ADDR *to, CORE_ADDR oldloc)
else
{
decode_M_packet (&cs.own_buf[1], &mem_addr, &mem_len, &mem_buf);
if (write_inferior_memory (mem_addr, mem_buf, mem_len) == 0)
if (target_write_memory (mem_addr, mem_buf, mem_len) == 0)
write_ok (cs.own_buf);
else
write_enn (cs.own_buf);

View File

@ -1026,7 +1026,7 @@ gdb_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr, int len)
if (ret == 0)
{
if (set_desired_thread ())
ret = write_inferior_memory (memaddr, myaddr, len);
ret = target_write_memory (memaddr, myaddr, len);
else
ret = EIO;
done_accessing_memory ();

View File

@ -146,9 +146,11 @@ target_read_uint32 (CORE_ADDR memaddr, uint32_t *result)
return read_inferior_memory (memaddr, (gdb_byte *) result, sizeof (*result));
}
/* See target/target.h. */
int
write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
int len)
target_write_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
ssize_t len)
{
/* Make a copy of the data because check_mem_write may need to
update it. */
@ -157,14 +159,6 @@ write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
return (*the_target->write_memory) (memaddr, buffer.data (), len);
}
/* See target/target.h. */
int
target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, ssize_t len)
{
return write_inferior_memory (memaddr, myaddr, len);
}
ptid_t
mywait (ptid_t ptid, struct target_waitstatus *ourstatus, int options,
int connected_wait)

View File

@ -167,7 +167,7 @@ struct target_ops
int (*read_memory) (CORE_ADDR memaddr, unsigned char *myaddr, int len);
/* Write memory to the inferior process. This should generally be
called through write_inferior_memory, which handles breakpoint shadowing.
called through target_write_memory, which handles breakpoint shadowing.
Write LEN bytes from the buffer at MYADDR to MEMADDR.
@ -726,9 +726,6 @@ void done_accessing_memory (void);
int read_inferior_memory (CORE_ADDR memaddr, unsigned char *myaddr, int len);
int write_inferior_memory (CORE_ADDR memaddr, const unsigned char *myaddr,
int len);
int set_desired_thread ();
const char *target_pid_to_str (ptid_t);

View File

@ -440,26 +440,26 @@ static int
write_inferior_data_pointer (CORE_ADDR symaddr, CORE_ADDR val)
{
void *pval = (void *) (uintptr_t) val;
return write_inferior_memory (symaddr,
return target_write_memory (symaddr,
(unsigned char *) &pval, sizeof (pval));
}
static int
write_inferior_integer (CORE_ADDR symaddr, int val)
{
return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val));
return target_write_memory (symaddr, (unsigned char *) &val, sizeof (val));
}
static int
write_inferior_int8 (CORE_ADDR symaddr, int8_t val)
{
return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val));
return target_write_memory (symaddr, (unsigned char *) &val, sizeof (val));
}
static int
write_inferior_uinteger (CORE_ADDR symaddr, unsigned int val)
{
return write_inferior_memory (symaddr, (unsigned char *) &val, sizeof (val));
return target_write_memory (symaddr, (unsigned char *) &val, sizeof (val));
}
static CORE_ADDR target_malloc (ULONGEST size);
@ -517,7 +517,7 @@ m_tracepoint_action_download (const struct tracepoint_action *action)
{
CORE_ADDR ipa_action = target_malloc (sizeof (struct collect_memory_action));
write_inferior_memory (ipa_action, (unsigned char *) action,
target_write_memory (ipa_action, (unsigned char *) action,
sizeof (struct collect_memory_action));
return ipa_action;
@ -540,7 +540,7 @@ r_tracepoint_action_download (const struct tracepoint_action *action)
{
CORE_ADDR ipa_action = target_malloc (sizeof (struct collect_registers_action));
write_inferior_memory (ipa_action, (unsigned char *) action,
target_write_memory (ipa_action, (unsigned char *) action,
sizeof (struct collect_registers_action));
return ipa_action;
@ -560,7 +560,7 @@ x_tracepoint_action_download (const struct tracepoint_action *action)
CORE_ADDR ipa_action = target_malloc (sizeof (struct eval_expr_action));
CORE_ADDR expr;
write_inferior_memory (ipa_action, (unsigned char *) action,
target_write_memory (ipa_action, (unsigned char *) action,
sizeof (struct eval_expr_action));
expr = download_agent_expr (((struct eval_expr_action *) action)->expr);
write_inferior_data_pointer (ipa_action
@ -608,7 +608,7 @@ l_tracepoint_action_download (const struct tracepoint_action *action)
CORE_ADDR ipa_action
= target_malloc (sizeof (struct collect_static_trace_data_action));
write_inferior_memory (ipa_action, (unsigned char *) action,
target_write_memory (ipa_action, (unsigned char *) action,
sizeof (struct collect_static_trace_data_action));
return ipa_action;
@ -1458,14 +1458,14 @@ clear_inferior_trace_buffer (void)
ipa_trace_buffer_ctrl.wrap = ipa_trace_buffer_hi;
/* A traceframe with zeroed fields marks the end of trace data. */
write_inferior_memory (ipa_sym_addrs.addr_trace_buffer_ctrl,
target_write_memory (ipa_sym_addrs.addr_trace_buffer_ctrl,
(unsigned char *) &ipa_trace_buffer_ctrl,
sizeof (ipa_trace_buffer_ctrl));
write_inferior_uinteger (ipa_sym_addrs.addr_trace_buffer_ctrl_curr, 0);
/* A traceframe with zeroed fields marks the end of trace data. */
write_inferior_memory (ipa_trace_buffer_lo,
target_write_memory (ipa_trace_buffer_lo,
(unsigned char *) &ipa_traceframe,
sizeof (ipa_traceframe));
@ -6009,12 +6009,12 @@ download_agent_expr (struct agent_expr *expr)
CORE_ADDR expr_bytes;
expr_addr = target_malloc (sizeof (*expr));
write_inferior_memory (expr_addr, (unsigned char *) expr, sizeof (*expr));
target_write_memory (expr_addr, (unsigned char *) expr, sizeof (*expr));
expr_bytes = target_malloc (expr->length);
write_inferior_data_pointer (expr_addr + offsetof (struct agent_expr, bytes),
expr_bytes);
write_inferior_memory (expr_bytes, expr->bytes, expr->length);
target_write_memory (expr_bytes, expr->bytes, expr->length);
return expr_addr;
}
@ -6067,7 +6067,7 @@ download_tracepoint_1 (struct tracepoint *tpoint)
tracepoints before clearing our own copy. */
target_tracepoint.hit_count = 0;
write_inferior_memory (tpptr, (unsigned char *) &target_tracepoint,
target_write_memory (tpptr, (unsigned char *) &target_tracepoint,
sizeof (target_tracepoint));
if (tpoint->cond)
@ -6279,14 +6279,14 @@ download_trace_state_variables (void)
Assume no next, fixup when needed. */
target_tsv.next = NULL;
write_inferior_memory (ptr, (unsigned char *) &target_tsv,
target_write_memory (ptr, (unsigned char *) &target_tsv,
sizeof (target_tsv));
if (tsv->name != NULL)
{
size_t size = strlen (tsv->name) + 1;
CORE_ADDR name_addr = target_malloc (size);
write_inferior_memory (name_addr,
target_write_memory (name_addr,
(unsigned char *) tsv->name, size);
write_inferior_data_pointer (ptr
+ offsetof (struct trace_state_variable,
@ -6548,7 +6548,7 @@ upload_fast_traceframes (void)
(int) (ipa_trace_buffer_hi - ipa_trace_buffer_lo));
}
if (write_inferior_memory (ipa_trace_buffer_ctrl_addr,
if (target_write_memory (ipa_trace_buffer_ctrl_addr,
(unsigned char *) &ipa_trace_buffer_ctrl,
sizeof (struct ipa_trace_buffer_control)))
return;