From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 126524 invoked by alias); 6 Mar 2015 14:31:25 -0000 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 Received: (qmail 126509 invoked by uid 89); 6 Mar 2015 14:31:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,KAM_FROM_URIBL_PCCC,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-pa0-f47.google.com Received: from mail-pa0-f47.google.com (HELO mail-pa0-f47.google.com) (209.85.220.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 06 Mar 2015 14:31:24 +0000 Received: by padfa1 with SMTP id fa1so51844291pad.9 for ; Fri, 06 Mar 2015 06:31:22 -0800 (PST) X-Received: by 10.66.136.17 with SMTP id pw17mr26367114pab.33.1425652282649; Fri, 06 Mar 2015 06:31:22 -0800 (PST) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by mx.google.com with ESMTPSA id qn14sm9780360pab.33.2015.03.06.06.31.20 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 06 Mar 2015 06:31:21 -0800 (PST) From: Yao Qi To: Pedro Alves Cc: gdb-patches@sourceware.org Subject: Re: [pushed 1/2] PR gdb/18002: Fix reinsert of a permanent breakpoints References: <1425598969-7666-1-git-send-email-palves@redhat.com> <1425598969-7666-2-git-send-email-palves@redhat.com> Date: Fri, 06 Mar 2015 14:31:00 -0000 In-Reply-To: <1425598969-7666-2-git-send-email-palves@redhat.com> (Pedro Alves's message of "Thu, 5 Mar 2015 23:42:48 +0000") Message-ID: <86d24mi4ei.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00172.txt.bz2 Pedro Alves writes: > 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. Yes, that is what I observed on aarch64-linux too. > > 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. This patch fixes gdb.base/bp-permanent.exp FAILs on aarch64-linux too, but there are some remains, which are not related. > 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 *gdb= arch, >=20=20 > /* Save the memory contents in the shadow_contents buffer and then > write the breakpoint instruction. */ > - bp_tgt->shadow_len =3D bplen; > readbuf =3D alloca (bplen); > val =3D target_read_memory (addr, readbuf, bplen); > if (val =3D=3D 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 =3D bplen; > memcpy (bp_tgt->shadow_contents, readbuf, bplen); > + Your fix looks right to me, although I am testing a different one, in which bp_location_has_shadow returns false if bl->permanent is true. Anyway, Thanks for fixing this bug, Pedro. --=20 Yao (=E9=BD=90=E5=B0=A7)