public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCHv2 11/16] gdb: remove reggroup_next and reggroup_prev
Date: Wed, 6 Apr 2022 10:22:24 -0400	[thread overview]
Message-ID: <0b75bf81-3865-001e-8a8a-d6907f0ee296@polymtl.ca> (raw)
In-Reply-To: <3a1ef96c90157a4193af462837b63e90c0fcd6c8.1649246539.git.aburgess@redhat.com>

> @@ -146,62 +146,15 @@ reggroups_init (struct obstack *obstack)
>    return groups;
>  }
>  
> -/* A register group iterator.  */
> -
> -struct reggroup *
> -reggroup_next (struct gdbarch *gdbarch, const struct reggroup *last)
> -{
> -  /* Don't allow this function to be called during architecture
> -     creation.  If there are no groups, use the default groups list.  */
> -  struct reggroups *groups
> -    = (struct reggroups *) gdbarch_data (gdbarch, reggroups_data);
> -  gdb_assert (groups != nullptr);
> -  gdb_assert (groups->size () > 0);
> -
> -  /* Return the first/next reggroup.  */
> -  if (last == nullptr)
> -    return groups->groups ().front ();
> -  for (int i = 0; i < groups->size (); ++i)
> -    {
> -      if (groups->groups ()[i] == last)
> -	{
> -	  if (i + 1 < groups->size ())
> -	    return groups->groups ()[i + 1];
> -	  else
> -	    return nullptr;
> -	}
> -    }
> -
> -  return nullptr;
> -}
> -
>  /* See reggroups.h.  */
> -
> -struct reggroup *
> -reggroup_prev (struct gdbarch *gdbarch, const struct reggroup *curr)
> +const std::vector<const reggroup *>
> +gdbarch_reggroups (struct gdbarch *gdbarch)

Should this return a reference to the existing vector, so it doesn't
make a copy of the vector each time?

> diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
> index b968947fa1c..acffc75238a 100644
> --- a/gdb/tui/tui-regs.c
> +++ b/gdb/tui/tui-regs.c
> @@ -514,34 +514,48 @@ tui_data_item_window::rerender (WINDOW *handle, int field_width)
>      (void) wstandend (handle);
>  }
>  
> -/* Helper for "tui reg next", wraps a call to REGGROUP_NEXT, but adds wrap
> -   around behaviour.  Will never return nullptr.  If CURRENT_GROUP is
> -   nullptr (e.g. if the tui register window has only just been displayed
> -   and has no current group selected), then the first register group will
> -   be returned.  */
> +/* Helper for "tui reg next", returns the next register group after
> +   CURRENT_GROUP in the register group list for GDBARCH, with wrap around
> +   behaviour.
> +
> +   If CURRENT_GROUP is nullptr (e.g. if the tui register window has only
> +   just been displayed and has no current group selected) or the currently
> +   selected register group can't be found (e.g. if the architecture has
> +   changed since the register window was last updated), then the last
> +   register group will be returned.  */

last or next?  This is for tui_reg_next.

>  
>  static const reggroup *
>  tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch)
>  {
> -  const reggroup *group = reggroup_next (gdbarch, current_group);
> -  if (group == NULL)
> -    group = reggroup_next (gdbarch, NULL);
> -  return group;
> +  const std::vector<const reggroup *> &groups = gdbarch_reggroups (gdbarch);
> +  auto it = std::find (groups.begin (), groups.end (), current_group);
> +  if (it != groups.end ())
> +    it++;
> +  if (it == groups.end ())
> +    return groups.front ();
> +  return *it;

My only thought for the conversion to vector is that using an
intrusive_list would be a nice lightweight solution for those next/prev
cases.  You wouldn't have to iterate the vector to find the current
reggroup, to find the one after it.  However, it would probably not
handle the "if the architecture has changed since the register window
was last updated case", where you want to check if the current group is
part of gdbarch's reggroups.  When the current architecture changes
though, I think it should trigger an update of the register window to
show that new architecture's registers so... maybe we don't need this
check?


  reply	other threads:[~2022-04-06 14:22 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31 21:04 [PATCH 00/16] Default register groups, and general related cleanup Andrew Burgess
2022-03-31 21:04 ` [PATCH 01/16] gdb: don't try to use readline before it's initialized Andrew Burgess
2022-03-31 21:04 ` [PATCH 02/16] gdb: add some const in gdb/reggroups.c Andrew Burgess
2022-03-31 21:04 ` [PATCH 03/16] gdb: make gdbarch_register_reggroup_p take a const reggroup * Andrew Burgess
2022-04-04 22:35   ` Lancelot SIX
2022-04-05  8:24     ` Andrew Burgess
2022-03-31 21:04 ` [PATCH 04/16] gdb: switch to using 'const reggroup *' in tui-regs.{c, h} Andrew Burgess
2022-03-31 21:04 ` [PATCH 05/16] gdb: use 'const reggroup *' in python/py-registers.c file Andrew Burgess
2022-03-31 21:04 ` [PATCH 06/16] gdb: have reggroup_find return a const Andrew Burgess
2022-03-31 21:04 ` [PATCH 07/16] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess
2022-03-31 21:04 ` [PATCH 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden Andrew Burgess
2022-03-31 21:04 ` [PATCH 09/16] gdb: always add the default register groups Andrew Burgess
2022-03-31 21:04 ` [PATCH 10/16] gdb: convert reggroups to use a std::vector Andrew Burgess
2022-03-31 21:04 ` [PATCH 11/16] gdb: remove reggroup_next and reggroup_prev Andrew Burgess
2022-04-05 23:11   ` Lancelot SIX
2022-04-06 12:06     ` Andrew Burgess
2022-03-31 21:04 ` [PATCH 12/16] gdb: more 'const' in gdb/reggroups.{c,h} Andrew Burgess
2022-03-31 21:04 ` [PATCH 13/16] gdb: make the pre-defined register groups const Andrew Burgess
2022-03-31 21:04 ` [PATCH 14/16] gdb: convert reggroup to a C++ class with constructor, etc Andrew Burgess
2022-03-31 21:04 ` [PATCH 15/16] gdb: move struct reggroup into reggroups.h header Andrew Burgess
2022-03-31 21:04 ` [PATCH 16/16] gdb: update comments throughout reggroups.{c,h} files Andrew Burgess
2022-04-06 14:28   ` Simon Marchi
2022-04-06 12:04 ` [PATCHv2 00/16] Default register groups, and general related cleanup Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 01/16] gdb: don't try to use readline before it's initialized Andrew Burgess
2022-04-06 12:57     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 02/16] gdb: add some const in gdb/reggroups.c Andrew Burgess
2022-04-06 12:58     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 03/16] gdb: make gdbarch_register_reggroup_p take a const reggroup * Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 04/16] gdb: switch to using 'const reggroup *' in tui-regs.{c, h} Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 05/16] gdb: use 'const reggroup *' in python/py-registers.c file Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 06/16] gdb: have reggroup_find return a const Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 07/16] gdb/tui: avoid theoretical bug with 'tui reg' command Andrew Burgess
2022-04-06 13:02     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 08/16] gdb/tui: fix 'tui reg next/prev' command when data window is hidden Andrew Burgess
2022-04-06 13:13     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 09/16] gdb: always add the default register groups Andrew Burgess
2022-04-06 13:22     ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 10/16] gdb: convert reggroups to use a std::vector Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 11/16] gdb: remove reggroup_next and reggroup_prev Andrew Burgess
2022-04-06 14:22     ` Simon Marchi [this message]
2022-04-06 14:23       ` Simon Marchi
2022-04-06 12:04   ` [PATCHv2 12/16] gdb: more 'const' in gdb/reggroups.{c,h} Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 13/16] gdb: make the pre-defined register groups const Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 14/16] gdb: convert reggroup to a C++ class with constructor, etc Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 15/16] gdb: move struct reggroup into reggroups.h header Andrew Burgess
2022-04-06 12:04   ` [PATCHv2 16/16] gdb: update comments throughout reggroups.{c, h} files Andrew Burgess
2022-04-06 14:34   ` [PATCHv2 00/16] Default register groups, and general related cleanup Simon Marchi
2022-04-07 15:16     ` Andrew Burgess

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=0b75bf81-3865-001e-8a8a-d6907f0ee296@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).