diff options
author | Andrew Burgess <aburgess@redhat.com> | 2025-02-17 10:51:30 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2025-02-24 16:57:24 +0000 |
commit | dbfac07a71613288529d4b40c9a48ad76c19b360 (patch) | |
tree | 5a40c3da1238ebdceb742f30821a5058f428444e | |
parent | 4fd9516e3300249a9fe90d5c7ba6b63ba3058857 (diff) | |
download | binutils-dbfac07a71613288529d4b40c9a48ad76c19b360.zip binutils-dbfac07a71613288529d4b40c9a48ad76c19b360.tar.gz binutils-dbfac07a71613288529d4b40c9a48ad76c19b360.tar.bz2 |
gdb/tui: use correct setting to control asm window styling
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>
-rw-r--r-- | gdb/testsuite/gdb.tui/tui-disasm-styling.exp | 65 | ||||
-rw-r--r-- | gdb/testsuite/lib/tuiterm.exp | 23 | ||||
-rw-r--r-- | gdb/tui/tui-disasm.c | 2 |
3 files changed, 85 insertions, 5 deletions
diff --git a/gdb/testsuite/gdb.tui/tui-disasm-styling.exp b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp new file mode 100644 index 0000000..513d787 --- /dev/null +++ b/gdb/testsuite/gdb.tui/tui-disasm-styling.exp @@ -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" diff --git a/gdb/testsuite/lib/tuiterm.exp b/gdb/testsuite/lib/tuiterm.exp index 0c4e3d1..4aa1ea2 100644 --- a/gdb/testsuite/lib/tuiterm.exp +++ b/gdb/testsuite/lib/tuiterm.exp @@ -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 } diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index f45c30c..bb1ff7b 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -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. */ |