16b31aa
2005-12-14  Jeff Johnston  <jjohnstn@redhat.com>
16b31aa
16b31aa
	* symfile-mem.c (read_memory): New static read callback function.
16b31aa
	(symfile_add_from_memory): Pass read_memory to bfd instead of
16b31aa
	target_read_memory.
16b31aa
	* target.c (target_xfer_memory): Add support for LONGEST len and
16b31aa
	change all callers.
16b31aa
	(deprecated_debug_xfer_memory, target_read_memory): Ditto.
16b31aa
	(target_write_memory, do_xfer_memory): Ditto.
16b31aa
	(target_xfer_memory_partial, target_read_memory_partial): Ditto.
16b31aa
	(target_write_memory_partial): Ditto.
16b31aa
	* infptrace.c (child_xfer_memory): Ditto.
16b31aa
	* linux-nat.c (linux_nat_xfer_memory): Ditto.
16b31aa
	(linux_nat_proc_xfer_memory): Ditto.
16b31aa
	* dcache.c (dcache_xfer_memory): Ditto.
16b31aa
	* exec.c (xfer_memory): Ditto.
16b31aa
	* remote.c (remote_xfer_memory): Ditto.
16b31aa
	* remote-sim.c (gdbsim_xfer_interior_memory): Ditto.
16b31aa
	* target.h: Change prototypes for functions changed above.
16b31aa
	* linux-nat.h: Ditto.
16b31aa
	* remote.h: Ditto.
16b31aa
	* dcache.h: Ditto.
16b31aa
aefb0e1
Index: gdb-6.6/gdb/symfile-mem.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/symfile-mem.c	2007-01-20 16:09:05.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/symfile-mem.c	2007-01-20 16:09:17.000000000 +0100
9231e41
@@ -58,6 +58,14 @@
16b31aa
 #include "elf/common.h"
16b31aa
 
16b31aa
 
16b31aa
+/* Local callback routine to pass to bfd to read from target memory,
16b31aa
+   using a len constrained to INT_MAX.  */
16b31aa
+static int
9231e41
+read_target_memory (bfd_vma addr, bfd_byte *buf, int len)
16b31aa
+{
16b31aa
+  return target_read_memory (addr, buf, (LONGEST)len);
16b31aa
+}
16b31aa
+
16b31aa
 /* Read inferior memory at ADDR to find the header of a loaded object file
16b31aa
    and read its in-core symbols out of inferior memory.  TEMPL is a bfd
9231e41
    representing the target's format.  NAME is the name to use for this
9231e41
@@ -78,7 +86,7 @@ symbol_file_add_from_memory (struct bfd 
9231e41
     error (_("add-symbol-file-from-memory not supported for this target"));
16b31aa
 
16b31aa
   nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase,
16b31aa
-					 target_read_memory);
16b31aa
+					 read_target_memory);
16b31aa
   if (nbfd == NULL)
9231e41
     error (_("Failed to read a valid object file image from memory."));
16b31aa
 
aefb0e1
Index: gdb-6.6/gdb/target.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/target.c	2007-01-20 16:09:12.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/target.c	2007-01-20 16:09:17.000000000 +0100
aefb0e1
@@ -56,7 +56,7 @@ static int nosymbol (char *, CORE_ADDR *
aefb0e1
 
aefb0e1
 static void tcomplain (void) ATTR_NORETURN;
aefb0e1
 
aefb0e1
-static int nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
aefb0e1
+static LONGEST nomemory (CORE_ADDR, char *, int, int, struct target_ops *);
aefb0e1
 
aefb0e1
 static int return_zero (void);
aefb0e1
 
aefb0e1
@@ -284,7 +284,7 @@ target_mourn_inferior (void)
aefb0e1
   observer_notify_mourn_inferior (&current_target);
aefb0e1
 }
aefb0e1
 
aefb0e1
-static int
aefb0e1
+static LONGEST
aefb0e1
 nomemory (CORE_ADDR memaddr, char *myaddr, int len, int write,
aefb0e1
 	  struct target_ops *t)
aefb0e1
 {
aefb0e1
@@ -517,7 +517,7 @@ update_current_target (void)
aefb0e1
 	    (void (*) (void))
16b31aa
 	    noprocess);
aefb0e1
   de_fault (deprecated_xfer_memory,
aefb0e1
-	    (int (*) (CORE_ADDR, gdb_byte *, int, int, struct mem_attrib *, struct target_ops *))
9231e41
+	    (LONGEST (*) (CORE_ADDR, gdb_byte *, LONGEST, int, struct mem_attrib *, struct target_ops *))
16b31aa
 	    nomemory);
aefb0e1
   de_fault (to_files_info,
aefb0e1
 	    (void (*) (struct target_ops *))
aefb0e1
@@ -1178,7 +1178,7 @@ target_xfer_partial (struct target_ops *
aefb0e1
    it makes no progress, and then return how much was transferred). */
16b31aa
 
16b31aa
 int
9231e41
-target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
9231e41
+target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, LONGEST len)
16b31aa
 {
aefb0e1
   if (target_read (&current_target, TARGET_OBJECT_MEMORY, NULL,
aefb0e1
 		   myaddr, memaddr, len) == len)
aefb0e1
@@ -1188,7 +1188,7 @@ target_read_memory (CORE_ADDR memaddr, g
16b31aa
 }
16b31aa
 
16b31aa
 int
9231e41
-target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
9231e41
+target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr, LONGEST len)
16b31aa
 {
aefb0e1
   if (target_write (&current_target, TARGET_OBJECT_MEMORY, NULL,
aefb0e1
 		    myaddr, memaddr, len) == len)
aefb0e1
@@ -2186,8 +2186,8 @@ debug_to_prepare_to_store (void)
16b31aa
   fprintf_unfiltered (gdb_stdlog, "target_prepare_to_store ()\n");
16b31aa
 }
16b31aa
 
16b31aa
-static int
9231e41
-deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, int len,
16b31aa
+static LONGEST
9231e41
+deprecated_debug_xfer_memory (CORE_ADDR memaddr, bfd_byte *myaddr, LONGEST len,
16b31aa
 			      int write, struct mem_attrib *attrib,
16b31aa
 			      struct target_ops *target)
16b31aa
 {
aefb0e1
@@ -2197,9 +2197,9 @@ deprecated_debug_xfer_memory (CORE_ADDR 
16b31aa
 						attrib, target);
16b31aa
 
16b31aa
   fprintf_unfiltered (gdb_stdlog,
16b31aa
-		      "target_xfer_memory (0x%x, xxx, %d, %s, xxx) = %d",
16b31aa
+		      "target_xfer_memory (0x%x, xxx, %ld, %s, xxx) = %d",
16b31aa
 		      (unsigned int) memaddr,	/* possable truncate long long */
16b31aa
-		      len, write ? "write" : "read", retval);
16b31aa
+		      (long)len, write ? "write" : "read", retval);
16b31aa
 
16b31aa
   if (retval > 0)
16b31aa
     {
aefb0e1
Index: gdb-6.6/gdb/target.h
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/target.h	2007-01-20 16:09:10.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/target.h	2007-01-20 16:09:17.000000000 +0100
aefb0e1
@@ -347,10 +347,10 @@ struct target_ops
16b31aa
        NOTE: cagney/2004-10-01: This has been entirely superseeded by
16b31aa
        to_xfer_partial and inferior inheritance.  */
16b31aa
 
9231e41
-    int (*deprecated_xfer_memory) (CORE_ADDR memaddr, gdb_byte *myaddr,
16b31aa
-				   int len, int write,
9231e41
-				   struct mem_attrib *attrib,
9231e41
-				   struct target_ops *target);
9231e41
+    LONGEST (*deprecated_xfer_memory) (CORE_ADDR memaddr, gdb_byte *myaddr,
9231e41
+				       LONGEST len, int write,
9231e41
+				       struct mem_attrib *attrib,
9231e41
+				       struct target_ops *target);
16b31aa
 
9231e41
     void (*to_files_info) (struct target_ops *);
9231e41
     int (*to_insert_breakpoint) (struct bp_target_info *);
aefb0e1
@@ -605,16 +605,17 @@ extern DCACHE *target_dcache;
16b31aa
 
16b31aa
 extern int target_read_string (CORE_ADDR, char **, int, int *);
16b31aa
 
9231e41
-extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len);
9231e41
+extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
9231e41
+			       LONGEST len);
16b31aa
 
9231e41
 extern int target_write_memory (CORE_ADDR memaddr, const gdb_byte *myaddr,
9231e41
-				int len);
9231e41
+				LONGEST len);
16b31aa
 
9231e41
-extern int xfer_memory (CORE_ADDR, gdb_byte *, int, int,
16b31aa
-			struct mem_attrib *, struct target_ops *);
9231e41
+extern LONGEST xfer_memory (CORE_ADDR, gdb_byte *, LONGEST, int,
16b31aa
+			    struct mem_attrib *, struct target_ops *);
16b31aa
 
9231e41
-extern int child_xfer_memory (CORE_ADDR, gdb_byte *, int, int,
16b31aa
-			      struct mem_attrib *, struct target_ops *);
9231e41
+extern LONGEST child_xfer_memory (CORE_ADDR, gdb_byte *, LONGEST, int,
9231e41
+				  struct mem_attrib *, struct target_ops *);
16b31aa
 
aefb0e1
 /* Fetches the target's memory map.  If one is found it is sorted
aefb0e1
    and returned, after some consistency checking.  Otherwise, NULL
aefb0e1
Index: gdb-6.6/gdb/infptrace.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/infptrace.c	2005-12-17 23:34:01.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/infptrace.c	2007-01-20 16:09:17.000000000 +0100
aefb0e1
@@ -331,17 +331,17 @@ store_inferior_registers (int regnum)
16b31aa
    deprecated_child_ops doesn't allow memory operations to cross below
16b31aa
    us in the target stack anyway.  */
16b31aa
 
16b31aa
-int
9231e41
-child_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
16b31aa
+LONGEST
9231e41
+child_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, LONGEST len, int write,
16b31aa
 		   struct mem_attrib *attrib, struct target_ops *target)
16b31aa
 {
16b31aa
-  int i;
16b31aa
+  LONGEST i;
16b31aa
   /* Round starting address down to longword boundary.  */
16b31aa
   CORE_ADDR addr = memaddr & -(CORE_ADDR) sizeof (PTRACE_TYPE_RET);
16b31aa
   /* Round ending address up; get number of longwords that makes.  */
16b31aa
-  int count = ((((memaddr + len) - addr) + sizeof (PTRACE_TYPE_RET) - 1)
9231e41
-	       / sizeof (PTRACE_TYPE_RET));
16b31aa
-  int alloc = count * sizeof (PTRACE_TYPE_RET);
9231e41
+  LONGEST count = ((((memaddr + len) - addr) + sizeof (PTRACE_TYPE_RET) - 1)
9231e41
+		   / sizeof (PTRACE_TYPE_RET));
16b31aa
+  LONGEST alloc = count * sizeof (PTRACE_TYPE_RET);
16b31aa
   PTRACE_TYPE_RET *buffer;
16b31aa
   struct cleanup *old_chain = NULL;
16b31aa
 
aefb0e1
Index: gdb-6.6/gdb/dcache.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/dcache.c	2006-08-15 20:46:24.000000000 +0200
aefb0e1
+++ gdb-6.6/gdb/dcache.c	2007-01-20 16:09:17.000000000 +0100
aefb0e1
@@ -519,9 +519,9 @@ dcache_free (DCACHE *dcache)
16b31aa
 
16b31aa
    This routine is indended to be called by remote_xfer_ functions. */
16b31aa
 
16b31aa
-int
16b31aa
+LONGEST
9231e41
 dcache_xfer_memory (DCACHE *dcache, CORE_ADDR memaddr, gdb_byte *myaddr,
9231e41
-		    int len, int should_write)
16b31aa
+		    LONGEST len, int should_write)
16b31aa
 {
16b31aa
   int i;
9231e41
   int (*xfunc) (DCACHE *dcache, CORE_ADDR addr, gdb_byte *ptr);
aefb0e1
Index: gdb-6.6/gdb/dcache.h
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/dcache.h	2005-12-17 23:33:59.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/dcache.h	2007-01-20 16:09:17.000000000 +0100
16b31aa
@@ -37,7 +37,7 @@ void dcache_free (DCACHE *);
16b31aa
 
16b31aa
 /* Simple to call from <remote>_xfer_memory */
16b31aa
 
9231e41
-int dcache_xfer_memory (DCACHE *cache, CORE_ADDR mem, gdb_byte *my,
9231e41
-			int len, int should_write);
9231e41
+LONGEST dcache_xfer_memory (DCACHE *cache, CORE_ADDR mem, gdb_byte *my,
9231e41
+			    LONGEST len, int should_write);
16b31aa
 
16b31aa
 #endif /* DCACHE_H */
aefb0e1
Index: gdb-6.6/gdb/exec.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/exec.c	2006-11-10 20:20:35.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/exec.c	2007-01-20 16:09:17.000000000 +0100
aefb0e1
@@ -452,8 +452,8 @@ map_vmap (bfd *abfd, bfd *arch)
16b31aa
    The same routine is used to handle both core and exec files;
16b31aa
    we just tail-call it with more arguments to select between them.  */
16b31aa
 
16b31aa
-int
9231e41
-xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
16b31aa
+LONGEST
9231e41
+xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, LONGEST len, int write,
9231e41
 	     struct mem_attrib *attrib, struct target_ops *target)
16b31aa
 {
9231e41
   int res;
aefb0e1
Index: gdb-6.6/gdb/linux-nat.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/linux-nat.c	2007-01-20 16:09:14.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/linux-nat.c	2007-01-20 16:09:17.000000000 +0100
aefb0e1
@@ -3266,7 +3266,7 @@ linux_xfer_partial (struct target_ops *o
9231e41
 	 Revert when Bugzilla 147436 is fixed.  */
9231e41
       if (iterate_over_lwps (ia64_linux_check_stack_region, &range) != NULL)
9231e41
 	{ /* This region contains ia64 rse registers, we have to re-read.  */
9231e41
-	  int xxfer;
9231e41
+	  LONGEST xxfer;
9231e41
 
9231e41
 	  /* Re-read register stack area.  */
9231e41
 	  xxfer = super_xfer_partial (ops, object, annex,
aefb0e1
Index: gdb-6.6/gdb/remote.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/remote.c	2007-01-20 16:09:12.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/remote.c	2007-01-20 16:09:17.000000000 +0100
16b31aa
@@ -27,6 +27,7 @@
16b31aa
 #include "gdb_string.h"
16b31aa
 #include <ctype.h>
16b31aa
 #include <fcntl.h>
16b31aa
+#include <limits.h>
16b31aa
 #include "inferior.h"
16b31aa
 #include "bfd.h"
16b31aa
 #include "symfile.h"
aefb0e1
@@ -4185,19 +4186,27 @@ remote_read_bytes (CORE_ADDR memaddr, gd
9231e41
    if SHOULD_WRITE is nonzero.  Returns length of data written or
9231e41
    read; 0 for error.  TARGET is unused.  */
16b31aa
 
16b31aa
-static int
9231e41
-remote_xfer_memory (CORE_ADDR mem_addr, gdb_byte *buffer, int mem_len,
16b31aa
+static LONGEST
9231e41
+remote_xfer_memory (CORE_ADDR mem_addr, gdb_byte *buffer, LONGEST mem_len,
16b31aa
 		    int should_write, struct mem_attrib *attrib,
16b31aa
 		    struct target_ops *target)
16b31aa
 {
16b31aa
   int res;
16b31aa
+  int len;
16b31aa
+
9231e41
+
16b31aa
+  /* This routine is not set up to handle > INT_MAX bytes.  */
16b31aa
+  if (mem_len >= (LONGEST)INT_MAX)
16b31aa
+    return 0;
16b31aa
+
16b31aa
+  len = (int)mem_len;
16b31aa
 
aefb0e1
   if (should_write)
aefb0e1
     res = remote_write_bytes (mem_addr, buffer, mem_len);
16b31aa
   else
aefb0e1
     res = remote_read_bytes (mem_addr, buffer, mem_len);
16b31aa
 
16b31aa
-  return res;
16b31aa
+  return (LONGEST)res;
16b31aa
 }
16b31aa
 
aefb0e1
 /* Sends a packet with content determined by the printf format string
aefb0e1
Index: gdb-6.6/gdb/remote-sim.c
9231e41
===================================================================
aefb0e1
--- gdb-6.6.orig/gdb/remote-sim.c	2006-11-10 20:20:36.000000000 +0100
aefb0e1
+++ gdb-6.6/gdb/remote-sim.c	2007-01-20 16:10:10.000000000 +0100
aefb0e1
@@ -745,11 +745,14 @@ gdbsim_prepare_to_store (void)
16b31aa
 
16b31aa
    Returns the number of bytes transferred. */
16b31aa
 
16b31aa
-static int
9231e41
-gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len,
16b31aa
+static LONGEST
9231e41
+gdbsim_xfer_inferior_memory (CORE_ADDR memaddr, gdb_byte *myaddr, LONGEST len,
16b31aa
 			     int write, struct mem_attrib *attrib,
16b31aa
 			     struct target_ops *target)
16b31aa
 {
16b31aa
+  /* Convert to len type that sim_read and sim_write can handle.  */
16b31aa
+  int xfer_len = (int)len;
16b31aa
+
aefb0e1
   /* If no program is running yet, then ignore the simulator for
aefb0e1
      memory.  Pass the request down to the next target, hopefully
aefb0e1
      an exec file.  */
aefb0e1
@@ -765,22 +768,22 @@ gdbsim_xfer_inferior_memory (CORE_ADDR m
16b31aa
       printf_filtered ("gdbsim_xfer_inferior_memory: myaddr 0x");
16b31aa
       gdb_print_host_address (myaddr, gdb_stdout);
16b31aa
       printf_filtered (", memaddr 0x%s, len %d, write %d\n",
16b31aa
-		       paddr_nz (memaddr), len, write);
16b31aa
+		       paddr_nz (memaddr), xfer_len, write);
16b31aa
       if (sr_get_debug () && write)
16b31aa
-	dump_mem (myaddr, len);
16b31aa
+	dump_mem (myaddr, xfer_len);
16b31aa
     }
16b31aa
 
16b31aa
   if (write)
16b31aa
     {
16b31aa
-      len = sim_write (gdbsim_desc, memaddr, myaddr, len);
16b31aa
+      xfer_len = sim_write (gdbsim_desc, memaddr, myaddr, xfer_len);
16b31aa
     }
16b31aa
   else
16b31aa
     {
16b31aa
-      len = sim_read (gdbsim_desc, memaddr, myaddr, len);
16b31aa
-      if (sr_get_debug () && len > 0)
16b31aa
-	dump_mem (myaddr, len);
16b31aa
+      xfer_len = sim_read (gdbsim_desc, memaddr, myaddr, xfer_len);
16b31aa
+      if (sr_get_debug () && xfer_len > 0)
16b31aa
+	dump_mem (myaddr, xfer_len);
16b31aa
     }
16b31aa
-  return len;
16b31aa
+  return (LONGEST)xfer_len;
16b31aa
 }
16b31aa
 
16b31aa
 static void