aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2023-11-13 21:22:50 +0100
committerTom de Vries <tdevries@suse.de>2023-11-13 21:22:50 +0100
commitff3c86a844225a0f8848b2aee0b1628114c01377 (patch)
treee5acefcea5741da303caba64eb4dbd309ba11d15 /gdb/tui
parent70911fd87f261d3726fea4699a4ffdd5623482b7 (diff)
downloadbinutils-ff3c86a844225a0f8848b2aee0b1628114c01377.zip
binutils-ff3c86a844225a0f8848b2aee0b1628114c01377.tar.gz
binutils-ff3c86a844225a0f8848b2aee0b1628114c01377.tar.bz2
[gdb/tui] Add tui_win_info::{box_width,box_size}
In tui_source_window::set_contents we have: ... /* Take hilite (window border) into account, when calculating the number of lines. */ int nlines = height - 2; ... The '2' represents the total size of the window border (or box, in can_box terms), in this case one line at the top and one line at the bottom. Likewise, '1' is used to represent the width of the window border. Introduce new functions: - tui_win_info::box_width () and - tui_win_info::box_size () that can be used instead instead of these hardcoded constants. Implement these such that they return 0 when can_box () == false. Tested patch completeness by making all windows unboxed: ... @@ -85,7 +85,7 @@ struct tui_win_info /* Return true if this window can be boxed. */ virtual bool can_box () const { - return true; + return false; } int box_width () const ... and test-driving TUI. This required eliminating an assert in tui_source_window_base::show_source_content, I've included that part as well. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-data.h12
-rw-r--r--gdb/tui/tui-disasm.c2
-rw-r--r--gdb/tui/tui-regs.c10
-rw-r--r--gdb/tui/tui-source.c4
-rw-r--r--gdb/tui/tui-wingeneral.c2
-rw-r--r--gdb/tui/tui-winsource.c20
-rw-r--r--gdb/tui/tui-winsource.h4
7 files changed, 35 insertions, 19 deletions
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index a1e44f7..5bb5ef9 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -88,6 +88,18 @@ public:
return true;
}
+ /* Return the width of the box. */
+ int box_width () const
+ {
+ return can_box () ? 1 : 0;
+ }
+
+ /* Return the size of the box. */
+ int box_size () const
+ {
+ return 2 * box_width ();
+ }
+
/* Resize this window. The parameters are used to set the window's
size and position. */
virtual void resize (int height, int width,
diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index dcafbfb..ffcb95b 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -341,7 +341,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
cur_pc = tui_location.addr ();
/* Window size, excluding highlight box. */
- max_lines = height - 2;
+ max_lines = height - box_size ();
/* Get temporary table that will hold all strings (addr & insn). */
std::vector<tui_asm_line> asm_lines;
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index 1a351e6..01538d4 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -281,15 +281,15 @@ tui_data_window::display_registers_from (int start_element_no)
for (i = 0; i < start_element_no; i++)
m_regs_content[i].y = 0;
- m_regs_column_count = (width - 2) / m_item_width;
+ m_regs_column_count = (width - box_size ()) / m_item_width;
if (m_regs_column_count == 0)
m_regs_column_count = 1;
- m_item_width = (width - 2) / m_regs_column_count;
+ m_item_width = (width - box_size ()) / m_regs_column_count;
/* Now create each data "sub" window, and write the display into
it. */
int cur_y = 1;
- while (i < m_regs_content.size () && cur_y <= height - 2)
+ while (i < m_regs_content.size () && cur_y <= height - box_size ())
{
for (int j = 0;
j < m_regs_column_count && i < m_regs_content.size ();
@@ -325,7 +325,7 @@ tui_data_window::display_reg_element_at_line (int start_element_no,
int last_line_no, first_line_on_last_page;
last_line_no = last_regs_line_no ();
- first_line_on_last_page = last_line_no - (height - 2);
+ first_line_on_last_page = last_line_no - (height - box_size ());
if (first_line_on_last_page < 0)
first_line_on_last_page = 0;
@@ -400,7 +400,7 @@ tui_data_window::erase_data_content (const char *prompt)
check_and_display_highlight_if_needed ();
if (prompt != NULL)
{
- int half_width = (width - 2) / 2;
+ int half_width = (width - box_size ()) / 2;
int x_pos;
if (strlen (prompt) >= half_width)
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 6625f0c..5e9a954 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -53,7 +53,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
/* Take hilite (window border) into account, when
calculating the number of lines. */
- int nlines = height - 2;
+ int nlines = height - box_size ();
std::string srclines;
const std::vector<off_t> *offsets;
@@ -201,7 +201,7 @@ tui_source_window::line_is_displayed (int line) const
void
tui_source_window::maybe_update (frame_info_ptr fi, symtab_and_line sal)
{
- int start_line = (sal.line - ((height - 2) / 2)) + 1;
+ int start_line = (sal.line - ((height - box_size ()) / 2)) + 1;
if (start_line <= 0)
start_line = 1;
diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 5e1b3d2..af4fc74 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -106,7 +106,7 @@ box_win (struct tui_win_info *win_info,
{
/* Emit "+-TITLE-+" -- so 2 characters on the right and 2 on
the left. */
- int max_len = win_info->width - 2 - 2;
+ int max_len = win_info->width - win_info->box_size () - 2;
if (win_info->title ().size () <= max_len)
mvwaddstr (win, 0, 2, win_info->title ().c_str ());
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 7eabc52..83ce480 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -211,7 +211,7 @@ void
tui_source_window_base::do_erase_source_content (const char *str)
{
int x_pos;
- int half_width = (width - 2) / 2;
+ int half_width = (width - box_size ()) / 2;
m_content.clear ();
if (handle != NULL)
@@ -347,7 +347,7 @@ tui_source_window_base::refresh_window ()
gdb_assert (pad_width > 0 || m_pad.get () == nullptr);
gdb_assert (pad_x + view_width <= pad_width || m_pad.get () == nullptr);
- int sminrow = y + 1;
+ int sminrow = y + box_width ();
int smincol = x + left_margin;
int smaxrow = sminrow + m_content.size () - 1;
int smaxcol = smincol + view_width - 1;
@@ -412,11 +412,15 @@ tui_source_window_base::show_source_content ()
for (int lineno = 0; lineno < m_content.size (); lineno++)
show_source_line (lineno);
- /* Calling check_and_display_highlight_if_needed will call refresh_window
- (so long as the current window can be boxed), which will ensure that
- the newly loaded window content is copied to the screen. */
- gdb_assert (can_box ());
- check_and_display_highlight_if_needed ();
+ if (can_box ())
+ {
+ /* Calling check_and_display_highlight_if_needed will call refresh_window
+ (so long as the current window can be boxed), which will ensure that
+ the newly loaded window content is copied to the screen. */
+ check_and_display_highlight_if_needed ();
+ }
+ else
+ refresh_window ();
}
tui_source_window_base::tui_source_window_base ()
@@ -693,7 +697,7 @@ tui_source_window_base::update_exec_info (bool refresh_p)
if (src_element->is_exec_point)
element[TUI_EXEC_POS] = '>';
- mvwaddstr (handle.get (), i + 1, 1, element);
+ mvwaddstr (handle.get (), i + box_width (), box_width (), element);
show_line_number (i);
}
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 4a35512..dccce0e 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -206,13 +206,13 @@ private:
/* Return the size of the left margin space, this is the space used to
display things like breakpoint markers. */
int left_margin () const
- { return 1 + TUI_EXECINFO_SIZE + extra_margin (); }
+ { return box_width () + TUI_EXECINFO_SIZE + extra_margin (); }
/* Return the width of the area that is available for window content.
This is the window width minus the borders and the left margin, which
is used for displaying things like breakpoint markers. */
int view_width () const
- { return width - left_margin () - 1; }
+ { return width - left_margin () - box_width (); }
void show_source_content ();