[PATCH 21/24] Make some tui_source_window_base members "protected"

Tom Tromey
2020-01-04T18:34:40Z

This renames a few members of tui_source_window_base, and makes them
"protected".

2020-01-04 Tom Tromey <tom@tromey.com>

* tui/tui-layout.c (extract_display_start_addr): Rewrite.
* tui/tui-disasm.h (struct tui_disasm_window)
<display_start_addr>: Declare.
* tui/tui-source.h (struct tui_source_window)
<display_start_addr>: Declare.
* tui/tui-winsource.h (struct tui_source_window_base)
<show_source_line, display_start_addr>: New methods.
<m_horizontal_offset, m_start_line_or_addr, m_gdbarch, m_content>:
Rename and move to protected section.
* tui/tui-winsource.c (tui_source_window_base::update_source_window)
(tui_source_window_base::do_erase_source_content): Update.
(tui_source_window_base::show_source_line): Now a method.
(tui_source_window_base::show_source_content)
(tui_source_window_base::tui_source_window_base)
(tui_source_window_base::rerender)
(tui_source_window_base::refill)
(tui_source_window_base::do_scroll_horizontal)
(tui_source_window_base::set_is_exec_point_at)
(tui_source_window_base::update_breakpoint_info)
(tui_source_window_base::update_exec_info): Update.
* tui/tui-source.c (tui_source_window::set_contents)
(tui_source_window::showing_source_p)
(tui_source_window::do_scroll_vertical)
(tui_source_window::location_matches_p)
(tui_source_window::line_is_displayed): Update.
(tui_source_window::display_start_addr): New method.
* tui/tui-disasm.c (tui_disasm_window::set_contents)
(tui_disasm_window::do_scroll_vertical)
(tui_disasm_window::location_matches_p): Update.
(tui_disasm_window::display_start_addr): New method.

Change-Id: I74d72b9da5f458664427db643a108634690c6e19
---
gdb/ChangeLog | 33 +++++++++++++++++
gdb/tui/tui-disasm.c | 40 ++++++++++++---------
gdb/tui/tui-disasm.h | 3 ++
gdb/tui/tui-layout.c | 22 +++---------
gdb/tui/tui-source.c | 43 ++++++++++++++---------
gdb/tui/tui-source.h | 3 ++
gdb/tui/tui-winsource.c | 78 ++++++++++++++++++++---------------------
gdb/tui/tui-winsource.h | 23 +++++++-----
8 files changed, 148 insertions(+), 97 deletions(-)

diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c
index f482086ca2e..741d0cad222 100644
--- a/gdb/tui/tui-disasm.c
+++ b/gdb/tui/tui-disasm.c
@@ -203,7 +203,7 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
const struct symtab_and_line &sal)
{
int i;
- int offset = horizontal_offset;
+ int offset = m_horizontal_offset;
int max_lines, line_width;
CORE_ADDR cur_pc;
struct tui_locator_window *locator = tui_locator_win_info_ptr ();
@@ -214,9 +214,9 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
if (pc == 0)
return false;

- gdbarch = arch;
- start_line_or_addr.loa = LOA_ADDRESS;
- start_line_or_addr.u.addr = pc;
+ m_gdbarch = arch;
+ m_start_line_or_addr.loa = LOA_ADDRESS;
+ m_start_line_or_addr.u.addr = pc;
cur_pc = locator->addr;

/* Window size, excluding highlight box. */
@@ -226,16 +226,16 @@ tui_disasm_window::set_contents (struct gdbarch *arch,
/* Get temporary table that will hold all strings (addr & insn). */
std::vector<tui_asm_line> asm_lines (max_lines);
size_t addr_size = 0;
- tui_disassemble (gdbarch, asm_lines, pc, 0, max_lines, &addr_size);
+ tui_disassemble (m_gdbarch, asm_lines, pc, 0, max_lines, &addr_size);

/* Align instructions to the same column. */
insn_pos = (1 + (addr_size / tab_len)) * tab_len;

/* Now construct each line. */
- content.resize (max_lines);
+ m_content.resize (max_lines);
for (i = 0; i < max_lines; i++)
{
- tui_source_element *src = &content[i];
+ tui_source_element *src = &m_content[i];

std::string line
= (asm_lines[i].addr_string
@@ -321,11 +321,11 @@ tui_get_low_disassembly_address (struct gdbarch *gdbarch,
void
tui_disasm_window::do_scroll_vertical (int num_to_scroll)
{
- if (!content.empty ())
+ if (!m_content.empty ())
{
CORE_ADDR pc;

- pc = start_line_or_addr.u.addr;
+ pc = m_start_line_or_addr.u.addr;
if (num_to_scroll >= 0)
num_to_scroll++;
else
@@ -333,16 +333,16 @@ tui_disasm_window::do_scroll_vertical (int num_to_scroll)

symtab_and_line sal {};
sal.pspace = current_program_space;
- sal.pc = tui_find_disassembly_address (gdbarch, pc, num_to_scroll);
- update_source_window_as_is (gdbarch, sal);
+ sal.pc = tui_find_disassembly_address (m_gdbarch, pc, num_to_scroll);
+ update_source_window_as_is (m_gdbarch, sal);
}
}

bool
tui_disasm_window::location_matches_p (struct bp_location *loc, int line_no)
{
- return (content[line_no].line_or_addr.loa == LOA_ADDRESS
- && content[line_no].line_or_addr.u.addr == loc->address);
+ return (m_content[line_no].line_or_addr.loa == LOA_ADDRESS
+ && m_content[line_no].line_or_addr.u.addr == loc->address);
}

bool
@@ -352,11 +352,11 @@ tui_disasm_window::addr_is_displayed (CORE_ADDR addr) const
int threshold = SCROLL_THRESHOLD;

int i = 0;
- while (i < content.size () - threshold && !is_displayed)
+ while (i < m_content.size () - threshold && !is_displayed)
{
is_displayed
- = (content[i].line_or_addr.loa == LOA_ADDRESS
- && content[i].line_or_addr.u.addr == addr);
+ = (m_content[i].line_or_addr.loa == LOA_ADDRESS
+ && m_content[i].line_or_addr.u.addr == addr);
i++;
}

@@ -394,3 +394,11 @@ tui_disasm_window::maybe_update (struct frame_info *fi, symtab_and_line sal)
set_is_exec_point_at (a);
}
}
+
+void
+tui_disasm_window::display_start_addr (struct gdbarch **gdbarch_p,
+ CORE_ADDR *addr_p)
+{
+ *gdbarch_p = m_gdbarch;
+ *addr_p = m_start_line_or_addr.u.addr;
+}
diff --git a/gdb/tui/tui-disasm.h b/gdb/tui/tui-disasm.h
index dd020310746..0eb6c9e7290 100644
--- a/gdb/tui/tui-disasm.h
+++ b/gdb/tui/tui-disasm.h
@@ -48,6 +48,9 @@ struct tui_disasm_window : public tui_source_window_base
do_erase_source_content (_("[ No Assembly Available ]"));
}

+ void display_start_addr (struct gdbarch **gdbarch_p,
+ CORE_ADDR *addr_p) override;
+
protected:

void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index d55660f89f6..352de57f551 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -274,27 +274,15 @@ tui_remove_some_windows ()
static void
extract_display_start_addr (struct gdbarch **gdbarch_p, CORE_ADDR *addr_p)
{
- struct gdbarch *gdbarch = nullptr;
- CORE_ADDR addr = 0;
- CORE_ADDR pc;
- struct symtab_and_line cursal = get_current_source_symtab_and_line ();
-
if (TUI_SRC_WIN != nullptr)
- {
- gdbarch = TUI_SRC_WIN->gdbarch;
- find_line_pc (cursal.symtab,
- TUI_SRC_WIN->start_line_or_addr.u.line_no,
- &pc);
- addr = pc;
- }
+ TUI_SRC_WIN->display_start_addr (gdbarch_p, addr_p);
else if (TUI_DISASM_WIN != nullptr)
+ TUI_DISASM_WIN->display_start_addr (gdbarch_p, addr_p);
+ else
{
- gdbarch = TUI_DISASM_WIN->gdbarch;
- addr = TUI_DISASM_WIN->start_line_or_addr.u.addr;
+ *gdbarch_p = nullptr;
+ *addr_p = 0;
}
-
- *gdbarch_p = gdbarch;
- *addr_p = addr;
}

void
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index e028b724d23..ead4c7cf522 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -74,9 +74,9 @@ tui_source_window::set_contents (struct gdbarch *arch,
m_fullname = make_unique_xstrdup (symtab_to_fullname (s));

cur_line = 0;
- gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
- start_line_or_addr.loa = LOA_LINE;
- cur_line_no = start_line_or_addr.u.line_no = line_no;
+ m_gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
+ m_start_line_or_addr.loa = LOA_LINE;
+ cur_line_no = m_start_line_or_addr.u.line_no = line_no;

int digits = 0;
if (compact_source)
@@ -88,16 +88,15 @@ tui_source_window::set_contents (struct gdbarch *arch,
}

const char *iter = srclines.c_str ();
- content.resize (nlines);
+ m_content.resize (nlines);
while (cur_line < nlines)
{
- struct tui_source_element *element
- = &content[cur_line];
+ struct tui_source_element *element = &m_content[cur_line];

std::string text;
if (*iter != '\0')
text = tui_copy_source_line (&iter, cur_line_no,
- horizontal_offset,
+ m_horizontal_offset,
line_width, digits);

/* Set whether element is the execution point
@@ -109,7 +108,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
symtab_to_fullname (s)) == 0
&& cur_line_no == locator->line_no);

- content[cur_line].line = std::move (text);
+ m_content[cur_line].line = std::move (text);

cur_line++;
cur_line_no++;
@@ -124,7 +123,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
bool
tui_source_window::showing_source_p (const char *fullname) const
{
- return (!content.empty ()
+ return (!m_content.empty ()
&& (filename_cmp (tui_locator_win_info_ptr ()->full_name.c_str (),
fullname) == 0));
}
@@ -134,7 +133,7 @@ tui_source_window::showing_source_p (const char *fullname) const
void
tui_source_window::do_scroll_vertical (int num_to_scroll)
{
- if (!content.empty ())
+ if (!m_content.empty ())
{
struct tui_line_or_address l;
struct symtab *s;
@@ -146,12 +145,12 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
s = cursal.symtab;

l.loa = LOA_LINE;
- l.u.line_no = start_line_or_addr.u.line_no
+ l.u.line_no = m_start_line_or_addr.u.line_no
+ num_to_scroll;
const std::vector<off_t> *offsets;
if (g_source_cache.get_line_charpos (s, &offsets)
&& l.u.line_no > offsets->size ())
- l.u.line_no = start_line_or_addr.u.line_no;
+ l.u.line_no = m_start_line_or_addr.u.line_no;
if (l.u.line_no <= 0)
l.u.line_no = 1;

@@ -162,8 +161,8 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
bool
tui_source_window::location_matches_p (struct bp_location *loc, int line_no)
{
- return (content[line_no].line_or_addr.loa == LOA_LINE
- && content[line_no].line_or_addr.u.line_no == loc->line_number
+ return (m_content[line_no].line_or_addr.loa == LOA_LINE
+ && m_content[line_no].line_or_addr.u.line_no == loc->line_number
&& loc->symtab != NULL
&& filename_cmp (m_fullname.get (),
symtab_to_fullname (loc->symtab)) == 0);
@@ -177,11 +176,11 @@ tui_source_window::line_is_displayed (int line) const
bool is_displayed = false;
int threshold = SCROLL_THRESHOLD;
int i = 0;
- while (i < content.size () - threshold && !is_displayed)
+ while (i < m_content.size () - threshold && !is_displayed)
{
is_displayed
- = (content[i].line_or_addr.loa == LOA_LINE
- && content[i].line_or_addr.u.line_no == line);
+ = (m_content[i].line_or_addr.loa == LOA_LINE
+ && m_content[i].line_or_addr.u.line_no == line);
i++;
}

@@ -212,3 +211,13 @@ tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal)
set_is_exec_point_at (l);
}
}
+
+void
+tui_source_window::display_start_addr (struct gdbarch **gdbarch_p,
+ CORE_ADDR *addr_p)
+{
+ struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+
+ *gdbarch_p = m_gdbarch;
+ find_line_pc (cursal.symtab, m_start_line_or_addr.u.line_no, addr_p);
+}
diff --git a/gdb/tui/tui-source.h b/gdb/tui/tui-source.h
index 58dc5e88cf7..1df84cf304c 100644
--- a/gdb/tui/tui-source.h
+++ b/gdb/tui/tui-source.h
@@ -53,6 +53,9 @@ struct tui_source_window : public tui_source_window_base
do_erase_source_content (_("[ No Source Available ]"));
}

+ void display_start_addr (struct gdbarch **gdbarch_p,
+ CORE_ADDR *addr_p) override;
+
protected:

void do_scroll_vertical (int num_to_scroll) override;
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index bd7a34ebbd5..592115a7347 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -169,7 +169,7 @@ tui_source_window_base::update_source_window
(struct gdbarch *gdbarch,
const struct symtab_and_line &sal)
{
- horizontal_offset = 0;
+ m_horizontal_offset = 0;
update_source_window_as_is (gdbarch, sal);
}

@@ -228,7 +228,7 @@ tui_source_window_base::do_erase_source_content (const char *str)
int x_pos;
int half_width = (width - 2) / 2;

- content.clear ();
+ m_content.clear ();
if (handle != NULL)
{
werase (handle.get ());
@@ -249,37 +249,37 @@ tui_source_window_base::do_erase_source_content (const char *str)

/* Redraw the complete line of a source or disassembly window. */
-static void
-tui_show_source_line (struct tui_source_window_base *win_info, int lineno)
+void
+tui_source_window_base::show_source_line (int lineno)
{
struct tui_source_element *line;
int x;

- line = &win_info->content[lineno - 1];
+ line = &m_content[lineno - 1];
if (line->is_exec_point)
- tui_set_reverse_mode (win_info->handle.get (), true);
+ tui_set_reverse_mode (handle.get (), true);

- wmove (win_info->handle.get (), lineno, TUI_EXECINFO_SIZE);
- tui_puts (line->line.c_str (), win_info->handle.get ());
+ wmove (handle.get (), lineno, TUI_EXECINFO_SIZE);
+ tui_puts (line->line.c_str (), handle.get ());
if (line->is_exec_point)
- tui_set_reverse_mode (win_info->handle.get (), false);
+ tui_set_reverse_mode (handle.get (), false);

/* Clear to end of line but stop before the border. */
- x = getcurx (win_info->handle.get ());
- while (x + 1 < win_info->width)
+ x = getcurx (handle.get ());
+ while (x + 1 < width)
{
- waddch (win_info->handle.get (), ' ');
- x = getcurx (win_info->handle.get ());
+ waddch (handle.get (), ' ');
+ x = getcurx (handle.get ());
}
}

void
tui_source_window_base::show_source_content ()
{
- gdb_assert (!content.empty ());
+ gdb_assert (!m_content.empty ());

- for (int lineno = 1; lineno <= content.size (); lineno++)
- tui_show_source_line (this, lineno);
+ for (int lineno = 1; lineno <= m_content.size (); lineno++)
+ show_source_line (lineno);

check_and_display_highlight_if_needed ();
refresh_window ();
@@ -287,8 +287,8 @@ tui_source_window_base::show_source_content ()

tui_source_window_base::tui_source_window_base ()
{
- start_line_or_addr.loa = LOA_ADDRESS;
- start_line_or_addr.u.addr = 0;
+ m_start_line_or_addr.loa = LOA_ADDRESS;
+ m_start_line_or_addr.u.addr = 0;

gdb::observers::source_styling_changed.attach
(std::bind (&tui_source_window::style_changed, this),
@@ -312,16 +312,16 @@ tui_source_window_base::update_tab_width ()
void
tui_source_window_base::rerender ()
{
- if (!content.empty ())
+ if (!m_content.empty ())
{
struct symtab_and_line cursal
= get_current_source_symtab_and_line ();

- if (start_line_or_addr.loa == LOA_LINE)
- cursal.line = start_line_or_addr.u.line_no;
+ if (m_start_line_or_addr.loa == LOA_LINE)
+ cursal.line = m_start_line_or_addr.u.line_no;
else
- cursal.pc = start_line_or_addr.u.addr;
- update_source_window (gdbarch, cursal);
+ cursal.pc = m_start_line_or_addr.u.addr;
+ update_source_window (m_gdbarch, cursal);
}
else if (deprecated_safe_get_selected_frame () != NULL)
{
@@ -356,12 +356,12 @@ tui_source_window_base::refill ()
if (sal.pspace == nullptr)
sal.pspace = current_program_space;

- if (start_line_or_addr.loa == LOA_LINE)
- sal.line = start_line_or_addr.u.line_no;
+ if (m_start_line_or_addr.loa == LOA_LINE)
+ sal.line = m_start_line_or_addr.u.line_no;
else
- sal.pc = start_line_or_addr.u.addr;
+ sal.pc = m_start_line_or_addr.u.addr;

- update_source_window_as_is (gdbarch, sal);
+ update_source_window_as_is (m_gdbarch, sal);
}

/* Scroll the source forward or backward horizontally. */
@@ -369,12 +369,12 @@ tui_source_window_base::refill ()
void
tui_source_window_base::do_scroll_horizontal (int num_to_scroll)
{
- if (!content.empty ())
+ if (!m_content.empty ())
{
- int offset = horizontal_offset + num_to_scroll;
+ int offset = m_horizontal_offset + num_to_scroll;
if (offset < 0)
offset = 0;
- horizontal_offset = offset;
+ m_horizontal_offset = offset;
refill ();
}
}
@@ -390,11 +390,11 @@ tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
int i;

i = 0;
- while (i < content.size ())
+ while (i < m_content.size ())
{
bool new_state;
struct tui_line_or_address content_loa =
- content[i].line_or_addr;
+ m_content[i].line_or_addr;

if (content_loa.loa == l.loa
&& ((l.loa == LOA_LINE && content_loa.u.line_no == l.u.line_no)
@@ -402,11 +402,11 @@ tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
new_state = true;
else
new_state = false;
- if (new_state != content[i].is_exec_point)
+ if (new_state != m_content[i].is_exec_point)
{
changed = true;
- content[i].is_exec_point = new_state;
- tui_show_source_line (this, i + 1);
+ m_content[i].is_exec_point = new_state;
+ show_source_line (i + 1);
}
i++;
}
@@ -440,11 +440,11 @@ tui_source_window_base::update_breakpoint_info
int i;
bool need_refresh = false;

- for (i = 0; i < content.size (); i++)
+ for (i = 0; i < m_content.size (); i++)
{
struct tui_source_element *line;

- line = &content[i];
+ line = &m_content[i];
if (current_only && !line->is_exec_point)
continue;

@@ -493,9 +493,9 @@ void
tui_source_window_base::update_exec_info ()
{
update_breakpoint_info (nullptr, true);
- for (int i = 0; i < content.size (); i++)
+ for (int i = 0; i < m_content.size (); i++)
{
- struct tui_source_element *src_element = &content[i];
+ struct tui_source_element *src_element = &m_content[i];
char element[TUI_EXECINFO_SIZE] = " ";

/* Now update the exec info content based upon the state
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index 4ac20d80502..501dd31ccfd 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -90,6 +90,18 @@ protected:
virtual bool set_contents (struct gdbarch *gdbarch,
const struct symtab_and_line &sal) = 0;

+ /* Redraw the complete line of a source or disassembly window. */
+ void show_source_line (int lineno);
+
+ /* Used for horizontal scroll. */
+ int m_horizontal_offset = 0;
+ struct tui_line_or_address m_start_line_or_addr;
+
+ /* Architecture associated with code at this location. */
+ struct gdbarch *m_gdbarch = nullptr;
+
+ std::vector<tui_source_element> m_content;
+
public:

/* Refill the source window's source cache and update it. If this
@@ -125,14 +137,9 @@ public:
/* Erase the source content. */
virtual void erase_source_content () = 0;

- /* Used for horizontal scroll. */
- int horizontal_offset = 0;
- struct tui_line_or_address start_line_or_addr;
-
- /* Architecture associated with code at this location. */
- struct gdbarch *gdbarch = nullptr;
-
- std::vector<tui_source_element> content;
+ /* Return the start address and gdbarch. */
+ virtual void display_start_addr (struct gdbarch **gdbarch_p,
+ CORE_ADDR *addr_p) = 0;

private:

--
2.17.2