This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFA] Ignore breakpoints when reading memory.
- From: Vladimir Prus <vladimir at codesourcery dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sat, 1 Dec 2007 14:19:45 +0300
- Subject: [RFA] Ignore breakpoints when reading memory.
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);
}
+
/* 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