public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Lancelot SIX <lsix@lancelotsix.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 15/16] gdb: make cmd_list_element var an optional union
Date: Mon, 19 Jul 2021 10:32:09 -0400	[thread overview]
Message-ID: <a01ad63b-cc3e-e2e6-32b4-97d154fba05b@polymtl.ca> (raw)
In-Reply-To: <20210714232112.wsn7pits6uuz3nf5@ubuntu.lan>

On 2021-07-14 7:22 p.m., Lancelot SIX wrote:
> On Wed, Jul 14, 2021 at 03:22:41PM -0400, Simon Marchi wrote:
>>
>> I am certainly for this kind of consistency checks, making sure we
>> access the right data the right way.  This is what I did with struct
>> dynamic_prop, for example.
>>
>> I was thinking of adding accessors too, eventually.  I am not very good
>> with advanced C++ templates though, so what I had in mind was more
>> something like the obvious:
>>
>>   struct cmd_list_element
>>   {
>>     int *var_as_int () // or int &
>>     {
>>       gdb_assert (m_var_type == a
>> 		  || m_var_type == b);
>>       return m_var.int_var;
>>     }
>>
>>     unsigned int *var_as_unsigned_int () // or unsigned int &
>>     {
>>       gdb_assert (m_var_type == c
>> 		  || m_var_type == c);
>>       return m_var.unsigned_int_var;
>>     }
>>
>>     // And so on.
>>   };
>>
>> Your last proposition is a bit better in the sense that you ask "give me
>> the variable location for a var_zuinteger".  With mine, you still have
>> to know that a var_zuinteger uses the unsigned int member.  But at
>> least, there's a gdb_assert to catch mistakes at runtime.
>>
>> Whether it's worth the extra complexity... I can't tell, I would have to
>> see the complete patch.  I would also have to see how that fits with the
>> upcoming fix I have for bug 28085.  In the mean time, does it make your
>> life more difficult if we merge my patch?  I would guess not, since
>> you'll need to modify all the call sites (places that access setting
>> variables) anyway.  You can then decide to keep the union or not in your
>> patch.
>>
>> Simon
> 
> I have not yet finished updating all callsites, but here is a
> (hopefully) working patch if you want to see what it looks like.
> 
> I have not had a look at 28085 yet, so I do not yet if my approach gets
> in the way of fixing it.  For the moment, I do not have something
> similar to the gdb_optional you introduce, but it should not be too
> difficult to have something similar.
> 
> Anyway, to not hold back on my account.  I have not read your series
> carefully yet, but it seems a real improvement from the current
> situation.  If it helps fixing a bug, it is even better.  I can rework
> my patch to work on top of this one (at least if what it brings is
> considered worthwhile).
> 
> Lancelot.

I took a quick look, and that seems reasonable to me.  I don't think it
will conflict (in design) with my upcoming patch.  My upcoming patch
makes it so that some settings don't use the storage that is in
cmd_list_element at all, but instead provide some getter/setter
callback.  This is to fix display of settings where the "source of
truth" is not cmd_list_element::var.

With my patch, the code at various places becomes, conceptually:

  if (cmd_list_element::var is set)
    use cmd_list_element::var
  else
    use the getter/setter

I think it would be nice to make the first case (using
cmd_list_element::var for storage) just a specific case of using the
getter/setter.  That is, when we create a setting that uses
cmd_list_element::var for storage, we install a getter and a setter than
get and set the value in cmd_list_element::var.  But I haven't gotten
there yet.  You'll probably have some good ideas for achieving this :).

But before posting that patch, I'd like to decide how the current patch
series will end up, because that will very much affect how the next
patch will look like.

Simon

  reply	other threads:[~2021-07-19 14:33 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14  4:55 [PATCH 00/16] Bunch of commands related cleanups Simon Marchi
2021-07-14  4:55 ` [PATCH 01/16] gdb/testsuite: split gdb.python/py-parameter.exp in procs Simon Marchi
2021-07-14  4:55 ` [PATCH 02/16] gdb.base/setshow.exp: use save_vars to save/restore gdb_prompt Simon Marchi
2021-07-14  4:55 ` [PATCH 03/16] gdb.base/setshow.exp: split in procs Simon Marchi
2021-07-14  4:55 ` [PATCH 04/16] gdb.base/setshow.exp: fix duplicate test name Simon Marchi
2021-07-14  4:55 ` [PATCH 05/16] gdb: un-share set_inferior_cwd declaration Simon Marchi
2021-07-14  4:55 ` [PATCH 06/16] gdb: remove inferior::{argc,argv} Simon Marchi
2021-07-14  4:55 ` [PATCH 07/16] gdb: add setter/getter for inferior arguments Simon Marchi
2021-07-14  4:55 ` [PATCH 08/16] gdb: add setter/getter for inferior cwd Simon Marchi
2021-07-14  4:55 ` [PATCH 09/16] gdb: make inferior::m_args an std::string Simon Marchi
2021-07-14  4:55 ` [PATCH 10/16] gdb: make inferior::m_cwd " Simon Marchi
2021-07-14  4:55 ` [PATCH 11/16] gdb: make inferior::m_terminal " Simon Marchi
2021-07-14  4:55 ` [PATCH 12/16] gdb: rename cfunc to simple_func Simon Marchi
2021-07-14  4:55 ` [PATCH 13/16] gdb: remove cmd_list_element::function::sfunc Simon Marchi
2021-07-28 19:10   ` Tom Tromey
2021-07-28 21:17     ` Simon Marchi
2021-07-29 17:33       ` Tom Tromey
2021-07-14  4:55 ` [PATCH 14/16] gdb/testsuite: test get/set value of unregistered Guile parameter Simon Marchi
2021-07-23 19:42   ` Simon Marchi
2021-07-14  4:55 ` [PATCH 15/16] gdb: make cmd_list_element var an optional union Simon Marchi
2021-07-14 12:08   ` Lancelot SIX
2021-07-14 17:12     ` Lancelot SIX
2021-07-14 19:22       ` Simon Marchi
2021-07-14 23:22         ` Lancelot SIX
2021-07-19 14:32           ` Simon Marchi [this message]
2021-07-19 19:52             ` Simon Marchi
2021-07-20 23:03               ` Lancelot SIX
2021-07-23 19:56                 ` Simon Marchi
2021-07-23 20:46                   ` Lancelot SIX
2021-07-23 21:15                     ` Simon Marchi
2021-07-23 22:55                       ` Lancelot SIX
2021-07-24  2:04                         ` Simon Marchi
2021-07-28 20:13                 ` Tom Tromey
2021-07-28 20:45                   ` Lancelot SIX
2021-07-29 17:47                     ` Tom Tromey
2021-07-29 20:12                       ` Lancelot SIX
2021-07-30  2:09                         ` Simon Marchi
2021-07-30 17:47                           ` Lancelot SIX
2021-07-18 15:44   ` Lancelot SIX
2021-07-19 14:19     ` Simon Marchi
2021-07-19 20:58       ` Lancelot SIX
2021-07-28 19:47   ` Tom Tromey
2021-07-28 20:59     ` Simon Marchi
2021-07-29 17:41       ` Tom Tromey
2021-07-29 17:44         ` Simon Marchi
2021-07-29 17:49           ` Tom Tromey
2021-07-29 18:00             ` Simon Marchi
2021-07-14  4:55 ` [PATCH 16/16] gdb: make string-like set show commands use std::string variable Simon Marchi
2021-07-28 20:27   ` Tom Tromey
2021-07-28 21:03     ` Simon Marchi

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=a01ad63b-cc3e-e2e6-32b4-97d154fba05b@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=lsix@lancelotsix.com \
    /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).