public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Simplify tui_data_window::show_register_group
@ 2024-02-08 19:33 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-02-08 19:33 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b1adacb66386222a8da7e64126b80ae334b16089

commit b1adacb66386222a8da7e64126b80ae334b16089
Author: Tom Tromey <tom@tromey.com>
Date:   Sat Dec 16 19:41:54 2023 -0700

    Simplify tui_data_window::show_register_group
    
    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.
    
    Tested-By: Tom de Vries <tdevries@suse.de>
    Reviewed-By: Andrew Burgess <aburgess@redhat.com>
    Approved-By: Andrew Burgess <aburgess@redhat.com>

Diff:
---
 gdb/tui/tui-regs.c | 113 ++++++++++++++++++++---------------------------------
 gdb/tui/tui-regs.h |  21 +++++++---
 2 files changed, 57 insertions(+), 77 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index f1c3e2ed9d4..f7911b53bfb 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -101,24 +101,20 @@ tui_register_format (frame_info_ptr frame, int regnum)
   return str;
 }
 
-/* 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)
+/* Compute the register value from the given frame and format it for
+   the display.  update 'content' and set 'highlight' if the contents
+   changed.  */
+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, m_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 (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
     {
@@ -197,67 +191,46 @@ tui_data_window::show_registers (const reggroup *group)
 
 
 /* Set the data window to display the registers of the register group
-   using the given frame.  Values are refreshed only when
-   refresh_values_only is true.  */
+   using the given frame.  */
 
 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 &reg : m_regs_content)
+	reg.update (frame);
     }
 }
 
@@ -470,13 +443,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 bb4a0cfdb60..c1f89a5c1a6 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -29,22 +29,32 @@
 
 struct tui_data_item_window
 {
-  tui_data_item_window () = default;
+  tui_data_item_window (int regno, const frame_info_ptr &frame)
+    : m_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;
   bool highlight = false;
   bool visible = false;
   std::string content;
+
+private:
+
+  /* The register number.  */
+  const int m_regno;
 };
 
 /* The TUI registers window.  */
@@ -104,9 +114,8 @@ private:
      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.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-08 19:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08 19:33 [binutils-gdb] Simplify tui_data_window::show_register_group Tom Tromey

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).