gdb: Fix scrolling in TUI
[deliverable/binutils-gdb.git] / gdb / tui / tui-source.c
index 2d8ecee74731c395a5b9a11293e60dce49fb1106..13f2dc7cfe177904495e88fe95daad9ee92d0a0b 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -136,28 +136,29 @@ tui_source_window::do_scroll_vertical (int num_to_scroll)
 {
   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 = start_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 = start_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);
     }
 }
 
@@ -176,18 +177,17 @@ tui_source_window::location_matches_p (struct bp_location *loc, int line_no)
 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
This page took 0.031491 seconds and 4 git commands to generate.