From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Lancelot SIX <lsix@lancelotsix.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 3/4] gdb: Have setter and getter callbacks for settings
Date: Tue, 10 Aug 2021 21:01:52 -0400 [thread overview]
Message-ID: <7de0a03d-77bf-3b09-9a11-4a109afce8a8@polymtl.ca> (raw)
In-Reply-To: <20210810221852.bqbb6opnrlaqgob5@Plymouth>
On 2021-08-10 6:18 p.m., Lancelot SIX wrote:
>>> @@ -231,25 +427,50 @@ struct base_setting
>>> gdb_assert (var_type_uses<T> (this->m_var_type));
>>> gdb_assert (!this->empty ());
>>
>> I think this needs to call operator bool, like so:
>>
>> gdb_assert (*this);
>>
>> Otherwise, the assert fails when using a getter/setter (empty only
>> checks for m_var to be non-NULL, which is false when using
>> getter/setter).
>>
>
> Thanks for spotting this. The second assertion should only be on the
> branch that does not use the setter callback.
>
> I also realized that the 'set' method should use 'get_p<T> () = v', which
> includes this assertion making the one you ran into redundant.
>
>
>> I don't find this notation super clear, it might be clearer if we could
>> call a named method instead of operator bool. Maybe "empty" could mean
>> "does not have a buffer nor getter/setter"?
>
> I think I got confused about what empty means when I rebased the patch
> and handled the conflicts from the previous iteration. This is a good
> indication that the naming is not as good as it could be.
>
> 'empty' refers to the fact that there is an underlying buffer register.
> I could just check 'm_var != nullptr' in 'get_p' and 'operator bool()'.
> This is a protected method not meant to be used outside of the class
> anyway.
>
> The 'bool()' operator is intended to check if a setting is
> valid, i.e. 'get' and 'set' can be called without a guarantied error.
> We could use something like 'valid ()' instead (or 'good ()' if we want
> to mimic iostream). Not that 'empty' would not work, I think I would
> prefer to read
>
> if (foo.valid ())
> use (foo);
>
> over
>
> if (!foo.empty ())
> use (foo);
>
> I tend to prefer the affirmative version over the double negation.
>
> I’ll change that for the next iteration.
Another option would be to use
gdb::optional<setting> var;
in cmd_list_element, and make it such that a setting can never exist in
an invalid state. Two constructor would exist, one to construct a
setting with a pointer to a buffer and another with the setter/getter.
There would be no need (I think) for set_p and set_accessors.
But otherwise, `valid` sounds good to me as well.
Simon
next prev parent reply other threads:[~2021-08-11 1:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-08 19:22 [PATCH v2 0/4] gdb: Refactor cmd_list_element.var Lancelot SIX via Gdb-patches
2021-08-08 19:22 ` [PATCH v2 1/4] gdb: Add typesafe getter/setter for cmd_list_element.var Lancelot SIX via Gdb-patches
2021-08-10 1:29 ` Simon Marchi via Gdb-patches
2021-08-10 12:22 ` Simon Marchi via Gdb-patches
2021-08-10 21:58 ` Lancelot SIX via Gdb-patches
2021-08-11 0:56 ` Simon Marchi via Gdb-patches
2021-08-08 19:23 ` [PATCH v2 2/4] gdb: make string-like set show commands use std::string variable Lancelot SIX via Gdb-patches
2021-08-08 19:23 ` [PATCH v2 3/4] gdb: Have setter and getter callbacks for settings Lancelot SIX via Gdb-patches
2021-08-10 3:01 ` Simon Marchi via Gdb-patches
2021-08-10 22:18 ` Lancelot SIX via Gdb-patches
2021-08-11 1:01 ` Simon Marchi via Gdb-patches [this message]
2021-08-11 20:00 ` Lancelot SIX via Gdb-patches
2021-08-19 21:03 ` Simon Marchi via Gdb-patches
2021-08-20 7:04 ` Lancelot SIX via Gdb-patches
2021-08-08 19:23 ` [PATCH v2 4/4] gdb: Setting setter return a bool to tell if the value changed Lancelot SIX via Gdb-patches
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=7de0a03d-77bf-3b09-9a11-4a109afce8a8@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=lsix@lancelotsix.com \
--cc=simon.marchi@polymtl.ca \
/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