From patchwork Thu Mar 5 23:42:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 5486 Received: (qmail 69382 invoked by alias); 5 Mar 2015 23:42:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 69286 invoked by uid 89); 5 Mar 2015 23:42:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 05 Mar 2015 23:42:53 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t25Ngpt0012440 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 5 Mar 2015 18:42:52 -0500 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t25Ngng2017305 for ; Thu, 5 Mar 2015 18:42:51 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed 1/2] PR gdb/18002: Fix reinsert of a permanent breakpoints Date: Thu, 5 Mar 2015 23:42:48 +0000 Message-Id: <1425598969-7666-2-git-send-email-palves@redhat.com> In-Reply-To: <1425598969-7666-1-git-send-email-palves@redhat.com> References: <1425598969-7666-1-git-send-email-palves@redhat.com> When we find out that a breakpoint is set on top of a program breakpoint, we mark it as "permanent". E.g.,: ... if (bp_loc_is_permanent (loc)) { loc->inserted = 1; loc->permanent = 1; } ... Note we didn't fill in the breakpoint's shadow (shadow_len remains 0). In case the target claims support for evaluating breakpoint conditions, GDB sometimes reinserts breakpoints that are already inserted (to update the conditions on the target side). Since GDB doesn't know whether the target supports evaluating conditions _of_ software breakpoints (vs hardware breakpoints, etc.) until it actually tries it, if the target doesn't actually support z0 breakpoints, GDB ends up reinserting a GDB-managed software/memory breakpoint (mem-break.c). And that is the case that is buggy: breakpoints that are marked inserted contribute their shadows (if any) to the memory returned by target_read_memory, to mask out breakpoints. Permanent breakpoints are always marked as inserted. So if the permanent breakpoint doesn't have a shadow yet in its shadow buffer, but we set shadow_len before calling target_read_memory, then the still clear shadow_contents buffer will be used by the breakpoint masking code... And then from there on, the permanent breakpoint has a broken shadow buffer, and thus any memory read out of that address will read bogus code, and many random bad things fall out from that. The fix is just to set shadow_len at the same time shadow_contents is set, not one before and another after... Fixes all gdb.base/bp-permanent.exp FAILs on PPC64 GNU/Linux gdbserver and probably any other gdbserver port that doesn't do z0 breakpoints. gdb/ChangeLog: 2015-03-05 Pedro Alves PR gdb/18002 * mem-break.c (default_memory_insert_breakpoint): Set shadow_len after reading the breakpoint's shadow memory. --- gdb/ChangeLog | 6 ++++++ gdb/mem-break.c | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5ee18e7..bfb584c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2015-03-05 Pedro Alves + + PR gdb/18002 + * mem-break.c (default_memory_insert_breakpoint): Set shadow_len + after reading the breakpoint's shadow memory. + 2015-03-05 Mark Kettenis * hppabsd-nat.c: Remove file. diff --git a/gdb/mem-break.c b/gdb/mem-break.c index aeffc93..0fb53cf 100644 --- a/gdb/mem-break.c +++ b/gdb/mem-break.c @@ -53,12 +53,21 @@ default_memory_insert_breakpoint (struct gdbarch *gdbarch, /* Save the memory contents in the shadow_contents buffer and then write the breakpoint instruction. */ - bp_tgt->shadow_len = bplen; readbuf = alloca (bplen); val = target_read_memory (addr, readbuf, bplen); if (val == 0) { + /* These must be set together, either before or after the shadow + read, so that if we're "reinserting" a breakpoint that + doesn't have a shadow yet, the breakpoint masking code inside + target_read_memory doesn't mask out this breakpoint using an + unfilled shadow buffer. The core may be trying to reinsert a + permanent breakpoint, for targets that support breakpoint + conditions/commands on the target side for some types of + breakpoints, such as target remote. */ + bp_tgt->shadow_len = bplen; memcpy (bp_tgt->shadow_contents, readbuf, bplen); + val = target_write_raw_memory (addr, bp, bplen); }