From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 119325 invoked by alias); 29 Aug 2018 16:02:27 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 119308 invoked by uid 89); 29 Aug 2018 16:02:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=arches X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 29 Aug 2018 16:02:25 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id w7TG2JEY029190 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 29 Aug 2018 12:02:24 -0400 Received: by simark.ca (Postfix, from userid 112) id 3D0D41E4A3; Wed, 29 Aug 2018 12:02:19 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 137151E186; Wed, 29 Aug 2018 12:02:18 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 29 Aug 2018 16:02:00 -0000 From: Simon Marchi To: Joel Brobecker Cc: Tim Newsome , gdb Subject: Re: gdb requires watchpoints to fire after the write In-Reply-To: <20180829154739.GB2521@adacore.com> References: <3833782b96d47551263798eb78f448bd@polymtl.ca> <20180829154739.GB2521@adacore.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.6 X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg00051.txt.bz2 On 2018-08-29 11:47, Joel Brobecker wrote: >> I don't have experience with many different architectures, but as far >> as I >> know, the expectation of the GDB is that the watchpoint is reported >> after >> the write. Otherwise it wouldn't need to save the value of the >> watched >> expression. That's also how software watchpoints seem to work. >> >> The easiest way to deal with this would be to match GDB's expectation. >> But >> if you really prefer the behavior of reporting the watchpoint before >> the >> event, I suppose it's always possible to teach GDB about this, but >> it's a >> less trivial task. Especially that when you GDB evaluates whether the >> watch >> expression has changed value, it would need to consider the >> not-yet-written >> value in memory. >> >> I'm also curious to know if other architectures work in this way >> (report the >> event before the write actually take place). > > I seem to remember some architectures having different behaviors, > and so we have a couple of entry points in GDB. For > architecture-specific > settings, we have gdbarch_have_nonsteppable_watchpoint. For > target-specific > settings, you would use target_have_steppable_watchpoint. (IIRC) Indeed, the comment at infrun.c:5805 seems to hint that some (or all?) targets/arches do work like that? And the fix is that GDB does a single step to execute the instruction that modifies the memory, and then evaluates the expression. I hadn't thought about that. See: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/infrun.c;h=7731ccda68343b0118b9806615ff45b9f4d56c63;hb=HEAD#l5805 I'm just confused by this condition: if (stopped_by_watchpoint && (target_have_steppable_watchpoint || gdbarch_have_nonsteppable_watchpoint (gdbarch))) I don't understand why we check for target_have_steppable_watchpoint OR gdbarch_have_nonsteppable_watchpoint, they seem to mean opposite things. Simon