/* TUI display source/assembly window.
- Copyright (C) 1998-2014 Free Software Foundation, Inc.
+ Copyright (C) 1998-2019 Free Software Foundation, Inc.
Contributed by Hewlett-Packard Company.
#include "tui/tui.h"
#include "tui/tui-data.h"
+#include "tui/tui-io.h"
#include "tui/tui-stack.h"
#include "tui/tui-win.h"
#include "tui/tui-wingeneral.h"
/* Function to display the "main" routine. */
void
-tui_display_main (void)
+tui_display_main ()
{
- if ((tui_source_windows ())->count > 0)
+ if (!tui_source_windows ().empty ())
{
struct gdbarch *gdbarch;
CORE_ADDR addr;
tui_get_begin_asm_address (&gdbarch, &addr);
if (addr != (CORE_ADDR) 0)
{
- struct symtab_and_line sal;
+ struct symtab *s;
tui_update_source_windows_with_addr (gdbarch, addr);
- sal = find_pc_line (addr, 0);
- if (sal.symtab)
- tui_update_locator_fullname (symtab_to_fullname (sal.symtab));
+ s = find_pc_line_symtab (addr);
+ if (s != NULL)
+ tui_update_locator_fullname (symtab_to_fullname (s));
else
tui_update_locator_fullname ("??");
}
struct tui_line_or_address line_or_addr,
int noerror)
{
- win_info->detail.source_info.horizontal_offset = 0;
+ tui_source_window_base *base = (tui_source_window_base *) win_info;
+ base->horizontal_offset = 0;
tui_update_source_window_as_is (win_info, gdbarch, s, line_or_addr, noerror);
return;
tui_update_exec_info (win_info);
if (win_info->generic.type == SRC_WIN)
{
- struct symtab_and_line sal;
-
- init_sal (&sal);
+ symtab_and_line sal;
+
sal.line = line_or_addr.u.line_no +
(win_info->generic.content_size - 2);
sal.symtab = s;
- sal.pspace = s->objfile->pspace;
- set_current_source_symtab_and_line (&sal);
+ sal.pspace = SYMTAB_PSPACE (s);
+ set_current_source_symtab_and_line (sal);
/* If the focus was in the asm win, put it in the src win if
we don't have a split layout. */
if (tui_win_with_focus () == TUI_DISASM_WIN
}
else
{
- int i;
-
- for (i = 0; i < (tui_source_windows ())->count; i++)
+ for (struct tui_source_window_base *win_info : tui_source_windows ())
{
- struct tui_win_info *win_info = (tui_source_windows ())->list[i];
-
tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT);
tui_clear_exec_info_content (win_info);
}
if (!s)
return;
- gdbarch = get_objfile_arch (s->objfile);
+ gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
switch (tui_current_layout ())
{
tui_erase_source_content (win_info, display_prompt);
for (i = 0; i < win_info->generic.content_size; i++)
{
- struct tui_win_element *element =
- (struct tui_win_element *) win_info->generic.content[i];
+ struct tui_win_element *element = win_info->generic.content[i];
element->which_element.source.has_break = FALSE;
element->which_element.source.is_exec_point = FALSE;
int x_pos;
int half_width = (win_info->generic.width - 2) / 2;
- if (win_info->generic.handle != (WINDOW *) NULL)
+ if (win_info->generic.handle != NULL)
{
werase (win_info->generic.handle);
tui_check_and_display_highlight_if_needed (win_info);
if (display_prompt == EMPTY_SOURCE_PROMPT)
{
- char *no_src_str;
+ const char *no_src_str;
if (win_info->generic.type == SRC_WIN)
no_src_str = NO_SRC_STRING;
mvwaddstr (win_info->generic.handle,
(win_info->generic.height / 2),
x_pos,
- no_src_str);
+ (char *) no_src_str);
/* elz: Added this function call to set the real contents of
the window to what is on the screen, so that later calls
tui_show_source_line (struct tui_win_info *win_info, int lineno)
{
struct tui_win_element *line;
- int x, y;
+ int x;
- line = (struct tui_win_element *) win_info->generic.content[lineno - 1];
+ line = win_info->generic.content[lineno - 1];
if (line->which_element.source.is_exec_point)
- wattron (win_info->generic.handle, A_STANDOUT);
+ tui_set_reverse_mode (win_info->generic.handle, true);
- mvwaddstr (win_info->generic.handle, lineno, 1,
- line->which_element.source.line);
+ wmove (win_info->generic.handle, lineno, 1);
+ tui_puts (line->which_element.source.line,
+ win_info->generic.handle);
if (line->which_element.source.is_exec_point)
- wattroff (win_info->generic.handle, A_STANDOUT);
+ tui_set_reverse_mode (win_info->generic.handle, false);
/* Clear to end of line but stop before the border. */
- getyx (win_info->generic.handle, y, x);
+ x = getcurx (win_info->generic.handle);
while (x + 1 < win_info->generic.width)
{
waddch (win_info->generic.handle, ' ');
- getyx (win_info->generic.handle, y, x);
+ x = getcurx (win_info->generic.handle);
}
}
win_info->generic.content_in_use = TRUE;
}
+/* See tui-data.h. */
-/* Scroll the source forward or backward horizontally. */
void
-tui_horizontal_source_scroll (struct tui_win_info *win_info,
- enum tui_scroll_direction direction,
- int num_to_scroll)
+tui_source_window_base::refill ()
{
- if (win_info->generic.content != NULL)
+ symtab *s = nullptr;
+
+ if (generic.type == SRC_WIN)
{
- struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch;
- int offset;
- struct symtab *s = NULL;
+ symtab_and_line cursal = get_current_source_symtab_and_line ();
+ s = (cursal.symtab == NULL
+ ? find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)))
+ : cursal.symtab);
+ }
- if (win_info->generic.type == SRC_WIN)
- {
- struct symtab_and_line cursal
- = get_current_source_symtab_and_line ();
+ tui_update_source_window_as_is (this, gdbarch, s,
+ generic.content[0]
+ ->which_element.source.line_or_addr,
+ FALSE);
+}
- if (cursal.symtab == NULL)
- s = find_pc_symtab (get_frame_pc (get_selected_frame (NULL)));
- else
- s = cursal.symtab;
- }
+/* Scroll the source forward or backward horizontally. */
+
+void
+tui_source_window_base::do_scroll_horizontal
+ (enum tui_scroll_direction direction, int num_to_scroll)
+{
+ if (generic.content != NULL)
+ {
+ int offset;
if (direction == LEFT_SCROLL)
- offset = win_info->detail.source_info.horizontal_offset
- + num_to_scroll;
+ offset = horizontal_offset + num_to_scroll;
else
{
- offset = win_info->detail.source_info.horizontal_offset
- - num_to_scroll;
+ offset = horizontal_offset - num_to_scroll;
if (offset < 0)
offset = 0;
}
- win_info->detail.source_info.horizontal_offset = offset;
- tui_update_source_window_as_is (win_info, gdbarch, s,
- ((struct tui_win_element *)
- win_info->generic.content[0])->which_element.source.line_or_addr,
- FALSE);
+ horizontal_offset = offset;
+ refill ();
}
-
- return;
}
line_no. */
void
-tui_set_is_exec_point_at (struct tui_line_or_address l,
- struct tui_win_info *win_info)
+tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
{
int changed = 0;
int i;
- tui_win_content content = (tui_win_content) win_info->generic.content;
+ tui_win_content content = generic.content;
i = 0;
- while (i < win_info->generic.content_size)
+ while (i < generic.content_size)
{
int new_state;
struct tui_line_or_address content_loa =
{
changed++;
content[i]->which_element.source.is_exec_point = new_state;
- tui_show_source_line (win_info, i + 1);
+ tui_show_source_line (this, i + 1);
}
i++;
}
if (changed)
- tui_refresh_win (&win_info->generic);
+ refill ();
}
/* Update the execution windows to show the active breakpoints.
This is called whenever a breakpoint is inserted, removed or
has its state changed. */
void
-tui_update_all_breakpoint_info (void)
+tui_update_all_breakpoint_info ()
{
- struct tui_list *list = tui_source_windows ();
- int i;
-
- for (i = 0; i < list->count; i++)
+ for (tui_source_window_base *win : tui_source_windows ())
{
- struct tui_win_info *win = list->list[i];
-
if (tui_update_breakpoint_info (win, FALSE))
{
tui_update_exec_info (win);
{
int i;
int need_refresh = 0;
- struct tui_source_info *src = &win->detail.source_info;
+ tui_source_window_base *src = (tui_source_window_base *) win;
for (i = 0; i < win->generic.content_size; i++)
{
int mode;
struct tui_source_element *line;
- line = &((struct tui_win_element *)
- win->generic.content[i])->which_element.source;
+ line = &win->generic.content[i]->which_element.source;
if (current_only && !line->is_exec_point)
continue;
those that we already hit. */
mode = 0;
for (bp = breakpoint_chain;
- bp != (struct breakpoint *) NULL;
+ bp != NULL;
bp = bp->next)
{
struct bp_location *loc;
{
enum tui_status ret = TUI_SUCCESS;
- if (win_info->detail.source_info.execution_info
- != (struct tui_gen_win_info *) NULL)
+ tui_source_window_base *base = (tui_source_window_base *) win_info;
+ if (base->execution_info != NULL)
{
- struct tui_gen_win_info *exec_info_ptr
- = win_info->detail.source_info.execution_info;
+ struct tui_gen_win_info *exec_info_ptr = base->execution_info;
if (exec_info_ptr->content == NULL)
exec_info_ptr->content =
- (void **) tui_alloc_content (win_info->generic.height,
- exec_info_ptr->type);
+ tui_alloc_content (win_info->generic.height, exec_info_ptr->type);
if (exec_info_ptr->content != NULL)
{
int i;
struct tui_win_element *src_element;
int mode;
- element = (struct tui_win_element *) exec_info_ptr->content[i];
- src_element = (struct tui_win_element *)
- win_info->generic.content[i];
+ element = exec_info_ptr->content[i];
+ src_element = win_info->generic.content[i];
memset(element->which_element.simple_string, ' ',
sizeof(element->which_element.simple_string));
void
tui_show_exec_info_content (struct tui_win_info *win_info)
{
- struct tui_gen_win_info *exec_info
- = win_info->detail.source_info.execution_info;
+ tui_source_window_base *base = (tui_source_window_base *) win_info;
+ struct tui_gen_win_info *exec_info = base->execution_info;
int cur_line;
werase (exec_info->handle);
mvwaddstr (exec_info->handle,
cur_line,
0,
- ((struct tui_win_element *)
- exec_info->content[cur_line - 1])->which_element.simple_string);
+ (char *) exec_info->content[cur_line - 1]
+ ->which_element.simple_string);
tui_refresh_win (exec_info);
exec_info->content_in_use = TRUE;
}
void
tui_erase_exec_info_content (struct tui_win_info *win_info)
{
- struct tui_gen_win_info *exec_info
- = win_info->detail.source_info.execution_info;
+ tui_source_window_base *base = (tui_source_window_base *) win_info;
+ struct tui_gen_win_info *exec_info = base->execution_info;
werase (exec_info->handle);
tui_refresh_win (exec_info);
void
tui_clear_exec_info_content (struct tui_win_info *win_info)
{
- win_info->detail.source_info.execution_info->content_in_use = FALSE;
+ tui_source_window_base *base = (tui_source_window_base *) win_info;
+ base->execution_info->content_in_use = FALSE;
tui_erase_exec_info_content (win_info);
return;
enum tui_status
tui_alloc_source_buffer (struct tui_win_info *win_info)
{
- char *src_line_buf;
int i, line_width, max_lines;
- max_lines = win_info->generic.height; /* Less the highlight box. */
- line_width = win_info->generic.width - 1;
- /*
- * Allocate the buffer for the source lines. Do this only once
- * since they will be re-used for all source displays. The only
- * other time this will be done is when a window's size changes.
- */
+ /* The window width/height includes the highlight box. Determine actual
+ content dimensions, including string null-terminators. */
+ max_lines = win_info->generic.height - 2;
+ line_width = win_info->generic.width - 2 + 1;
+
+ /* Allocate the buffer for the source lines. */
if (win_info->generic.content == NULL)
{
- src_line_buf = (char *)
- xmalloc ((max_lines * line_width) * sizeof (char));
- if (src_line_buf == (char *) NULL)
- {
- fputs_unfiltered ("Unable to Allocate Memory for "
- "Source or Disassembly Display.\n",
- gdb_stderr);
- return TUI_FAILURE;
- }
/* Allocate the content list. */
- if ((win_info->generic.content =
- (void **) tui_alloc_content (max_lines, SRC_WIN)) == NULL)
- {
- xfree (src_line_buf);
- fputs_unfiltered ("Unable to Allocate Memory for "
- "Source or Disassembly Display.\n",
- gdb_stderr);
- return TUI_FAILURE;
- }
+ win_info->generic.content = tui_alloc_content (max_lines, SRC_WIN);
for (i = 0; i < max_lines; i++)
- ((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line =
- src_line_buf + (line_width * i);
+ win_info->generic.content[i]->which_element.source.line
+ = (char *) xmalloc (line_width);
}
return TUI_SUCCESS;
while (i < win_info->generic.content_size - threshold
&& !is_displayed)
{
- is_displayed = (((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line_or_addr.loa
- == LOA_LINE)
- && (((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line_or_addr.u.line_no
- == (int) line);
+ is_displayed
+ = win_info->generic.content[i]
+ ->which_element.source.line_or_addr.loa == LOA_LINE
+ && win_info->generic.content[i]
+ ->which_element.source.line_or_addr.u.line_no == line;
i++;
}
while (i < win_info->generic.content_size - threshold
&& !is_displayed)
{
- is_displayed = (((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line_or_addr.loa
- == LOA_ADDRESS)
- && (((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line_or_addr.u.addr
- == addr);
+ is_displayed
+ = win_info->generic.content[i]
+ ->which_element.source.line_or_addr.loa == LOA_ADDRESS
+ && win_info->generic.content[i]
+ ->which_element.source.line_or_addr.u.addr == addr;
i++;
}