Introduce tui_source_window_base::set_contents method

This introduces the tui_source_window_base::set_contents method and
implements it in the subclasses.  This removes a check of the window
type.

gdb/ChangeLog
2019-08-16  Tom Tromey  <tom@tromey.com>

	* tui/tui-winsource.h (struct tui_source_window_base)
	<set_contents>: Declare.
	* tui/tui-winsource.c
	(tui_source_window_base::update_source_window_as_is): Update.
	* tui/tui-source.h (struct tui_source_window) <set_contents>:
	Declare.
	(tui_set_source_content): Don't declare.
	* tui/tui-source.c (tui_source_window::set_contents): Rename from
	tui_set_source_content.
	* tui/tui-disasm.h (struct tui_disasm_window) <set_contents>:
	Declare.
	(tui_set_disassem_content): Don't declare.
	* tui/tui-disasm.c (tui_disasm_window::set_contents): Rename from
	tui_set_disassem_content.
This commit is contained in:
Tom Tromey 2019-07-11 18:42:20 -06:00
parent 2ddaf61443
commit 81c82c4b90
7 changed files with 67 additions and 39 deletions

View File

@ -1,3 +1,20 @@
2019-08-16 Tom Tromey <tom@tromey.com>
* tui/tui-winsource.h (struct tui_source_window_base)
<set_contents>: Declare.
* tui/tui-winsource.c
(tui_source_window_base::update_source_window_as_is): Update.
* tui/tui-source.h (struct tui_source_window) <set_contents>:
Declare.
(tui_set_source_content): Don't declare.
* tui/tui-source.c (tui_source_window::set_contents): Rename from
tui_set_source_content.
* tui/tui-disasm.h (struct tui_disasm_window) <set_contents>:
Declare.
(tui_set_disassem_content): Don't declare.
* tui/tui-disasm.c (tui_disasm_window::set_contents): Rename from
tui_set_disassem_content.
2019-08-16 Tom Tromey <tom@tromey.com>
* tui/tui-winsource.h (struct tui_source_window_base)

View File

@ -162,11 +162,12 @@ tui_find_disassembly_address (struct gdbarch *gdbarch, CORE_ADDR pc, int from)
/* Function to set the disassembly window's content. */
enum tui_status
tui_set_disassem_content (tui_source_window_base *win_info,
struct gdbarch *gdbarch, CORE_ADDR pc)
tui_disasm_window::set_contents (struct gdbarch *arch,
struct symtab *s,
struct tui_line_or_address line_or_addr)
{
int i;
int offset = win_info->horizontal_offset;
int offset = horizontal_offset;
int max_lines, line_width;
CORE_ADDR cur_pc;
struct tui_locator_window *locator = tui_locator_win_info_ptr ();
@ -176,17 +177,19 @@ tui_set_disassem_content (tui_source_window_base *win_info,
int addr_size, insn_size;
char *line;
gdb_assert (line_or_addr.loa == LOA_ADDRESS);
CORE_ADDR pc = line_or_addr.u.addr;
if (pc == 0)
return TUI_FAILURE;
win_info->gdbarch = gdbarch;
win_info->start_line_or_addr.loa = LOA_ADDRESS;
win_info->start_line_or_addr.u.addr = pc;
gdbarch = arch;
start_line_or_addr.loa = LOA_ADDRESS;
start_line_or_addr.u.addr = pc;
cur_pc = locator->addr;
/* Window size, excluding highlight box. */
max_lines = win_info->height - 2;
line_width = win_info->width - 2;
max_lines = height - 2;
line_width = width - 2;
/* Get temporary table that will hold all strings (addr & insn). */
asm_lines = XALLOCAVEC (struct tui_asm_line, max_lines);
@ -216,12 +219,12 @@ tui_set_disassem_content (tui_source_window_base *win_info,
line = (char*) alloca (insn_pos + insn_size + 1);
/* Now construct each line. */
win_info->content.resize (max_lines);
content.resize (max_lines);
for (i = 0; i < max_lines; i++)
{
int cur_len;
tui_source_element *src = &win_info->content[i];
tui_source_element *src = &content[i];
strcpy (line, asm_lines[i].addr_string);
cur_len = strlen (line);
memset (line + cur_len, ' ', insn_pos - cur_len);

View File

@ -57,14 +57,17 @@ protected:
void do_scroll_vertical (int num_to_scroll) override;
enum tui_status set_contents
(struct gdbarch *gdbarch,
struct symtab *s,
struct tui_line_or_address line_or_addr) override;
private:
/* Answer whether a particular line number or address is displayed
in the current source window. */
bool addr_is_displayed (CORE_ADDR addr) const;
};
extern enum tui_status tui_set_disassem_content (tui_source_window_base *,
struct gdbarch *, CORE_ADDR);
extern void tui_show_disassem (struct gdbarch *, CORE_ADDR);
extern void tui_show_disassem_and_update_source (struct gdbarch *, CORE_ADDR);
extern void tui_get_begin_asm_address (struct gdbarch **, CORE_ADDR *);

View File

@ -123,10 +123,13 @@ copy_source_line (const char **ptr, int line_no, int first_col,
/* Function to display source in the source window. */
enum tui_status
tui_set_source_content (tui_source_window_base *win_info,
struct symtab *s,
int line_no)
tui_source_window::set_contents (struct gdbarch *arch,
struct symtab *s,
struct tui_line_or_address line_or_addr)
{
gdb_assert (line_or_addr.loa == LOA_LINE);
int line_no = line_or_addr.u.line_no;
enum tui_status ret = TUI_FAILURE;
if (s != NULL)
@ -134,10 +137,10 @@ tui_set_source_content (tui_source_window_base *win_info,
int line_width, nlines;
ret = TUI_SUCCESS;
line_width = win_info->width - 1;
line_width = width - 1;
/* Take hilite (window border) into account, when
calculating the number of lines. */
nlines = (line_no + (win_info->height - 2)) - line_no;
nlines = (line_no + (height - 2)) - line_no;
std::string srclines;
if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
@ -150,28 +153,27 @@ tui_set_source_content (tui_source_window_base *win_info,
= tui_locator_win_info_ptr ();
const char *s_filename = symtab_to_filename_for_display (s);
xfree (win_info->title);
win_info->title = xstrdup (s_filename);
xfree (title);
title = xstrdup (s_filename);
xfree (win_info->fullname);
win_info->fullname = xstrdup (symtab_to_fullname (s));
xfree (fullname);
fullname = xstrdup (symtab_to_fullname (s));
cur_line = 0;
win_info->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
win_info->start_line_or_addr.loa = LOA_LINE;
cur_line_no = win_info->start_line_or_addr.u.line_no = line_no;
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;
const char *iter = srclines.c_str ();
win_info->content.resize (nlines);
content.resize (nlines);
while (cur_line < nlines)
{
struct tui_source_element *element
= &win_info->content[cur_line];
= &content[cur_line];
std::string text;
if (*iter != '\0')
text = copy_source_line (&iter, cur_line_no,
win_info->horizontal_offset,
text = copy_source_line (&iter, cur_line_no, horizontal_offset,
line_width);
/* Set whether element is the execution point
@ -183,8 +185,8 @@ tui_set_source_content (tui_source_window_base *win_info,
symtab_to_fullname (s)) == 0
&& cur_line_no == locator->line_no);
xfree (win_info->content[cur_line].line);
win_info->content[cur_line].line
xfree (content[cur_line].line);
content[cur_line].line
= xstrdup (text.c_str ());
cur_line++;

View File

@ -60,6 +60,11 @@ protected:
void do_scroll_vertical (int num_to_scroll) override;
enum tui_status set_contents
(struct gdbarch *gdbarch,
struct symtab *s,
struct tui_line_or_address line_or_addr) override;
private:
void style_changed ();
@ -72,9 +77,6 @@ private:
gdb::observers::token m_observable;
};
extern enum tui_status tui_set_source_content (tui_source_window_base *,
struct symtab *,
int);
extern void tui_show_symtab_source (tui_source_window_base *,
struct gdbarch *, struct symtab *,
struct tui_line_or_address);

View File

@ -88,12 +88,8 @@ tui_source_window_base::update_source_window_as_is
struct symtab *s,
struct tui_line_or_address line_or_addr)
{
enum tui_status ret;
if (type == SRC_WIN)
ret = tui_set_source_content (this, s, line_or_addr.u.line_no);
else
ret = tui_set_disassem_content (this, gdbarch, line_or_addr.u.addr);
enum tui_status ret
= set_contents (gdbarch, s, line_or_addr);
if (ret == TUI_FAILURE)
erase_source_content ();

View File

@ -104,6 +104,11 @@ protected:
void rerender () override;
virtual enum tui_status set_contents
(struct gdbarch *gdbarch,
struct symtab *s,
struct tui_line_or_address line_or_addr) = 0;
public:
void clear_detail ();