[PATCH 00/61] More TUI refactorings

classic Classic list List threaded Threaded
70 messages Options
1234
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/61] More TUI refactorings

Tom Tromey-2
Here is another series of TUI cleanups.  It covers several things.

I made an attempt to remove most of the uses of the TUI_*_WIN globals,
and to remove explicit checks of window types.  I think this is
important if we want to be able to easily add new types of windows:
the core code should be able to manipulate windows without regard to
their exact contents.

This transformation isn't complete, but this series takes it pretty
far, with many of the remaining uses being in the layout code (mainly
tui-layout.c, but also other files) -- which, if we're going to add
new windows types, is going to need to be rewritten anyhow.  (Also,
even once this is all done, I suspect the command window will always
be a singleton with special code here and there in the TUI anyhow.)

This series also simplifies window creation and management.  By the
end of the series, init_and_make_win is completely gone, replaced with
ordinary uses of "new" at the appropriate spots.  These transforms
make this code much simpler to understand, IMO.

The TUI source code is also rearranged somewhat.  In particular, by
the end of the series, the declaration for a window class is in the
appropriate .h file (that is, most are moved out of tui-data.h), and
all the methods for a given class are grouped into a single .c file.

A couple of small bugs have been fixed in this series.  See the patch
"Fix flushing bug in tui_puts_internal" and also "Remove deleted
breakpoint from TUI display".

Finally, the series contains a fair amount of trivia, just random
little things I noticed while working on the code.

In some cases this series introduces functions, only to remove them
some patches later.  This is a side effect of how I wrote the patches,
but TBH I think it makes each individual patch more clear -- bundling
the two patches together would make the result less obviously correct.

I've tested this as well as I could.  You may want to give it a try,
though.  It is on the "t/tui-rewrite" branch in my github.

Tom


Reply | Threaded
Open this post in threaded view
|

[PATCH 01/61] Introduce can_scroll method

Tom Tromey-2
This introduces a "can_scroll" method, removing a spot that explicitly
checks a window's type.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-data.h (struct tui_win_info) <can_scroll>: New method.
        (struct tui_cmd_window) <can_scroll>: New method.
        * tui/tui-command.c (tui_dispatch_ctrl_char): Use can_scroll
        method.
---
 gdb/ChangeLog         |  7 +++++++
 gdb/tui/tui-command.c |  7 +++----
 gdb/tui/tui-data.h    | 11 +++++++++++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/gdb/tui/tui-command.c b/gdb/tui/tui-command.c
index 259620f7ce7..bd16f801d26 100644
--- a/gdb/tui/tui-command.c
+++ b/gdb/tui/tui-command.c
@@ -48,10 +48,9 @@ tui_dispatch_ctrl_char (unsigned int ch)
   if (ch == '\f')
     tui_refresh_all_win ();
 
-  /* If the command window has the logical focus, or no-one does
-     assume it is the command window; in this case, pass the character
-     on through and do nothing here.  */
-  if (win_info == NULL || win_info == TUI_CMD_WIN)
+  /* If no window has the focus, or if the focus window can't scroll,
+     just pass the character through.  */
+  if (win_info == NULL || !win_info->can_scroll ())
     return ch;
 
   switch (ch)
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 412be1ce756..6a243c3d2f9 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -352,6 +352,12 @@ public:
   void left_scroll (int num_to_scroll);
   void right_scroll (int num_to_scroll);
 
+  /* Return true if this window can be scrolled, false otherwise.  */
+  virtual bool can_scroll () const
+  {
+    return true;
+  }
+
   /* Can this window ever be highlighted?  */
   bool can_highlight = true;
 
@@ -524,6 +530,11 @@ struct tui_cmd_window : public tui_win_info
     return CMD_NAME;
   }
 
+  bool can_scroll () const override
+  {
+    return false;
+  }
+
   int start_line = 0;
 
 protected:
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 02/61] Check can_highlight in tui_check_and_display_highlight_if_needed

Tom Tromey-2
In reply to this post by Tom Tromey-2
tui_check_and_display_highlight_if_needed currently checks the
window's type; but this can be replaced with a check of
"can_highlight", making it more polymorphically-correct.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-wingeneral.c
        (tui_check_and_display_highlight_if_needed): Check can_highlight.
---
 gdb/ChangeLog            | 5 +++++
 gdb/tui/tui-wingeneral.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index cf8d9fc3959..c15739c594b 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -128,7 +128,7 @@ tui_highlight_win (struct tui_win_info *win_info)
 void
 tui_check_and_display_highlight_if_needed (struct tui_win_info *win_info)
 {
-  if (win_info != NULL && win_info->type != CMD_WIN)
+  if (win_info != NULL && win_info->can_highlight)
     {
       if (win_info->is_highlighted)
  tui_highlight_win (win_info);
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 03/61] Remove some uses of TUI_WIN_SRC

Tom Tromey-2
In reply to this post by Tom Tromey-2
This adds a 'win_info' parameter to a couple of functions.  This
reduces the number of references to the TUI_WIN_SRC global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-winsource.c (tui_update_source_window_as_is)
        (tui_update_source_windows_with_addr): Update.
        * tui/tui-source.h (tui_set_source_content)
        (tui_show_symtab_source): Add "win_info" parameter.
        * tui/tui-source.c (tui_set_source_content): Add "win_info"
        parameter.
        (tui_show_symtab_source): Likewise.
---
 gdb/ChangeLog           | 10 ++++++++++
 gdb/tui/tui-source.c    | 42 ++++++++++++++++++++---------------------
 gdb/tui/tui-source.h    |  6 ++++--
 gdb/tui/tui-winsource.c |  9 +++++----
 4 files changed, 40 insertions(+), 27 deletions(-)

diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 81ede061570..e62ee4ea5f9 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -123,7 +123,8 @@ copy_source_line (const char **ptr, int line_no, int first_col,
 
 /* Function to display source in the source window.  */
 enum tui_status
-tui_set_source_content (struct symtab *s,
+tui_set_source_content (tui_source_window_base *win_info,
+ struct symtab *s,
  int line_no,
  int noerror)
 {
@@ -134,11 +135,11 @@ tui_set_source_content (struct symtab *s,
       int line_width, nlines;
 
       ret = TUI_SUCCESS;
-      tui_alloc_source_buffer (TUI_SRC_WIN);
-      line_width = TUI_SRC_WIN->width - 1;
+      tui_alloc_source_buffer (win_info);
+      line_width = win_info->width - 1;
       /* Take hilite (window border) into account, when
  calculating the number of lines.  */
-      nlines = (line_no + (TUI_SRC_WIN->height - 2)) - line_no;
+      nlines = (line_no + (win_info->height - 2)) - line_no;
 
       std::string srclines;
       if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
@@ -159,32 +160,30 @@ tui_set_source_content (struct symtab *s,
   int cur_line_no, cur_line;
   struct tui_locator_window *locator
     = tui_locator_win_info_ptr ();
-  struct tui_source_window_base *src
-    = (struct tui_source_window_base *) TUI_SRC_WIN;
   const char *s_filename = symtab_to_filename_for_display (s);
 
-  xfree (TUI_SRC_WIN->title);
-  TUI_SRC_WIN->title = xstrdup (s_filename);
+  xfree (win_info->title);
+  win_info->title = xstrdup (s_filename);
 
-  xfree (src->fullname);
-  src->fullname = xstrdup (symtab_to_fullname (s));
+  xfree (win_info->fullname);
+  win_info->fullname = xstrdup (symtab_to_fullname (s));
 
   cur_line = 0;
-  src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
-  src->start_line_or_addr.loa = LOA_LINE;
-  cur_line_no = src->start_line_or_addr.u.line_no = line_no;
+  win_info->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
+  win_info->start_line_or_addr.loa = LOA_LINE;
+  cur_line_no = win_info->start_line_or_addr.u.line_no = line_no;
 
   const char *iter = srclines.c_str ();
-  TUI_SRC_WIN->content.resize (nlines);
+  win_info->content.resize (nlines);
   while (cur_line < nlines)
     {
       struct tui_source_element *element
- = &TUI_SRC_WIN->content[cur_line];
+ = &win_info->content[cur_line];
 
       std::string text;
       if (*iter != '\0')
  text = copy_source_line (&iter, cur_line_no,
- src->horizontal_offset,
+ win_info->horizontal_offset,
  line_width);
 
       /* Set whether element is the execution point
@@ -196,8 +195,8 @@ tui_set_source_content (struct symtab *s,
  symtab_to_fullname (s)) == 0
    && cur_line_no == locator->line_no);
 
-      xfree (TUI_SRC_WIN->content[cur_line].line);
-      TUI_SRC_WIN->content[cur_line].line
+      xfree (win_info->content[cur_line].line);
+      win_info->content[cur_line].line
  = xstrdup (text.c_str ());
 
       cur_line++;
@@ -276,12 +275,13 @@ tui_set_source_content_nil (struct tui_source_window_base *win_info,
 /* Function to display source in the source window.  This function
    initializes the horizontal scroll to 0.  */
 void
-tui_show_symtab_source (struct gdbarch *gdbarch, struct symtab *s,
+tui_show_symtab_source (tui_source_window_base *win_info,
+ struct gdbarch *gdbarch, struct symtab *s,
  struct tui_line_or_address line,
  int noerror)
 {
-  TUI_SRC_WIN->horizontal_offset = 0;
-  tui_update_source_window_as_is (TUI_SRC_WIN, gdbarch, s, line, noerror);
+  win_info->horizontal_offset = 0;
+  tui_update_source_window_as_is (win_info, gdbarch, s, line, noerror);
 }
 
 
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 9e1dc1a6e10..8ceb194e392 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -30,9 +30,11 @@ struct tui_win_info;
 extern void tui_set_source_content_nil (struct tui_source_window_base *,
  const char *);
 
-extern enum tui_status tui_set_source_content (struct symtab *,
+extern enum tui_status tui_set_source_content (tui_source_window_base *,
+       struct symtab *,
        int, int);
-extern void tui_show_symtab_source (struct gdbarch *, struct symtab *,
+extern void tui_show_symtab_source (tui_source_window_base *,
+    struct gdbarch *, struct symtab *,
     struct tui_line_or_address,
     int);
 extern int tui_source_is_displayed (const char *);
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index dbede410278..c7c04dfe816 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -94,7 +94,8 @@ tui_update_source_window_as_is (struct tui_source_window_base *win_info,
   enum tui_status ret;
 
   if (win_info->type == SRC_WIN)
-    ret = tui_set_source_content (s, line_or_addr.u.line_no, noerror);
+    ret = tui_set_source_content (win_info, s, line_or_addr.u.line_no,
+  noerror);
   else
     ret = tui_set_disassem_content (gdbarch, line_or_addr.u.addr);
 
@@ -121,7 +122,7 @@ tui_update_source_window_as_is (struct tui_source_window_base *win_info,
      we don't have a split layout.  */
   if (tui_win_with_focus () == TUI_DISASM_WIN
       && tui_current_layout () != SRC_DISASSEM_COMMAND)
-    tui_set_win_focus_to (TUI_SRC_WIN);
+    tui_set_win_focus_to (win_info);
  }
     }
 
@@ -153,7 +154,7 @@ tui_update_source_windows_with_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
   sal = find_pc_line (addr, 0);
   l.loa = LOA_LINE;
   l.u.line_no = sal.line;
-  tui_show_symtab_source (gdbarch, sal.symtab, l, FALSE);
+  tui_show_symtab_source (TUI_SRC_WIN, gdbarch, sal.symtab, l, FALSE);
   break;
  }
     }
@@ -191,7 +192,7 @@ tui_update_source_windows_with_line (struct symtab *s, int line)
     default:
       l.loa = LOA_LINE;
       l.u.line_no = line;
-      tui_show_symtab_source (gdbarch, s, l, FALSE);
+      tui_show_symtab_source (TUI_SRC_WIN, gdbarch, s, l, FALSE);
       if (tui_current_layout () == SRC_DISASSEM_COMMAND)
  {
   find_line_pc (s, line, &pc);
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 04/61] Consolidate "if"s in tui_show_frame_info

Tom Tromey-2
In reply to this post by Tom Tromey-2
tui_show_frame_info has two parallel "if"s with the same condition and
no intervening code.  The second "if" perhaps wasn't obviously
identical, but earlier refactorings made it clearer, by pointing out
that only source and disassembly windows can be handled here.  This
merges the two statements.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-stack.c (tui_show_frame_info): Consolidate "if"s.
---
 gdb/ChangeLog       |  4 +++
 gdb/tui/tui-stack.c | 62 ++++++++++++++++++++-------------------------
 2 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c
index f761ac1f701..e1b996d7e6c 100644
--- a/gdb/tui/tui-stack.c
+++ b/gdb/tui/tui-stack.c
@@ -341,8 +341,6 @@ tui_show_frame_info (struct frame_info *fi)
 
   if (fi)
     {
-      int start_line;
-      CORE_ADDR low;
       struct tui_locator_window *locator = tui_locator_win_info_ptr ();
       int source_already_displayed;
       CORE_ADDR pc;
@@ -372,32 +370,15 @@ tui_show_frame_info (struct frame_info *fi)
  return 0;
 
       tui_show_locator_content ();
-      start_line = 0;
       for (struct tui_source_window_base *win_info : tui_source_windows ())
  {
   if (win_info == TUI_SRC_WIN)
     {
-      start_line = (locator->line_no -
-   (win_info->viewport_height / 2)) + 1;
+      int start_line = (locator->line_no -
+ (win_info->viewport_height / 2)) + 1;
       if (start_line <= 0)
  start_line = 1;
-    }
-  else
-    {
-      if (find_pc_partial_function (get_frame_pc (fi),
-    NULL, &low, NULL) == 0)
- {
-  /* There is no symbol available for current PC.  There is no
-     safe way how to "disassemble backwards".  */
-  low = get_frame_pc (fi);
- }
-      else
- low = tui_get_low_disassembly_address (get_frame_arch (fi),
-       low, get_frame_pc (fi));
-    }
 
-  if (win_info == TUI_SRC_WIN)
-    {
       struct tui_line_or_address l;
 
       l.loa = LOA_LINE;
@@ -415,23 +396,34 @@ tui_show_frame_info (struct frame_info *fi)
     }
   else
     {
-      if (win_info == TUI_DISASM_WIN)
+      CORE_ADDR low;
+
+      if (find_pc_partial_function (get_frame_pc (fi),
+    NULL, &low, NULL) == 0)
+ {
+  /* There is no symbol available for current PC.  There is no
+     safe way how to "disassemble backwards".  */
+  low = get_frame_pc (fi);
+ }
+      else
+ low = tui_get_low_disassembly_address (get_frame_arch (fi),
+       low, get_frame_pc (fi));
+
+      struct tui_line_or_address a;
+
+      a.loa = LOA_ADDRESS;
+      a.u.addr = low;
+      if (!tui_addr_is_displayed (locator->addr,
+  win_info, TRUE))
+ tui_update_source_window (win_info, get_frame_arch (fi),
+  sal.symtab, a, TRUE);
+      else
  {
-  struct tui_line_or_address a;
-
-  a.loa = LOA_ADDRESS;
-  a.u.addr = low;
-  if (!tui_addr_is_displayed (locator->addr,
-      win_info, TRUE))
-    tui_update_source_window (win_info, get_frame_arch (fi),
-      sal.symtab, a, TRUE);
-  else
-    {
-      a.u.addr = locator->addr;
-      win_info->set_is_exec_point_at (a);
-    }
+  a.u.addr = locator->addr;
+  win_info->set_is_exec_point_at (a);
  }
     }
+
   tui_update_exec_info (win_info);
  }
 
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 05/61] Remove deleted breakpoint from TUI display

Tom Tromey-2
In reply to this post by Tom Tromey-2
PR tui/24722 points out that deleting a breakpoint does not cause the
"b" to be removed from the breakpoint display.  The issue here was
that the breakpoint still exists at the moment the breakpoint-deleted
observer is notified.  This fixes the problem by specially handling
the case where a breakpoint is being removed.

2019-07-04  Tom Tromey  <[hidden email]>

        PR tui/24722:
        * tui/tui-winsource.h (tui_update_all_breakpoint_info)
        (tui_update_breakpoint_info): Add "being_deleted" parameter.
        * tui/tui-winsource.c (tui_update_source_window_as_is): Update.
        (tui_update_all_breakpoint_info): Add "being_deleted" parameter.
        (tui_update_breakpoint_info): Likewise.
        * tui/tui-hooks.c (tui_event_create_breakpoint)
        (tui_event_delete_breakpoint, tui_event_modify_breakpoint):
        Update.
---
 gdb/ChangeLog           | 12 ++++++++++++
 gdb/tui/tui-hooks.c     |  6 +++---
 gdb/tui/tui-winsource.c | 29 ++++++++++++++++-------------
 gdb/tui/tui-winsource.h | 19 +++++++++++++------
 4 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 9bac4a883aa..71010530749 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -91,7 +91,7 @@ tui_register_changed (struct frame_info *frame, int regno)
 static void
 tui_event_create_breakpoint (struct breakpoint *b)
 {
-  tui_update_all_breakpoint_info ();
+  tui_update_all_breakpoint_info (nullptr);
 }
 
 /* Breakpoint deletion hook.
@@ -99,13 +99,13 @@ tui_event_create_breakpoint (struct breakpoint *b)
 static void
 tui_event_delete_breakpoint (struct breakpoint *b)
 {
-  tui_update_all_breakpoint_info ();
+  tui_update_all_breakpoint_info (b);
 }
 
 static void
 tui_event_modify_breakpoint (struct breakpoint *b)
 {
-  tui_update_all_breakpoint_info ();
+  tui_update_all_breakpoint_info (nullptr);
 }
 
 /* Refresh TUI's frame and register information.  This is a hook intended to be
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index c7c04dfe816..22cd54ee9b8 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -106,7 +106,7 @@ tui_update_source_window_as_is (struct tui_source_window_base *win_info,
     }
   else
     {
-      tui_update_breakpoint_info (win_info, 0);
+      tui_update_breakpoint_info (win_info, nullptr, false);
       tui_show_source_content (win_info);
       tui_update_exec_info (win_info);
       if (win_info->type == SRC_WIN)
@@ -382,15 +382,14 @@ tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
     refill ();
 }
 
-/* Update the execution windows to show the active breakpoints.
-   This is called whenever a breakpoint is inserted, removed or
-   has its state changed.  */
+/* See tui-winsource.h.  */
+
 void
-tui_update_all_breakpoint_info ()
+tui_update_all_breakpoint_info (struct breakpoint *being_deleted)
 {
   for (tui_source_window_base *win : tui_source_windows ())
     {
-      if (tui_update_breakpoint_info (win, FALSE))
+      if (tui_update_breakpoint_info (win, being_deleted, false))
         {
           tui_update_exec_info (win);
         }
@@ -398,18 +397,19 @@ tui_update_all_breakpoint_info ()
 }
 
 
-/* Scan the source window and the breakpoints to update the has_break
+/* Scan the source window and the breakpoints to update the break_mode
    information for each line.
 
-   Returns 1 if something changed and the execution window must be
+   Returns true if something changed and the execution window must be
    refreshed.  */
 
-int
-tui_update_breakpoint_info (struct tui_source_window_base *win,
-    int current_only)
+bool
+tui_update_breakpoint_info (struct tui_source_window_base *win,
+    struct breakpoint *being_deleted,
+    bool current_only)
 {
   int i;
-  int need_refresh = 0;
+  bool need_refresh = false;
   tui_source_window_base *src = (tui_source_window_base *) win;
 
   for (i = 0; i < win->content.size (); i++)
@@ -435,6 +435,9 @@ tui_update_breakpoint_info (struct tui_source_window_base *win,
   gdb_assert (line->line_or_addr.loa == LOA_LINE
       || line->line_or_addr.loa == LOA_ADDRESS);
 
+  if (bp == being_deleted)
+    continue;
+
   for (loc = bp->loc; loc != NULL; loc = loc->next)
     {
       if ((win == TUI_SRC_WIN
@@ -491,7 +494,7 @@ tui_set_exec_info_content (struct tui_source_window_base *win_info)
       tui_exec_info_content *content
  = win_info->execution_info->maybe_allocate_content (win_info->height);
 
-      tui_update_breakpoint_info (win_info, 1);
+      tui_update_breakpoint_info (win_info, nullptr, true);
       for (int i = 0; i < win_info->content.size (); i++)
  {
   tui_exec_info_content &element = content[i];
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 2a85a008812..c1087f4490a 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -28,14 +28,21 @@ struct tui_win_info;
 
 /* Update the execution windows to show the active breakpoints.  This
    is called whenever a breakpoint is inserted, removed or has its
-   state changed.  */
-extern void tui_update_all_breakpoint_info (void);
+   state changed.  Normally BEING_DELETED is nullptr; if not nullptr,
+   it indicates a breakpoint that is in the process of being deleted,
+   and which should therefore be ignored by the update.  This is done
+   because the relevant observer is notified before the breakpoint is
+   removed from the list of breakpoints.  */
+extern void tui_update_all_breakpoint_info (struct breakpoint *being_deleted);
 
 /* Scan the source window and the breakpoints to update the break_mode
-   information for each line.  Returns 1 if something changed and the
-   execution window must be refreshed.  */
-extern int tui_update_breakpoint_info (struct tui_source_window_base *win,
-       int current_only);
+   information for each line.  Returns true if something changed and
+   the execution window must be refreshed.  See
+   tui_update_all_breakpoint_info for a description of
+   BEING_DELETED.  */
+extern bool tui_update_breakpoint_info (struct tui_source_window_base *win,
+ struct breakpoint *being_deleted,
+ bool current_only);
 
 /* Function to display the "main" routine.  */
 extern void tui_display_main (void);
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 06/61] Introduce tui_data_window::last_regs_line_no method

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_last_regs_line_no into a method on tui_data_window,
allowing the removal of uses of the TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.h (tui_last_regs_line_no): Don't declare.
        * tui/tui-regs.c (tui_data_window::last_regs_line_no): Rename from
        tui_last_regs_line_no.
        (tui_display_reg_element_at_line)
        (tui_display_registers_from_line): Update.
        * tui/tui-data.h (struct tui_data_window) <last_regs_line_no>: New
        method.
---
 gdb/ChangeLog      | 10 ++++++++++
 gdb/tui/tui-data.h |  4 ++++
 gdb/tui/tui-regs.c | 17 ++++++++---------
 gdb/tui/tui-regs.h |  1 -
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 6a243c3d2f9..9b1e892aefe 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -490,6 +490,10 @@ struct tui_data_window : public tui_win_info
   bool display_regs = false;
   struct reggroup *current_group = nullptr;
 
+  /* Answer the number of the last line in the regs display.  If there
+     are no registers (-1) is returned.  */
+  int last_regs_line_no () const;
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 32e82b23482..e9fbf4b0752 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -63,18 +63,17 @@ static enum tui_status tui_get_register (struct frame_info *frame,
 ** PUBLIC FUNCTIONS                     **
 ******************************************/
 
-/* Answer the number of the last line in the regs display.  If there
-   are no registers (-1) is returned.  */
+/* See tui-data.h.  */
+
 int
-tui_last_regs_line_no (void)
+tui_data_window::last_regs_line_no () const
 {
   int num_lines = (-1);
 
-  if (!TUI_DATA_WIN->regs_content.empty ())
+  if (!regs_content.empty ())
     {
-      num_lines = (TUI_DATA_WIN->regs_content.size ()
-   / TUI_DATA_WIN->regs_column_count);
-      if (TUI_DATA_WIN->regs_content.size () % TUI_DATA_WIN->regs_column_count)
+      num_lines = regs_content.size () / regs_column_count;
+      if (regs_content.size () % regs_column_count)
  num_lines++;
     }
   return num_lines;
@@ -354,7 +353,7 @@ tui_display_reg_element_at_line (int start_element_no,
  {
   int last_line_no, first_line_on_last_page;
 
-  last_line_no = tui_last_regs_line_no ();
+  last_line_no = TUI_DATA_WIN->last_regs_line_no ();
   first_line_on_last_page
     = last_line_no - (TUI_DATA_WIN->height - 2);
   if (first_line_on_last_page < 0)
@@ -390,7 +389,7 @@ tui_display_registers_from_line (int line_no,
  { /* If we must display regs (force_display is true), then
      make sure that we don't display off the end of the
      registers.  */
-  if (line_no >= tui_last_regs_line_no ())
+  if (line_no >= TUI_DATA_WIN->last_regs_line_no ())
     {
       if ((line = tui_line_from_reg_element_no (
  TUI_DATA_WIN->regs_content.size () - 1)) < 0)
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index 54b1b0870f7..fcb440dcf11 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -28,7 +28,6 @@ extern void tui_check_register_values (struct frame_info *);
 extern void tui_show_registers (struct reggroup *group);
 extern void tui_display_registers_from (int);
 extern int tui_display_registers_from_line (int, int);
-extern int tui_last_regs_line_no (void);
 extern int tui_first_reg_element_inline (int);
 extern int tui_line_from_reg_element_no (int);
 extern int tui_first_reg_element_no_inline (int lineno);
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 07/61] Introduce tui_data_window::line_from_reg_element_no method

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_line_from_reg_element_no to be a method on
tui_data_window, allowing for the removal of some uses of the
TUI_DATA_WIN global.  (Actually, in this particular patch, the number
of uses is not decreased, but rather the uses are moved to spots that
are already using the global, i.e., increasing the clustering.)

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.c (tui_display_data_from)
        (tui_data_window::do_scroll_vertical): Update.
        * tui/tui-regs.h (tui_line_from_reg_element_no): Don't declare.
        * tui/tui-regs.c (tui_data_window::line_from_reg_element_no):
        Rename from tui_line_from_reg_element_no.
        (tui_display_registers_from_line): Update.
        * tui/tui-data.h (struct tui_data_window)
        <line_from_reg_element_no>: New method.
---
 gdb/ChangeLog         | 11 +++++++++++
 gdb/tui/tui-data.h    |  5 +++++
 gdb/tui/tui-regs.c    | 12 +++++-------
 gdb/tui/tui-regs.h    |  1 -
 gdb/tui/tui-windata.c |  4 ++--
 5 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 9b1e892aefe..081d0dfa449 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -494,6 +494,11 @@ struct tui_data_window : public tui_win_info
      are no registers (-1) is returned.  */
   int last_regs_line_no () const;
 
+  /* Answer the line number that the register element at element_no is
+     on.  If element_no is greater than the number of register
+     elements there are, -1 is returned.  */
+  int line_from_reg_element_no (int element_no) const;
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index e9fbf4b0752..03e91496b0f 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -79,21 +79,19 @@ tui_data_window::last_regs_line_no () const
   return num_lines;
 }
 
+/* See tui-data.h.  */
 
-/* Answer the line number that the register element at element_no is
-   on.  If element_no is greater than the number of register elements
-   there are, -1 is returned.  */
 int
-tui_line_from_reg_element_no (int element_no)
+tui_data_window::line_from_reg_element_no (int element_no) const
 {
-  if (element_no < TUI_DATA_WIN->regs_content.size ())
+  if (element_no < regs_content.size ())
     {
       int i, line = (-1);
 
       i = 1;
       while (line == (-1))
  {
-  if (element_no < TUI_DATA_WIN->regs_column_count * i)
+  if (element_no < regs_column_count * i)
     line = i - 1;
   else
     i++;
@@ -391,7 +389,7 @@ tui_display_registers_from_line (int line_no,
      registers.  */
   if (line_no >= TUI_DATA_WIN->last_regs_line_no ())
     {
-      if ((line = tui_line_from_reg_element_no (
+      if ((line = TUI_DATA_WIN->line_from_reg_element_no (
  TUI_DATA_WIN->regs_content.size () - 1)) < 0)
  line = 0;
     }
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index fcb440dcf11..f6ed8628f2a 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -29,7 +29,6 @@ extern void tui_show_registers (struct reggroup *group);
 extern void tui_display_registers_from (int);
 extern int tui_display_registers_from_line (int, int);
 extern int tui_first_reg_element_inline (int);
-extern int tui_line_from_reg_element_no (int);
 extern int tui_first_reg_element_no_inline (int lineno);
 
 #endif /* TUI_TUI_REGS_H */
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index 7ff50a0c905..ac3e6d6e097 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -134,7 +134,7 @@ tui_display_data_from (int element_no, int reuse_windows)
   int first_line = (-1);
 
   if (element_no < TUI_DATA_WIN->regs_content.size ())
-    first_line = tui_line_from_reg_element_no (element_no);
+    first_line = TUI_DATA_WIN->line_from_reg_element_no (element_no);
   else
     { /* Calculate the first_line from the element number.  */
     }
@@ -173,7 +173,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
 
   first_element_no = first_data_item_displayed ();
   if (first_element_no < regs_content.size ())
-    first_line = tui_line_from_reg_element_no (first_element_no);
+    first_line = line_from_reg_element_no (first_element_no);
   else
     { /* Calculate the first line from the element number which is in
         the general data content.  */
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 08/61] Introduce tui_data_window::first_reg_element_no_inline

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_first_reg_element_no_inline to be a method on
tui_data_window.  This again moves uses of the TUI_DATA_WIN global
from this function into other functions that are already using the
global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.h (tui_first_reg_element_no_inline): Don't
        declare.
        * tui/tui-regs.c (tui_data_window::first_reg_element_no_inline):
        Rename from tui_first_reg_element_no_inline.
        (tui_display_reg_element_at_line)
        (tui_display_registers_from_line): Update.
        * tui/tui-data.h (struct tui_data_window)
        <first_reg_element_no_inline>: New method.
---
 gdb/ChangeLog      | 11 +++++++++++
 gdb/tui/tui-data.h |  4 ++++
 gdb/tui/tui-regs.c | 16 +++++++---------
 gdb/tui/tui-regs.h |  1 -
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 081d0dfa449..676345c528a 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -499,6 +499,10 @@ struct tui_data_window : public tui_win_info
      elements there are, -1 is returned.  */
   int line_from_reg_element_no (int element_no) const;
 
+  /* Answer the index of the first element in line_no.  If line_no is
+     past the register area (-1) is returned.  */
+  int first_reg_element_no_inline (int line_no) const;
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 03e91496b0f..d005fe36c23 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -103,16 +103,13 @@ tui_data_window::line_from_reg_element_no (int element_no) const
     return (-1);
 }
 
+/* See tui-data.h.  */
 
-/* Answer the index of the first element in line_no.  If line_no is
-   past the register area (-1) is returned.  */
 int
-tui_first_reg_element_no_inline (int line_no)
+tui_data_window::first_reg_element_no_inline (int line_no) const
 {
-  if ((line_no * TUI_DATA_WIN->regs_column_count)
-      <= TUI_DATA_WIN->regs_content.size ())
-    return (((line_no + 1) * TUI_DATA_WIN->regs_column_count)
-    - TUI_DATA_WIN->regs_column_count);
+  if (line_no * regs_column_count <= regs_content.size ())
+    return ((line_no + 1) * regs_column_count) - regs_column_count;
   else
     return (-1);
 }
@@ -362,7 +359,8 @@ tui_display_reg_element_at_line (int start_element_no,
      display at.  */
   if (start_line_no > first_line_on_last_page)
     element_no
-      = tui_first_reg_element_no_inline (first_line_on_last_page);
+      = (TUI_DATA_WIN->first_reg_element_no_inline
+ (first_line_on_last_page));
  }
       tui_display_registers_from (element_no);
     }
@@ -399,7 +397,7 @@ tui_display_registers_from_line (int line_no,
       else
  line = line_no;
 
-      element_no = tui_first_reg_element_no_inline (line);
+      element_no = TUI_DATA_WIN->first_reg_element_no_inline (line);
       if (element_no < TUI_DATA_WIN->regs_content.size ())
  tui_display_reg_element_at_line (element_no, line);
       else
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index f6ed8628f2a..866af458e10 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -29,6 +29,5 @@ extern void tui_show_registers (struct reggroup *group);
 extern void tui_display_registers_from (int);
 extern int tui_display_registers_from_line (int, int);
 extern int tui_first_reg_element_inline (int);
-extern int tui_first_reg_element_no_inline (int lineno);
 
 #endif /* TUI_TUI_REGS_H */
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 09/61] Remove tui_display_data_from_line

Tom Tromey-2
In reply to this post by Tom Tromey-2
tui_display_data_from_line is just a wrapper for
tui_display_registers_from_line, so remove it.  Also, nothing passed 0
as the "force_display" parameter to tui_display_registers_from_line,
so remove that parameter as well.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.h (tui_display_data_from_line): Don't declare.
        * tui/tui-windata.c (tui_display_data_from_line): Remove.
        (tui_display_data_from, tui_data_window::do_scroll_vertical): Call
        tui_display_registers_from_line.
        * tui/tui-regs.h (tui_display_registers_from_line): Update.
        * tui/tui-regs.c (tui_display_registers_from_line): Remove
        "force_display" parameter.
---
 gdb/ChangeLog         | 10 ++++++++++
 gdb/tui/tui-regs.c    | 30 +++++++++++++-----------------
 gdb/tui/tui-regs.h    |  2 +-
 gdb/tui/tui-windata.c | 20 ++------------------
 gdb/tui/tui-windata.h |  1 -
 5 files changed, 26 insertions(+), 37 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index d005fe36c23..ae38d343822 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -372,38 +372,34 @@ tui_display_reg_element_at_line (int start_element_no,
    data window.  Answers the line number that the display actually
    started from.  If nothing is displayed (-1) is returned.  */
 int
-tui_display_registers_from_line (int line_no,
- int force_display)
+tui_display_registers_from_line (int line_no)
 {
+  tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
   if (!TUI_DATA_WIN->regs_content.empty ())
     {
-      int line, element_no;
+      int element_no;
 
       if (line_no < 0)
- line = 0;
-      else if (force_display)
- { /* If we must display regs (force_display is true), then
-     make sure that we don't display off the end of the
+ line_no = 0;
+      else
+ {
+  /* Make sure that we don't display off the end of the
      registers.  */
   if (line_no >= TUI_DATA_WIN->last_regs_line_no ())
     {
-      if ((line = TUI_DATA_WIN->line_from_reg_element_no (
+      if ((line_no = TUI_DATA_WIN->line_from_reg_element_no (
  TUI_DATA_WIN->regs_content.size () - 1)) < 0)
- line = 0;
+ line_no = 0;
     }
-  else
-    line = line_no;
  }
-      else
- line = line_no;
 
-      element_no = TUI_DATA_WIN->first_reg_element_no_inline (line);
+      element_no = TUI_DATA_WIN->first_reg_element_no_inline (line_no);
       if (element_no < TUI_DATA_WIN->regs_content.size ())
- tui_display_reg_element_at_line (element_no, line);
+ tui_display_reg_element_at_line (element_no, line_no);
       else
- line = (-1);
+ line_no = (-1);
 
-      return line;
+      return line_no;
     }
 
   return (-1); /* Nothing was displayed.  */
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index 866af458e10..c1054696493 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -27,7 +27,7 @@
 extern void tui_check_register_values (struct frame_info *);
 extern void tui_show_registers (struct reggroup *group);
 extern void tui_display_registers_from (int);
-extern int tui_display_registers_from_line (int, int);
+extern int tui_display_registers_from_line (int);
 extern int tui_first_reg_element_inline (int);
 
 #endif /* TUI_TUI_REGS_H */
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index ac3e6d6e097..4f18d73aec2 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -111,22 +111,6 @@ tui_display_all_data (void)
 }
 
 
-/* Function to display the data starting at line, line_no, in the data
-   window.  */
-void
-tui_display_data_from_line (int line_no)
-{
-  int _line_no = line_no;
-
-  if (line_no < 0)
-    _line_no = 0;
-
-  tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
-
-  tui_display_registers_from_line (_line_no, TRUE);
-}
-
-
 /* Display data starting at element element_no.  */
 void
 tui_display_data_from (int element_no, int reuse_windows)
@@ -144,7 +128,7 @@ tui_display_data_from (int element_no, int reuse_windows)
       tui_erase_data_content (NULL);
       if (!reuse_windows)
  tui_delete_data_content_windows ();
-      tui_display_data_from_line (first_line);
+      tui_display_registers_from_line (first_line);
     }
 }
 
@@ -184,7 +168,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
       first_line += num_to_scroll;
       tui_erase_data_content (NULL);
       tui_delete_data_content_windows ();
-      tui_display_data_from_line (first_line);
+      tui_display_registers_from_line (first_line);
     }
 }
 
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index 1aba67520ec..fd8e6257da7 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -26,7 +26,6 @@
 
 extern void tui_erase_data_content (const char *);
 extern void tui_display_all_data (void);
-extern void tui_display_data_from_line (int);
 extern void tui_delete_data_content_windows (void);
 extern void tui_refresh_data_win (void);
 extern void tui_display_data_from (int, int);
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 10/61] Remove tui_display_data_from

Tom Tromey-2
In reply to this post by Tom Tromey-2
tui_display_data_from is only called from a single place.  Inlining it
there lets us remove some uses of the TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.h (tui_display_data_from): Don't declare.
        * tui/tui-windata.c (tui_display_data_from): Remove.
        (tui_data_window::refresh_all): Update.
---
 gdb/ChangeLog         |  6 ++++++
 gdb/tui/tui-windata.c | 35 ++++++++++++-----------------------
 gdb/tui/tui-windata.h |  1 -
 3 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index 4f18d73aec2..722d0a5e26e 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -111,28 +111,6 @@ tui_display_all_data (void)
 }
 
 
-/* Display data starting at element element_no.  */
-void
-tui_display_data_from (int element_no, int reuse_windows)
-{
-  int first_line = (-1);
-
-  if (element_no < TUI_DATA_WIN->regs_content.size ())
-    first_line = TUI_DATA_WIN->line_from_reg_element_no (element_no);
-  else
-    { /* Calculate the first_line from the element number.  */
-    }
-
-  if (first_line >= 0)
-    {
-      tui_erase_data_content (NULL);
-      if (!reuse_windows)
- tui_delete_data_content_windows ();
-      tui_display_registers_from_line (first_line);
-    }
-}
-
-
 /* Function to redisplay the contents of the data window.  */
 void
 tui_data_window::refresh_all ()
@@ -143,7 +121,18 @@ tui_data_window::refresh_all ()
       int first_element = first_data_item_displayed ();
 
       if (first_element >= 0) /* Re-use existing windows.  */
- tui_display_data_from (first_element, TRUE);
+ {
+  int first_line = (-1);
+
+  if (first_element < regs_content.size ())
+    first_line = line_from_reg_element_no (first_element);
+
+  if (first_line >= 0)
+    {
+      tui_erase_data_content (NULL);
+      tui_display_registers_from_line (first_line);
+    }
+ }
     }
 }
 
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index fd8e6257da7..9970cfae547 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -28,6 +28,5 @@ extern void tui_erase_data_content (const char *);
 extern void tui_display_all_data (void);
 extern void tui_delete_data_content_windows (void);
 extern void tui_refresh_data_win (void);
-extern void tui_display_data_from (int, int);
 
 #endif /* TUI_TUI_WINDATA_H */
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 11/61] Introduce tui_data_window::display_all_data method

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_display_all_data to be a method on tui_data_window.
This helps cluster uses of the TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.h (tui_display_all_data): Don't declare.
        * tui/tui-windata.c (tui_data_window::display_all_data): Rename
        from tui_display_all_data.
        * tui/tui-win.c
        (tui_data_window::do_make_visible_with_new_height): Update.
        * tui/tui-regs.c (tui_show_registers): Update.
        * tui/tui-layout.c (tui_set_layout): Update.
        * tui/tui-data.h (struct tui_data_window) <display_all_data>: New
        method.
---
 gdb/ChangeLog         | 12 ++++++++++++
 gdb/tui/tui-data.h    |  4 ++++
 gdb/tui/tui-layout.c  |  2 +-
 gdb/tui/tui-regs.c    |  2 +-
 gdb/tui/tui-win.c     |  2 +-
 gdb/tui/tui-windata.c |  6 +++---
 gdb/tui/tui-windata.h |  1 -
 7 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 676345c528a..5cdd7561e62 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -503,6 +503,10 @@ struct tui_data_window : public tui_win_info
      past the register area (-1) is returned.  */
   int first_reg_element_no_inline (int line_no) const;
 
+  /* This function displays the data that is in the data window's
+     content.  It does not set the content.  */
+  void display_all_data ();
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index d9a1f08ac1f..9e683cfa919 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -215,7 +215,7 @@ tui_set_layout (enum tui_layout_type layout_type)
   if (!regs_populate
       && (new_layout == SRC_DATA_COMMAND
   || new_layout == DISASSEM_DATA_COMMAND))
-    tui_display_all_data ();
+    TUI_DATA_WIN->display_all_data ();
 
   tui_update_source_windows_with_addr (gdbarch, addr);
 
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index ae38d343822..59933639f6f 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -157,7 +157,7 @@ tui_show_registers (struct reggroup *group)
     data_item_win->highlight = false;
  }
       TUI_DATA_WIN->current_group = group;
-      tui_display_all_data ();
+      TUI_DATA_WIN->display_all_data ();
     }
 }
 
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 557f8b5d2d6..ee03cf38e14 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -1366,7 +1366,7 @@ tui_source_window_base::do_make_visible_with_new_height ()
 void
 tui_data_window::do_make_visible_with_new_height ()
 {
-  tui_display_all_data ();
+  display_all_data ();
 }
 
 /* See tui-data.h.  */
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index 722d0a5e26e..dd2daf19332 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -97,15 +97,15 @@ tui_erase_data_content (const char *prompt)
 /* This function displays the data that is in the data window's
    content.  It does not set the content.  */
 void
-tui_display_all_data (void)
+tui_data_window::display_all_data ()
 {
-  if (TUI_DATA_WIN->regs_content.empty ())
+  if (regs_content.empty ())
     tui_erase_data_content (NO_DATA_STRING);
   else
     {
       tui_erase_data_content (NULL);
       tui_delete_data_content_windows ();
-      tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
+      tui_check_and_display_highlight_if_needed (this);
       tui_display_registers_from (0);
     }
 }
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index 9970cfae547..adffcafacb4 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -25,7 +25,6 @@
 #include "tui/tui-data.h"
 
 extern void tui_erase_data_content (const char *);
-extern void tui_display_all_data (void);
 extern void tui_delete_data_content_windows (void);
 extern void tui_refresh_data_win (void);
 
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 12/61] Don't declare unimplemented functions

Tom Tromey-2
In reply to this post by Tom Tromey-2
A couple of functions were declared but never defined.  This removes
the declarations.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.h (tui_refresh_data_win): Don't declare.
        * tui/tui-regs.h (tui_first_reg_element_inline): Don't declare.
---
 gdb/ChangeLog         | 5 +++++
 gdb/tui/tui-regs.h    | 1 -
 gdb/tui/tui-windata.h | 1 -
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index c1054696493..c99910b2c7e 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -28,6 +28,5 @@ extern void tui_check_register_values (struct frame_info *);
 extern void tui_show_registers (struct reggroup *group);
 extern void tui_display_registers_from (int);
 extern int tui_display_registers_from_line (int);
-extern int tui_first_reg_element_inline (int);
 
 #endif /* TUI_TUI_REGS_H */
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index adffcafacb4..fce4e6defc9 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -26,6 +26,5 @@
 
 extern void tui_erase_data_content (const char *);
 extern void tui_delete_data_content_windows (void);
-extern void tui_refresh_data_win (void);
 
 #endif /* TUI_TUI_WINDATA_H */
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 13/61] Introduce tui_data_window::delete_data_content_windows method

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_delete_data_content_windows to be a method on
tui_data_window, removing some uses of the TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.h (tui_delete_data_content_windows): Don't
        declare.
        * tui/tui-windata.c
        (tui_data_window::delete_data_content_windows): Rename from
        tui_delete_data_content_windows.
        (tui_data_window::display_all_data)
        (tui_data_window::do_scroll_vertical): Update.
        * tui/tui-data.h (struct tui_data_window)
        <delete_data_content_windows>: New method.
---
 gdb/ChangeLog         | 12 ++++++++++++
 gdb/tui/tui-data.h    |  4 ++++
 gdb/tui/tui-windata.c |  8 ++++----
 gdb/tui/tui-windata.h |  1 -
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 5cdd7561e62..9a908115231 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -507,6 +507,10 @@ struct tui_data_window : public tui_win_info
      content.  It does not set the content.  */
   void display_all_data ();
 
+  /* Function to delete all the item windows in the data window.  This
+     is usually done when the data window is scrolled.  */
+  void delete_data_content_windows ();
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index dd2daf19332..02cd6d0b727 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -60,9 +60,9 @@ tui_data_window::first_data_item_displayed ()
 /* Function to delete all the item windows in the data window.  This
    is usually done when the data window is scrolled.  */
 void
-tui_delete_data_content_windows (void)
+tui_data_window::delete_data_content_windows ()
 {
-  for (auto &&win : TUI_DATA_WIN->regs_content)
+  for (auto &&win : regs_content)
     {
       tui_delete_win (win->handle);
       win->handle = NULL;
@@ -104,7 +104,7 @@ tui_data_window::display_all_data ()
   else
     {
       tui_erase_data_content (NULL);
-      tui_delete_data_content_windows ();
+      delete_data_content_windows ();
       tui_check_and_display_highlight_if_needed (this);
       tui_display_registers_from (0);
     }
@@ -156,7 +156,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
     {
       first_line += num_to_scroll;
       tui_erase_data_content (NULL);
-      tui_delete_data_content_windows ();
+      delete_data_content_windows ();
       tui_display_registers_from_line (first_line);
     }
 }
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index fce4e6defc9..419b22f3658 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -25,6 +25,5 @@
 #include "tui/tui-data.h"
 
 extern void tui_erase_data_content (const char *);
-extern void tui_delete_data_content_windows (void);
 
 #endif /* TUI_TUI_WINDATA_H */
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 14/61] Introduce tui_data_window::erase_data_content method

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_erase_data_content to be a method on tui_data_window,
allowing for the removal of some uses of the TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-windata.h (tui_erase_data_content): Don't declare.
        * tui/tui-windata.c (tui_data_window::erase_data_content): Rename
        from tui_erase_data_content.
        (tui_data_window::display_all_data)
        (tui_data_window::refresh_all)
        (tui_data_window::do_scroll_vertical): Update.
        * tui/tui-regs.c (tui_show_registers): Update.
        * tui/tui-data.h (struct tui_data_window) <erase_data_content>:
        New method.
---
 gdb/ChangeLog         | 12 ++++++++++++
 gdb/tui/tui-data.h    |  2 ++
 gdb/tui/tui-regs.c    |  2 +-
 gdb/tui/tui-windata.c | 25 +++++++++++--------------
 gdb/tui/tui-windata.h |  2 --
 5 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 9a908115231..e1c85df31bf 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -511,6 +511,8 @@ struct tui_data_window : public tui_win_info
      is usually done when the data window is scrolled.  */
   void delete_data_content_windows ();
 
+  void erase_data_content (const char *prompt);
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 59933639f6f..9b396e429e2 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -146,7 +146,7 @@ tui_show_registers (struct reggroup *group)
   if (ret == TUI_FAILURE)
     {
       TUI_DATA_WIN->current_group = 0;
-      tui_erase_data_content (NO_REGS_STRING);
+      TUI_DATA_WIN->erase_data_content (NO_REGS_STRING);
     }
   else
     {
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index 02cd6d0b727..abbed3f16a1 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -72,25 +72,22 @@ tui_data_window::delete_data_content_windows ()
 
 
 void
-tui_erase_data_content (const char *prompt)
+tui_data_window::erase_data_content (const char *prompt)
 {
-  werase (TUI_DATA_WIN->handle);
-  tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
+  werase (handle);
+  tui_check_and_display_highlight_if_needed (this);
   if (prompt != NULL)
     {
-      int half_width = (TUI_DATA_WIN->width - 2) / 2;
+      int half_width = (width - 2) / 2;
       int x_pos;
 
       if (strlen (prompt) >= half_width)
  x_pos = 1;
       else
  x_pos = half_width - strlen (prompt);
-      mvwaddstr (TUI_DATA_WIN->handle,
- (TUI_DATA_WIN->height / 2),
- x_pos,
- (char *) prompt);
+      mvwaddstr (handle, (height / 2), x_pos, (char *) prompt);
     }
-  wrefresh (TUI_DATA_WIN->handle);
+  wrefresh (handle);
 }
 
 
@@ -100,10 +97,10 @@ void
 tui_data_window::display_all_data ()
 {
   if (regs_content.empty ())
-    tui_erase_data_content (NO_DATA_STRING);
+    erase_data_content (NO_DATA_STRING);
   else
     {
-      tui_erase_data_content (NULL);
+      erase_data_content (NULL);
       delete_data_content_windows ();
       tui_check_and_display_highlight_if_needed (this);
       tui_display_registers_from (0);
@@ -115,7 +112,7 @@ tui_data_window::display_all_data ()
 void
 tui_data_window::refresh_all ()
 {
-  tui_erase_data_content (NULL);
+  erase_data_content (NULL);
   if (!regs_content.empty ())
     {
       int first_element = first_data_item_displayed ();
@@ -129,7 +126,7 @@ tui_data_window::refresh_all ()
 
   if (first_line >= 0)
     {
-      tui_erase_data_content (NULL);
+      erase_data_content (NULL);
       tui_display_registers_from_line (first_line);
     }
  }
@@ -155,7 +152,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
   if (first_line >= 0)
     {
       first_line += num_to_scroll;
-      tui_erase_data_content (NULL);
+      erase_data_content (NULL);
       delete_data_content_windows ();
       tui_display_registers_from_line (first_line);
     }
diff --git a/gdb/tui/tui-windata.h b/gdb/tui/tui-windata.h
index 419b22f3658..3b89eefabc0 100644
--- a/gdb/tui/tui-windata.h
+++ b/gdb/tui/tui-windata.h
@@ -24,6 +24,4 @@
 
 #include "tui/tui-data.h"
 
-extern void tui_erase_data_content (const char *);
-
 #endif /* TUI_TUI_WINDATA_H */
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 15/61] Introduce two more tui_data_window methods

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_display_registers_from and
tui_display_registers_from_line to be methods on tui_data_window,
allowing for the removal of more uses of the TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.h (tui_display_registers_from)
        (tui_display_registers_from_line): Don't declare.
        * tui/tui-windata.c (tui_data_window::display_all_data)
        (tui_data_window::refresh_all)
        (tui_data_window::do_scroll_vertical): Update.
        * tui/tui-regs.c (tui_data_window::display_registers_from): Rename
        from tui_display_registers_from.
        (tui_display_reg_element_at_line): Update.
        (tui_data_window::display_registers_from_line): Rename from
        tui_display_registers_from_line.
        * tui/tui-data.h (struct tui_data_window) <display_registers_from,
        display_registers_from_line>: New methods.
---
 gdb/ChangeLog         | 15 +++++++++++++++
 gdb/tui/tui-data.h    | 11 +++++++++++
 gdb/tui/tui-regs.c    | 43 ++++++++++++++++++++-----------------------
 gdb/tui/tui-regs.h    |  2 --
 gdb/tui/tui-windata.c |  6 +++---
 5 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index e1c85df31bf..e5b4b0f6aa0 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -513,6 +513,17 @@ struct tui_data_window : public tui_win_info
 
   void erase_data_content (const char *prompt);
 
+  /* Function to display the registers in the content from
+     'start_element_no' until the end of the register content or the
+     end of the display height.  No checking for displaying past the
+     end of the registers is done here.  */
+  void display_registers_from (int start_element_no);
+
+  /* Function to display the registers starting at line line_no in the
+     data window.  Answers the line number that the display actually
+     started from.  If nothing is displayed (-1) is returned.  */
+  int display_registers_from_line (int line_no);
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 9b396e429e2..042563f0495 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -249,14 +249,14 @@ tui_show_register_group (struct reggroup *group,
    of the display height.  No checking for displaying past the end of
    the registers is done here.  */
 void
-tui_display_registers_from (int start_element_no)
+tui_data_window::display_registers_from (int start_element_no)
 {
-  if (!TUI_DATA_WIN->regs_content.empty ())
+  if (!regs_content.empty ())
     {
       int j, item_win_width, cur_y;
 
       int max_len = 0;
-      for (auto &&data_item_win : TUI_DATA_WIN->regs_content)
+      for (auto &&data_item_win : regs_content)
         {
           char *p;
           int len;
@@ -278,28 +278,25 @@ tui_display_registers_from (int start_element_no)
       item_win_width = max_len + 1;
       int i = start_element_no;
 
-      TUI_DATA_WIN->regs_column_count =
-        (TUI_DATA_WIN->width - 2) / item_win_width;
-      if (TUI_DATA_WIN->regs_column_count == 0)
-        TUI_DATA_WIN->regs_column_count = 1;
-      item_win_width =
-        (TUI_DATA_WIN->width - 2) / TUI_DATA_WIN->regs_column_count;
+      regs_column_count = (width - 2) / item_win_width;
+      if (regs_column_count == 0)
+        regs_column_count = 1;
+      item_win_width = (width - 2) / regs_column_count;
 
       /* Now create each data "sub" window, and write the display into
  it.  */
       cur_y = 1;
-      while (i < TUI_DATA_WIN->regs_content.size ()
-     && cur_y <= TUI_DATA_WIN->viewport_height)
+      while (i < regs_content.size ()
+     && cur_y <= viewport_height)
  {
   for (j = 0;
-       j < TUI_DATA_WIN->regs_column_count
- && i < TUI_DATA_WIN->regs_content.size ();
+       j < regs_column_count && i < regs_content.size ();
        j++)
     {
       struct tui_data_item_window *data_item_win;
 
       /* Create the window if necessary.  */
-      data_item_win = TUI_DATA_WIN->regs_content[i].get ();
+      data_item_win = regs_content[i].get ();
               if (data_item_win->handle != NULL
                   && (data_item_win->height != 1
                       || data_item_win->width != item_win_width
@@ -362,7 +359,7 @@ tui_display_reg_element_at_line (int start_element_no,
       = (TUI_DATA_WIN->first_reg_element_no_inline
  (first_line_on_last_page));
  }
-      tui_display_registers_from (element_no);
+      TUI_DATA_WIN->display_registers_from (element_no);
     }
 }
 
@@ -372,10 +369,10 @@ tui_display_reg_element_at_line (int start_element_no,
    data window.  Answers the line number that the display actually
    started from.  If nothing is displayed (-1) is returned.  */
 int
-tui_display_registers_from_line (int line_no)
+tui_data_window::display_registers_from_line (int line_no)
 {
-  tui_check_and_display_highlight_if_needed (TUI_DATA_WIN);
-  if (!TUI_DATA_WIN->regs_content.empty ())
+  tui_check_and_display_highlight_if_needed (this);
+  if (!regs_content.empty ())
     {
       int element_no;
 
@@ -385,16 +382,16 @@ tui_display_registers_from_line (int line_no)
  {
   /* Make sure that we don't display off the end of the
      registers.  */
-  if (line_no >= TUI_DATA_WIN->last_regs_line_no ())
+  if (line_no >= last_regs_line_no ())
     {
-      if ((line_no = TUI_DATA_WIN->line_from_reg_element_no (
- TUI_DATA_WIN->regs_content.size () - 1)) < 0)
+      line_no = line_from_reg_element_no (regs_content.size () - 1);
+      if (line_no < 0)
  line_no = 0;
     }
  }
 
-      element_no = TUI_DATA_WIN->first_reg_element_no_inline (line_no);
-      if (element_no < TUI_DATA_WIN->regs_content.size ())
+      element_no = first_reg_element_no_inline (line_no);
+      if (element_no < regs_content.size ())
  tui_display_reg_element_at_line (element_no, line_no);
       else
  line_no = (-1);
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index c99910b2c7e..354605c96f2 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -26,7 +26,5 @@
 
 extern void tui_check_register_values (struct frame_info *);
 extern void tui_show_registers (struct reggroup *group);
-extern void tui_display_registers_from (int);
-extern int tui_display_registers_from_line (int);
 
 #endif /* TUI_TUI_REGS_H */
diff --git a/gdb/tui/tui-windata.c b/gdb/tui/tui-windata.c
index abbed3f16a1..9256e0e26b6 100644
--- a/gdb/tui/tui-windata.c
+++ b/gdb/tui/tui-windata.c
@@ -103,7 +103,7 @@ tui_data_window::display_all_data ()
       erase_data_content (NULL);
       delete_data_content_windows ();
       tui_check_and_display_highlight_if_needed (this);
-      tui_display_registers_from (0);
+      display_registers_from (0);
     }
 }
 
@@ -127,7 +127,7 @@ tui_data_window::refresh_all ()
   if (first_line >= 0)
     {
       erase_data_content (NULL);
-      tui_display_registers_from_line (first_line);
+      display_registers_from_line (first_line);
     }
  }
     }
@@ -154,7 +154,7 @@ tui_data_window::do_scroll_vertical (int num_to_scroll)
       first_line += num_to_scroll;
       erase_data_content (NULL);
       delete_data_content_windows ();
-      tui_display_registers_from_line (first_line);
+      display_registers_from_line (first_line);
     }
 }
 
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 16/61] Introduce tui_data_window::display_reg_element_at_line method

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_display_reg_element_at_line to be a method on
tui_data_window, allowing for the removal of some uses of the
TUI_DATA_WIN global.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.c (tui_data_window::display_reg_element_at_line):
        Rename from tui_display_reg_element_at_line.
        (tui_data_window::display_registers_from_line): Update.
        * tui/tui-data.h (struct tui_data_window)
        <display_reg_element_at_line>: New method.
---
 gdb/ChangeLog      |  8 ++++++++
 gdb/tui/tui-data.h |  7 +++++++
 gdb/tui/tui-regs.c | 21 +++++++++------------
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index e5b4b0f6aa0..b3592e39133 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -535,6 +535,13 @@ protected:
   /* Return the index of the first element displayed.  If none are
      displayed, then return -1.  */
   int first_data_item_displayed ();
+
+  /* Function to display the registers in the content from
+     'start_element_no' on 'start_line_no' until the end of the
+     register content or the end of the display height.  This function
+     checks that we won't display off the end of the register
+     display.  */
+  void display_reg_element_at_line (int start_element_no, int start_line_no);
 };
 
 struct tui_cmd_window : public tui_win_info
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 042563f0495..eea8cf45acf 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -333,11 +333,11 @@ tui_data_window::display_registers_from (int start_element_no)
    'start_element_no' on 'start_line_no' until the end of the register
    content or the end of the display height.  This function checks
    that we won't display off the end of the register display.  */
-static void
-tui_display_reg_element_at_line (int start_element_no,
- int start_line_no)
+void
+tui_data_window::display_reg_element_at_line (int start_element_no,
+      int start_line_no)
 {
-  if (!TUI_DATA_WIN->regs_content.empty ())
+  if (!regs_content.empty ())
     {
       int element_no = start_element_no;
 
@@ -345,9 +345,8 @@ tui_display_reg_element_at_line (int start_element_no,
  {
   int last_line_no, first_line_on_last_page;
 
-  last_line_no = TUI_DATA_WIN->last_regs_line_no ();
-  first_line_on_last_page
-    = last_line_no - (TUI_DATA_WIN->height - 2);
+  last_line_no = last_regs_line_no ();
+  first_line_on_last_page = last_line_no - (height - 2);
   if (first_line_on_last_page < 0)
     first_line_on_last_page = 0;
 
@@ -355,11 +354,9 @@ tui_display_reg_element_at_line (int start_element_no,
      registers, adjust what element to really start the
      display at.  */
   if (start_line_no > first_line_on_last_page)
-    element_no
-      = (TUI_DATA_WIN->first_reg_element_no_inline
- (first_line_on_last_page));
+    element_no = first_reg_element_no_inline (first_line_on_last_page);
  }
-      TUI_DATA_WIN->display_registers_from (element_no);
+      display_registers_from (element_no);
     }
 }
 
@@ -392,7 +389,7 @@ tui_data_window::display_registers_from_line (int line_no)
 
       element_no = first_reg_element_no_inline (line_no);
       if (element_no < regs_content.size ())
- tui_display_reg_element_at_line (element_no, line_no);
+ display_reg_element_at_line (element_no, line_no);
       else
  line_no = (-1);
 
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 17/61] Parameterize tui_show_register_group with window

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_show_register_group not to reference the TUI_DATA_WIN
global, instead leaving that to its caller.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.c (tui_show_registers): Update.
        (tui_show_register_group): Add win_info parameter.
---
 gdb/ChangeLog      |  5 +++++
 gdb/tui/tui-regs.c | 24 +++++++++++++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index eea8cf45acf..f99e7c12f7f 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -49,7 +49,8 @@
 ******************************************/
 static void tui_display_register (struct tui_data_item_window *data);
 
-static void tui_show_register_group (struct reggroup *group,
+static void tui_show_register_group (tui_data_window *win_info,
+     struct reggroup *group,
      struct frame_info *frame,
      int refresh_values_only);
 
@@ -139,7 +140,7 @@ tui_show_registers (struct reggroup *group)
 
   if (target_has_registers && target_has_stack && target_has_memory)
     {
-      tui_show_register_group (group, get_selected_frame (NULL),
+      tui_show_register_group (TUI_DATA_WIN, group, get_selected_frame (NULL),
        group == TUI_DATA_WIN->current_group);
       ret = TUI_SUCCESS;
     }
@@ -167,7 +168,8 @@ tui_show_registers (struct reggroup *group)
    refresh_values_only is TRUE.  */
 
 static void
-tui_show_register_group (struct reggroup *group,
+tui_show_register_group (tui_data_window *win_info,
+ struct reggroup *group,
                          struct frame_info *frame,
  int refresh_values_only)
 {
@@ -179,8 +181,8 @@ tui_show_register_group (struct reggroup *group,
   /* Make a new title showing which group we display.  */
   snprintf (title, sizeof (title) - 1, "Register group: %s",
             reggroup_name (group));
-  xfree (TUI_DATA_WIN->title);
-  TUI_DATA_WIN->title = xstrdup (title);
+  xfree (win_info->title);
+  win_info->title = xstrdup (title);
 
   /* See how many registers must be displayed.  */
   nr_regs = 0;
@@ -202,14 +204,14 @@ tui_show_register_group (struct reggroup *group,
     }
 
   if (!refresh_values_only)
-    TUI_DATA_WIN->regs_content.clear ();
+    win_info->regs_content.clear ();
 
-  if (nr_regs < TUI_DATA_WIN->regs_content.size ())
-    TUI_DATA_WIN->regs_content.resize (nr_regs);
+  if (nr_regs < win_info->regs_content.size ())
+    win_info->regs_content.resize (nr_regs);
   else
     {
-      for (int i = TUI_DATA_WIN->regs_content.size (); i < nr_regs; ++i)
- TUI_DATA_WIN->regs_content.emplace_back (new tui_data_item_window ());
+      for (int i = win_info->regs_content.size (); i < nr_regs; ++i)
+ win_info->regs_content.emplace_back (new tui_data_item_window ());
     }
 
   /* Now set the register names and values.  */
@@ -229,7 +231,7 @@ tui_show_register_group (struct reggroup *group,
       if (name == 0 || *name == '\0')
  continue;
 
-      data_item_win = TUI_DATA_WIN->regs_content[pos].get ();
+      data_item_win = win_info->regs_content[pos].get ();
       if (data_item_win)
  {
   if (!refresh_values_only)
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 18/61] Simplify tui_show_registers

Tom Tromey-2
In reply to this post by Tom Tromey-2
tui_show_registers keeps a local status variable, but it is not
actually needed.  This rearranges the function to remove the variable.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.c (tui_show_registers): Simplify.
---
 gdb/ChangeLog      |  4 ++++
 gdb/tui/tui-regs.c | 17 ++++++-----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index f99e7c12f7f..931787ae4b5 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -121,8 +121,6 @@ tui_data_window::first_reg_element_no_inline (int line_no) const
 void
 tui_show_registers (struct reggroup *group)
 {
-  enum tui_status ret = TUI_FAILURE;
-
   /* Make sure the curses mode is enabled.  */
   tui_enable ();
 
@@ -142,15 +140,7 @@ tui_show_registers (struct reggroup *group)
     {
       tui_show_register_group (TUI_DATA_WIN, group, get_selected_frame (NULL),
        group == TUI_DATA_WIN->current_group);
-      ret = TUI_SUCCESS;
-    }
-  if (ret == TUI_FAILURE)
-    {
-      TUI_DATA_WIN->current_group = 0;
-      TUI_DATA_WIN->erase_data_content (NO_REGS_STRING);
-    }
-  else
-    {
+
       /* Clear all notation of changed values.  */
       for (auto &&data_item_win : TUI_DATA_WIN->regs_content)
  {
@@ -160,6 +150,11 @@ tui_show_registers (struct reggroup *group)
       TUI_DATA_WIN->current_group = group;
       TUI_DATA_WIN->display_all_data ();
     }
+  else
+    {
+      TUI_DATA_WIN->current_group = 0;
+      TUI_DATA_WIN->erase_data_content (NO_REGS_STRING);
+    }
 }
 
 
--
2.17.2

Reply | Threaded
Open this post in threaded view
|

[PATCH 19/61] Minor tui_reg_next / tui_reg_prev cleanup

Tom Tromey-2
In reply to this post by Tom Tromey-2
This changes tui_reg_next and tui_reg_prev so that they don't need to
reference the TUI_DATA_WIN globals.

2019-07-04  Tom Tromey  <[hidden email]>

        * tui/tui-regs.c (tui_reg_next, tui_reg_prev): Add "current_group"
        parameter.  Don't reference globals.
        (tui_reg_command): Update.
---
 gdb/ChangeLog      |  6 ++++++
 gdb/tui/tui-regs.c | 21 +++++++++++----------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 931787ae4b5..31b252e2aa8 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -468,14 +468,13 @@ tui_display_register (struct tui_data_item_window *data)
    register window is not currently being displayed.  */
 
 static struct reggroup *
-tui_reg_next (struct gdbarch *gdbarch)
+tui_reg_next (struct reggroup *current_group, struct gdbarch *gdbarch)
 {
   struct reggroup *group = NULL;
 
-  if (TUI_DATA_WIN != NULL)
+  if (current_group != NULL)
     {
-      group = TUI_DATA_WIN->current_group;
-      group = reggroup_next (gdbarch, group);
+      group = reggroup_next (gdbarch, current_group);
       if (group == NULL)
         group = reggroup_next (gdbarch, NULL);
     }
@@ -487,14 +486,13 @@ tui_reg_next (struct gdbarch *gdbarch)
    register window is not currently being displayed.  */
 
 static struct reggroup *
-tui_reg_prev (struct gdbarch *gdbarch)
+tui_reg_prev (struct reggroup *current_group, struct gdbarch *gdbarch)
 {
   struct reggroup *group = NULL;
 
-  if (TUI_DATA_WIN != NULL)
+  if (current_group != NULL)
     {
-      group = TUI_DATA_WIN->current_group;
-      group = reggroup_prev (gdbarch, group);
+      group = reggroup_prev (gdbarch, current_group);
       if (group == NULL)
  group = reggroup_prev (gdbarch, NULL);
     }
@@ -524,10 +522,13 @@ tui_reg_command (const char *args, int from_tty)
       if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
  tui_set_layout_by_name (DATA_NAME);
 
+      struct reggroup *current_group = NULL;
+      if (TUI_DATA_WIN != NULL)
+ current_group = TUI_DATA_WIN->current_group;
       if (strncmp (args, "next", len) == 0)
- match = tui_reg_next (gdbarch);
+ match = tui_reg_next (current_group, gdbarch);
       else if (strncmp (args, "prev", len) == 0)
- match = tui_reg_prev (gdbarch);
+ match = tui_reg_prev (current_group, gdbarch);
 
       /* This loop matches on the initial part of a register group
  name.  If this initial part in ARGS matches only one register
--
2.17.2

1234