gdb/testsuite/dap: prefix some procs with _
[binutils-gdb.git] / gdb / tui / tui-winsource.c
index 2300b9ab1e923a0edbe0816b1dc75c2687e85898..87099ac26f5a0b6045948da6bc1e47d2ecf3ccad 100644 (file)
@@ -1,6 +1,6 @@
 /* TUI display source/assembly window.
 
-   Copyright (C) 1998-2020 Free Software Foundation, Inc.
+   Copyright (C) 1998-2023 Free Software Foundation, Inc.
 
    Contributed by Hewlett-Packard Company.
 
@@ -28,6 +28,7 @@
 #include "source.h"
 #include "objfiles.h"
 #include "filenames.h"
+#include "safe-ctype.h"
 
 #include "tui/tui.h"
 #include "tui/tui-data.h"
@@ -38,6 +39,7 @@
 #include "tui/tui-winsource.h"
 #include "tui/tui-source.h"
 #include "tui/tui-disasm.h"
+#include "tui/tui-location.h"
 #include "gdb_curses.h"
 
 /* Function to display the "main" routine.  */
@@ -57,7 +59,7 @@ tui_display_main ()
 
          tui_update_source_windows_with_addr (gdbarch, addr);
          s = find_pc_line_symtab (addr);
-         tui_update_locator_fullname (s);
+         tui_location.set_location (s);
        }
     }
 }
@@ -107,7 +109,9 @@ tui_copy_source_line (const char **ptr, int *length)
        {
          /* Nothing.  */
        }
-      else if (c < 040 && c != '\t')
+      else if (c == '\t')
+       process_tab ();
+      else if (ISCNTRL (c))
        {
          result.push_back ('^');
          result.push_back (c + 0100);
@@ -119,8 +123,6 @@ tui_copy_source_line (const char **ptr, int *length)
          result.push_back ('?');
          ++column;
        }
-      else if (c == '\t')
-       process_tab ();
       else
        result.push_back (c);
     }
@@ -197,7 +199,7 @@ tui_update_source_windows_with_line (struct symtab_and_line sal)
   if (sal.symtab != nullptr)
     {
       find_line_pc (sal.symtab, sal.line, &sal.pc);
-      gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
+      gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
     }
 
   for (struct tui_source_window_base *win_info : tui_source_windows ())
@@ -249,8 +251,12 @@ tui_source_window_base::show_source_line (int lineno)
 /* See tui-winsource.h.  */
 
 void
-tui_source_window_base::refresh_pad ()
+tui_source_window_base::refresh_window ()
 {
+  /* tui_win_info::refresh_window would draw the empty background window to
+     the screen, potentially creating a flicker.  */
+  wnoutrefresh (handle.get ());
+
   int pad_width = std::max (m_max_length, width);
   int left_margin = 1 + TUI_EXECINFO_SIZE + extra_margin ();
   int view_width = width - left_margin - 1;
@@ -259,7 +265,7 @@ tui_source_window_base::refresh_pad ()
      scrolled beyond where we clip.  */
   m_horizontal_offset = pad_x;
   prefresh (m_pad.get (), 0, pad_x, y + 1, x + left_margin,
-           y + 1 + m_content.size (), x + left_margin + view_width - 1);
+           y + m_content.size (), x + left_margin + view_width - 1);
 }
 
 void
@@ -270,15 +276,14 @@ tui_source_window_base::show_source_content ()
   check_and_display_highlight_if_needed ();
 
   int pad_width = std::max (m_max_length, width);
-  if (m_pad == nullptr || pad_width > getmaxx (m_pad.get ()))
+  if (m_pad == nullptr || pad_width > getmaxx (m_pad.get ())
+      || m_content.size () > getmaxy (m_pad.get ()))
     m_pad.reset (newpad (m_content.size (), pad_width));
 
   werase (m_pad.get ());
   for (int lineno = 0; lineno < m_content.size (); lineno++)
     show_source_line (lineno);
 
-  refresh_pad ();
-
   refresh_window ();
 }
 
@@ -287,14 +292,14 @@ tui_source_window_base::tui_source_window_base ()
   m_start_line_or_addr.loa = LOA_ADDRESS;
   m_start_line_or_addr.u.addr = 0;
 
-  gdb::observers::source_styling_changed.attach
+  gdb::observers::styling_changed.attach
     (std::bind (&tui_source_window::style_changed, this),
-     m_observable);
+     m_observable, "tui-winsource");
 }
 
 tui_source_window_base::~tui_source_window_base ()
 {
-  gdb::observers::source_styling_changed.detach (m_observable);
+  gdb::observers::styling_changed.detach (m_observable);
 }
 
 /* See tui-data.h.  */
@@ -324,7 +329,7 @@ tui_source_window_base::rerender ()
     {
       struct symtab_and_line cursal
        = get_current_source_symtab_and_line ();
-      struct frame_info *frame = deprecated_safe_get_selected_frame ();
+      frame_info_ptr frame = deprecated_safe_get_selected_frame ();
       struct gdbarch *gdbarch = get_frame_arch (frame);
 
       struct symtab *s = find_pc_line_symtab (get_frame_pc (frame));
@@ -348,7 +353,7 @@ tui_source_window_base::refill ()
       sal = get_current_source_symtab_and_line ();
       if (sal.symtab == NULL)
        {
-         struct frame_info *fi = deprecated_safe_get_selected_frame ();
+         frame_info_ptr fi = deprecated_safe_get_selected_frame ();
          if (fi != nullptr)
            sal = find_pc_line (get_frame_pc (fi), 0);
        }
@@ -376,7 +381,7 @@ tui_source_window_base::do_scroll_horizontal (int num_to_scroll)
       if (offset < 0)
        offset = 0;
       m_horizontal_offset = offset;
-      refresh_pad ();
+      refresh_window ();
     }
 }
 
@@ -399,15 +404,15 @@ tui_source_window_base::set_is_exec_point_at (struct tui_line_or_address l)
 
       if (content_loa.loa == l.loa
          && ((l.loa == LOA_LINE && content_loa.u.line_no == l.u.line_no)
-              || (l.loa == LOA_ADDRESS && content_loa.u.addr == l.u.addr)))
-        new_state = true;
+             || (l.loa == LOA_ADDRESS && content_loa.u.addr == l.u.addr)))
+       new_state = true;
       else
        new_state = false;
       if (new_state != m_content[i].is_exec_point)
-        {
-          changed = true;
-          m_content[i].is_exec_point = new_state;
-        }
+       {
+         changed = true;
+         m_content[i].is_exec_point = new_state;
+       }
       i++;
     }
   if (changed)
@@ -446,20 +451,18 @@ tui_source_window_base::update_breakpoint_info
 
       line = &m_content[i];
       if (current_only && !line->is_exec_point)
-         continue;
+        continue;
 
       /* Scan each breakpoint to see if the current line has something to
-         do with it.  Identify enable/disabled breakpoints as well as
-         those that we already hit.  */
+        do with it.  Identify enable/disabled breakpoints as well as
+        those that we already hit.  */
       tui_bp_flags mode = 0;
-      iterate_over_breakpoints ([&] (breakpoint *bp) -> bool
-        {
-         struct bp_location *loc;
-
+      for (breakpoint *bp : all_breakpoints ())
+       {
          if (bp == being_deleted)
-           return false;
+           continue;
 
-         for (loc = bp->loc; loc != NULL; loc = loc->next)
+         for (bp_location *loc : bp->locations ())
            {
              if (location_matches_p (loc, i))
                {
@@ -475,13 +478,13 @@ tui_source_window_base::update_breakpoint_info
                    mode |= TUI_BP_HARDWARE;
                }
            }
-         return false;
-        });
+       }
+
       if (line->break_mode != mode)
-        {
-          line->break_mode = mode;
-          need_refresh = true;
-        }
+       {
+         line->break_mode = mode;
+         need_refresh = true;
+       }
     }
   return need_refresh;
 }