[3/3,gdb/tui] Add set tui contents-highlight on/off

Message ID 20230516084352.27225-4-tdevries@suse.de
State New
Headers
Series Allow highlighting in windows contents to be switched off |

Commit Message

Tom de Vries May 16, 2023, 8:43 a.m. UTC
  TUI highlights various parts of TUI windows:
- highlighting of the current execution point in the assembly and source
  windows,
- highlighting of changed registers in the register window.

Add a new command "set tui contents-highlight on/off" that allows us to disable
this.

The default is on, so there's no change in behaviour.

Note that the highlighting in all three windows is shadowed by the ">" marker,
so we're not losing information by switching off the highlighting.

Tested on x86_64-linux.
---
 gdb/doc/gdb.texinfo              |  7 ++++
 gdb/testsuite/gdb.tui/source.exp | 59 ++++++++++++++++++++++++++++++++
 gdb/tui/tui-regs.c               |  4 +--
 gdb/tui/tui-regs.h               |  4 +--
 gdb/tui/tui-win.c                | 39 +++++++++++++++++++++
 gdb/tui/tui-win.h                |  4 +++
 gdb/tui/tui-winsource.c          |  4 +--
 7 files changed, 115 insertions(+), 6 deletions(-)
 create mode 100644 gdb/testsuite/gdb.tui/source.exp
  

Comments

Eli Zaretskii May 16, 2023, 3:02 p.m. UTC | #1
> Cc: Tom Tromey <tom@tromey.com>
> Date: Tue, 16 May 2023 10:43:52 +0200
> From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
> 
> TUI highlights various parts of TUI windows:
> - highlighting of the current execution point in the assembly and source
>   windows,
> - highlighting of changed registers in the register window.
> 
> Add a new command "set tui contents-highlight on/off" that allows us to disable
> this.
> 
> The default is on, so there's no change in behaviour.
> 
> Note that the highlighting in all three windows is shadowed by the ">" marker,
> so we're not losing information by switching off the highlighting.
> 
> Tested on x86_64-linux.
> ---
>  gdb/doc/gdb.texinfo              |  7 ++++
>  gdb/testsuite/gdb.tui/source.exp | 59 ++++++++++++++++++++++++++++++++
>  gdb/tui/tui-regs.c               |  4 +--
>  gdb/tui/tui-regs.h               |  4 +--
>  gdb/tui/tui-win.c                | 39 +++++++++++++++++++++
>  gdb/tui/tui-win.h                |  4 +++
>  gdb/tui/tui-winsource.c          |  4 +--
>  7 files changed, 115 insertions(+), 6 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.tui/source.exp

The documentation part is OK, thanks.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
  

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 77bc4323912..836cf9623ad 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -30322,6 +30322,13 @@  The default display uses more space for line numbers; the compact
 display uses only as much space as is needed for the line numbers in
 the current file.
 
+@item set tui contents-highlight @r{[}on@r{|}off@r{]}
+@kindex set tui contents-highlight
+Determine whether TUI windows contents is highlighted, such as highlighting
+of the current execution point in the assembly and source windows,
+and highlighting of changed registers in the register window.  The
+default is @code{on}.
+
 @kindex set debug tui
 @item set debug tui @r{[}on|off@r{]}
 Turn on or off display of @value{GDBN} internal debug messages relating
diff --git a/gdb/testsuite/gdb.tui/source.exp b/gdb/testsuite/gdb.tui/source.exp
new file mode 100644
index 00000000000..d6b231dc43f
--- /dev/null
+++ b/gdb/testsuite/gdb.tui/source.exp
@@ -0,0 +1,59 @@ 
+# Copyright 2023 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that "set tui compact-source on" has the intended effect.
+
+require allow_tui_tests
+
+tuiterm_env
+
+standard_testfile main-one-line.c
+
+if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
+    return -1
+}
+
+Term::clean_restart 24 80 $binfile
+
+gdb_test_no_output "maint set tui-left-margin-verbose on"
+
+if { ![runto_main] } {
+    return -1
+}
+
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+    return
+}
+
+
+set screen_line_with_main 6
+set screen_line [Term::get_line_with_attrs $screen_line_with_main]
+
+set src_line_with_main [gdb_get_line_number "int main"]
+
+set re "int main () { return 0; }"
+set re "${src_line_with_main}_<reverse:1>$re<reverse:0>"
+set re [string_to_regexp $re]
+gdb_assert { [regexp $re $screen_line] == 1} "src line: reverse"
+
+Term::command "set tui contents-highlight off"
+Term::command "set style enabled off"
+set screen_line [Term::get_line_with_attrs $screen_line_with_main]
+
+set re "int main () { return 0; }"
+set re "${src_line_with_main}_$re "
+set re [string_to_regexp $re]
+gdb_assert { [regexp $re $screen_line] == 1} "src line: normal"
diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c
index af3b21b0f9d..43724d9dd14 100644
--- a/gdb/tui/tui-regs.c
+++ b/gdb/tui/tui-regs.c
@@ -487,7 +487,7 @@  tui_data_window::check_register_values (frame_info_ptr frame)
 void
 tui_data_item_window::rerender (WINDOW *handle, int field_width)
 {
-  if (highlight)
+  if (tui_contents_highlight && highlight)
     /* We ignore the return value, casting it to void in order to avoid
        a compiler warning.  The warning itself was introduced by a patch
        to ncurses 5.7 dated 2009-08-29, changing this macro to expand
@@ -540,7 +540,7 @@  tui_data_item_window::rerender (WINDOW *handle, int field_width)
   if (content.size () < field_width)
     waddstr (handle, n_spaces (field_width - content.size ()));
 
-  if (highlight)
+  if (tui_contents_highlight && highlight)
     /* We ignore the return value, casting it to void in order to avoid
        a compiler warning.  The warning itself was introduced by a patch
        to ncurses 5.7 dated 2009-08-29, changing this macro to expand
diff --git a/gdb/tui/tui-regs.h b/gdb/tui/tui-regs.h
index 5adff6300aa..e0f299d4410 100644
--- a/gdb/tui/tui-regs.h
+++ b/gdb/tui/tui-regs.h
@@ -68,6 +68,8 @@  struct tui_data_window : public tui_win_info
     return m_current_group;
   }
 
+  void rerender () override;
+
 protected:
 
   void do_scroll_vertical (int num_to_scroll) override;
@@ -75,8 +77,6 @@  struct tui_data_window : public tui_win_info
   {
   }
 
-  void rerender () override;
-
 private:
 
   /* Display the registers in the content from 'start_element_no'
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index 7926e2d7a18..e0ad6551c59 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -916,6 +916,33 @@  tui_show_tab_width (struct ui_file *file, int from_tty,
 
 /* See tui-win.h.  */
 
+bool tui_contents_highlight = true;
+
+static void
+show_tui_contents_highlight (ui_file *file,
+				 int from_tty,
+				 cmd_list_element *c,
+				 const char *value)
+{
+  gdb_printf (file, _("\
+Highlighting TUI windows content is %s.\n"),
+	      value);
+}
+
+static void
+set_tui_contents_highlight (const char *ignore, int from_tty,
+			    cmd_list_element *c)
+{
+  if (TUI_SRC_WIN != nullptr)
+    TUI_SRC_WIN->refill ();
+  if (TUI_DISASM_WIN != nullptr)
+    TUI_DISASM_WIN->refill ();
+  if (TUI_DATA_WIN != nullptr)
+    TUI_DATA_WIN->rerender ();
+}
+
+/* See tui-win.h.  */
+
 bool compact_source = false;
 
 /* Callback for "set tui compact-source".  */
@@ -1330,6 +1357,18 @@  in a compact form.  The compact form uses less horizontal space."),
 			   tui_set_compact_source, tui_show_compact_source,
 			   &tui_setlist, &tui_showlist);
 
+  add_setshow_boolean_cmd ("contents-highlight", class_tui,
+			   &tui_contents_highlight, _("\
+Set whether TUI windows contents is highlighted."), _("\
+Show whether TUI windows contents is highlighted."), _("\
+Determine whether TUI windows contents is highlighted, such as highlighting\n\
+of the current execution point in the assembly and source windows,\n\
+highlighting of the status window, and highlighting of changed registers in\n\
+the register window."),
+			   set_tui_contents_highlight,
+			   show_tui_contents_highlight,
+			   &tui_setlist, &tui_showlist);
+
   add_setshow_boolean_cmd ("tui-current-position", class_maintenance,
 			   &style_tui_current_position, _("\
 Set whether to style text highlighted by the TUI's current position indicator."),
diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h
index 5ace83a742a..ab1a4e177a9 100644
--- a/gdb/tui/tui-win.h
+++ b/gdb/tui/tui-win.h
@@ -61,4 +61,8 @@  extern bool style_tui_current_position;
 /* Whether to replace the spaces in the left margin with '_' and '0'.  */
 extern bool tui_left_margin_verbose;
 
+/* Whether to highlight various parts of the windows content using standout
+   and reverse.  */
+extern bool tui_contents_highlight;
+
 #endif /* TUI_TUI_WIN_H */
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 3c4ce501e5e..f245eecc965 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -301,13 +301,13 @@  tui_source_window_base::show_source_line (int lineno)
   struct tui_source_element *line;
 
   line = &m_content[lineno];
-  if (line->is_exec_point)
+  if (tui_contents_highlight && line->is_exec_point)
     tui_set_reverse_mode (m_pad.get (), true);
 
   wmove (m_pad.get (), lineno, 0);
   puts_to_pad_with_skip (line->line.c_str (), m_pad_offset);
 
-  if (line->is_exec_point)
+  if (tui_contents_highlight && line->is_exec_point)
     tui_set_reverse_mode (m_pad.get (), false);
 }