From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27897 invoked by alias); 1 Dec 2007 11:19:56 -0000 Received: (qmail 27889 invoked by uid 22791); 1 Dec 2007 11:19:55 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 01 Dec 2007 11:19:51 +0000 Received: (qmail 24914 invoked from network); 1 Dec 2007 11:19:49 -0000 Received: from unknown (HELO 172.16.unknown.plus.ru) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 1 Dec 2007 11:19:49 -0000 From: Vladimir Prus Date: Sat, 01 Dec 2007 11:19:00 -0000 Subject: [RFA] Ignore breakpoints when reading memory. To: gdb-patches@sources.redhat.com X-TUID: d7e3a0d534037c41 X-Length: 5715 X-UID: 84 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200712011419.45773.vladimir@codesourcery.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2007-12/txt/msg00009.txt.bz2 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