From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CC92F3858C52; Fri, 12 Aug 2022 11:42:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC92F3858C52 From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug breakpoints/29480] New: [gdb] watchpoint condition on specific value change Date: Fri, 12 Aug 2022 11:42:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: breakpoints X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Aug 2022 11:42:59 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D29480 Bug ID: 29480 Summary: [gdb] watchpoint condition on specific value change Product: gdb Version: HEAD Status: NEW Severity: enhancement Priority: P2 Component: breakpoints Assignee: unassigned at sourceware dot org Reporter: vries at gcc dot gnu.org Target Milestone: --- Somebody asked on IRC: ... is it possible to setup a watchpoint that fires off when the value of a mem= ory location changes from one specific value to another? ... I wrote this test example: ... $ cat test.c int v =3D 0; int main (void) { v =3D 1; v =3D 2; v =3D 3; v =3D 2; return 0; } $ gcc -g test.c ... and decided I wanted to set a watchpoint on the change from 3 to 2. I suppose it's possible to do this in python somehow, but I decided to try something more simple. I wrote this patch that introduces two new convenience variables: ... diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 37f70a77721..90ec605aeeb 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5062,7 +5062,10 @@ watchpoint_check (bpstat *bs) new_val))) { bs->old_val =3D b->val; + set_internalvar (lookup_internalvar ("_wp_old_val"), + bs->old_val.get ()); b->val =3D release_value (new_val); + set_internalvar (lookup_internalvar ("_wp_val"), b->val.get ()); b->val_valid =3D true; if (new_val !=3D NULL) value_free_to_mark (mark); ... and managed to do: ... $ gdb -q -batch a.out -ex "watch v" -ex "cond 1 \$_wp_old_val =3D=3D 3 && \= $_wp_val =3D=3D 2" -ex run Hardware watchpoint 1: v Hardware watchpoint 1: v Old value =3D 3 New value =3D 2 main () at test.c:12 12 return 0; ... --=20 You are receiving this mail because: You are on the CC list for the bug.=