This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 5/7] go32-nat.c: Don't install a deprecated_xfer_memory method


This removes yet another instance of a deprecated_xfer_memory user.

Unfortunately djgpp's write_child function takes a non-const buffer
pointer, while GDB's xfer_partial api passes a const pointer.  To be
const-correct, we need to copy that buffer to a non-const buffer, and
pass the copy to write_child.  This is actually what
target.c:default_xfer_partial itself does, when calling into the
ops->deprecated_xfer_memory hook.

Tested by cross-building djgpp gdb, on x86-64 Fedora 17.

gdb/
2014-02-19  Pedro Alves  <palves@redhat.com>

	* go32-nat.c (my_write_child): New function.
	(go32_xfer_memory): Rewrite as to_xfer_partial helper.
	(go32_xfer_partial): New function.
	(init_go32_ops): Don't install a deprecated_xfer_memory hook.
	Instad a to_xfer_partial hook.
---
 gdb/go32-nat.c | 76 ++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 56 insertions(+), 20 deletions(-)

diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c
index 2e91b12..7978a5e 100644
--- a/gdb/go32-nat.c
+++ b/gdb/go32-nat.c
@@ -577,31 +577,67 @@ go32_prepare_to_store (struct target_ops *self, struct regcache *regcache)
 {
 }
 
+
+/* Const-correct version of DJGPP's write_child, which unfortunately
+   takes a non-const buffer pointer.  */
+
 static int
-go32_xfer_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len, int write,
-		  struct mem_attrib *attrib, struct target_ops *target)
+my_write_child (unsigned child_addr, const void *buf, unsigned len)
 {
-  if (write)
+  static void *buffer = NULL;
+  static unsigned buffer_len = 0;
+  int res;
+
+  if (buffer_len < len)
     {
-      if (write_child (memaddr, myaddr, len))
-	{
-	  return 0;
-	}
-      else
-	{
-	  return len;
-	}
+      buffer = xrealloc (buffer, len);
+      buffer_len = len;
     }
+
+  memcpy (buffer, buf, len);
+  res = write_child (child_addr, buffer, len);
+  xfree (buffer);
+  return res;
+}
+
+/* Helper for go32_xfer_partial that handles memory transfers.
+   Arguments are like target_xfer_partial.  */
+
+static enum target_xfer_status
+go32_xfer_memory (gdb_byte *readbuf, const gdb_byte *writebuf,
+		  ULONGEST memaddr, ULONGEST len, ULONGEST *xfered_len)
+{
+  int res;
+
+  if (writebuf != NULL)
+    res = my_write_child (memaddr, writebuf, len);
   else
+    res = read_child (memaddr, readbuf, len);
+
+  if (res <= 0)
+    return TARGET_XFER_E_IO;
+
+  *xfered_len = res;
+  return TARGET_XFER_OK;
+}
+
+/* Target to_xfer_partial implementation.  */
+
+static enum target_xfer_status
+go32_xfer_partial (struct target_ops *ops, enum target_object object,
+		   const char *annex, gdb_byte *readbuf,
+		   const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+		   ULONGEST *xfered_len)
+{
+  switch (object)
     {
-      if (read_child (memaddr, myaddr, len))
-	{
-	  return 0;
-	}
-      else
-	{
-	  return len;
-	}
+    case TARGET_OBJECT_MEMORY:
+      return go32_xfer_memory (readbuf, writebuf, offset, len, xfered_len);
+
+    default:
+      return ops->beneath->to_xfer_partial (ops->beneath, object, annex,
+					    readbuf, writebuf, offset, len,
+					    xfered_len);
     }
 }
 
@@ -957,7 +993,7 @@ init_go32_ops (void)
   go32_ops.to_fetch_registers = go32_fetch_registers;
   go32_ops.to_store_registers = go32_store_registers;
   go32_ops.to_prepare_to_store = go32_prepare_to_store;
-  go32_ops.deprecated_xfer_memory = go32_xfer_memory;
+  go32_ops.to_xfer_partial = go32_xfer_partial;
   go32_ops.to_files_info = go32_files_info;
   go32_ops.to_insert_breakpoint = memory_insert_breakpoint;
   go32_ops.to_remove_breakpoint = memory_remove_breakpoint;
-- 
1.7.11.7


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]