From: Andrew Burgess <aburgess@redhat.com>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 03/14] Simplify tui_data_window::show_register_group
Date: Mon, 18 Dec 2023 15:42:46 +0000 [thread overview]
Message-ID: <87msu74ivd.fsf@redhat.com> (raw)
In-Reply-To: <20231217-tui-regs-cleanup-v1-3-67bd0ea1e8be@tromey.com>
Tom Tromey <tom@tromey.com> writes:
> This simplifies tui_data_window::show_register_group, renaming it as
> well. The old method had two loops to iterate over all the registers
> for the arch, but in the new scheme, the vector is set up when
> switching groups, and then updates simply iterate over the vector.
>
> tui_data_item_window is made self-updating, which also clarifies the
> code somewhat.
> ---
> gdb/tui/tui-regs.c | 104 ++++++++++++++++++++---------------------------------
> gdb/tui/tui-regs.h | 16 ++++++---
> 2 files changed, 49 insertions(+), 71 deletions(-)
>
> diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
> index 91fbf75c250..7b8bf323f50 100644
> --- a/gdb/tui/tui-regs.c
> +++ b/gdb/tui/tui-regs.c
> @@ -104,21 +104,17 @@ tui_register_format (frame_info_ptr frame, int regnum)
> /* Get the register value from the given frame and format it for the
> display. When changedp is set, check if the new register value has
> changed with respect to the previous call. */
> -static void
> -tui_get_register (frame_info_ptr frame,
> - struct tui_data_item_window *data,
> - int regnum, bool *changedp)
> +void
> +tui_data_item_window::update (const frame_info_ptr &frame)
The comment on this function needs updating.
> {
> - if (changedp)
> - *changedp = false;
> if (target_has_registers ())
> {
> - std::string new_content = tui_register_format (frame, regnum);
> + std::string new_content = tui_register_format (frame, regno);
>
> - if (changedp != NULL && data->content != new_content)
> - *changedp = true;
> + if (content != new_content)
> + highlight = true;
>
> - data->content = std::move (new_content);
> + content = std::move (new_content);
> }
> }
>
> @@ -178,13 +174,11 @@ tui_data_window::show_registers (const reggroup *group)
>
> if (target_has_registers () && target_has_stack () && target_has_memory ())
> {
> - show_register_group (group, get_selected_frame (NULL),
> - group == m_current_group);
> + update_register_data (group, get_selected_frame (NULL));
Maybe s/NULL/nullptr/ ?
>
> /* Clear all notation of changed values. */
> for (auto &&data_item_win : m_regs_content)
> data_item_win.highlight = false;
> - m_current_group = group;
> }
> else
> {
> @@ -201,63 +195,43 @@ tui_data_window::show_registers (const reggroup *group)
> refresh_values_only is true. */
>
> void
> -tui_data_window::show_register_group (const reggroup *group,
> - frame_info_ptr frame,
> - bool refresh_values_only)
> +tui_data_window::update_register_data (const reggroup *group,
> + frame_info_ptr frame)
The comment on this function needs updating.
> {
> - struct gdbarch *gdbarch = get_frame_arch (frame);
> - int nr_regs;
> - int regnum, pos;
> -
> - /* Make a new title showing which group we display. */
> - this->set_title (string_printf ("Register group: %s", group->name ()));
> -
> - /* See how many registers must be displayed. */
> - nr_regs = 0;
> - for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
> + if (group != m_current_group)
> {
> - const char *name;
> -
> - /* Must be in the group. */
> - if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
> - continue;
> -
> - /* If the register name is empty, it is undefined for this
> - processor, so don't display anything. */
> - name = gdbarch_register_name (gdbarch, regnum);
> - if (*name == '\0')
> - continue;
> -
> - nr_regs++;
> - }
> + m_current_group = group;
>
> - m_regs_content.resize (nr_regs);
> + /* Make a new title showing which group we display. */
> + this->set_title (string_printf ("Register group: %s", group->name ()));
>
> - /* Now set the register names and values. */
> - pos = 0;
> - for (regnum = 0; regnum < gdbarch_num_cooked_regs (gdbarch); regnum++)
> - {
> - struct tui_data_item_window *data_item_win;
> - const char *name;
> + /* Create the registers. */
> + m_regs_content.clear ();
>
> - /* Must be in the group. */
> - if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
> - continue;
> + struct gdbarch *gdbarch = get_frame_arch (frame);
> + for (int regnum = 0;
> + regnum < gdbarch_num_cooked_regs (gdbarch);
> + regnum++)
> + {
> + /* Must be in the group. */
> + if (!gdbarch_register_reggroup_p (gdbarch, regnum, group))
> + continue;
>
> - /* If the register name is empty, it is undefined for this
> - processor, so don't display anything. */
> - name = gdbarch_register_name (gdbarch, regnum);
> - if (*name == '\0')
> - continue;
> + /* If the register name is empty, it is undefined for this
> + processor, so don't display anything. */
> + const char *name = gdbarch_register_name (gdbarch, regnum);
> + if (*name == '\0')
> + continue;
>
> - data_item_win = &m_regs_content[pos];
> - if (!refresh_values_only)
> - {
> - data_item_win->regno = regnum;
> - data_item_win->highlight = false;
> + m_regs_content.emplace_back (regnum, frame);
> }
> - tui_get_register (frame, data_item_win, regnum, 0);
> - pos++;
> + }
> + else
> + {
> + /* The group did not change, so we can simply update each
> + item. */
> + for (tui_data_item_window ® : m_regs_content)
> + reg.update (frame);
> }
> }
>
> @@ -470,13 +444,11 @@ tui_data_window::check_register_values (frame_info_ptr frame)
> show_registers (m_current_group);
> else
> {
> - for (auto &&data_item_win : m_regs_content)
> + for (tui_data_item_window &data_item_win : m_regs_content)
> {
> bool was_hilighted = data_item_win.highlight;
>
> - tui_get_register (frame, &data_item_win,
> - data_item_win.regno,
> - &data_item_win.highlight);
> + data_item_win.update (frame);
>
> /* Register windows whose y == 0 are outside the visible area. */
> if ((data_item_win.highlight || was_hilighted)
> diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
> index 1abd22cd382..9c451ba5996 100644
> --- a/gdb/tui/tui-regs.h
> +++ b/gdb/tui/tui-regs.h
> @@ -29,19 +29,26 @@
>
> struct tui_data_item_window
> {
> - tui_data_item_window () = default;
> + tui_data_item_window (int regno, const frame_info_ptr &frame)
> + : regno (regno)
> + {
> + update (frame);
> + highlight = false;
> + }
>
> DISABLE_COPY_AND_ASSIGN (tui_data_item_window);
>
> tui_data_item_window (tui_data_item_window &&) = default;
>
> + void update (const frame_info_ptr &frame);
> +
> void rerender (WINDOW *handle, int field_width);
>
> /* Location. */
> int x = 0;
> int y = 0;
> /* The register number. */
> - int regno = -1;
> + int regno;
If we're touching this anyway, maybe we could take the opportunity to
make this private?
Thanks,
Andrew
> bool highlight = false;
> bool visible = false;
> std::string content;
> @@ -104,9 +111,8 @@ struct tui_data_window : public tui_win_info
> display off the end of the register display. */
> void display_reg_element_at_line (int start_element_no, int start_line_no);
>
> - void show_register_group (const reggroup *group,
> - frame_info_ptr frame,
> - bool refresh_values_only);
> + void update_register_data (const reggroup *group,
> + frame_info_ptr frame);
>
> /* Answer the number of the last line in the regs display. If there
> are no registers (-1) is returned. */
>
> --
> 2.43.0
next prev parent reply other threads:[~2023-12-18 15:42 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-17 19:50 [PATCH 00/14] Cleanups for the TUi register window Tom Tromey
2023-12-17 19:50 ` [PATCH 01/14] Use pop_back in tui_register_format Tom Tromey
2023-12-17 19:50 ` [PATCH 02/14] Minor C++ cleanups in tui-regs.c Tom Tromey
2023-12-17 19:50 ` [PATCH 03/14] Simplify tui_data_window::show_register_group Tom Tromey
2023-12-18 15:42 ` Andrew Burgess [this message]
2024-01-20 17:11 ` Tom Tromey
2023-12-17 19:50 ` [PATCH 04/14] Rename tui_data_item_window -> tui_register_info Tom Tromey
2023-12-17 19:50 ` [PATCH 05/14] Remove tui_register_info::visible Tom Tromey
2023-12-18 17:29 ` Hannes Domani
2024-01-20 17:02 ` Tom Tromey
2023-12-18 19:00 ` Andrew Burgess
2024-01-20 17:05 ` Tom Tromey
2023-12-17 19:50 ` [PATCH 06/14] Move scrollok call in register window Tom Tromey
2023-12-18 19:28 ` Andrew Burgess
2023-12-18 23:33 ` Tom Tromey
2023-12-17 19:50 ` [PATCH 07/14] Simplify update_register_data Tom Tromey
2023-12-18 19:48 ` Andrew Burgess
2024-01-20 17:06 ` Tom Tromey
2023-12-17 19:50 ` [PATCH 08/14] Remove the TUI register window rerender overload Tom Tromey
2023-12-18 19:54 ` Andrew Burgess
2024-01-20 17:17 ` Tom Tromey
2023-12-17 19:50 ` [PATCH 09/14] Simplify tui_data_win::erase_data_content Tom Tromey
2023-12-17 19:50 ` [PATCH 10/14] Remove tui_refreshing_registers Tom Tromey
2023-12-17 19:50 ` [PATCH 11/14] Remove redundant check from tui_refresh_frame_and_register_information Tom Tromey
2023-12-18 17:32 ` Hannes Domani
2023-12-18 23:35 ` Tom Tromey
2023-12-19 10:26 ` Andrew Burgess
2024-01-20 18:21 ` Tom Tromey
2023-12-17 19:50 ` [PATCH 12/14] Return void from tui_show_frame_info Tom Tromey
2023-12-17 19:50 ` [PATCH 13/14] Rename show_registers -> set_register_group Tom Tromey
2023-12-17 19:50 ` [PATCH 14/14] Update TUI register window when the inferior exits Tom Tromey
2023-12-18 14:07 ` [PATCH 00/14] Cleanups for the TUi register window Tom de Vries
2023-12-19 10:31 ` 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=87msu74ivd.fsf@redhat.com \
--to=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.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).