Simplify TUI C-x 2 binding
[deliverable/binutils-gdb.git] / gdb / tui / tui-source.c
index 0728263b8c5f180fdc5b425473d80861774baf7a..3c7a8e10008c84a8bbef531c35345f6350eff8ce 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.
 
@@ -55,7 +55,7 @@ tui_source_window::set_contents (struct gdbarch *arch,
   line_width = width - TUI_EXECINFO_SIZE - 1;
   /* Take hilite (window border) into account, when
      calculating the number of lines.  */
-  nlines = (line_no + (height - 2)) - line_no;
+  nlines = height - 2;
 
   std::string srclines;
   const std::vector<off_t> *offsets;
@@ -136,28 +136,31 @@ 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;
+      find_line_pc (cursal.symtab, cursal.line, &cursal.pc);
+      for (struct tui_source_window_base *win_info : tui_source_windows ())
+       win_info->update_source_window_as_is (arch, cursal);
     }
 }
 
@@ -176,24 +179,23 @@ 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
 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;
 
This page took 0.024438 seconds and 4 git commands to generate.