Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Ignore breakpoints when reading memory.
@ 2007-12-01 11:19 Vladimir Prus
  2007-12-04 18:14 ` Mark Kettenis
  2007-12-04 19:22 ` Daniel Jacobowitz
  0 siblings, 2 replies; 10+ messages in thread
From: Vladimir Prus @ 2007-12-01 11:19 UTC (permalink / raw)
  To: gdb-patches


This commit prepares us for always-inserted-breakpoints mode.
If breakpoints are always inserted, then reading the code memory
will read the breakpoint instructions, not the original content.
This patch makes us try to restore the original comments using
the breakpoints table. OK?

- Volodya

	* breakpoint.h (breakpoint_restore_shadows): New
	declaration.
	* breakpoint.c (breakpoint_restore_shadows): New.
	(read_memory_nobpt): Use breakpoint_restore_shadows.
	* target.c (memory_xfer_partial): Call
	breakpoint_restore_shadows.
---
 gdb/breakpoint.c |   80 ++++++++++++++++++++++-------------------------------
 gdb/breakpoint.h |    4 +++
 gdb/target.c     |   13 +++++++--
 3 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 59fec71..4365a3a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -713,14 +713,23 @@ commands_from_control_command (char *arg, struct command_line *cmd)
 int
 read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
 {
-  int status;
-  const struct bp_location *b;
+  int status = target_read_memory (memaddr, myaddr, len);
+  if (status)
+    return status;
+
+  breakpoint_restore_shadows (myaddr, memaddr, len);
+  return 0;  
+}
+
+void
+breakpoint_restore_shadows (gdb_byte *buf,
+			    ULONGEST memaddr, 
+			    LONGEST len)
+{
+  struct bp_location *b;
   CORE_ADDR bp_addr = 0;
   int bp_size = 0;
-
-  if (gdbarch_breakpoint_from_pc (current_gdbarch, &bp_addr, &bp_size) == NULL)
-    /* No breakpoints on this machine. */
-    return target_read_memory (memaddr, myaddr, len);
+  int bptoffset = 0;
 
   ALL_BP_LOCATIONS (b)
   {
@@ -739,60 +748,37 @@ read_memory_nobpt (CORE_ADDR memaddr, gdb_byte *myaddr, unsigned len)
     if (bp_size == 0)
       /* bp isn't valid, or doesn't shadow memory.  */
       continue;
+
     if (bp_addr + bp_size <= memaddr)
       /* The breakpoint is entirely before the chunk of memory we
          are reading.  */
       continue;
+
     if (bp_addr >= memaddr + len)
       /* The breakpoint is entirely after the chunk of memory we are
          reading. */
       continue;
-    /* Copy the breakpoint from the shadow contents, and recurse for
-       the things before and after.  */
-    {
-      /* Offset within shadow_contents.  */
-      int bptoffset = 0;
 
-      if (bp_addr < memaddr)
-	{
-	  /* Only copy the second part of the breakpoint.  */
-	  bp_size -= memaddr - bp_addr;
-	  bptoffset = memaddr - bp_addr;
-	  bp_addr = memaddr;
-	}
-
-      if (bp_addr + bp_size > memaddr + len)
-	{
-	  /* Only copy the first part of the breakpoint.  */
-	  bp_size -= (bp_addr + bp_size) - (memaddr + len);
-	}
-
-      memcpy (myaddr + bp_addr - memaddr,
-	      b->target_info.shadow_contents + bptoffset, bp_size);
+    /* Offset within shadow_contents.  */
+    if (bp_addr < memaddr)
+      {
+	/* Only copy the second part of the breakpoint.  */
+	bp_size -= memaddr - bp_addr;
+	bptoffset = memaddr - bp_addr;
+	bp_addr = memaddr;
+      }
 
-      if (bp_addr > memaddr)
-	{
-	  /* Copy the section of memory before the breakpoint.  */
-	  status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
-	  if (status != 0)
-	    return status;
-	}
+    if (bp_addr + bp_size > memaddr + len)
+      {
+	/* Only copy the first part of the breakpoint.  */
+	bp_size -= (bp_addr + bp_size) - (memaddr + len);
+      }
 
-      if (bp_addr + bp_size < memaddr + len)
-	{
-	  /* Copy the section of memory after the breakpoint.  */
-	  status = read_memory_nobpt (bp_addr + bp_size,
-				      myaddr + bp_addr + bp_size - memaddr,
-				      memaddr + len - (bp_addr + bp_size));
-	  if (status != 0)
-	    return status;
-	}
-      return 0;
-    }
+    memcpy (buf + bp_addr - memaddr,
+	    b->target_info.shadow_contents + bptoffset, bp_size);
   }
-  /* Nothing overlaps.  Just call read_memory_noerr.  */
-  return target_read_memory (memaddr, myaddr, len);
 }
+
 \f
 
 /* A wrapper function for inserting catchpoints.  */
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 3855485..9f98718 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -859,4 +859,8 @@ extern int deprecated_remove_raw_breakpoint (void *);
    target.  */
 int watchpoints_triggered (struct target_waitstatus *);
 
+extern void breakpoint_restore_shadows (gdb_byte *buf,
+					ULONGEST memaddr, 
+					LONGEST len);
+
 #endif /* !defined (BREAKPOINT_H) */
diff --git a/gdb/target.c b/gdb/target.c
index d89a7fb..f19c54d 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1071,7 +1071,11 @@ memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf
       if (res <= 0)
 	return -1;
       else
-	return res;
+	{
+	  if (readbuf)
+	    breakpoint_restore_shadows (readbuf, memaddr, reg_len);
+	  return res;
+	}
     }
 
   /* If none of those methods found the memory we wanted, fall back
@@ -1089,17 +1093,20 @@ memory_xfer_partial (struct target_ops *ops, void *readbuf, const void *writebuf
       res = ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
 				  readbuf, writebuf, memaddr, reg_len);
       if (res > 0)
-	return res;
+	break;
 
       /* We want to continue past core files to executables, but not
 	 past a running target's memory.  */
       if (ops->to_has_all_memory)
-	return res;
+	break;
 
       ops = ops->beneath;
     }
   while (ops != NULL);
 
+  if (readbuf)
+    breakpoint_restore_shadows (readbuf, memaddr, reg_len);
+
   /* If we still haven't got anything, return the last error.  We
      give up.  */
   return res;
-- 
1.5.3.5



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-01-21 18:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-01 11:19 [RFA] Ignore breakpoints when reading memory Vladimir Prus
2007-12-04 18:14 ` Mark Kettenis
2007-12-04 19:12   ` Jim Blandy
2008-01-21 17:19   ` Jim Blandy
2007-12-04 19:22 ` Daniel Jacobowitz
2007-12-05 22:31   ` Jim Blandy
2007-12-13 19:23     ` Vladimir Prus
2008-01-21 17:20     ` Jim Blandy
2008-01-21 18:24       ` Vladimir Prus
2008-01-21 18:37         ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox