From patchwork Fri Sep 30 09:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 58207 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57CC4385C421 for ; Fri, 30 Sep 2022 09:16:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57CC4385C421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664529408; bh=B2JN6dAuiA8XH3ouEg5VT/JRgU0jHbbWHFc0xrnN52I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pnj+8Ggdv59ZW8UyIgIjjpBSjM3ujjuF2+GCrQTNgs8F2YhREejQQ8JLb20/AvedZ uTeVpu4vqCHsoe/7y/nwW/MNaieyBG0NaiPfz7nHZJpyl4Z6CNUBKyI3vqtHyDzDbQ 59De4YZ2nQqCXdIZMhnKx8iDGjfPMIa3clZCrO1o= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@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"