From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YSOaGRgqR2oSJSMAWB0awg (envelope-from ) for ; Thu, 02 Jul 2026 23:18:48 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=YxjjlxbA; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 658F81E070; Thu, 02 Jul 2026 23:18:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7A89C1E070 for ; Thu, 02 Jul 2026 23:18:46 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08D5B4BA23FB for ; Fri, 3 Jul 2026 03:18:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 08D5B4BA23FB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=YxjjlxbA Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 182764BA5434 for ; Fri, 3 Jul 2026 03:18:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 182764BA5434 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 182764BA5434 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1030 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783048699; cv=none; b=LO0npB5/2Zf7AOfPdrHB6X1f00T4eVWaxjvpJtQ+/Q8TazwndRrSaRfGf9DEzJHGX2e6BL8z+4rnHAFlf6uWZgIxluIloRD4J54jnhsdEApLQRVRYcnuswjq+/WdUGLMOrstM9DCr6mhvyp5MrrSlIMxSjYmBzqlk6zGW9e6Vg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783048699; c=relaxed/simple; bh=P1zCurn3gZB33s2MNlQNfIKd8PEzLWquxcmgZT07Ywo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PxD28R9OEyA4YuDiMl4DBck4KxwVU61BsGUnKaH2NCF6wWpZsSstNUHD0aWxYEUO3kzTp8JCgLlYohSr0e3HC6pic4+V4pOvWwmQBNBH+ssvmrkWzxQlyaHh/drITauMRnJk2ToorY+3SBjyBBPGri2f925Bl+Qoceseo8hXbus= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=YxjjlxbA DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 182764BA5434 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-38060005f1cso1076142a91.0 for ; Thu, 02 Jul 2026 20:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1783048698; x=1783653498; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HHcYSuoLrZxabXjPKeOqD9vMy7wzd0Ql9hHoKOGKF98=; b=YxjjlxbA/SjgFH2GFivwI4hGNsF4XpSZHvkmoWD/wvVJjDvgZi3LfpuOzWgoYmaazU VKXiy6isy8NSTqY1jlCU24m8Za9WA6W0g3cmm6M7CsZt7WUDEfeoEkD15JkwjywoJw4v x+g1D4L2AiLIFGMZe4TOS9iLB0i+7po/Ea0POyZio037u3d4qhPZA4JfglpTsvGhtgHc 5QRt5qr/9RUORA+0jXID9uoF7uUsZrwH4PYnm6U0Uy7ILeGUH+kXb3OmjfVsVRK/dLFk 6jmnY2gJloAYBVKcJk0RVnHBfMxAZOzDTlrYIt0HG9uU0m0bJ48FTBOhjuE1vFvmarKG VUxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783048698; x=1783653498; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HHcYSuoLrZxabXjPKeOqD9vMy7wzd0Ql9hHoKOGKF98=; b=tFhhGbZohm5vzMHDMtitBE4GY/wkFLn0AygbWhz5dTTJzyybG+1hFwXOqOBiZvZG/6 LGgvfNqWBFrkcJ4gMC2gyRNt7VaQZ/312SbpLrH7uvfqAA5+t4KiGXN8/u0cFbIAYjGU r7GxOX+3tPOzLKtMVV9rv9/bhHA0lVDwOSjE5K0+7LRm1p1sGQ0umxxwPeskHY30UOVT 57U57Y2d04+8/2b36nRkr4I7ACCftRdhBXNGpePnXbHRGZsWsYmDGeahLOq+6TMG5xVB iQ5/v/aPIFiSWDLVxgFGYmh5XXLDabIZyBH/UyTUHBIBlBe4ibSzI80AZWns6velXey7 mdbw== X-Gm-Message-State: AOJu0YwXopgyLKVTMomFveEqHNZlJnbG3rGkqNA4LH9/tjVfIe9NLa2O PLf1RWch4tIDkhpC64/Jj/pYct+OWA43mnROHDKZuYKYg+zfNh3Rcuoqjt0YV7d3udo= X-Gm-Gg: AfdE7cl7rHhG1IAlIALYoprEXXVyIDGKg2I6dfIFIc2ZIHHPD0wGUvoKbHiBRdCaD+R nrwFptJrKgra3JkPatgtwkanQJ8FbYtsMvM94hWhKuWVaqpE3alJHRLgYa4PNDUTh2KzgkAKh2X SRvNr8rPtZ8I+vIzk3poJnRpZjoLlJwnxx9+NFUioRdCkSmtXSITwgc/OkiyN+dl8dWjWHAWZGs gfxbAkPvd1at8CN80oNoEPUC0+1Q7OK5dC3tJ6tiyjmMbPlqOhDJI9E3QIQ7sOyROM5bm18DHL2 YwNc1xlHVipZzN+Yi584UvynVTf1KZxfPz9hrNT9T+w/Z80NsXN00NZVXRLIAw/RWO+rGk/t1hl qBptPesmqFWeF6xf686lEKeIRkUi0GYWUrG3lSgD/0LBFIdBLd4VChQaf8Ev68b+IB4qejSGzUk +wL5aCRULIWcjJl5SWnkb0s3Q= X-Received: by 2002:a17:90b:5251:b0:380:8bb9:aba9 with SMTP id 98e67ed59e1d1-38112063c22mr3070554a91.3.1783048697823; Thu, 02 Jul 2026 20:18:17 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30f290b6bc2sm1928194eec.27.2026.07.02.20.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Jul 2026 20:18:17 -0700 (PDT) From: Thiago Jung Bauermann To: Hannes Domani Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Prevent downgrading of hardware watchpoints if possible In-Reply-To: <20260109194839.1598134-1-ssbssa@yahoo.de> (Hannes Domani's message of "Fri, 9 Jan 2026 20:48:39 +0100") References: <20260109194839.1598134-1-ssbssa.ref@yahoo.de> <20260109194839.1598134-1-ssbssa@yahoo.de> User-Agent: mu4e 1.14.2; emacs 30.2 Date: Fri, 03 Jul 2026 03:18:15 +0000 Message-ID: <87a4s8oj60.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org Hannes Domani writes: > The lazy flag of a value can tell us if the value contents are available. > But this could be either because it was simply never actually accessed, > or it tried to be accessed, and failed. > The latter are interesting for watchpoints, the former are not. > > Currently it only uses lazy values if they are at the head of the value > chain, but this is fragile logic, and degrades some watchpoints to > software watchpoints where it's actually not necessary. > > So this adds a new value flag 'm_fetch_lazy_failed' which tells if the > watchpoint expression actually tried to access the value and failed. > And this is used instead of the value chain location to tell if a lazy > value should be used as a watchpoint location. > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=3D27423 > --- > gdb/breakpoint.c | 11 ++-- > .../gdb.base/watchpoint-hw-no-degradation.c | 51 +++++++++++++++++++ > .../gdb.base/watchpoint-hw-no-degradation.exp | 38 ++++++++++++++ > gdb/value.c | 3 ++ > gdb/value.h | 12 ++++- > 5 files changed, 108 insertions(+), 7 deletions(-) > create mode 100644 gdb/testsuite/gdb.base/watchpoint-hw-no-degradation.c > create mode 100644 gdb/testsuite/gdb.base/watchpoint-hw-no-degradation.e= xp I like the solution, thanks! Reviewed-by: Thiago Jung Bauermann Just one nit in the testcase: > diff --git a/gdb/testsuite/gdb.base/watchpoint-hw-no-degradation.exp b/gd= b/testsuite/gdb.base/watchpoint-hw-no-degradation.exp > new file mode 100644 > index 00000000000..94ef335c77f > --- /dev/null > +++ b/gdb/testsuite/gdb.base/watchpoint-hw-no-degradation.exp > @@ -0,0 +1,38 @@ > +# Copyright 2009-2026 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Test if watchpoint doesn't degrade to a software watchpoint if part of > +# expression isn't accessible at time of watchpoint creation. > + > +require allow_hw_watchpoint_access_tests > + > +standard_testfile > + > +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { > + return -1 > +} > + > +if {![runto_main]} { > + return -1 > +} There's no need to return a value from the top-level. Please change the returns above to just "return". > + > +gdb_breakpoint [gdb_get_line_number "mmap (p, len"] > +gdb_continue_to_breakpoint "mmap" > + > +gdb_test "eval \"watch *(int *)%p =3D=3D 0\",p" \ > + "Hardware watchpoint $decimal: .*" > + > +gdb_test "continue" \ > + "Old value =3D .*New value =3D 0.*" =E2=8B=AE > diff --git a/gdb/value.h b/gdb/value.h > index 8dc3192f637..77919082fe3 100644 > --- a/gdb/value.h > +++ b/gdb/value.h > @@ -138,6 +138,7 @@ struct value > m_stack (false), > m_is_zero (false), > m_in_history (false), > + m_fetch_lazy_failed (false), > m_type (type_), > m_enclosing_type (type_) > { > @@ -279,7 +280,13 @@ struct value > { return m_lazy; } >=20=20 > void set_lazy (bool val) > - { m_lazy =3D val; } > + { > + m_lazy =3D val; > + m_fetch_lazy_failed =3D false; > + } > + > + bool fetch_lazy_failed () const > + { return m_fetch_lazy_failed; } >=20=20 > /* If a value represents a C++ object, then the `type' field gives the > object's compile-time type. If the object actually belongs to some > @@ -681,6 +688,9 @@ struct value > /* True if this a value recorded in value history; false otherwise. */ > bool m_in_history : 1; >=20=20 > + /* True if fetch_lazy() did not finish sucessfully. */ > + bool m_fetch_lazy_failed : 1; > + > /* Location of value (if lval). */ > union > { As a side note, because of this: /* Note that the fields in this structure are arranged to save a bit of memory. */ struct value { I decided to check: (top-gdb) ptype /o value /* offset | size */ type =3D struct value { private: /* 0 | 4 */ lval_type m_lval; /* 4: 0 | 1 */ bool m_modifiable : 1; /* 4: 1 | 1 */ bool m_lazy : 1; /* 4: 2 | 1 */ bool m_initialized : 1; /* 4: 3 | 1 */ bool m_stack : 1; /* 4: 4 | 1 */ bool m_is_zero : 1; /* 4: 5 | 1 */ bool m_in_history : 1; /* 4: 6 | 1 */ bool m_fetch_lazy_failed : 1; /* XXX 1-bit hole */ /* XXX 3-byte hole */ /* 8 | 40 */ union { /* 8 */ CORE_ADDR address; This patch doesn't change the size of struct value. --=20 Thiago (he/him)