* [PATCH 2/3] [gdb/tui] Add tui_win_info::{box_width,box_size}
2023-11-10 13:00 [PATCH 1/3] [gdb/tui] Refactor prefresh call in tui_source_window_base::refresh_window Tom de Vries
@ 2023-11-10 13:00 ` Tom de Vries
2023-11-13 17:42 ` Tom Tromey
2023-11-10 13:00 ` [PATCH 3/3] [gdb/tui] Don't include border_width in left_margin Tom de Vries
2023-11-13 17:41 ` [PATCH 1/3] [gdb/tui] Refactor prefresh call in tui_source_window_base::refresh_window Tom Tromey
2 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2023-11-10 13:00 UTC (permalink / raw)
To: gdb-patches
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.
---
gdb/tui/tui-data.h | 12 ++++++++++++
gdb/tui/tui-disasm.c | 2 +-
gdb/tui/tui-regs.c | 10 +++++-----
gdb/tui/tui-source.c | 4 ++--
gdb/tui/tui-wingeneral.c | 2 +-
gdb/tui/tui-winsource.c | 20 ++++++++++++--------
gdb/tui/tui-winsource.h | 4 ++--
7 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index a1e44f77cc1..5bb5ef9d941 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -88,6 +88,18 @@ struct tui_win_info
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 c1ed491c558..4e9c2341ddd 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 1a351e60cee..01538d49961 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 6625f0cf088..5e9a954f7c2 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 5e1b3d2e62e..af4fc746cba 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 7eabc522d85..83ce48090a0 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 4a355121906..dccce0efca1 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -206,13 +206,13 @@ struct tui_source_window_base : public tui_win_info
/* 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 ();
--
2.35.3
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] [gdb/tui] Don't include border_width in left_margin
2023-11-10 13:00 [PATCH 1/3] [gdb/tui] Refactor prefresh call in tui_source_window_base::refresh_window Tom de Vries
2023-11-10 13:00 ` [PATCH 2/3] [gdb/tui] Add tui_win_info::{box_width,box_size} Tom de Vries
@ 2023-11-10 13:00 ` Tom de Vries
2023-11-13 17:42 ` Tom Tromey
2023-11-13 17:41 ` [PATCH 1/3] [gdb/tui] Refactor prefresh call in tui_source_window_base::refresh_window Tom Tromey
2 siblings, 1 reply; 6+ messages in thread
From: Tom de Vries @ 2023-11-10 13:00 UTC (permalink / raw)
To: gdb-patches
Currently left_margin does not match its documentation:
...
/* Return the size of the left margin space, this is the space used to
display things like breakpoint markers. */
int left_margin () const
{ return box_width () + TUI_EXECINFO_SIZE + extra_margin (); }
...
It is stated that the left margin is reserved to display things, but
the box_width is not used for that.
Fix this by dropping box_width () from the left_margin calculation.
Tested on x86_64-linux.
---
gdb/tui/tui-winsource.c | 2 +-
gdb/tui/tui-winsource.h | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 83ce48090a0..ea4ca219292 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -348,7 +348,7 @@ tui_source_window_base::refresh_window ()
gdb_assert (pad_x + view_width <= pad_width || m_pad.get () == nullptr);
int sminrow = y + box_width ();
- int smincol = x + left_margin;
+ int smincol = x + box_width () + left_margin;
int smaxrow = sminrow + m_content.size () - 1;
int smaxcol = smincol + view_width - 1;
prefresh (m_pad.get (), 0, pad_x, sminrow, smincol, smaxrow, smaxcol);
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index dccce0efca1..c2826165a10 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -206,13 +206,13 @@ struct tui_source_window_base : public tui_win_info
/* Return the size of the left margin space, this is the space used to
display things like breakpoint markers. */
int left_margin () const
- { return box_width () + TUI_EXECINFO_SIZE + extra_margin (); }
+ { return 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 () - box_width (); }
+ { return width - left_margin () - box_size (); }
void show_source_content ();
--
2.35.3
^ permalink raw reply [flat|nested] 6+ messages in thread