From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by sourceware.org (Postfix) with ESMTPS id D126D385114C for ; Fri, 30 Sep 2022 15:37:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D126D385114C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f52.google.com with SMTP id b4so444270wrs.1 for ; Fri, 30 Sep 2022 08:37:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:to:subject :x-gm-message-state:from:to:cc:subject:date; bh=j049YVlQVIhezS4SXPp7zbIKM1J0D8qThlrja26QI1k=; b=rxTFroTdJRRTKNK2sj4sqHl5dM270TOyKO7unyPbLksNRxOL48uCwK0QMSFdHYmNxT 7aWYFh+aK5b2tg57cYAmtYQUi/lrkJoeNk7Y/UTR9DFdyl3PIRB4cavEsug3LL83PDDl TXPcqY9/srD08letYCMsh+z5wza55S4kGoYZQKhp5t5z4YC3VzbPe17TSryXBCBANUiK ev1zJoqMwzBmAAiuA0JMbABwxx17p3Uz7OWy8TalHvgPHxFZBMYffbhD5Yd0cw1T8TqV R4klOz0nLhXKJYYxK+ycH7r454Oat1rJNpaK2unXL94KxkOYX90Y5MVQ2DraRaE5ZoPL uMjQ== X-Gm-Message-State: ACrzQf3MhD+G7oTp7Jv9vBJroKDlj6zOpA87z9zqhMbMUAn4cF0H5k7q hkTtqdhLYTHqBocfC/CkDjR+0GClI+VuOQ== X-Google-Smtp-Source: AMsMyM4Eim+aE5/0QwTp3O3SyOQJyJv0KjieKaiOmnT0X4WoNIc1GVkl8GLfia1CDy4QeRFr8Bej+Q== X-Received: by 2002:adf:d1ce:0:b0:22a:36d6:da05 with SMTP id b14-20020adfd1ce000000b0022a36d6da05mr6508999wrd.719.1664552262705; Fri, 30 Sep 2022 08:37:42 -0700 (PDT) Received: from ?IPv6:2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653? ([2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653]) by smtp.gmail.com with ESMTPSA id f15-20020a05600c490f00b003a2e92edeccsm6842257wmp.46.2022.09.30.08.37.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 30 Sep 2022 08:37:41 -0700 (PDT) Subject: Re: [RFC][gdb/cli] Add convenience vars _wp_old_val and _wp_val To: Tom de Vries , gdb-patches@sourceware.org References: <20220930091614.GA30107@delia.home> From: Pedro Alves Message-ID: <0fd34b60-1eba-c7cf-3792-13cc2c2b1d9b@palves.net> Date: Fri, 30 Sep 2022 16:37:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20220930091614.GA30107@delia.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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-List-Received-Date: Fri, 30 Sep 2022 15:37:46 -0000 On 2022-09-30 10:16 a.m., Tom de Vries via Gdb-patches wrote: > 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 > ... Cool. I like it. Can also be used in the watchpoint's commands. It can't be safely used in regular CLI after the watchpoint hit is process, though, given another watchpoint may trigger meanwhile. I mean, say, in non-stop, you do: (gdb) c -a & Hardware watchpoint 2: v Old value = 3 New value = 2 main () at foo.c:12 12 return 0; # time passes, you type other gdb commands. (gdb) print $_wp_old_val # you want to look at wp's 2 value, but just as you're # typing this, another watchpoint triggers: Hardware watchpoint 3: o Old value = 4 New value = 5 main () at foo.c:14 14 return 2; (gdb) print $_wp_old_val $123 = 4 # whoops A way to make this safer would be to make it a convenience function instead, that takes as argument the number of the watchpoint, like: (gdb) p $_wp_old_val(2) For the condition example, you'd write: (gdb) cond 2 $_wp_old_val($bpnum) == 3 && $_wp_val($bpnum) == 2 I guess that isn't as convenient. Unless... I guess the convenient functions could default to $bpnum if no argument is passed? That'd reduce it to: (gdb) cond 2 $_wp_old_val() == 3 && $_wp_val() == 2 If that's still too much, I guess we could have both separately named convenience variables and convenience functions. > 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? I'm fine with the shorter names as you proposed.