]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/tui: change some macros to functions
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 31 May 2024 02:54:05 +0000 (22:54 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Sat, 8 Jun 2024 02:52:54 +0000 (22:52 -0400)
Change the `TUI_*` macros to access known windows to functions.  Define
them in their respective files, because trying to define them in
tui-data.h would end up causing include cycles.

This makes static analysis (detection of unused include files in this
case) more accurate, and I think in general we should avoid hiding
code behind macros if not necessary.

Change-Id: I1e38cee843984c48ab34030b19dac0d726f851af
Approved-By: Tom Tromey <tom@tromey.com>
17 files changed:
gdb/tui/tui-command.c
gdb/tui/tui-command.h
gdb/tui/tui-data.h
gdb/tui/tui-disasm.c
gdb/tui/tui-disasm.h
gdb/tui/tui-hooks.c
gdb/tui/tui-io.c
gdb/tui/tui-layout.c
gdb/tui/tui-layout.h
gdb/tui/tui-regs.c
gdb/tui/tui-regs.h
gdb/tui/tui-source.h
gdb/tui/tui-status.c
gdb/tui/tui-status.h
gdb/tui/tui-win.c
gdb/tui/tui-winsource.c
gdb/tui/tui.c

index b0ae8f39e0eb238d44e33045e28936a3072d9e36..d36c1372fb88a48fd8c131c8fee8ea52baa2f5a1 100644 (file)
@@ -61,7 +61,7 @@ tui_cmd_window::resize (int height_, int width_, int origin_x, int origin_y)
 void
 tui_refresh_cmd_win (void)
 {
-  WINDOW *w = TUI_CMD_WIN->handle.get ();
+  WINDOW *w = tui_cmd_win ()->handle.get ();
 
   tui_wrefresh (w);
 }
index 2dc579bce30c96f1756f39d4e04edb69fe747b25..90b8de7535b5ec9b2f09936ceb201ac723e6a21f 100644 (file)
@@ -55,6 +55,14 @@ struct tui_cmd_window
   int start_line = 0;
 };
 
+/* Return the instance of the command windows.  */
+
+inline tui_cmd_window *
+tui_cmd_win ()
+{
+  return dynamic_cast<tui_cmd_window *> (tui_win_list[CMD_WIN]);
+}
+
 /* Refresh the command window.  */
 extern void tui_refresh_cmd_win (void);
 
index 4b75e72653b41e922afa82f69bb6e65dc68299b5..04cce0244318be38af6c0253e8ca2298cdd6d16e 100644 (file)
@@ -290,17 +290,6 @@ struct tui_always_visible_window : public virtual tui_win_info
 /* Global Data.  */
 extern struct tui_win_info *tui_win_list[MAX_MAJOR_WINDOWS];
 
-#define TUI_SRC_WIN \
-  (gdb::checked_static_cast<tui_source_window *> (tui_win_list[SRC_WIN]))
-#define TUI_DISASM_WIN \
-  (gdb::checked_static_cast<tui_disasm_window *> (tui_win_list[DISASSEM_WIN]))
-#define TUI_DATA_WIN \
-  (gdb::checked_static_cast<tui_data_window *> (tui_win_list[DATA_WIN]))
-#define TUI_CMD_WIN \
-  (dynamic_cast<tui_cmd_window *> (tui_win_list[CMD_WIN]))
-#define TUI_STATUS_WIN \
-  (dynamic_cast<tui_status_window *> (tui_win_list[STATUS_WIN]))
-
 /* All the windows that are currently instantiated, in layout
    order.  */
 extern std::vector<tui_win_info *> tui_windows;
index 07ca37603b8ccc0df6851068951037ca7dbd6311..24a5044ed3799ed7033e679f6ed8c336e6b9ff47 100644 (file)
@@ -433,12 +433,12 @@ tui_get_low_disassembly_address (struct gdbarch *gdbarch,
 
   /* Determine where to start the disassembly so that the pc is about
      in the middle of the viewport.  */
-  if (TUI_DISASM_WIN != NULL)
-    pos = TUI_DISASM_WIN->height;
-  else if (TUI_CMD_WIN == NULL)
+  if (tui_disasm_win () != nullptr)
+    pos = tui_disasm_win ()->height;
+  else if (tui_cmd_win () == nullptr)
     pos = tui_term_height () / 2 - 2;
   else
-    pos = tui_term_height () - TUI_CMD_WIN->height - 2;
+    pos = tui_term_height () - tui_cmd_win ()->height - 2;
   pos = (pos - 2) / 2;
 
   pc = tui_find_disassembly_address (gdbarch, pc, -pos);
index 0aef091069b726df0398f6bae447341548dcd4ac..4a7735450ce46349588edab5b9cd2c252bf7cbc1 100644 (file)
@@ -64,6 +64,15 @@ private:
   bool addr_is_displayed (CORE_ADDR addr) const;
 };
 
+/* Return the instance of the disassembly windows.  */
+
+inline tui_disasm_window *
+tui_disasm_win ()
+{
+  return gdb::checked_static_cast<tui_disasm_window *>
+    (tui_win_list[DISASSEM_WIN]);
+}
+
 extern void tui_get_begin_asm_address (struct gdbarch **, CORE_ADDR *);
 
 #endif /* TUI_TUI_DISASM_H */
index 70874e5460a3c6473946212e2f456960fb133d4c..9dcf789ccae9cb55e04dc5f6ee45cbf62dc9e62b 100644 (file)
@@ -71,7 +71,7 @@ tui_register_changed (const frame_info_ptr &frame, int regno)
      up in the other.  So we always use the selected frame here, and ignore
      FRAME.  */
   fi = get_selected_frame (NULL);
-  TUI_DATA_WIN->check_register_values (fi);
+  tui_data_win ()->check_register_values (fi);
 }
 
 /* Breakpoint creation hook.
@@ -132,7 +132,7 @@ tui_refresh_frame_and_register_information ()
 
       /* Refresh the register window if it's visible.  */
       if (tui_is_window_visible (DATA_WIN))
-       TUI_DATA_WIN->check_register_values (fi);
+       tui_data_win ()->check_register_values (fi);
     }
   else
     {
index 09fba029496659da501b6945d0d35f33005f710c..299a809a939fd8fafe323af163c57f73bc865c8d 100644 (file)
@@ -165,7 +165,7 @@ do_tui_putc (WINDOW *w, char c)
 static void
 update_cmdwin_start_line ()
 {
-  TUI_CMD_WIN->start_line = getcury (TUI_CMD_WIN->handle.get ());
+  tui_cmd_win ()->start_line = getcury (tui_cmd_win ()->handle.get ());
 }
 
 /* Print a character in the curses command window.  The output is
@@ -175,7 +175,7 @@ update_cmdwin_start_line ()
 static void
 tui_putc (char c)
 {
-  do_tui_putc (TUI_CMD_WIN->handle.get (), c);
+  do_tui_putc (tui_cmd_win ()->handle.get (), c);
   update_cmdwin_start_line ();
 }
 
@@ -458,7 +458,7 @@ void
 tui_puts (const char *string, WINDOW *w)
 {
   if (w == nullptr)
-    w = TUI_CMD_WIN->handle.get ();
+    w = tui_cmd_win ()->handle.get ();
 
   while (true)
     {
@@ -509,7 +509,7 @@ tui_puts (const char *string, WINDOW *w)
       string = next;
     }
 
-  if (TUI_CMD_WIN != nullptr && w == TUI_CMD_WIN->handle.get ())
+  if (tui_cmd_win () != nullptr && w == tui_cmd_win ()->handle.get ())
     update_cmdwin_start_line ();
 }
 
@@ -553,7 +553,7 @@ tui_puts_internal (WINDOW *w, const char *string, int *height)
        }
     }
 
-  if (TUI_CMD_WIN != nullptr && w == TUI_CMD_WIN->handle.get ())
+  if (tui_cmd_win () != nullptr && w == tui_cmd_win ()->handle.get ())
     update_cmdwin_start_line ();
   if (saw_nl)
     wrefresh (w);
@@ -583,8 +583,8 @@ tui_redisplay_readline (void)
   
   int c_pos = -1;
   int c_line = -1;
-  WINDOW *w = TUI_CMD_WIN->handle.get ();
-  int start_line = TUI_CMD_WIN->start_line;
+  WINDOW *w = tui_cmd_win ()->handle.get ();
+  int start_line = tui_cmd_win ()->start_line;
   wmove (w, start_line, 0);
   int height = 1;
   if (prompt != nullptr)
@@ -624,17 +624,17 @@ tui_redisplay_readline (void)
          waddch (w, c);
        }
       if (c == '\n')
-       TUI_CMD_WIN->start_line = getcury (w);
+       tui_cmd_win ()->start_line = getcury (w);
       int col = getcurx (w);
       if (col < prev_col)
        height++;
       prev_col = col;
     }
   wclrtobot (w);
-  TUI_CMD_WIN->start_line = getcury (w);
+  tui_cmd_win ()->start_line = getcury (w);
   if (c_line >= 0)
     wmove (w, c_line, c_pos);
-  TUI_CMD_WIN->start_line -= height - 1;
+  tui_cmd_win ()->start_line -= height - 1;
 
   wrefresh (w);
   fflush(stdout);
@@ -709,7 +709,7 @@ tui_mld_puts (const struct match_list_displayer *displayer, const char *s)
 static void
 tui_mld_flush (const struct match_list_displayer *displayer)
 {
-  wrefresh (TUI_CMD_WIN->handle.get ());
+  wrefresh (tui_cmd_win ()->handle.get ());
 }
 
 /* TUI version of displayer.erase_entire_line.  */
@@ -717,7 +717,7 @@ tui_mld_flush (const struct match_list_displayer *displayer)
 static void
 tui_mld_erase_entire_line (const struct match_list_displayer *displayer)
 {
-  WINDOW *w = TUI_CMD_WIN->handle.get ();
+  WINDOW *w = tui_cmd_win ()->handle.get ();
   int cur_y = getcury (w);
 
   wmove (w, cur_y, 0);
@@ -755,7 +755,7 @@ gdb_wgetch (WINDOW *win)
 static int
 tui_mld_getc (FILE *fp)
 {
-  WINDOW *w = TUI_CMD_WIN->handle.get ();
+  WINDOW *w = tui_cmd_win ()->handle.get ();
   int c = gdb_wgetch (w);
 
   return c;
@@ -1037,7 +1037,7 @@ tui_inject_newline_into_command_window ()
 {
   gdb_assert (tui_active);
 
-  WINDOW *w = TUI_CMD_WIN->handle.get ();
+  WINDOW *w = tui_cmd_win ()->handle.get ();
 
   /* When hitting return with an empty input, gdb executes the last
      command.  If we emit a newline, this fills up the command window
@@ -1062,8 +1062,8 @@ tui_inject_newline_into_command_window ()
       int px, py;
       getyx (w, py, px);
       px += rl_end - rl_point;
-      py += px / TUI_CMD_WIN->width;
-      px %= TUI_CMD_WIN->width;
+      py += px / tui_cmd_win ()->width;
+      px %= tui_cmd_win ()->width;
       wmove (w, py, px);
       tui_putc ('\n');
     }
@@ -1097,7 +1097,7 @@ tui_getc_1 (FILE *fp)
   int ch;
   WINDOW *w;
 
-  w = TUI_CMD_WIN->handle.get ();
+  w = tui_cmd_win ()->handle.get ();
 
 #ifdef TUI_USE_PIPE_FOR_READLINE
   /* Flush readline output.  */
index 143254bcf9904670863e3fe02f335d5d77ca55c7..3cb5a05b626a82b808010308aac2529ca7e8caa8 100644 (file)
@@ -79,8 +79,8 @@ tui_apply_current_layout (bool preserve_cmd_win_size_p)
       tui_win_list[win_type] = nullptr;
 
   /* This should always be made visible by a layout.  */
-  gdb_assert (TUI_CMD_WIN != nullptr);
-  gdb_assert (TUI_CMD_WIN->is_visible ());
+  gdb_assert (tui_cmd_win () != nullptr);
+  gdb_assert (tui_cmd_win ()->is_visible ());
 
   /* Get the new list of currently visible windows.  */
   std::vector<tui_win_info *> new_tui_windows;
@@ -132,7 +132,7 @@ tui_set_layout (tui_layout_split *layout)
 
   std::string new_fingerprint = applied_layout->layout_fingerprint ();
   bool preserve_command_window_size
-    = (TUI_CMD_WIN != nullptr && old_fingerprint == new_fingerprint);
+    = (tui_cmd_win () != nullptr && old_fingerprint == new_fingerprint);
 
   tui_apply_current_layout (preserve_command_window_size);
 }
@@ -233,10 +233,10 @@ void
 tui_regs_layout ()
 {
   /* If there's already a register window, we're done.  */
-  if (TUI_DATA_WIN != nullptr)
+  if (tui_data_win () != nullptr)
     return;
 
-  tui_set_layout (TUI_DISASM_WIN != nullptr
+  tui_set_layout (tui_disasm_win () != nullptr
                  ? asm_regs_layout
                  : src_regs_layout);
 }
@@ -261,9 +261,9 @@ tui_remove_some_windows ()
     {
       /* Try leaving the source or disassembly window.  If neither
         exists, just do nothing.  */
-      focus = TUI_SRC_WIN;
+      focus = tui_src_win ();
       if (focus == nullptr)
-       focus = TUI_DISASM_WIN;
+       focus = tui_disasm_win ();
       if (focus == nullptr)
        return;
     }
@@ -817,7 +817,7 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_,
   int prev = -1;
   for (int i = 0; i < m_splits.size (); ++i)
     {
-      bool cmd_win_already_exists = TUI_CMD_WIN != nullptr;
+      bool cmd_win_already_exists = tui_cmd_win () != nullptr;
 
       /* Always call get_sizes, to ensure that the window is
         instantiated.  This is a bit gross but less gross than adding
@@ -841,8 +841,8 @@ tui_layout_split::apply (int x_, int y_, int width_, int height_,
             that the resizing step, below, does the right thing with
             this window.  */
          info[i].min_size = (m_vertical
-                             ? TUI_CMD_WIN->height
-                             : TUI_CMD_WIN->width);
+                             ? tui_cmd_win ()->height
+                             : tui_cmd_win ()->width);
          info[i].max_size = info[i].min_size;
        }
 
index f621f9cea55dda221a113ba2d6999685022309b4..a401efcb8538f30de619bd6f2464cb40ebbd6371 100644 (file)
@@ -59,8 +59,8 @@ public:
   virtual std::unique_ptr<tui_layout_base> clone () const = 0;
 
   /* Change the size and location of this layout.  When
-     PRESERVE_CMD_WIN_SIZE_P is true the current size of the TUI_CMD_WIN
-     is preserved, otherwise, the TUI_CMD_WIN will resize just like any
+     PRESERVE_CMD_WIN_SIZE_P is true the current size of the command window
+     is preserved, otherwise, the command window will resize just like any
      other window.  */
   virtual void apply (int x, int y, int width, int height,
                      bool preserve_cmd_win_size_p) = 0;
@@ -350,8 +350,8 @@ extern void tui_regs_layout ();
 extern void tui_remove_some_windows ();
 
 /* Apply the current layout.  When PRESERVE_CMD_WIN_SIZE_P is true the
-   current size of the TUI_CMD_WIN is preserved, otherwise, the TUI_CMD_WIN
-   will resize just like any other window.  */
+   current size of the command window is preserved, otherwise, the command
+   window will resize just like any other window.  */
 extern void tui_apply_current_layout (bool);
 
 /* Adjust the window height of WIN to NEW_HEIGHT.  */
index 8db269181237695ab221362e4ccab71cacf10095..50708fd383fcafa09351a9945aa6075e11b06a8d 100644 (file)
@@ -515,11 +515,11 @@ 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 () == nullptr || !tui_data_win ()->is_visible ())
        tui_regs_layout ();
 
       const reggroup *match = nullptr;
-      const reggroup *current_group = TUI_DATA_WIN->get_current_group ();
+      const reggroup *current_group = tui_data_win ()->get_current_group ();
       if (strncmp (args, "next", len) == 0)
        match = tui_reg_next (current_group, gdbarch);
       else if (strncmp (args, "prev", len) == 0)
@@ -543,7 +543,7 @@ tui_reg_command (const char *args, int from_tty)
       if (match == NULL)
        error (_("unknown register group '%s'"), args);
 
-      TUI_DATA_WIN->set_register_group (match);
+      tui_data_win ()->set_register_group (match);
     }
   else
     {
index 07b951316b6b3ee43a90a04f9f9bd9f8dd23fec9..4a799e6b2f682a20eb8361df00cf5347df5cf27a 100644 (file)
@@ -145,4 +145,12 @@ private:
   gdbarch *m_gdbarch = nullptr;
 };
 
+/* Return the instance of the registers window.  */
+
+inline tui_data_window *
+tui_data_win ()
+{
+  return gdb::checked_static_cast<tui_data_window *> (tui_win_list[DATA_WIN]);
+}
+
 #endif /* TUI_TUI_REGS_H */
index 103b11e7273765a24c24a4372aa4140a47df25a9..9a72ed90b476b8c96e5370ed27a5a0f5bc8df7a0 100644 (file)
@@ -82,4 +82,12 @@ private:
   gdb::unique_xmalloc_ptr<char> m_fullname;
 };
 
+/* Return the instance of the source window.  */
+
+inline tui_source_window *
+tui_src_win ()
+{
+  return gdb::checked_static_cast<tui_source_window *> (tui_win_list[SRC_WIN]);
+}
+
 #endif /* TUI_TUI_SOURCE_H */
index c7750af6ea0bb419ed4540ca2dabbce6c47c6369..de754cbe6a6c35583f10d03219b4c3d9bff6d88b 100644 (file)
@@ -315,7 +315,7 @@ void
 tui_show_status_content ()
 {
   if (tui_is_window_visible (STATUS_WIN))
-    TUI_STATUS_WIN->rerender ();
+    tui_status_win ()->rerender ();
 }
 
 /* Command to update the display with the current execution point.  */
index 0af44664104290b23b23075131198795ae27f6f8..f7cd2d4191c2c2fefa7d450b2fee0fd391671304 100644 (file)
@@ -50,6 +50,14 @@ private:
   std::string make_status_line () const;
 };
 
+/* Return the instance of the status window.  */
+
+inline tui_status_window *
+tui_status_win ()
+{
+  return dynamic_cast<tui_status_window *> (tui_win_list[STATUS_WIN]);
+}
+
 extern void tui_show_status_content (void);
 extern void tui_show_frame_info (const frame_info_ptr &);
 
index 45cc22a647480254cc83411eb5650a955b5e0bf6..f43ead8e7dd159108f498561fbad24ee68ce8b67 100644 (file)
@@ -203,10 +203,10 @@ static void
 set_style_tui_current_position (const char *ignore, int from_tty,
                                cmd_list_element *c)
 {
-  if (TUI_SRC_WIN != nullptr)
-    TUI_SRC_WIN->refill ();
-  if (TUI_DISASM_WIN != nullptr)
-    TUI_DISASM_WIN->refill ();
+  if (tui_src_win () != nullptr)
+    tui_src_win ()->refill ();
+  if (tui_disasm_win () != nullptr)
+    tui_disasm_win ()->refill ();
 }
 
 /* Tui internal configuration variables.  These variables are updated
@@ -424,8 +424,8 @@ tui_update_gdb_sizes (void)
 
   if (tui_active)
     {
-      width = TUI_CMD_WIN->width;
-      height = TUI_CMD_WIN->height;
+      width = tui_cmd_win ()->width;
+      height = tui_cmd_win ()->height;
     }
   else
     {
@@ -513,7 +513,7 @@ tui_resize_all (void)
       resize_term (screenheight, screenwidth);
 #endif      
       /* Turn keypad off while we resize.  */
-      keypad (TUI_CMD_WIN->handle.get (), FALSE);
+      keypad (tui_cmd_win ()->handle.get (), FALSE);
       tui_update_gdb_sizes ();
       tui_set_term_height_to (screenheight);
       tui_set_term_width_to (screenwidth);
@@ -526,7 +526,7 @@ tui_resize_all (void)
         window to resize proportionately with containing terminal, rather
         than maintaining a fixed size.  */
       tui_apply_current_layout (false); /* Turn keypad back on.  */
-      keypad (TUI_CMD_WIN->handle.get (), TRUE);
+      keypad (tui_cmd_win ()->handle.get (), TRUE);
     }
 }
 
@@ -862,8 +862,8 @@ static void
 tui_set_compact_source (const char *ignore, int from_tty,
                        struct cmd_list_element *c)
 {
-  if (TUI_SRC_WIN != nullptr)
-    TUI_SRC_WIN->refill ();
+  if (tui_src_win () != nullptr)
+    tui_src_win ()->refill ();
 }
 
 /* Callback for "show tui compact-source".  */
@@ -1081,7 +1081,7 @@ parse_scrolling_args (const char *arg,
                error (_("Unrecognized window `%s'"), wname);
              if (!(*win_to_scroll)->is_visible ())
                error (_("Window is not visible"));
-             else if (*win_to_scroll == TUI_CMD_WIN)
+             else if (*win_to_scroll == tui_cmd_win ())
                *win_to_scroll = *(tui_source_windows ().begin ());
            }
        }
index e68efadcf1858498e3637f9e6f495cb8702ae302..a05f6480d800b7fcaaaf57d8dd300130bad4a108 100644 (file)
@@ -459,7 +459,7 @@ tui_source_window_base::rerender ()
       struct gdbarch *gdbarch = get_frame_arch (frame);
 
       struct symtab *s = find_pc_line_symtab (get_frame_pc (frame));
-      if (this != TUI_SRC_WIN)
+      if (this != tui_src_win ())
        find_line_pc (s, cursal.line, &cursal.pc);
 
       /* This centering code is copied from tui_source_window::maybe_update.
@@ -492,7 +492,7 @@ tui_source_window_base::refill ()
 {
   symtab_and_line sal {};
 
-  if (this == TUI_SRC_WIN)
+  if (this == tui_src_win ())
     {
       sal = get_current_source_symtab_and_line ();
       if (sal.symtab == NULL)
index 63b01ba55c849ccc49800c05c8366fa67e6b5882..1318caed2059cead5585f065b3c46b77c84b9c7c 100644 (file)
@@ -470,9 +470,9 @@ tui_enable (void)
 
       tui_show_frame_info (deprecated_safe_get_selected_frame ());
       tui_set_initial_layout ();
-      tui_set_win_focus_to (TUI_SRC_WIN);
-      keypad (TUI_CMD_WIN->handle.get (), TRUE);
-      wrefresh (TUI_CMD_WIN->handle.get ());
+      tui_set_win_focus_to (tui_src_win ());
+      keypad (tui_cmd_win ()->handle.get (), TRUE);
+      wrefresh (tui_cmd_win ()->handle.get ());
       tui_finish_init = false;
     }
   else
@@ -595,11 +595,11 @@ bool
 tui_get_command_dimension (unsigned int *width, 
                           unsigned int *height)
 {
-  if (!tui_active || (TUI_CMD_WIN == NULL))
+  if (!tui_active || (tui_cmd_win () == NULL))
     return false;
   
-  *width = TUI_CMD_WIN->width;
-  *height = TUI_CMD_WIN->height;
+  *width = tui_cmd_win ()->width;
+  *height = tui_cmd_win ()->height;
   return true;
 }