+2020-02-22 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.
+
2020-02-22 Tom Tromey <tom@tromey.com>
* NEWS: Add entry for gdb.register_window_type.
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 ();
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. */
/* Get temporary table that will hold all strings (addr & insn). */
std::vector<tui_asm_line> asm_lines;
size_t addr_size = 0;
- tui_disassemble (gdbarch, asm_lines, pc, max_lines, &addr_size);
+ tui_disassemble (m_gdbarch, asm_lines, pc, 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;
CORE_ADDR addr;
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;
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
tui_disasm_window::addr_is_displayed (CORE_ADDR addr) const
{
- if (content.size () < SCROLL_THRESHOLD)
+ if (m_content.size () < SCROLL_THRESHOLD)
return false;
- for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; ++i)
+ for (size_t i = 0; i < m_content.size () - SCROLL_THRESHOLD; ++i)
{
- if (content[i].line_or_addr.loa == LOA_ADDRESS
- && content[i].line_or_addr.u.addr == addr)
+ if (m_content[i].line_or_addr.loa == LOA_ADDRESS
+ && m_content[i].line_or_addr.u.addr == addr)
return true;
}
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;
+}
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;
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
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)
}
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
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++;
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));
}
void
tui_source_window::do_scroll_vertical (int num_to_scroll)
{
- if (!content.empty ())
+ if (!m_content.empty ())
{
struct symtab *s;
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
- struct gdbarch *arch = gdbarch;
+ struct gdbarch *arch = m_gdbarch;
if (cursal.symtab == NULL)
{
else
s = cursal.symtab;
- int line_no = start_line_or_addr.u.line_no + num_to_scroll;
+ int 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)
&& line_no > offsets->size ())
- line_no = start_line_or_addr.u.line_no;
+ line_no = m_start_line_or_addr.u.line_no;
if (line_no <= 0)
line_no = 1;
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);
bool
tui_source_window::line_is_displayed (int line) const
{
- if (content.size () < SCROLL_THRESHOLD)
+ if (m_content.size () < SCROLL_THRESHOLD)
return false;
- for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; ++i)
+ for (size_t i = 0; i < m_content.size () - SCROLL_THRESHOLD; ++i)
{
- if (content[i].line_or_addr.loa == LOA_LINE
- && content[i].line_or_addr.u.line_no == line)
+ if (m_content[i].line_or_addr.loa == LOA_LINE
+ && m_content[i].line_or_addr.u.line_no == line)
return true;
}
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);
+}
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;
(struct gdbarch *gdbarch,
const struct symtab_and_line &sal)
{
- horizontal_offset = 0;
+ m_horizontal_offset = 0;
update_source_window_as_is (gdbarch, sal);
}
int x_pos;
int half_width = (width - 2) / 2;
- content.clear ();
+ m_content.clear ();
if (handle != NULL)
{
werase (handle.get ());
/* 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 ();
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),
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)
{
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. */
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 ();
}
}
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)
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++;
}
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;
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
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
/* 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: