This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] Remove an excess memcpy in remote.c
- From: Daniel Jacobowitz <drow at false dot org>
- To: gdb-patches at sourceware dot org
- Date: Tue, 15 Aug 2006 14:19:48 -0400
- Subject: [commit] Remove an excess memcpy in remote.c
This memcpy has been there for years, because remote_xfer_memory took a
non-const argument. I added it, although I think I copied it from
elsewhere. There's not really any disadvantage to casting the const
writebuf to non-const for this purpose, since we know it won't be modified,
but anyway we can do it right now; call remote_write_bytes directly.
In the process it fixes a theoretical buglet on platforms which use both
fileio and the dubious gdbarch_remote_translate_xfer_address hook.
Tested and committed.
--
Daniel Jacobowitz
CodeSourcery
2006-08-15 Daniel Jacobowitz <dan@codesourcery.com>
* remote.c (remote_write_bytes): Take a const buffer argument.
Do the checks from remote_xfer_memory.
(remote_read_bytes): Do the checks from remote_xfer_memory.
(remote_xfer_memory): Remove checks pushed into lower level
functions.
(remote_xfer_partial): Call remote_write_bytes and remote_read_bytes
directly.
* remote.h (remote_write_bytes): Update prototype.
---
gdb/remote.c | 46 ++++++++++++++++++++++++----------------------
gdb/remote.h | 3 ++-
2 files changed, 26 insertions(+), 23 deletions(-)
Index: src/gdb/remote.c
===================================================================
--- src.orig/gdb/remote.c 2006-08-10 23:21:52.000000000 -0400
+++ src/gdb/remote.c 2006-08-11 10:31:58.000000000 -0400
@@ -3853,7 +3853,7 @@ check_binary_download (CORE_ADDR addr)
error. Only transfer a single packet. */
int
-remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
+remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
{
struct remote_state *rs = get_remote_state ();
char *buf;
@@ -3865,6 +3865,15 @@ remote_write_bytes (CORE_ADDR memaddr, g
int payload_size;
int payload_length;
+ /* Should this be the selected frame? */
+ gdbarch_remote_translate_xfer_address (current_gdbarch,
+ current_regcache,
+ memaddr, len,
+ &memaddr, &len);
+
+ if (len <= 0)
+ return 0;
+
/* Verify that the target can support a binary download. */
check_binary_download (memaddr);
@@ -4023,6 +4032,15 @@ remote_read_bytes (CORE_ADDR memaddr, gd
int max_buf_size; /* Max size of packet output buffer. */
int origlen;
+ /* Should this be the selected frame? */
+ gdbarch_remote_translate_xfer_address (current_gdbarch,
+ current_regcache,
+ memaddr, len,
+ &memaddr, &len);
+
+ if (len <= 0)
+ return 0;
+
max_buf_size = get_memory_read_packet_size ();
/* The packet buffer will be large enough for the payload;
get_memory_packet_size ensures this. */
@@ -4090,22 +4108,12 @@ remote_xfer_memory (CORE_ADDR mem_addr,
int should_write, struct mem_attrib *attrib,
struct target_ops *target)
{
- CORE_ADDR targ_addr;
- int targ_len;
int res;
- /* Should this be the selected frame? */
- gdbarch_remote_translate_xfer_address (current_gdbarch,
- current_regcache,
- mem_addr, mem_len,
- &targ_addr, &targ_len);
- if (targ_len <= 0)
- return 0;
-
if (should_write)
- res = remote_write_bytes (targ_addr, buffer, targ_len);
+ res = remote_write_bytes (mem_addr, buffer, mem_len);
else
- res = remote_read_bytes (targ_addr, buffer, targ_len);
+ res = remote_read_bytes (mem_addr, buffer, mem_len);
return res;
}
@@ -5270,22 +5278,16 @@ remote_xfer_partial (struct target_ops *
char *p2;
char query_type;
- /* Handle memory using remote_xfer_memory. */
+ /* Handle memory using the standard memory routines. */
if (object == TARGET_OBJECT_MEMORY)
{
int xfered;
errno = 0;
if (writebuf != NULL)
- {
- void *buffer = xmalloc (len);
- struct cleanup *cleanup = make_cleanup (xfree, buffer);
- memcpy (buffer, writebuf, len);
- xfered = remote_xfer_memory (offset, buffer, len, 1, NULL, ops);
- do_cleanups (cleanup);
- }
+ xfered = remote_write_bytes (offset, writebuf, len);
else
- xfered = remote_xfer_memory (offset, readbuf, len, 0, NULL, ops);
+ xfered = remote_read_bytes (offset, readbuf, len);
if (xfered > 0)
return xfered;
Index: src/gdb/remote.h
===================================================================
--- src.orig/gdb/remote.h 2006-08-10 23:23:47.000000000 -0400
+++ src/gdb/remote.h 2006-08-10 23:23:54.000000000 -0400
@@ -55,7 +55,8 @@ extern void remote_cisco_objfile_relocat
extern void async_remote_interrupt_twice (void *arg);
-extern int remote_write_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len);
+extern int remote_write_bytes (CORE_ADDR memaddr, const gdb_byte *myaddr,
+ int len);
extern int remote_read_bytes (CORE_ADDR memaddr, gdb_byte *myaddr, int len);