Remove NULL check from tui_reg_command
[deliverable/binutils-gdb.git] / gdb / tui / tui-regs.c
index 52f67026b549043e76f1b346f111729c53461795..b3c7ce627b46de0d7a8c16026ac0e4ef9c7fadbf 100644 (file)
@@ -32,7 +32,6 @@
 #include "target.h"
 #include "tui/tui-layout.h"
 #include "tui/tui-win.h"
-#include "tui/tui-windata.h"
 #include "tui/tui-wingeneral.h"
 #include "tui/tui-file.h"
 #include "tui/tui-regs.h"
 
 #include "gdb_curses.h"
 
-
-/*****************************************
-** STATIC LOCAL FUNCTIONS FORWARD DECLS    **
-******************************************/
 static void tui_display_register (struct tui_data_item_window *data);
 
 static void tui_show_register_group (tui_data_window *win_info,
@@ -59,12 +54,15 @@ static void tui_get_register (struct frame_info *frame,
                              int regnum, bool *changedp);
 
 
+/* See tui-regs.h.  */
 
-/*****************************************
-** PUBLIC FUNCTIONS                     **
-******************************************/
+tui_data_item_window::~tui_data_item_window ()
+{
+  xfree (value);
+  xfree (content);
+}
 
-/* See tui-data.h.  */
+/* See tui-regs.h.  */
 
 int
 tui_data_window::last_regs_line_no () const
@@ -80,7 +78,7 @@ tui_data_window::last_regs_line_no () const
   return num_lines;
 }
 
-/* See tui-data.h.  */
+/* See tui-regs.h.  */
 
 int
 tui_data_window::line_from_reg_element_no (int element_no) const
@@ -104,7 +102,7 @@ tui_data_window::line_from_reg_element_no (int element_no) const
     return (-1);
 }
 
-/* See tui-data.h.  */
+/* See tui-regs.h.  */
 
 int
 tui_data_window::first_reg_element_no_inline (int line_no) const
@@ -140,7 +138,7 @@ tui_show_registers (struct reggroup *group)
 
   /* Make sure the register window is visible.  If not, select an
      appropriate layout.  */
-  if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
+  if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible ())
     tui_reg_layout ();
 
   if (group == 0)
@@ -167,7 +165,7 @@ tui_show_registers (struct reggroup *group)
   else
     {
       TUI_DATA_WIN->current_group = 0;
-      TUI_DATA_WIN->erase_data_content (NO_REGS_STRING);
+      TUI_DATA_WIN->erase_data_content (_("[ Register Values Unavailable ]"));
     }
 }
 
@@ -255,7 +253,7 @@ tui_show_register_group (tui_data_window *win_info,
     }
 }
 
-/* See tui-data.h.  */
+/* See tui-regs.h.  */
 
 void
 tui_data_window::display_registers_from (int start_element_no)
@@ -322,7 +320,7 @@ tui_data_window::display_registers_from (int start_element_no)
                  data_item_win->width = item_win_width;
                  data_item_win->origin.x = (item_win_width * j) + 1;
                  data_item_win->origin.y = cur_y;
-                 tui_make_window (data_item_win, DONT_BOX_WINDOW);
+                 tui_make_window (data_item_win);
                   scrollok (data_item_win->handle, FALSE);
                }
               touchwin (data_item_win->handle);
@@ -337,7 +335,7 @@ tui_data_window::display_registers_from (int start_element_no)
     }
 }
 
-/* See tui-data.h.  */
+/* See tui-regs.h.  */
 
 void
 tui_data_window::display_reg_element_at_line (int start_element_no,
@@ -366,12 +364,12 @@ tui_data_window::display_reg_element_at_line (int start_element_no,
     }
 }
 
-/* See tui-data.h.  */
+/* See tui-regs.h.  */
 
 int
 tui_data_window::display_registers_from_line (int line_no)
 {
-  tui_check_and_display_highlight_if_needed (this);
+  check_and_display_highlight_if_needed ();
   if (!regs_content.empty ())
     {
       int element_no;
@@ -403,6 +401,149 @@ tui_data_window::display_registers_from_line (int line_no)
 }
 
 
+/* Answer the index first element displayed.  If none are displayed,
+   then return (-1).  */
+int
+tui_data_window::first_data_item_displayed ()
+{
+  for (int i = 0; i < regs_content.size (); i++)
+    {
+      struct tui_gen_win_info *data_item_win;
+
+      data_item_win = regs_content[i].get ();
+      if (data_item_win->is_visible ())
+       return i;
+    }
+
+  return -1;
+}
+
+/* See tui-regs.h.  */
+
+void
+tui_data_window::delete_data_content_windows ()
+{
+  for (auto &&win : regs_content)
+    {
+      tui_delete_win (win->handle);
+      win->handle = NULL;
+    }
+}
+
+
+void
+tui_data_window::erase_data_content (const char *prompt)
+{
+  werase (handle);
+  check_and_display_highlight_if_needed ();
+  if (prompt != NULL)
+    {
+      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 (handle, (height / 2), x_pos, (char *) prompt);
+    }
+  wrefresh (handle);
+}
+
+/* See tui-regs.h.  */
+
+void
+tui_data_window::display_all_data ()
+{
+  if (regs_content.empty ())
+    erase_data_content (NO_DATA_STRING);
+  else
+    {
+      erase_data_content (NULL);
+      delete_data_content_windows ();
+      check_and_display_highlight_if_needed ();
+      display_registers_from (0);
+    }
+}
+
+
+/* Function to redisplay the contents of the data window.  */
+void
+tui_data_window::refresh_all ()
+{
+  erase_data_content (NULL);
+  if (!regs_content.empty ())
+    {
+      int first_element = first_data_item_displayed ();
+
+      if (first_element >= 0)  /* Re-use existing windows.  */
+       {
+         int first_line = (-1);
+
+         if (first_element < regs_content.size ())
+           first_line = line_from_reg_element_no (first_element);
+
+         if (first_line >= 0)
+           {
+             erase_data_content (NULL);
+             display_registers_from_line (first_line);
+           }
+       }
+    }
+}
+
+
+/* Scroll the data window vertically forward or backward.  */
+void
+tui_data_window::do_scroll_vertical (int num_to_scroll)
+{
+  int first_element_no;
+  int first_line = (-1);
+
+  first_element_no = first_data_item_displayed ();
+  if (first_element_no < regs_content.size ())
+    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.  */
+    }
+
+  if (first_line >= 0)
+    {
+      first_line += num_to_scroll;
+      erase_data_content (NULL);
+      delete_data_content_windows ();
+      display_registers_from_line (first_line);
+    }
+}
+
+/* See tui-regs.h.  */
+
+void
+tui_data_window::rerender ()
+{
+  /* Delete all data item windows.  */
+  for (auto &&win : regs_content)
+    {
+      tui_delete_win (win->handle);
+      win->handle = NULL;
+    }
+  display_all_data ();
+}
+
+/* See tui-regs.h.  */
+
+void
+tui_data_window::refresh_window ()
+{
+  tui_gen_win_info::refresh_window ();
+  for (auto &&win : regs_content)
+    {
+      if (win != NULL)
+       win->refresh_window ();
+    }
+}
+
 /* This function check all displayed registers for changes in values,
    given a particular frame.  If the values have changed, they are
    updated with the new value and highlighted.  */
@@ -410,7 +551,7 @@ void
 tui_check_register_values (struct frame_info *frame)
 {
   if (TUI_DATA_WIN != NULL
-      && TUI_DATA_WIN->is_visible)
+      && TUI_DATA_WIN->is_visible ())
     {
       if (TUI_DATA_WIN->regs_content.empty ()
          && TUI_DATA_WIN->display_regs)
@@ -525,12 +666,10 @@ tui_reg_command (const char *args, int from_tty)
       /* Make sure the register window is visible.  If not, select an
         appropriate layout.  We need to do this before trying to run the
         'next' or 'prev' commands.  */
-      if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible)
+      if (TUI_DATA_WIN == NULL || !TUI_DATA_WIN->is_visible ())
        tui_reg_layout ();
 
-      struct reggroup *current_group = NULL;
-      if (TUI_DATA_WIN != NULL)
-       current_group = TUI_DATA_WIN->current_group;
+      struct reggroup *current_group = TUI_DATA_WIN->current_group;
       if (strncmp (args, "next", len) == 0)
        match = tui_reg_next (current_group, gdbarch);
       else if (strncmp (args, "prev", len) == 0)
@@ -600,23 +739,6 @@ tui_reggroup_completer (struct cmd_list_element *ignore,
     }
 }
 
-void
-_initialize_tui_regs (void)
-{
-  struct cmd_list_element **tuicmd, *cmd;
-
-  tuicmd = tui_get_cmd_list ();
-
-  cmd = add_cmd ("reg", class_tui, tui_reg_command, _("\
-TUI command to control the register window."), tuicmd);
-  set_cmd_completer (cmd, tui_reggroup_completer);
-}
-
-
-/*****************************************
-** STATIC LOCAL FUNCTIONS                 **
-******************************************/
-
 /* Get the register from the frame and return a printable
    representation of it.  */
 
@@ -666,3 +788,15 @@ tui_get_register (struct frame_info *frame,
       xfree (prev_content);
     }
 }
+
+void
+_initialize_tui_regs (void)
+{
+  struct cmd_list_element **tuicmd, *cmd;
+
+  tuicmd = tui_get_cmd_list ();
+
+  cmd = add_cmd ("reg", class_tui, tui_reg_command, _("\
+TUI command to control the register window."), tuicmd);
+  set_cmd_completer (cmd, tui_reggroup_completer);
+}
This page took 0.026931 seconds and 4 git commands to generate.