public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Tom de Vries <tdevries@suse.de>, gdb-patches@sourceware.org
Subject: Re: [RFC][gdb/cli] Add convenience vars _wp_old_val and _wp_val
Date: Fri, 30 Sep 2022 16:37:40 +0100	[thread overview]
Message-ID: <0fd34b60-1eba-c7cf-3792-13cc2c2b1d9b@palves.net> (raw)
In-Reply-To: <20220930091614.GA30107@delia.home>

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.

  reply	other threads:[~2022-09-30 15:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30  9:16 Tom de Vries
2022-09-30 15:37 ` Pedro Alves [this message]
2022-10-07 19:41   ` Tom Tromey
2022-10-08  6:11     ` Tom de Vries
2022-10-10 13:49     ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0fd34b60-1eba-c7cf-3792-13cc2c2b1d9b@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).