aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2024-05-30 22:54:05 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2024-06-07 22:52:54 -0400
commit8a39a981bd8d576de0d343b8c2eee47655d8c720 (patch)
treed0d36339b4cdf19b9a2a05ba9aa6fd862fa5a2d1 /gdb
parentb56d975cc8083e49c35be3a35faf1744da54fabc (diff)
downloadgdb-8a39a981bd8d576de0d343b8c2eee47655d8c720.zip
gdb-8a39a981bd8d576de0d343b8c2eee47655d8c720.tar.gz
gdb-8a39a981bd8d576de0d343b8c2eee47655d8c720.tar.bz2
gdb/tui: change some macros to functions
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>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/tui/tui-command.c2
-rw-r--r--gdb/tui/tui-command.h8
-rw-r--r--gdb/tui/tui-data.h11
-rw-r--r--gdb/tui/tui-disasm.c8
-rw-r--r--gdb/tui/tui-disasm.h9
-rw-r--r--gdb/tui/tui-hooks.c4
-rw-r--r--gdb/tui/tui-io.c34
-rw-r--r--gdb/tui/tui-layout.c20
-rw-r--r--gdb/tui/tui-layout.h8
-rw-r--r--gdb/tui/tui-regs.c6
-rw-r--r--gdb/tui/tui-regs.h8
-rw-r--r--gdb/tui/tui-source.h8
-rw-r--r--gdb/tui/tui-status.c2
-rw-r--r--gdb/tui/tui-status.h8
-rw-r--r--gdb/tui/tui-win.c22
-rw-r--r--gdb/tui/tui-winsource.c4
-rw-r--r--gdb/tui/tui.c12
17 files changed, 102 insertions, 72 deletions
diff --git a/gdb/tui/tui-command.c b/gdb/tui/tui-command.c
index b0ae8f3..d36c137 100644
--- a/gdb/tui/tui-command.c
+++ b/gdb/tui/tui-command.c
@@ -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);
}
diff --git a/gdb/tui/tui-command.h b/gdb/tui/tui-command.h
index 2dc579b..90b8de7 100644
--- a/gdb/tui/tui-command.h
+++ b/gdb/tui/tui-command.h
@@ -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);
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index 4b75e72..04cce02 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -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;
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index 07ca376..24a5044 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -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);
diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h
index 0aef091..4a77354 100644
--- a/gdb/tui/tui-disasm.h
+++ b/gdb/tui/tui-disasm.h
@@ -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 */
diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 70874e5..9dcf789 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -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
{
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 09fba02..299a809 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -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. */
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index 143254b..3cb5a05 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -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;
}
diff --git a/gdb/tui/tui-layout.h b/gdb/tui/tui-layout.h
index f621f9c..a401efc 100644
--- a/gdb/tui/tui-layout.h
+++ b/gdb/tui/tui-layout.h
@@ -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. */
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 8db2691..50708fd 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -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
{
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index 07b9513..4a799e6 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -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 */
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 103b11e..9a72ed9 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -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 */
diff --git a/gdb/tui/tui-status.c b/gdb/tui/tui-status.c
index c7750af..de754cb 100644
--- a/gdb/tui/tui-status.c
+++ b/gdb/tui/tui-status.c
@@ -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. */
diff --git a/gdb/tui/tui-status.h b/gdb/tui/tui-status.h
index 0af4466..f7cd2d4 100644
--- a/gdb/tui/tui-status.h
+++ b/gdb/tui/tui-status.h
@@ -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 &);
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 45cc22a..f43ead8 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -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 ());
}
}
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index e68efad..a05f648 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -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)
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 63b01ba..1318cae 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -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;
}