From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 1qT7K/2zNmOddgIAWB0awg (envelope-from ) for ; Fri, 30 Sep 2022 05:16:45 -0400 Received: by simark.ca (Postfix, from userid 112) id A66CE1E112; Fri, 30 Sep 2022 05:16:45 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=gUYuj6xF; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 088DE1E07B for ; Fri, 30 Sep 2022 05:16:45 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 844B63854142 for ; Fri, 30 Sep 2022 09:16:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 844B63854142 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664529404; bh=B2JN6dAuiA8XH3ouEg5VT/JRgU0jHbbWHFc0xrnN52I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gUYuj6xFF4OOtQhl6F0EDHauA48sGsFyg6BVNCgUuBpn1veDBRvYbHbzohKJ2LHKs PDuzaILC47YwtNaNhMkwiz5lFvV6azPcfNZWfNP6tfKEWEAK3sultPPK5vbmerSSAg W3hpRlp+uIcLgTPauQzabzRSLb8zUfiuyK3bjWCs= Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id DBC3B3854149 for ; Fri, 30 Sep 2022 09:16:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DBC3B3854149 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E7EEF1F86B for ; Fri, 30 Sep 2022 09:16:17 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D3CD013776 for ; Fri, 30 Sep 2022 09:16:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id S9WQMuGzNmNkWAAAMHmgww (envelope-from ) for ; Fri, 30 Sep 2022 09:16:17 +0000 Date: Fri, 30 Sep 2022 11:16:16 +0200 To: gdb-patches@sourceware.org Subject: [RFC][gdb/cli] Add convenience vars _wp_old_val and _wp_val Message-ID: <20220930091614.GA30107@delia.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tom de Vries via Gdb-patches Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Hi, Add convenience variables _wp_old_val and _wp_val, that match the reported values of a stopped watchpoint: ... Hardware watchpoint 2: v Old value = 3 New value = 2 main () at watchpoint-convenience-vars.c:12 12 return 0; (gdb) print $_wp_old_val $1 = 3 (gdb) print $_wp_val $2 = 2 ... These can be used in a watchpoint condition, for instance to only stop when changing from one value to another value: ... (gdb) cond 2 $_wp_old_val == 3 && $_wp_val == 2 ... RFC for now, so no docs yet. What about naming? Maybe _wp_old_value and _wp_new_value are more intuitive because they match the "Old value = _/ New value = _" message? Tested on x86_64-linux. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29480 Any comments? Thanks, - Tom [gdb/cli] Add convenience vars _wp_old_val and _wp_val --- gdb/breakpoint.c | 4 +++ .../gdb.base/watchpoint-convenience-vars.c | 30 ++++++++++++++++ .../gdb.base/watchpoint-convenience-vars.exp | 40 ++++++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 002f4a935b1..15b5356cb98 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -5060,7 +5060,11 @@ watchpoint_check (bpstat *bs) new_val))) { bs->old_val = b->val; + if (bs->old_val.get () != nullptr) + set_internalvar (lookup_internalvar ("_wp_old_val"), + bs->old_val.get ()); b->val = release_value (new_val); + set_internalvar (lookup_internalvar ("_wp_val"), b->val.get ()); b->val_valid = true; if (new_val != NULL) value_free_to_mark (mark); diff --git a/gdb/testsuite/gdb.base/watchpoint-convenience-vars.c b/gdb/testsuite/gdb.base/watchpoint-convenience-vars.c new file mode 100644 index 00000000000..8681fedb1d9 --- /dev/null +++ b/gdb/testsuite/gdb.base/watchpoint-convenience-vars.c @@ -0,0 +1,30 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 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 . */ + +int v = 0; + +int +main (void) +{ + v = 1; + v = 2; + + v = 3; + v = 2; + + return 0; +} diff --git a/gdb/testsuite/gdb.base/watchpoint-convenience-vars.exp b/gdb/testsuite/gdb.base/watchpoint-convenience-vars.exp new file mode 100644 index 00000000000..b5d1ed619f8 --- /dev/null +++ b/gdb/testsuite/gdb.base/watchpoint-convenience-vars.exp @@ -0,0 +1,40 @@ +# Copyright 2022 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 . + +# Check the watchpoint convenience variables _wp_old_val and _wp_val. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +if ![runto_main] { + return -1 +} + +# Set a watchpoint. +gdb_test "watch v" "\[Ww\]atchpoint 2: v" + +# Make the watchpoint conditional on a specific value transition, using +# watchpoint convenience variables. +gdb_test_no_output "cond 2 \$_wp_old_val == 3 && \$_wp_val == 2" + +# Verify that the watchpoint triggers on the value transition. +gdb_test "continue" "Old value = 3\r\nNew value = 2\r\n.*" + +# Verify the value of the convenience variables. +gdb_test "print \$_wp_old_val" " = 3" +gdb_test "print \$_wp_val" " = 2"