/* TUI display source window.
- Copyright (C) 1998-2019 Free Software Foundation, Inc.
+ Copyright (C) 1998-2020 Free Software Foundation, Inc.
Contributed by Hewlett-Packard Company.
/* Function to display source in the source window. */
bool
tui_source_window::set_contents (struct gdbarch *arch,
- struct symtab *s,
- struct tui_line_or_address line_or_addr)
+ const struct symtab_and_line &sal)
{
- gdb_assert (line_or_addr.loa == LOA_LINE);
- int line_no = line_or_addr.u.line_no;
+ struct symtab *s = sal.symtab;
+ int line_no = sal.line;
if (s == NULL)
return false;
{
if (!content.empty ())
{
- struct tui_line_or_address l;
struct symtab *s;
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
+ struct gdbarch *arch = gdbarch;
if (cursal.symtab == NULL)
- s = find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)));
+ {
+ struct frame_info *fi = get_selected_frame (NULL);
+ s = find_pc_line_symtab (get_frame_pc (fi));
+ arch = get_frame_arch (fi);
+ }
else
s = cursal.symtab;
- l.loa = LOA_LINE;
- l.u.line_no = content[0].line_or_addr.u.line_no
- + num_to_scroll;
+ int line_no = 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 ())
- /* line = s->nlines - win_info->content_size + 1; */
- /* elz: fix for dts 23398. */
- l.u.line_no = content[0].line_or_addr.u.line_no;
- if (l.u.line_no <= 0)
- l.u.line_no = 1;
-
- print_source_lines (s, l.u.line_no, l.u.line_no + 1, 0);
+ && line_no > offsets->size ())
+ line_no = start_line_or_addr.u.line_no;
+ if (line_no <= 0)
+ line_no = 1;
+
+ cursal.line = line_no;
+ update_source_window (arch, cursal);
}
}
bool
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)
+ if (content.size () < SCROLL_THRESHOLD)
+ return false;
+
+ for (size_t i = 0; i < content.size () - SCROLL_THRESHOLD; ++i)
{
- is_displayed
- = (content[i].line_or_addr.loa == LOA_LINE
- && content[i].line_or_addr.u.line_no == line);
- i++;
+ if (content[i].line_or_addr.loa == LOA_LINE
+ && content[i].line_or_addr.u.line_no == line)
+ return true;
}
- return is_displayed;
+ return false;
}
void
tui_source_window::maybe_update (struct frame_info *fi, symtab_and_line sal)
{
- int start_line = (sal.line - (viewport_height / 2)) + 1;
+ int start_line = (sal.line - ((height - 2) / 2)) + 1;
if (start_line <= 0)
start_line = 1;
bool source_already_displayed = (sal.symtab != 0
&& showing_source_p (m_fullname.get ()));
- struct tui_line_or_address l;
-
- l.loa = LOA_LINE;
- l.u.line_no = start_line;
if (!(source_already_displayed && line_is_displayed (sal.line)))
- update_source_window (get_frame_arch (fi), sal.symtab, l);
+ {
+ sal.line = start_line;
+ update_source_window (get_frame_arch (fi), sal);
+ }
else
{
+ struct tui_line_or_address l;
+
+ l.loa = LOA_LINE;
l.u.line_no = sal.line;
set_is_exec_point_at (l);
}