From 10e2d419a3084f5ed32c340cd27a94a911f694b9 Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Thu, 27 Jan 2005 20:09:10 +0000 Subject: 2005-01-27 Andrew Cagney * symfile-mem.c (do_target_read_memory): New function. (symbol_file_add_from_memory): Pass do_target_read_memory to bfd_elf_bfd_from_remote_memory. * corefile.c (write_memory): Update, make a copy of the read-only buffer. * target.c (target_read_memory): Update. (target_write_memory): Update, make a copy of the read-only buffer. * gdbcore.h (write_memory): Change buffer type to bfd_byte, make const. * target.h (target_read_memory, target_write_memory): Change buffer type to bfd_byte; for write_memory, make it const. --- gdb/ChangeLog | 13 +++++++++++++ gdb/corefile.c | 8 +++++--- gdb/gdbcore.h | 2 +- gdb/symfile-mem.c | 11 ++++++++++- gdb/target.c | 10 ++++++---- gdb/target.h | 5 +++-- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7732708..7ccfa71 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,18 @@ 2005-01-27 Andrew Cagney + * corefile.c (write_memory): Update, make a copy of the read-only + buffer. + * target.c (target_read_memory): Update. + (target_write_memory): Update, make a copy of the read-only + buffer. + * gdbcore.h (write_memory): Change buffer type to bfd_byte, make + const. + * target.h (target_read_memory, target_write_memory): Change + buffer type to bfd_byte; for write_memory, make it const. + * symfile-mem.c (do_target_read_memory): New function. + (symbol_file_add_from_memory): Pass do_target_read_memory to + bfd_elf_bfd_from_remote_memory. + * value.h: Indent using gdb_indent.sh. * configure: Regenerate to track ../gettext.m4 change. diff --git a/gdb/corefile.c b/gdb/corefile.c index 8ef3ed2..ff7003a 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -347,11 +347,13 @@ read_memory_typed_address (CORE_ADDR addr, struct type *type) /* Same as target_write_memory, but report an error if can't write. */ void -write_memory (CORE_ADDR memaddr, char *myaddr, int len) +write_memory (CORE_ADDR memaddr, const bfd_byte *myaddr, int len) { int status; - - status = target_write_memory (memaddr, myaddr, len); + bfd_byte *bytes = alloca (len); + + memcpy (bytes, myaddr, len); + status = target_write_memory (memaddr, bytes, len); if (status != 0) memory_error (status, memaddr); } diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h index 248b169..d4e9a9d 100644 --- a/gdb/gdbcore.h +++ b/gdb/gdbcore.h @@ -86,7 +86,7 @@ CORE_ADDR read_memory_typed_address (CORE_ADDR addr, struct type *type); byteswapping, alignment, different sizes for host vs. target types, etc. */ -extern void write_memory (CORE_ADDR memaddr, char *myaddr, int len); +extern void write_memory (CORE_ADDR memaddr, const bfd_byte *myaddr, int len); /* Store VALUE at ADDR in the inferior as a LEN-byte unsigned integer. */ extern void write_memory_unsigned_integer (CORE_ADDR addr, int len, diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 6cb04f2..61c168e 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -58,6 +58,15 @@ #include "elf/common.h" +/* FIXME: cagney/2005-01-27: Should be a function with the signature: + int (void *object, const bfd_byte *myaddr, int len). */ + +static int +do_target_read_memory (bfd_vma vma, char *myaddr, int len) +{ + return target_read_memory (vma, myaddr, len); +} + /* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. TEMPL is a bfd representing the target's format. NAME is the name to use for this @@ -78,7 +87,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name, error ("add-symbol-file-from-memory not supported for this target"); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, - target_read_memory); + do_target_read_memory); if (nbfd == NULL) error ("Failed to read a valid object file image from memory."); diff --git a/gdb/target.c b/gdb/target.c index bade14c..5a050af 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -995,7 +995,7 @@ xfer_using_stratum (enum target_object object, const char *annex, deal with partial reads should call target_read_memory_partial. */ int -target_read_memory (CORE_ADDR memaddr, char *myaddr, int len) +target_read_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len) { if (target_xfer_partial_p ()) return xfer_using_stratum (TARGET_OBJECT_MEMORY, NULL, @@ -1005,13 +1005,15 @@ target_read_memory (CORE_ADDR memaddr, char *myaddr, int len) } int -target_write_memory (CORE_ADDR memaddr, char *myaddr, int len) +target_write_memory (CORE_ADDR memaddr, const bfd_byte *myaddr, int len) { + bfd_byte *bytes = alloca (len); + memcpy (bytes, myaddr, len); if (target_xfer_partial_p ()) return xfer_using_stratum (TARGET_OBJECT_MEMORY, NULL, - memaddr, len, NULL, myaddr); + memaddr, len, NULL, bytes); else - return target_xfer_memory (memaddr, myaddr, len, 1); + return target_xfer_memory (memaddr, bytes, len, 1); } #ifndef target_stopped_data_address_p diff --git a/gdb/target.h b/gdb/target.h index 9665ade..ff9ba11 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -537,9 +537,10 @@ extern int do_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, extern int target_read_string (CORE_ADDR, char **, int, int *); -extern int target_read_memory (CORE_ADDR memaddr, char *myaddr, int len); +extern int target_read_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len); -extern int target_write_memory (CORE_ADDR memaddr, char *myaddr, int len); +extern int target_write_memory (CORE_ADDR memaddr, const bfd_byte *myaddr, + int len); extern int xfer_memory (CORE_ADDR, char *, int, int, struct mem_attrib *, struct target_ops *); -- cgit v1.1