Make TUI react to "set style enabled"
authorTom Tromey <tromey@adacore.com>
Fri, 8 Mar 2019 20:41:55 +0000 (13:41 -0700)
committerTom Tromey <tromey@adacore.com>
Thu, 14 Mar 2019 11:47:10 +0000 (05:47 -0600)
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.

This version of the patch incorporates Pedro's patch to provide a
clean way to force the TUI to update the source window's contents.

gdb/ChangeLog
2019-03-14  Pedro Alves  <palves@redhat.com>
    Tom Tromey  <tromey@adacore.com>

* tui/tui-winsource.h (tui_refill_source_window): Declare.
* tui/tui-winsource.c (tui_refill_source_window): New function,
from...
(tui_horizontal_source_scroll): ... here.  Move some logic.
* cli/cli-style.c (set_style_enabled): Notify new observable.
* tui/tui-hooks.c (tui_redisplay_source): New function.
(tui_attach_detach_observers): Attach or detach
tui_redisplay_source.
* observable.h (source_styling_changed): New observable.
* observable.c: Define source_styling_changed observable.

gdb/ChangeLog
gdb/cli/cli-style.c
gdb/observable.c
gdb/observable.h
gdb/tui/tui-hooks.c
gdb/tui/tui-winsource.c
gdb/tui/tui-winsource.h

index 24de651bf92838b7a0f3fb10286f2a10f99cbc92..2fcd6cdb388d9c0f05981dfb240d93a906424bfb 100644 (file)
@@ -1,3 +1,17 @@
+2019-03-14  Pedro Alves  <palves@redhat.com>
+           Tom Tromey  <tromey@adacore.com>
+
+       * tui/tui-winsource.h (tui_refill_source_window): Declare.
+       * tui/tui-winsource.c (tui_refill_source_window): New function,
+       from...
+       (tui_horizontal_source_scroll): ... here.  Move some logic.
+       * cli/cli-style.c (set_style_enabled): Notify new observable.
+       * tui/tui-hooks.c (tui_redisplay_source): New function.
+       (tui_attach_detach_observers): Attach or detach
+       tui_redisplay_source.
+       * observable.h (source_styling_changed): New observable.
+       * observable.c: Define source_styling_changed observable.
+
 2019-03-13  Tom Tromey  <tromey@adacore.com>
 
        * i386-gnu-nat.c (i386_gnu_nat_target::fetch_registers)
index ec385dae8a168cfc0446de24e3bbb7ae49243e38..fc91504d1f8f9b0e5e195e014d9084dc0ce164dd 100644 (file)
@@ -21,6 +21,7 @@
 #include "cli/cli-cmds.h"
 #include "cli/cli-style.h"
 #include "source-cache.h"
+#include "observable.h"
 
 /* True if styling is enabled.  */
 
@@ -216,6 +217,7 @@ static void
 set_style_enabled  (const char *args, int from_tty, struct cmd_list_element *c)
 {
   g_source_cache.clear ();
+  gdb::observers::source_styling_changed.notify ();
 }
 
 static void
index 331120624248f4d1e3a63036d3ee07c1058ba13e..c077b025932664a0a381c71a1f2a6bffe988b750 100644 (file)
@@ -74,6 +74,7 @@ DEFINE_OBSERVABLE (inferior_call_pre);
 DEFINE_OBSERVABLE (inferior_call_post);
 DEFINE_OBSERVABLE (register_changed);
 DEFINE_OBSERVABLE (user_selected_context_changed);
+DEFINE_OBSERVABLE (source_styling_changed);
 
 } /* namespace observers */
 } /* namespace gdb */
index 999ecfbc3535aacd1f7729dc50e2623c3a367569..edd1fffae0ac38223e01d5915f401bfd695f5be4 100644 (file)
@@ -228,6 +228,10 @@ extern observable<struct frame_info *, int> register_changed;
    frame has changed.  */
 extern observable<user_selected_what> user_selected_context_changed;
 
+/* This is notified when the source styling setting has changed and
+   should be reconsulted.  */
+extern observable<> source_styling_changed;
+
 } /* namespace observers */
 
 } /* namespace gdb */
index 98c6fd651fa48c58a8870eb16bccc54d98fec4f4..4a1d79e0ad0b8aaf19b416665595a6565d320fb7 100644 (file)
@@ -204,6 +204,18 @@ tui_normal_stop (struct bpstats *bs, int print_frame)
   tui_refresh_frame_and_register_information (/*registers_too_p=*/1);
 }
 
+/* Observer for source_cache_cleared.  */
+
+static void
+tui_redisplay_source ()
+{
+  if (tui_is_window_visible (SRC_WIN))
+    {
+      /* Force redisplay.  */
+      tui_refill_source_window (tui_win_list[SRC_WIN]);
+    }
+}
+
 /* Token associated with observers registered while TUI hooks are
    installed.  */
 static const gdb::observers::token tui_observers_token {};
@@ -239,6 +251,8 @@ tui_attach_detach_observers (bool attach)
                    tui_normal_stop, attach);
   attach_or_detach (gdb::observers::register_changed,
                    tui_register_changed, attach);
+  attach_or_detach (gdb::observers::source_styling_changed,
+                   tui_redisplay_source, attach);
 }
 
 /* Install the TUI specific hooks.  */
index 9336f7b1f76be04dde540e56ba1abf15206c8bbd..7fd460bde3f1cf9d11a774c657514c71bc679d5d 100644 (file)
@@ -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;
 }
 
 
index db33a4f73ef6f9bdabfdab586395a631a94eab24..920032b04eac31bf328ecb88e770f83b8535469e 100644 (file)
@@ -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 *);
This page took 0.036312 seconds and 4 git commands to generate.