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 1/2] Separate read and write in dcache_xfer_memory


This patch is to refactor dcache_xfer_memory to separate the code
reading and wring target memory.

gdb:

2013-10-18  Yao Qi  <yao@codesourcery.com>

	* dcache.c (dcache_xfer_memory): Separate memory read and
	write.
---
 gdb/dcache.c |   37 ++++++++++++++++++++++---------------
 1 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/gdb/dcache.c b/gdb/dcache.c
index acb9de4..316f3dd 100644
--- a/gdb/dcache.c
+++ b/gdb/dcache.c
@@ -491,9 +491,6 @@ dcache_xfer_memory (struct target_ops *ops, DCACHE *dcache,
 {
   int i;
   int res;
-  int (*xfunc) (DCACHE *dcache, CORE_ADDR addr, gdb_byte *ptr);
-
-  xfunc = should_write ? dcache_poke_byte : dcache_peek_byte;
 
   /* If this is a different inferior from what we've recorded,
      flush the cache.  */
@@ -515,23 +512,33 @@ dcache_xfer_memory (struct target_ops *ops, DCACHE *dcache,
 	return res;
       /* Update LEN to what was actually written.  */
       len = res;
+
+      for (i = 0; i < len; i++)
+	{
+	  if (!dcache_poke_byte (dcache, memaddr + i, myaddr + i))
+	    {
+	      /* That failed.  Discard its cache line so we don't have a
+		 partially read line.  */
+	      dcache_invalidate_line (dcache, memaddr + i);
+	      /* We still wrote LEN bytes.  */
+	      return len;
+	    }
+	}
     }
-      
-  for (i = 0; i < len; i++)
+  else
     {
-      if (!xfunc (dcache, memaddr + i, myaddr + i))
+      for (i = 0; i < len; i++)
 	{
-	  /* That failed.  Discard its cache line so we don't have a
-	     partially read line.  */
-	  dcache_invalidate_line (dcache, memaddr + i);
-	  /* If we're writing, we still wrote LEN bytes.  */
-	  if (should_write)
-	    return len;
-	  else
-	    return i;
+	  if (!dcache_peek_byte (dcache, memaddr + i, myaddr + i))
+	    {
+	      /* That failed.  Discard its cache line so we don't have a
+		 partially read line.  */
+	      dcache_invalidate_line (dcache, memaddr + i);
+	      return i;
+	    }
 	}
     }
-    
+
   return len;
 }
 
-- 
1.7.7.6


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