From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4805 invoked by alias); 11 Nov 2005 13:22:08 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 4794 invoked by uid 22791); 11 Nov 2005 13:22:06 -0000 Received: from zigzag.lvk.cs.msu.su (HELO zigzag.lvk.cs.msu.su) (158.250.17.23) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Fri, 11 Nov 2005 13:22:06 +0000 Received: from Debian-exim by zigzag.lvk.cs.msu.su with spam-scanned (Exim 4.50) id 1EaYqv-0003cZ-ML for gdb@sources.redhat.com; Fri, 11 Nov 2005 16:22:03 +0300 Received: from zigzag.lvk.cs.msu.su ([158.250.17.23]) by zigzag.lvk.cs.msu.su with esmtp (Exim 4.50) id 1EaYqv-0003cO-If for gdb@sources.redhat.com; Fri, 11 Nov 2005 16:22:01 +0300 From: Vladimir Prus To: gdb@sources.redhat.com Subject: read watchpoints ignored? Date: Fri, 11 Nov 2005 13:22:00 -0000 User-Agent: KMail/1.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200511111622.01337.ghost@cs.msu.su> X-SW-Source: 2005-11/txt/msg00228.txt.bz2 Hi, I found a situation when read watchpoints are ignored by gdb. Consider this program: #include int a, b, c; int main() { a = 10; printf("Here I am\n"); b = a; c = a; return 0; } and this gdb session: (gdb) b main Breakpoint 1 at 0x80483a4: file rw.cpp, line 8. (gdb) r Starting program: /tmp/a.out Breakpoint 1, main () at rw.cpp:8 8 a = 10; (gdb) rwatch a Hardware read watchpoint 2: a (gdb) c Continuing. Hardware read watchpoint 2: a Value = 10 0x080483bd in main () at rw.cpp:11 11 c = a; Expected result: gdb stops on "b = a" line. Actual result: gdb stops on "c = a". Here's why it happens. When breakpoint is set, gdb reads the current value of 'a', which is zero. After continue, a is assigned the value of '10', and then first read watchpoint fires (on "b = a"). We arrive to "bpstat_stop_status" (breakpoint.c), which has the following code: else if (b->type == bp_read_watchpoint || b->type == bp_access_watchpoint) { ... if (found) { ... int e = catch_errors (watchpoint_check, bs, message, RETURN_MASK_ALL); switch (e) { ....... case WP_VALUE_CHANGED: if (b->type == bp_read_watchpoint) { /* Don't stop: read watchpoints shouldn't fire if the value has changed. This is for targets which cannot set read-only watchpoints. */ bs->print_it = print_it_noop; bs->stop = 0; continue; } Since value of 'a' was changed by the "a = 10" line, "watchpoint_check" returns "WP_VALUE_CHANGED", and reporting of watchpoint is completely suppressed. Questions: 1. Is this a bug? 2. Can this bug be fixed by removing this inner if (b->type == bp_read_wathcpoint) statement? This will cause watchpoints to trigger more often on those target that don't have "read-only watchpoints", but there will be no risk of missing watchpoint. And I think missed watchpoint is more harm then spurious watchpoint. Opinions? - Volodya