aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorAndrei Pikas <gdb@mail.api.win>2024-10-05 22:27:44 +0300
committerTom Tromey <tom@tromey.com>2025-01-12 13:30:43 -0700
commit6447969d0ac774b6dec0f95a0d3d27c27d158690 (patch)
treee9812cfdd956f4c8e89f596b276ddc1c4ad8da45 /gdb/testsuite
parent338e0b05d8f2dd404eb0015bee31461dfe5ba307 (diff)
downloadbinutils-6447969d0ac774b6dec0f95a0d3d27c27d158690.zip
binutils-6447969d0ac774b6dec0f95a0d3d27c27d158690.tar.gz
binutils-6447969d0ac774b6dec0f95a0d3d27c27d158690.tar.bz2
Add an option with a color type.
Colors can be specified as "none" for terminal's default color, as a name of one of the eight standard colors of ISO/IEC 6429 "black", "red", "green", etc., as an RGB hexadecimal tripplet #RRGGBB for 24-bit TrueColor, or as an integer from 0 to 255. Integers 0 to 7 are the synonyms for the standard colors. Integers 8-15 are used for the so-called bright colors from the aixterm extended 16-color palette. Integers 16-255 are the indexes into xterm extended 256-color palette (usually 6x6x6 cube plus gray ramp). In general, 256-color palette is terminal dependent and sometimes can be changed with OSC 4 sequences, e.g. "\033]4;1;rgb:00/FF/00\033\\". It is the responsibility of the user to verify that the terminal supports the specified colors. PATCH v5 changes: documentation fixed. PATCH v6 changes: documentation fixed. PATCH v7 changes: rebase onto master and fixes after review. PATCH v8 changes: fixes after review.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.base/default.exp8
-rw-r--r--gdb/testsuite/gdb.base/style.exp197
-rw-r--r--gdb/testsuite/gdb.guile/scm-color.exp110
-rw-r--r--gdb/testsuite/gdb.guile/scm-parameter.exp47
-rw-r--r--gdb/testsuite/gdb.python/py-color.exp100
-rw-r--r--gdb/testsuite/gdb.python/py-parameter.exp53
-rw-r--r--gdb/testsuite/lib/gdb-utils.exp26
-rw-r--r--gdb/testsuite/lib/gdb.exp3
8 files changed, 530 insertions, 14 deletions
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index bbc95aa..f36def7 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -15,8 +15,11 @@
# Start with a fresh gdb
-gdb_exit
-gdb_start
+with_ansi_styling_terminal {
+ setenv TERM dumb
+ gdb_exit
+ gdb_start
+}
set prev_timeout $timeout
set timeout 60
@@ -684,6 +687,7 @@ set show_conv_list \
{$_probe_arg10 = <error: No frame selected>} \
{$_probe_arg11 = <error: No frame selected>} \
{$_cimag = <internal function _cimag>} \
+ {$_colorsupport = "monochrome"} \
{$_creal = <internal function _creal>} \
{$_isvoid = <internal function _isvoid>} \
{$_shell = <internal function _shell>} \
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 628c6b8..b027ab7 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -70,6 +70,9 @@ proc run_style_tests { } {
global currently_disabled_style decimal hex
with_ansi_styling_terminal {
+ setenv TERM xterm-256color
+ setenv COLORTERM truecolor
+
# Restart GDB with the correct TERM variable setting, this
# means that GDB will enable styling.
clean_restart_and_disable "restart 1" ${binfile}
@@ -311,6 +314,21 @@ proc run_style_tests { } {
set url [limited_style "http:.*html" file]
gdb_test "show version" "${vers}.*<$url>.*" \
"'show version' is styled"
+
+ if { $currently_disabled_style != "version" } {
+ # Check that colors in styling can be set as integer and as RGB hex
+ # triplet. Check that the version string is styled in the output of
+ # 'show version' according to the set colors.
+ gdb_test_no_output "set style version intensity normal"
+ gdb_test_no_output "set style version background 255"
+ gdb_test_no_output "set style version foreground #FED210"
+ gdb_test "show style version background" \
+ "The \033\\\[38;2;254;210;16;48;5;255;22;27m.*\".*version.*\".*style.*\033\\\[m background color is: 255" \
+ "Version's 256-color background style"
+ gdb_test "show style version foreground" \
+ "The \033\\\[38;2;254;210;16;48;5;255;22;27m.*\".*version.*\".*style.*\033\\\[m foreground color is: #FED210" \
+ "Version's TrueColor foreground style"
+ }
}
}
@@ -487,6 +505,179 @@ proc test_startup_version_string { } {
gdb_test "" "${vers}.*" "version is styled at startup"
}
+# Color support is disabled when TERM=dumb and COLORTERM="".
+# All colors are approximated to none when set.
+proc test_colorsupport_monochrome { } {
+ with_test_prefix "colorsupport_monochrome" {
+ with_ansi_styling_terminal {
+ setenv TERM dumb
+ gdb_exit
+ gdb_start
+ gdb_test "print \$_colorsupport" \
+ "\\\$1 = \"monochrome\"" \
+ "color support is monochrome"
+ gdb_test_no_output "set style enabled off"
+ gdb_test_no_output "set style filename foreground none"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: none" \
+ "none without approximation"
+ gdb_test_no_output "set style filename foreground blue"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: none" \
+ "blue approximated to none"
+ }
+ }
+}
+
+# Color support is limited by 8 colors when TERM=ansi and COLORTERM="".
+# All colors are approximated to basic colors when set.
+proc test_colorsupport_8color { } {
+ with_test_prefix "colorsupport_8color" {
+ with_ansi_styling_terminal {
+ gdb_exit
+ gdb_start
+ gdb_test "print \$_colorsupport" \
+ "\033\\\[.*m\\\$1\033\\\[m = \"monochrome,ansi_8color\"" \
+ "color support is 8 color"
+ gdb_test_no_output "set style enabled off"
+ gdb_test_no_output "set style filename foreground none"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: none" \
+ "none without approximation"
+ gdb_test_no_output "set style filename foreground yellow"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: yellow" \
+ "yellow without approximation"
+ gdb_test_no_output "set style filename foreground 9"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: red" \
+ "9 approximated to red"
+ gdb_test_no_output "set style filename foreground 118"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: green" \
+ "118 approximated to green"
+ gdb_test_no_output "set style filename foreground #000ABC"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: blue" \
+ "#000ABC approximated to blue"
+ }
+ }
+}
+
+# Color support is limited by 256 colors when TERM=xterm-256color and
+# COLORTERM="". All colors are approximated by 256 color palette when set.
+proc test_colorsupport_256color { } {
+ with_test_prefix "colorsupport_256color" {
+ with_ansi_styling_terminal {
+ setenv TERM xterm-256color
+ gdb_exit
+ gdb_start
+ gdb_test "print \$_colorsupport" \
+ "\033\\\[.*m\\\$1\033\\\[m = \"monochrome,ansi_8color,aixterm_16color,xterm_256color\"" \
+ "color support is 256 color"
+ gdb_test_no_output "set style enabled off"
+ gdb_test_no_output "set style filename foreground none"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: none" \
+ "none without approximation"
+ gdb_test_no_output "set style filename foreground red"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: red" \
+ "red without approximation"
+ gdb_test_no_output "set style filename foreground 9"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: 9" \
+ "9 without approximation"
+ gdb_test_no_output "set style filename foreground 118"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: 118" \
+ "118 without approximation"
+ gdb_test_no_output "set style filename foreground #CD00CD"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: 5" \
+ "#CD00CD approximated to 5"
+ gdb_test_no_output "set style filename foreground #FFAF12"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: 214" \
+ "#FFAF12 approximated to 214"
+ }
+ }
+}
+
+# Color support is limited by 16777216 colors when TERM=xterm-256color and
+# COLORTERM="truecolor". No approximation needed.
+proc test_colorsupport_truecolor { } {
+ with_test_prefix "colorsupport_truecolor" {
+ with_ansi_styling_terminal {
+ setenv TERM xterm-256color
+ setenv COLORTERM truecolor
+ gdb_exit
+ gdb_start
+ gdb_test "print \$_colorsupport" \
+ "\033\\\[.*m\\\$1\033\\\[m = \"monochrome,ansi_8color,aixterm_16color,xterm_256color,rgb_24bit\"" \
+ "color support is truecolor"
+ gdb_test_no_output "set style enabled off"
+ gdb_test_no_output "set style filename foreground none"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: none" \
+ "none without approximation"
+ gdb_test_no_output "set style filename foreground red"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: red" \
+ "red without approximation"
+ gdb_test_no_output "set style filename foreground 9"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: 9" \
+ "9 without approximation"
+ gdb_test_no_output "set style filename foreground 118"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: 118" \
+ "118 without approximation"
+ gdb_test_no_output "set style filename foreground #CD00CD"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: #CD00CD" \
+ "#CD00CD without approximation"
+ }
+ }
+}
+
+# Color support is limited by 16777216 colors when TERM=dumb and
+# COLORTERM=24bit. No approximation needed. Basic colors replaced with RGB.
+proc test_colorsupport_truecolor_only { } {
+ with_test_prefix "colorsupport_truecolor_only" {
+ with_ansi_styling_terminal {
+ setenv TERM dumb
+ setenv COLORTERM truecolor
+ gdb_exit
+ gdb_start
+ gdb_test "print \$_colorsupport" \
+ "\\\$1 = \"monochrome,rgb_24bit\"" \
+ "color support is truecolor only"
+ gdb_test_no_output "set style enabled off"
+ gdb_test_no_output "set style filename foreground none"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: none" \
+ "none without approximation"
+ gdb_test_no_output "set style filename foreground red"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: #DE382B" \
+ "red replaced by #DE382B"
+ gdb_test_no_output "set style filename foreground 9"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: #FF0000" \
+ "9 replaced by #FF0000"
+ gdb_test_no_output "set style filename foreground 118"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: #87FF00" \
+ "118 replaced by #87FF00"
+ gdb_test_no_output "set style filename foreground #CD00CD"
+ gdb_test "show style filename foreground" \
+ "The \"filename\" style foreground color is: #CD00CD" \
+ "#CD00CD without approximation"
+ }
+ }
+}
+
# Check to see if the Python styling of disassembler output is
# expected or not, this styling requires Python support in GDB, and
# the Python pygments module to be available.
@@ -521,3 +712,9 @@ test_disassembler_error_handling
# Finally, check the styling of the version string during startup.
test_startup_version_string
+
+test_colorsupport_monochrome
+test_colorsupport_8color
+test_colorsupport_256color
+test_colorsupport_truecolor
+test_colorsupport_truecolor_only
diff --git a/gdb/testsuite/gdb.guile/scm-color.exp b/gdb/testsuite/gdb.guile/scm-color.exp
new file mode 100644
index 0000000..9fd7f38
--- /dev/null
+++ b/gdb/testsuite/gdb.guile/scm-color.exp
@@ -0,0 +1,110 @@
+# Copyright (C) 2010-2024 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/>.
+
+# This file is part of the GDB testsuite.
+# It tests GDB parameter support in Guile.
+
+load_lib gdb-guile.exp
+
+require allow_guile_tests
+
+clean_restart
+
+gdb_install_guile_utils
+gdb_install_guile_module
+
+gdb_test_no_output [concat "guile (define (print_color_attrs c) " \
+ "(display (color-string c)) (display \" \") " \
+ "(display (color-colorspace c)) (display \" \") " \
+ "(display (color-none? c)) (display \" \") " \
+ "(display (color-indexed? c)) (display \" \") " \
+ "(display (color-direct? c)) (newline))"] \
+ "print_color_attrs helper"
+
+gdb_test "guile (print_color_attrs (make-color))" \
+ "none 0 #t #f #f" \
+ "print attrs of a color without params"
+
+gdb_test_no_output "guile (define c (make-color \"green\"))" \
+ "create color from basic name string"
+gdb_test "guile (print_color_attrs c)" "green 1 #f #t #f" \
+ "print attrs of a basic color name"
+gdb_test "guile (print (color-index c))" "2" \
+ "print index of a basic color name"
+
+gdb_test_no_output "guile (define c (make-color 2))" \
+ "create color from basic index"
+gdb_test "guile (print_color_attrs c)" "green 1 #f #t #f" \
+ "print attrs of a basic color"
+gdb_test "guile (print (color-index c))" "2" \
+ "print index of a basic color"
+
+gdb_test_no_output "guile (define c (make-color 14))" \
+ "create color from integer 14"
+gdb_test "guile (print_color_attrs c)" "14 2 #f #t #f" \
+ "print attrs of an color 14"
+gdb_test "guile (print (color-index c))" "14" \
+ "print index of color 14"
+
+gdb_test_no_output "guile (define c (make-color 2 #:color-space COLORSPACE_ANSI_8COLOR))" \
+ "create color from basic index and ansi colorspace"
+gdb_test "guile (print_color_attrs c)" "green 1 #f #t #f" \
+ "print attrs of a basic color with ansi colorspace"
+gdb_test "guile (print (color-index c))" "2" \
+ "print index of a basic color with ansi colorspace"
+
+gdb_test_no_output "guile (define c (make-color 2 #:color-space COLORSPACE_XTERM_256COLOR))" \
+ "create color from basic index and xterm256 colorspace"
+gdb_test "guile (print_color_attrs c)" "2 3 #f #t #f" \
+ "print attrs of a basic color with xterm256 colorspace"
+gdb_test "guile (print (color-index c))" "2" \
+ "print index of a basic color with xterm256 colorspace"
+
+gdb_test_no_output "guile (define c (make-color '(171 205 239) #:color-space COLORSPACE_RGB_24BIT))" \
+ "create color from rgb components"
+gdb_test "guile (print_color_attrs c)" "#ABCDEF 4 #f #f #t" \
+ "print attrs of an RGB color"
+gdb_test "guile (print (color-components c))" "\\(171 205 239\\)" \
+ "print components of an RGB color"
+
+gdb_test_no_output "guile (define c (make-color \"none\"))" \
+ "create color from string none"
+gdb_test "guile (print_color_attrs c)" "none 0 #t #f #f" \
+ "print attrs of a color none"
+
+gdb_test_no_output "guile (define c (make-color \"254\"))" \
+ "create color from string 254"
+gdb_test "guile (print_color_attrs c)" "254 3 #f #t #f" \
+ "print attrs of an color 254"
+gdb_test "guile (print (color-index c))" "254" \
+ "print index of color 254"
+
+gdb_test_no_output "guile (define c_none (make-color \"none\"))" \
+ "save default color"
+gdb_test_no_output "guile (define c_red (make-color \"red\"))" \
+ "save blue color"
+gdb_test_no_output "guile (define c_green (make-color \"green\"))" \
+ "save yellow color"
+gdb_test [concat "guile " \
+ "(display (color-escape-sequence c_red #t)) " \
+ "(display (color-escape-sequence c_green #f)) " \
+ "(display \"red on green\") " \
+ "(display (color-escape-sequence c_none #f)) " \
+ "(display \" red on default\") " \
+ "(display (color-escape-sequence c_none #t)) " \
+ "(newline)"] \
+ "\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
+ "escape sequences"
+
diff --git a/gdb/testsuite/gdb.guile/scm-parameter.exp b/gdb/testsuite/gdb.guile/scm-parameter.exp
index d10e9d2..eabd179 100644
--- a/gdb/testsuite/gdb.guile/scm-parameter.exp
+++ b/gdb/testsuite/gdb.guile/scm-parameter.exp
@@ -389,3 +389,50 @@ with_test_prefix "previously-ambiguous" {
}
rename scm_param_test_maybe_no_output ""
+
+# Test a color parameter.
+
+with_ansi_styling_terminal {
+ # This enables 256 colors support and disables colors approximation.
+ setenv TERM xterm-256color
+ setenv COLORTERM truecolor
+
+ # Start with a fresh gdb.
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+
+ gdb_install_guile_utils
+ gdb_install_guile_module
+
+ # We use "." here instead of ":" so that this works on win32 too.
+ set escaped_directory [string_to_regexp "$srcdir/$subdir"]
+
+ gdb_test_multiline "color gdb parameter" \
+ "guile" "" \
+ "(define test-color-param" "" \
+ " (make-parameter \"print test-color-param\"" "" \
+ " #:command-class COMMAND_DATA" "" \
+ " #:parameter-type PARAM_COLOR" "" \
+ " #:doc \"When set, test param does something useful. When disabled, does nothing.\"" "" \
+ " #:show-doc \"Show the state of the test-color-param.\"" "" \
+ " #:set-doc \"Set the state of the test-color-param.\"" "" \
+ " #:show-func (lambda (self value)" "" \
+ " (format #f \"The state of the test-color-param is ~a.\" value))" "" \
+ " #:initial-value (make-color \"green\")))" "" \
+ "(register-parameter! test-color-param)" "" \
+ "end"
+
+ with_test_prefix "test-color-param" {
+ with_test_prefix "initial-value" {
+ gdb_test "guile (print (parameter-value test-color-param))" "= #<gdb:color green COLORSPACE_ANSI_8COLOR>" "color parameter value (green)"
+ gdb_test "show print test-color-param" "The state of the test-color-param is green." "show initial value"
+ gdb_test_no_output "set print test-color-param 255"
+ }
+ with_test_prefix "new-value" {
+ gdb_test "show print test-color-param" "The state of the test-color-param is 255." "show new value"
+ gdb_test "guile (print (parameter-value test-color-param))" "= #<gdb:color 255 COLORSPACE_XTERM_256COLOR>" "color parameter value (255)"
+ gdb_test "set print test-color-param 256" "integer 256 out of range.*" "set invalid color parameter"
+ }
+ }
+}
diff --git a/gdb/testsuite/gdb.python/py-color.exp b/gdb/testsuite/gdb.python/py-color.exp
new file mode 100644
index 0000000..eb62d7f
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-color.exp
@@ -0,0 +1,100 @@
+# Copyright (C) 2010-2024 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/>.
+
+# This file is part of the GDB testsuite.
+# It tests gdb.parameter and gdb.Parameter.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+
+# Start with a fresh gdb.
+clean_restart
+
+gdb_test_no_output "python print_color_attrs = lambda c: print (c, c.colorspace, c.is_none, c.is_indexed, c.is_direct)" \
+ "print_color_attrs helper"
+
+gdb_test_no_output "python c = gdb.Color ()" \
+ "create color without params"
+gdb_test "python print_color_attrs (c)" "none 0 True False False" \
+ "print attrs of a color without params"
+
+gdb_test_no_output "python c = gdb.Color ('green')" \
+ "create color from basic name string"
+gdb_test "python print_color_attrs (c)" "green 1 False True False" \
+ "print attrs of a basic color name"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color name"
+
+gdb_test_no_output "python c = gdb.Color (2)" \
+ "create color from basic index"
+gdb_test "python print_color_attrs (c)" "green 1 False True False" \
+ "print attrs of a basic color"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color"
+
+gdb_test_no_output "python c = gdb.Color (14)" \
+ "create color from integer 14"
+gdb_test "python print_color_attrs (c)" "14 2 False True False" \
+ "print attrs of an color 14"
+gdb_test "python print (c.index)" "14" \
+ "print index of color 14"
+
+gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_ANSI_8COLOR)" \
+ "create color from basic index and ansi colorspace"
+gdb_test "python print_color_attrs (c)" "green 1 False True False" \
+ "print attrs of a basic color with ansi colorspace"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color with ansi colorspace"
+
+gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_XTERM_256COLOR)" \
+ "create color from basic index and xterm256 colorspace"
+gdb_test "python print_color_attrs (c)" "2 3 False True False" \
+ "print attrs of a basic color with xterm256 colorspace"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color with xterm256 colorspace"
+
+gdb_test_no_output "python c = gdb.Color ((171, 205, 239), gdb.COLORSPACE_RGB_24BIT)" \
+ "create color from rgb components"
+gdb_test "python print_color_attrs (c)" "#ABCDEF 4 False False True" \
+ "print attrs of an RGB color"
+gdb_test "python print (c.components)" "\\(171, 205, 239\\)" \
+ "print components of an RGB color"
+
+gdb_test_no_output "python c = gdb.Color ('none')" \
+ "create color from string none"
+gdb_test "python print_color_attrs (c)" "none 0 True False False" \
+ "print attrs of a color none"
+
+gdb_test_no_output "python c = gdb.Color ('254')" \
+ "create color from string 254"
+gdb_test "python print_color_attrs (c)" "254 3 False True False" \
+ "print attrs of an color 254"
+gdb_test "python print (c.index)" "254" \
+ "print index of color 254"
+
+gdb_test_no_output "python c_none = gdb.Color ('none')" \
+ "save default color"
+gdb_test_no_output "python c_red = gdb.Color ('red')" \
+ "save blue color"
+gdb_test_no_output "python c_green = gdb.Color ('green')" \
+ "save yellow color"
+gdb_test [concat "python print (c_red.escape_sequence (True) + " \
+ "c_green.escape_sequence (False) + 'red on green' + " \
+ "c_none.escape_sequence (False) + ' red on default' + " \
+ "c_none.escape_sequence (True))"] \
+ "\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
+ "escape sequences"
+
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index de524f4..74e4178 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -185,6 +185,58 @@ proc_with_prefix test_enum_parameter { } {
"Undefined item: \"three\".*" "set invalid enum parameter"
}
+# Test an color parameter.
+proc_with_prefix test_color_parameter { } {
+ global env
+ with_ansi_styling_terminal {
+ # This enables 256 colors support and disables colors approximation.
+ setenv TERM xterm-256color
+ setenv COLORTERM truecolor
+
+ clean_restart
+
+ gdb_test_multiline "color gdb parameter" \
+ "python" "" \
+ "class TestColorParam (gdb.Parameter):" "" \
+ " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
+ " show_doc = \"Show the state of the color\"" ""\
+ " set_doc = \"Set the state of the color\"" "" \
+ " def get_show_string (self, pvalue):" ""\
+ " return \"The state of the color is \" + str(pvalue)" ""\
+ " def get_set_string (self):" ""\
+ " return \"The state of the color has been set to \" + str(self.value)" ""\
+ " def __init__ (self, name):" "" \
+ " super (TestColorParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_COLOR)" "" \
+ " self.value = gdb.Color(\"green\")" "" \
+ "test_color_param = TestColorParam ('print test-color-param')" ""\
+ "end"
+
+ gdb_test "python print (test_color_param.value)" "green" \
+ "test color parameter value is green"
+ gdb_test "show print test-color-param" \
+ "The state of the color is green.*" \
+ "show parameter is initial value"
+ gdb_test "set print test-color-param 255" \
+ "The state of the color has been set to 255" "set color to 255"
+ gdb_test "show print test-color-param" \
+ "The state of the color is 255.*" "show parameter is new value"
+ gdb_test "python print (test_color_param.value)" "255" \
+ "test color parameter value is 255"
+ gdb_test_no_output "python test_color_param.value = gdb.Color(254)" \
+ "assign test_color_param.value to 254"
+ gdb_test "python print (test_color_param.value)" "254" \
+ "test color parameter value is integer"
+ gdb_test_no_output "python test_color_param.value = gdb.Color('#FED210')" \
+ "assign test_color_param.value to #FED210"
+ gdb_test "python print (test_color_param.value.components)" "\\(254, 210, 16\\)" \
+ "test color parameter components from RGB hex tripple value"
+ gdb_test "set print test-color-param 256" \
+ "integer 256 out of range.*" "set invalid color parameter"
+ gdb_test "python test_color_param.value = gdb.Color(256)" \
+ ".*Error occurred in Python: Palette color index 256 is out of range.*" "set invalid color value"
+ }
+}
+
# Test a file parameter.
proc_with_prefix test_file_parameter { } {
clean_restart
@@ -623,6 +675,7 @@ test_directories
test_data_directory
test_boolean_parameter
test_enum_parameter
+test_color_parameter
test_file_parameter
test_undocumented_parameter
test_really_undocumented_parameter
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 34223e6..b8ab30a 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -67,20 +67,24 @@ proc string_list_to_regexp { args } {
# "function", "variable", "address", etc.
proc style {str style} {
+ set fg 39
+ set bg 49
+ set intensity 22
+ set reverse 27
switch -exact -- $style {
- title { set style 1 }
- command { set style 1 }
- file { set style 32 }
- function { set style 33 }
- highlight { set style 31 }
- variable { set style 36 }
- address { set style 34 }
- metadata { set style 2 }
- version { set style "35;1" }
- line-number { set style 2 }
+ title { set intensity 1 }
+ command { set intensity 1 }
+ file { set fg 32 }
+ function { set fg 33 }
+ highlight { set fg 31 }
+ variable { set fg 36 }
+ address { set fg 34 }
+ metadata { set intensity 2 }
+ version { set fg 35; set intensity 1 }
+ line-number { set intensity 2 }
none { return $str }
}
- return "\033\\\[${style}m${str}\033\\\[m"
+ return "\033\\\[${fg};${bg};${intensity};${reverse}m${str}\033\\\[m"
}
# gdb_get_bp_addr num
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 7ee2043..85747b2 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -10265,10 +10265,11 @@ proc with_override { name override body } {
# Run BODY after setting the TERM environment variable to 'ansi', and
# unsetting the NO_COLOR environment variable.
proc with_ansi_styling_terminal { body } {
- save_vars { ::env(TERM) ::env(NO_COLOR) } {
+ save_vars { ::env(TERM) ::env(NO_COLOR) ::env(COLORTERM) } {
# Set environment variables to allow styling.
setenv TERM ansi
unset -nocomplain ::env(NO_COLOR)
+ unset -nocomplain ::env(COLORTERM)
set code [catch {uplevel 1 $body} result]
}