]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/tui: use correct setting to control asm window styling
authorAndrew Burgess <aburgess@redhat.com>
Mon, 17 Feb 2025 10:51:30 +0000 (10:51 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Mon, 24 Feb 2025 16:57:24 +0000 (16:57 +0000)
Currently the TUI's asm window uses `source_styling` to control
styling.  This setting is supposed to be for styling of source files
though, and the asm window displays disassembler output.

We have a different setting for this `disassemble_styling`, which is
controlled with 'set style disassembler enabled on|off'.

Switch to use the correct control variable.

I've written a new test for this, but this required some additions to
the tuiterm library in order to grab character attributes for a screen
region.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/testsuite/gdb.tui/tui-disasm-styling.exp [new file with mode: 0644]
gdb/testsuite/lib/tuiterm.exp
gdb/tui/tui-disasm.c

diff --git a/gdb/testsuite/gdb.tui/tui-disasm-styling.exp b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp
new file mode 100644 (file)
index 0000000..513d787
--- /dev/null
@@ -0,0 +1,65 @@
+# Copyright 2025 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/>.
+
+# Test that disassembler styling can be switched off.
+
+require allow_tui_tests
+
+tuiterm_env
+
+standard_testfile tui-layout.c
+
+if {[build_executable "failed to build" ${testfile} ${srcfile}] == -1} {
+    return
+}
+
+# Grab the contents of the asm box and check for styling.  If
+# EXPECT_STYLED is true then expect styling in the asm box, otherwise,
+# don't expect styling.
+
+proc check_asm_output { expect_styled testname } {
+    set asm_output [Term::get_region 1 1 78 13 "\n" true]
+    set has_styling [regexp -- "<fg:" $asm_output]
+    # The !! converts the booleans to a canonical form for comparison.
+    gdb_assert { [expr !!$has_styling == !!$expect_styled] } \
+       $testname
+}
+
+Term::clean_restart 24 80 $binfile
+if {![Term::enter_tui]} {
+    unsupported "TUI not supported"
+    return
+}
+
+Term::command "layout asm"
+Term::check_box "asm box" 0 0 80 15
+
+check_asm_output true "asm output is styled by default"
+
+Term::command "set style disassembler enabled off"
+check_asm_output false \
+    "asm output is not styled when disassembler styling is off"
+
+Term::command "set style disassembler enabled on"
+check_asm_output true "asm output is styled again"
+
+Term::command "set style enabled off"
+check_asm_output false "asm output is not styled when global switch is off"
+
+Term::command "set style enabled on"
+check_asm_output true "asm output is styled once again"
+
+Term::command "set style sources off"
+check_asm_output true "asm output is styled when source styling is off"
index 0c4e3d10003b1bca002d18f8f33d4f15ccf4f660..4aa1ea27d6d7fb04439d3019b919c606f6e88538 100644 (file)
@@ -1133,11 +1133,16 @@ namespace eval Term {
        gdb_assert {![regexp -- $regexp $contents]} $test_name
     }
 
-    # Get the region of the screen described by X, Y, WIDTH,
-    # and HEIGHT, and separate the lines using SEP.
-    proc get_region { x y width height sep } {
+    # Get the region of the screen described by X, Y, WIDTH, and
+    # HEIGHT, and separate the lines using SEP.  If ATTRS is true then
+    # include attribute information in the output.
+    proc get_region { x y width height sep { attrs false } } {
        variable _chars
 
+       if { $attrs } {
+           _reset_attrs region_attrs
+       }
+
        # Grab the contents of the box, join each line together
        # using $sep.
        set result ""
@@ -1148,9 +1153,19 @@ namespace eval Term {
                append result $sep
            }
            for {set xx $x} {$xx < [expr {$x + $width}]} {incr xx} {
-               append result [lindex $_chars($xx,$yy) 0]
+               if { $attrs } {
+                   set char_attrs [lindex $_chars($xx,$yy) 1]
+                   append result [apply_attrs region_attrs $char_attrs]
+               }
+
+               append result [get_char $xx $yy]
            }
        }
+       if { $attrs } {
+           _reset_attrs zero_attrs
+           set char_attrs [array get zero_attrs]
+           append result [apply_attrs region_attrs $char_attrs]
+       }
        return $result
     }
 
index f45c30c109bd0135327e981c5657b85c853cfa8a..bb1ff7bc93155daab88ed0c60e9094b7872812c9 100644 (file)
@@ -98,7 +98,7 @@ tui_disassemble (struct gdbarch *gdbarch,
                 CORE_ADDR pc, int count,
                 size_t *addr_size = nullptr)
 {
-  bool term_out = source_styling && gdb_stdout->can_emit_style_escape ();
+  bool term_out = disassembler_styling && gdb_stdout->can_emit_style_escape ();
   string_file gdb_dis_out (term_out);
 
   /* Must start with an empty list.  */