From patchwork Sun Dec 17 19:50:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 82352 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75E433858028 for ; Sun, 17 Dec 2023 19:51:45 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 60D97385842F for ; Sun, 17 Dec 2023 19:50:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60D97385842F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 60D97385842F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702842635; cv=none; b=CP82+THEyY1+k/5tP4scVoGw7WOLL8gaLT/XIa+vp8kW7eH28UVO/oATTfNXCLZK0cIOgtwB2QRfPj06ModHgap3Shq1mQ3pRl+uHigALVas1Mu+G3Uly8d+YzVkA/Rp3KOz47jT9/lwXXxv6K4GvL8i8QSGpDuKxeaCcIzd0po= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702842635; c=relaxed/simple; bh=sJYezDT9vtfZfdHMgBtazfTugngmCuyHjsNzLRaGpZ4=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=K91YnOT9InCUrr6FVPZdgtqBLEHN6SPp07SvA1LFtH8+5qMiwkomoX0O6mx7yzNanAg78sle8QT1OXwqV4pcjjIz2pSKL5VyIQTCs85rY0Qr5EqSOtlBm+sBqYvXZjTjz38WXGtzuFOEhXVsYerULHg6MBqAscvrXfWlpH4+D9Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5006a.ext.cloudfilter.net ([10.0.29.179]) by cmsmtp with ESMTPS id EAyvrb02jL9AgEx9irX1Xc; Sun, 17 Dec 2023 19:50:30 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Ex9grzz1y1J28Ex9hrZaOo; Sun, 17 Dec 2023 19:50:29 +0000 X-Authority-Analysis: v=2.4 cv=Tqz1ORbh c=1 sm=1 tr=0 ts=657f5105 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=e2cXIFwxEfEA:10 a=Qbun_eYptAEA:10 a=fZMDrX1XKuidMsmcEdAA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zYaJyu+98aiq4WTtQUpPXJ3p+SSXqEr7qiMM3BZzwAo=; b=oyX3U4KAMmFgFS7ackL4Iay6/e H7DbdfBeEkGsnt7I06ZsoYn3J/jlKlSM3eAYOQ+Wdq5smBj74l58w2yvNQrNAY9pi+bMdJ6gSb2B5 OKjPTy/pQ9HZBUjEx6In14Rt3; Received: from 71-211-161-25.hlrn.qwest.net ([71.211.161.25]:40716 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rEx9g-004MyY-25 for gdb-patches@sourceware.org; Sun, 17 Dec 2023 12:50:28 -0700 From: Tom Tromey Date: Sun, 17 Dec 2023 12:50:28 -0700 Subject: [PATCH 03/14] Simplify tui_data_window::show_register_group MIME-Version: 1.0 Message-Id: <20231217-tui-regs-cleanup-v1-3-67bd0ea1e8be@tromey.com> References: <20231217-tui-regs-cleanup-v1-0-67bd0ea1e8be@tromey.com> In-Reply-To: <20231217-tui-regs-cleanup-v1-0-67bd0ea1e8be@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.161.25 X-Source-L: No X-Exim-ID: 1rEx9g-004MyY-25 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-161-25.hlrn.qwest.net ([192.168.0.21]) [71.211.161.25]:40716 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfF30Zy/XjvQ3c+qsQDNFPRIZ8sarGRu+xYst0mAGKcOFD+BY74lcPDeeYHHnt1UdDUk/iPaAKgFlcXOrg00f8uaBjNyfvLwQymqtMCqQwY1FV64PBkaF JvqMyXxJ0zDwTh3uVwLZCqJbzHEGC0GiQZfgIH3SIEAL6CDMECjihpUngxvBAbkclV3kfBi1qfRUgCX1LbznrpD8KUsXElRPI+8= X-Spam-Status: No, score=-3022.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org 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) { - 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)); /* 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) { - 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; 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. */