From: Lancelot SIX <lsix@lancelotsix.com>
To: Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 11/16] gdb: remove reggroup_next and reggroup_prev
Date: Tue, 5 Apr 2022 23:11:53 +0000 [thread overview]
Message-ID: <20220405231144.kzqrzl2hmo32ifbv@ubuntu> (raw)
In-Reply-To: <439ec4ff1564f25ed90d70b0bd50ff55ccbec539.1648760270.git.aburgess@redhat.com>
> diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
> index b968947fa1c..65ec8241370 100644
> --- a/gdb/tui/tui-regs.c
> +++ b/gdb/tui/tui-regs.c
> @@ -523,10 +523,21 @@ tui_data_item_window::rerender (WINDOW *handle, int field_width)
> 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);
> +
> + if (current_group != nullptr)
> + for (int i = 0; i < groups.size (); ++i)
> + {
> + if (groups[i] == current_group)
> + {
> + if (i + 1 < groups.size ())
> + return groups[i + 1];
> + else
> + return groups.front ();
> + }
> + }
> +
> + return groups.front ();
> }
>
> /* Helper for "tui reg prev", wraps a call to REGGROUP_PREV, but adds wrap
> @@ -538,10 +549,27 @@ tui_reg_next (const reggroup *current_group, struct gdbarch *gdbarch)
> static const reggroup *
> tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch)
> {
> - const reggroup *group = reggroup_prev (gdbarch, current_group);
> - if (group == NULL)
> - group = reggroup_prev (gdbarch, NULL);
> - return group;
> + const std::vector<const reggroup *> &groups = gdbarch_reggroups (gdbarch);
> +
> + if (current_group != nullptr)
> + {
> + /* Iterate backwards. */
> + for (auto iter = groups.rbegin ();
> + iter != groups.rend ();
> + ++iter)
> + {
> + if (*iter == current_group)
> + {
> + ++iter;
> + if (iter == groups.rend ())
> + return groups.back ();
> + else
> + return *iter;
> + }
> + }
> + }
> +
> + return groups.back ();
> }
>
Hi,
It looks strange to have tui_reg_next implemented using iteration over
indexes while tui_reg_prev is implemented using iterators. It looks to
me that both cases are similar enough to use a similar pattern.
Also, the for loop can probably be replaced by a call to std::find which
the overall thing more concise:
static const reggroup *
tui_reg_prev (const reggroup *current_group, struct gdbarch *gdbarch)
{
const std::vector<const reggroup *> &groups = gdbarch_reggroups (gdbarch);
auto it = std::find (groups.rbegin (), groups.rend (), current_group);
it++;
if (it >= groups.rend ())
return groups.back ();
return *it;
}
and something similar for tui_reg_next, changing rbegin/rend with
begin/end and .back with .front.
WDYT?
Best,
Lancelot.
next prev parent reply other threads:[~2022-04-05 23:12 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 [this message]
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
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=20220405231144.kzqrzl2hmo32ifbv@ubuntu \
--to=lsix@lancelotsix.com \
--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).