Patchwork [RFC,8.3,1/3] Make TUI react to "set style enabled"

login
register
mail settings
Submitter Pedro Alves
Date March 13, 2019, 7:28 p.m.
Message ID <e51850d9-405c-2372-c25e-83f4b2edbaf6@redhat.com>
Download mbox | patch
Permalink /patch/31844/
State New
Headers show

Comments

Pedro Alves - March 13, 2019, 7:28 p.m.
On 03/08/2019 09:04 PM, Tom Tromey wrote:
> When the user toggles "set style enabled", the TUI should react by
> redrawing the source window, if necessary.  This patch implements this
> behavior.
> 
> No test because the TUI is generally not tested.
> 
> I was not sure of a clean way to force an update of the window's
> contents; see the new tui_redisplay_source for the workaround I used.

I went looking, and thought that it could be:

  tui_show_source_content (tui_win_list[SRC_WIN]);

That's what tui_refresh_all_win, coming from Ctrl-L, does.

But that won't work I think because we'd just refresh the current
source code cache, which includes the previous/now-stale
highlighting mode.

Maybe something like this?

From 5b7c86c6666ddc16b206fe04a492e99a33570a7f Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Wed, 13 Mar 2019 18:14:14 +0000
Subject: [PATCH] refactor

---
 gdb/tui/tui-hooks.c     |  2 +-
 gdb/tui/tui-winsource.c | 44 +++++++++++++++++++++++++-------------------
 gdb/tui/tui-winsource.h |  1 +
 3 files changed, 27 insertions(+), 20 deletions(-)
Tom Tromey - March 14, 2019, 11:43 a.m.
Pedro> Maybe something like this?
[...]

Thanks.  I've incorporated this into the patch.

Tom

Patch

diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c
index 162d6ef525..4a1d79e0ad 100644
--- a/gdb/tui/tui-hooks.c
+++ b/gdb/tui/tui-hooks.c
@@ -212,7 +212,7 @@  tui_redisplay_source ()
   if (tui_is_window_visible (SRC_WIN))
     {
       /* Force redisplay.  */
-      tui_horizontal_source_scroll (tui_win_list[SRC_WIN], LEFT_SCROLL, 0);
+      tui_refill_source_window (tui_win_list[SRC_WIN]);
     }
 }
 
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 9336f7b1f7..ab7756c1c4 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -306,8 +306,32 @@  tui_show_source_content (struct tui_win_info *win_info)
   win_info->generic.content_in_use = TRUE;
 }
 
+/* Refill the source window's source cache and update it.  If WIN_INFO
+   is a disassembly window, then just update it.  */
+
+void
+tui_refill_source_window (struct tui_win_info *win_info)
+{
+  symtab *s = nullptr;
+
+  if (win_info->generic.type == SRC_WIN)
+    {
+      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);
+    }
+
+  tui_update_source_window_as_is (win_info,
+				  win_info->detail.source_info.gdbarch,
+				  s,
+				  win_info->generic.content[0]
+				    ->which_element.source.line_or_addr,
+				  FALSE);
+}
 
 /* Scroll the source forward or backward horizontally.  */
+
 void
 tui_horizontal_source_scroll (struct tui_win_info *win_info,
 			      enum tui_scroll_direction direction,
@@ -315,20 +339,7 @@  tui_horizontal_source_scroll (struct tui_win_info *win_info,
 {
   if (win_info->generic.content != NULL)
     {
-      struct gdbarch *gdbarch = win_info->detail.source_info.gdbarch;
       int offset;
-      struct symtab *s = NULL;
-
-      if (win_info->generic.type == SRC_WIN)
-	{
-	  struct symtab_and_line cursal
-	    = get_current_source_symtab_and_line ();
-
-	  if (cursal.symtab == NULL)
-	    s = find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)));
-	  else
-	    s = cursal.symtab;
-	}
 
       if (direction == LEFT_SCROLL)
 	offset = win_info->detail.source_info.horizontal_offset
@@ -341,13 +352,8 @@  tui_horizontal_source_scroll (struct tui_win_info *win_info,
 	    offset = 0;
 	}
       win_info->detail.source_info.horizontal_offset = offset;
-      tui_update_source_window_as_is (win_info, gdbarch, s,
-				      win_info->generic.content[0]
-					->which_element.source.line_or_addr,
-				      FALSE);
+      tui_refill_source_window (win_info);
     }
-
-  return;
 }
 
 
diff --git a/gdb/tui/tui-winsource.h b/gdb/tui/tui-winsource.h
index db33a4f73e..920032b04e 100644
--- a/gdb/tui/tui-winsource.h
+++ b/gdb/tui/tui-winsource.h
@@ -56,6 +56,7 @@  extern void tui_show_source_content (struct tui_win_info *);
 extern void tui_horizontal_source_scroll (struct tui_win_info *,
 					  enum tui_scroll_direction, 
 					  int);
+extern void tui_refill_source_window (struct tui_win_info *);
 extern enum tui_status tui_set_exec_info_content (struct tui_win_info *);
 extern void tui_show_exec_info_content (struct tui_win_info *);
 extern void tui_erase_exec_info_content (struct tui_win_info *);