[binutils-gdb] gdb/tui: make tui_win_info::title private

Andrew Burgess aburgess@sourceware.org
Sat Jul 15 10:41:09 GMT 2023


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

commit 6c1e84f5c6f36263998ef1934bf3132c8cebe75e
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Mon Jul 10 15:56:47 2023 +0100

    gdb/tui: make tui_win_info::title private
    
    This commit builds on this earlier work:
    
      commit 9fe01a376b2fb096e4836e985ba316ce9dc02399
      Date:   Thu Jun 29 11:26:55 2023 -0600
    
          Update TUI window title when changed
    
    and makes tui_win_info::title private, renaming to m_title at the same
    time.  There's a new tui_win_info::title() member function to provide
    read-only access to the title.
    
    There should be no user visible changes after this commit.
    
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/python/py-tui.c      |  2 +-
 gdb/tui/tui-data.c       |  6 +++---
 gdb/tui/tui-data.h       | 13 +++++++++----
 gdb/tui/tui-regs.c       |  2 +-
 gdb/tui/tui-source.c     |  2 +-
 gdb/tui/tui-wingeneral.c | 10 +++++-----
 6 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/gdb/python/py-tui.c b/gdb/python/py-tui.c
index c52b04f9a51..f47f2278dda 100644
--- a/gdb/python/py-tui.c
+++ b/gdb/python/py-tui.c
@@ -509,7 +509,7 @@ gdbpy_tui_title (PyObject *self, void *closure)
 {
   gdbpy_tui_window *win = (gdbpy_tui_window *) self;
   REQUIRE_WINDOW (win);
-  return host_string_to_python_string (win->window->title.c_str ()).release ();
+  return host_string_to_python_string (win->window->title ().c_str ()).release ();
 }
 
 /* Set the title of the TUI window.  */
diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index abd2ec2b5fd..fc90df25ddd 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -155,11 +155,11 @@ tui_prev_win (struct tui_win_info *cur_win)
 /* See tui-data.h.  */
 
 void
-tui_win_info::set_title (const char *new_title)
+tui_win_info::set_title (std::string &&new_title)
 {
-  if (title != new_title)
+  if (m_title != new_title)
     {
-      title = new_title;
+      m_title = new_title;
       check_and_display_highlight_if_needed ();
     }
 }
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 030ce2a5438..d0e8d56fa07 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -148,7 +148,11 @@ public:
 
   /* A helper function to change the title and then redraw the
      surrounding box, if needed.  */
-  void set_title (const char *new_title);
+  void set_title (std::string &&new_title);
+
+  /* Return a reference to the current window title.  */
+  const std::string &title () const
+  { return m_title; }
 
   /* Window handle.  */
   std::unique_ptr<WINDOW, curses_deleter> handle;
@@ -160,9 +164,6 @@ public:
   int x = 0;
   int y = 0;
 
-  /* Window title to display.  */
-  std::string title;
-
   /* Is this window highlighted?  */
   bool is_highlighted = false;
 
@@ -175,6 +176,10 @@ protected:
   /* Scroll the contents horizontally.  This is only called via
      left_scroll and right_scroll.  */
   virtual void do_scroll_horizontal (int num_to_scroll) = 0;
+
+private:
+  /* Window title to display.  */
+  std::string m_title;
 };
 
 /* Constant definitions.  */
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 3a8fcfa5d27..1a351e60cee 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -210,7 +210,7 @@ tui_data_window::show_register_group (const reggroup *group,
   int regnum, pos;
 
   /* Make a new title showing which group we display.  */
-  title = string_printf ("Register group: %s", group->name ());
+  this->set_title (string_printf ("Register group: %s", group->name ()));
 
   /* See how many registers must be displayed.  */
   nr_regs = 0;
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 55cde258882..6625f0cf088 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -65,7 +65,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
   int cur_line_no, cur_line;
   const char *s_filename = symtab_to_filename_for_display (s);
 
-  title = s_filename;
+  set_title (s_filename);
 
   m_fullname = make_unique_xstrdup (symtab_to_fullname (s));
 
diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 2b63499683e..5e1b3d2e62e 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -102,19 +102,19 @@ box_win (struct tui_win_info *win_info,
 	   tui_border_hline, tui_border_hline,
 	   tui_border_ulcorner, tui_border_urcorner,
 	   tui_border_llcorner, tui_border_lrcorner);
-  if (!win_info->title.empty ())
+  if (!win_info->title ().empty ())
     {
       /* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
 	 the left.  */
       int max_len = win_info->width - 2 - 2;
 
-      if (win_info->title.size () <= max_len)
-	mvwaddstr (win, 0, 2, win_info->title.c_str ());
+      if (win_info->title ().size () <= max_len)
+	mvwaddstr (win, 0, 2, win_info->title ().c_str ());
       else
 	{
 	  std::string truncated
-	    = "..." + win_info->title.substr (win_info->title.size ()
-					      - max_len + 3);
+	    = "..." + win_info->title ().substr (win_info->title ().size ()
+						 - max_len + 3);
 	  mvwaddstr (win, 0, 2, truncated.c_str ());
 	}
     }


More information about the Gdb-cvs mailing list