Home | History | Annotate | Line # | Download | only in gdb.base
      1  1.1.1.4  christos # Copyright 2018-2024 Free Software Foundation, Inc.
      2      1.1  christos 
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16  1.1.1.3  christos load_lib gdb-python.exp
     17  1.1.1.3  christos 
     18      1.1  christos # Test CLI output styling.
     19      1.1  christos 
     20      1.1  christos standard_testfile
     21      1.1  christos 
     22  1.1.1.3  christos # Compile the test executable.
     23  1.1.1.3  christos if {[build_executable "failed to build" $testfile $srcfile {debug macros}]} {
     24  1.1.1.3  christos     return -1
     25  1.1.1.3  christos }
     26      1.1  christos 
     27  1.1.1.3  christos # The tests in this file are run multiple times with GDB's styles
     28  1.1.1.3  christos # disabled one at a time.  This variable is the style that is
     29  1.1.1.3  christos # currently disabled.
     30  1.1.1.3  christos set currently_disabled_style ""
     31  1.1.1.3  christos 
     32  1.1.1.3  christos # A wrapper around the 'style' function found in gdb-utils.exp,
     33  1.1.1.3  christos # filter out requests for the disabled style.
     34  1.1.1.3  christos proc limited_style { str style } {
     35  1.1.1.3  christos     global currently_disabled_style
     36      1.1  christos 
     37  1.1.1.3  christos     if { $style != $currently_disabled_style } {
     38  1.1.1.3  christos 	return [style $str $style]
     39      1.1  christos     }
     40      1.1  christos 
     41  1.1.1.3  christos     return $str
     42  1.1.1.3  christos }
     43  1.1.1.2  christos 
     44  1.1.1.3  christos # A wrapper around 'clean_restart' from gdb.exp, this performs the
     45  1.1.1.3  christos # normal clean_restart, but then disables the currently disabled
     46  1.1.1.3  christos # style.
     47  1.1.1.3  christos proc clean_restart_and_disable { prefix args } {
     48  1.1.1.3  christos     global currently_disabled_style
     49  1.1.1.3  christos 
     50  1.1.1.3  christos     with_test_prefix "$prefix" {
     51  1.1.1.3  christos 	eval "clean_restart $args"
     52  1.1.1.3  christos 
     53  1.1.1.3  christos 	if { $currently_disabled_style != "" } {
     54  1.1.1.3  christos 	    set st $currently_disabled_style
     55  1.1.1.3  christos 	    gdb_test_no_output "set style $st background none"
     56  1.1.1.3  christos 	    gdb_test_no_output "set style $st foreground none"
     57  1.1.1.3  christos 	    gdb_test_no_output "set style $st intensity normal"
     58  1.1.1.3  christos 	}
     59      1.1  christos     }
     60  1.1.1.3  christos }
     61  1.1.1.3  christos 
     62  1.1.1.3  christos # The core of this test script.  Run some tests of different aspects
     63  1.1.1.3  christos # of GDB's styling.
     64  1.1.1.3  christos #
     65  1.1.1.3  christos # Within this proc always use LIMITED_STYLE instead of STYLE, and
     66  1.1.1.3  christos # CLEAN_RESTART_AND_DISABLE instead of CLEAN_RESTART, this ensures
     67  1.1.1.3  christos # that the test operates as expected as styles are disabled.
     68  1.1.1.3  christos proc run_style_tests { } {
     69  1.1.1.3  christos     global testfile srcfile hex binfile
     70  1.1.1.3  christos     global currently_disabled_style decimal hex
     71  1.1.1.3  christos 
     72  1.1.1.4  christos     with_ansi_styling_terminal {
     73  1.1.1.3  christos 	# Restart GDB with the correct TERM variable setting, this
     74  1.1.1.3  christos 	# means that GDB will enable styling.
     75  1.1.1.3  christos 	clean_restart_and_disable "restart 1" ${binfile}
     76  1.1.1.3  christos 
     77  1.1.1.3  christos 	set readnow [readnow]
     78  1.1.1.3  christos 
     79  1.1.1.3  christos 	if {![runto_main]} {
     80  1.1.1.3  christos 	    return
     81  1.1.1.3  christos 	}
     82  1.1.1.3  christos 
     83  1.1.1.3  christos 	# Check that the source highlighter has not stripped away the
     84  1.1.1.3  christos 	# leading newlines.
     85  1.1.1.3  christos 	set main_line [gdb_get_line_number "break here"]
     86  1.1.1.3  christos 	gdb_test "list $main_line,$main_line" "return.*some_called_function.*"
     87  1.1.1.3  christos 
     88  1.1.1.3  christos 	gdb_test_no_output "set style enabled off"
     89  1.1.1.3  christos 
     90  1.1.1.3  christos 	set argv ""
     91  1.1.1.3  christos 	gdb_test_multiple "frame" "frame without styling" {
     92  1.1.1.4  christos 	    -re -wrap "main \\(argc=.*, (argv=$hex.*)\\).*style\\.c:\[0-9\].*" {
     93  1.1.1.3  christos 		set argv $expect_out(1,string)
     94  1.1.1.3  christos 		pass $gdb_test_name
     95  1.1.1.3  christos 	    }
     96  1.1.1.3  christos 	}
     97  1.1.1.3  christos 
     98  1.1.1.3  christos 	gdb_test_no_output "set style enabled on"
     99  1.1.1.3  christos 
    100  1.1.1.3  christos 	set main_expr [limited_style main function]
    101  1.1.1.3  christos 	set base_file_expr [limited_style ".*style\\.c" file]
    102  1.1.1.3  christos 	set file_expr "$base_file_expr:\[0-9\]+"
    103  1.1.1.3  christos 	set arg_expr [limited_style "arg." variable]
    104      1.1  christos 
    105  1.1.1.4  christos 	# On some embedded targets that don't fully support argc/argv,
    106  1.1.1.4  christos 	# argv may print as "0x0" or as an address with a symbol name
    107  1.1.1.4  christos 	# following, so use a regexp general enough to match that and
    108  1.1.1.4  christos 	# do not make assumptions about how long the address string is.
    109      1.1  christos 	gdb_test "frame" \
    110      1.1  christos 	    [multi_line \
    111  1.1.1.4  christos 		 "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+$arg_expr=$hex.*\\)\\s+at\\s+$file_expr" \
    112  1.1.1.3  christos 		 "\[0-9\]+\\s+.*return.* break here .*"]
    113  1.1.1.3  christos 	gdb_test "info breakpoints" "$main_expr at $file_expr.*"
    114  1.1.1.3  christos 
    115  1.1.1.3  christos 	gdb_test_no_output "set style sources off"
    116  1.1.1.3  christos 	gdb_test "frame" \
    117  1.1.1.3  christos 	    "\r\n\[^\033\]*break here.*" \
    118  1.1.1.3  christos 	    "frame without sources styling"
    119  1.1.1.3  christos 	gdb_test_no_output "set style sources on"
    120  1.1.1.3  christos 
    121  1.1.1.3  christos 	gdb_test "break -q main" "file $base_file_expr.*"
    122  1.1.1.3  christos 
    123  1.1.1.3  christos 	gdb_test "print &main" " = .* [limited_style $hex address] <$main_expr>"
    124  1.1.1.3  christos 
    125  1.1.1.3  christos 	# Regression test for a bug where line-wrapping would occur at
    126  1.1.1.3  christos 	# the wrong spot with styling.  There were different bugs at
    127  1.1.1.3  christos 	# different widths, so try two.
    128  1.1.1.3  christos 	foreach width {20 30} {
    129  1.1.1.3  christos 	    set argv_len [string length $argv]
    130  1.1.1.3  christos 	    if { $argv_len == 0 } {
    131  1.1.1.3  christos 		continue
    132  1.1.1.3  christos 	    }
    133  1.1.1.3  christos 
    134  1.1.1.3  christos 	    # There was also a bug where the styling could be wrong in
    135  1.1.1.3  christos 	    # the line listing; this is why the words from the source
    136  1.1.1.3  christos 	    # code are spelled out in the final result line of the
    137  1.1.1.3  christos 	    # test.
    138  1.1.1.4  christos 	    set re0_styled \
    139  1.1.1.4  christos 		[multi_line \
    140  1.1.1.4  christos 		     "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+$arg_expr=$hex\\)" \
    141  1.1.1.4  christos 		     "\\s+at\\s+$file_expr" \
    142  1.1.1.4  christos 		     "\[0-9\]+\\s+.*return.* break here .*"]
    143  1.1.1.3  christos 	    set re1_styled \
    144  1.1.1.3  christos 		[multi_line \
    145  1.1.1.3  christos 		     "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+" \
    146  1.1.1.4  christos 		     "\\s+$arg_expr=$hex.*\\)" \
    147  1.1.1.3  christos 		     "\\s+at\\s+$file_expr" \
    148  1.1.1.3  christos 		     "\[0-9\]+\\s+.*return.* break here .*"]
    149  1.1.1.3  christos 	    set re2_styled \
    150  1.1.1.3  christos 		[multi_line \
    151  1.1.1.3  christos 		     "#0\\s+$main_expr\\s+\\($arg_expr=.*" \
    152  1.1.1.4  christos 		     "\\s+$arg_expr=$hex.*\\)\\s+at\\s+$file_expr" \
    153  1.1.1.3  christos 		     "\[0-9\]+\\s+.*return.* break here .*"]
    154  1.1.1.3  christos 
    155  1.1.1.3  christos 	    # The length of the line containing argv containing:
    156  1.1.1.3  christos 	    # - 4 leading spaces
    157  1.1.1.3  christos 	    # - argv string
    158  1.1.1.3  christos 	    # - closing parenthesis
    159  1.1.1.3  christos 	    set line_len [expr 4 + $argv_len + 1]
    160  1.1.1.3  christos 
    161  1.1.1.4  christos 	    if { $argv == "argv=0x0" && $width >= 27 } {
    162  1.1.1.4  christos 		# Embedded target with no argv support.
    163  1.1.1.4  christos 		# #0  main (argc=0, argv=0x0)
    164  1.1.1.4  christos 		set re_styled $re0_styled
    165  1.1.1.4  christos 	    } elseif { $line_len > $width } {
    166  1.1.1.3  christos 		# At on the next line.
    167  1.1.1.3  christos 		set re_styled $re1_styled
    168  1.1.1.3  christos 	    } else {
    169  1.1.1.3  christos 		# At on the same line as argv.
    170  1.1.1.3  christos 		set re_styled $re2_styled
    171  1.1.1.3  christos 	    }
    172  1.1.1.3  christos 
    173  1.1.1.3  christos 	    # Override width for the duration of the command, letting
    174  1.1.1.3  christos 	    # GDB reset back to 0.  Doing this in the loop rather than
    175  1.1.1.3  christos 	    # after, avoids trying to do "set width 30" while width is
    176  1.1.1.3  christos 	    # 20, which causes horizontal scrolling in the case that
    177  1.1.1.3  christos 	    # the fallback stub-termcap.c is used:
    178  1.1.1.3  christos 	    # ^M<et width 30^M
    179  1.1.1.3  christos 	    # (gdb) FAIL: gdb.base/style.exp: all styles enabled: set width 30
    180  1.1.1.3  christos 	    gdb_test "with width $width -- frame" $re_styled \
    181  1.1.1.3  christos 		"frame when width=$width"
    182  1.1.1.3  christos 	}
    183      1.1  christos 
    184  1.1.1.2  christos 	set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
    185      1.1  christos 	gdb_test "info macro SOME_MACRO" \
    186  1.1.1.2  christos 	    "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
    187  1.1.1.3  christos 
    188  1.1.1.3  christos 	gdb_test_no_output "set width 0"
    189  1.1.1.3  christos 
    190  1.1.1.3  christos 	# If disassembler styling is being done by the Python pygments
    191  1.1.1.3  christos 	# module, then we can't be sure how the 'some_called_function'
    192  1.1.1.3  christos 	# symbol will be styled.  However, if pygments is not being
    193  1.1.1.3  christos 	# used then we can know how the symbol name will be styled.
    194  1.1.1.3  christos 	set main [limited_style main function]
    195  1.1.1.3  christos 	if { $::python_disassembly_styling } {
    196  1.1.1.3  christos 	    set func "some_called_function"
    197  1.1.1.3  christos 	} else {
    198  1.1.1.3  christos 	    set func [limited_style some_called_function function]
    199  1.1.1.3  christos 	}
    200  1.1.1.3  christos 	# Somewhere should see the call to the function.
    201  1.1.1.3  christos 	gdb_test "disassemble main" \
    202  1.1.1.3  christos 	    [concat "Dump of assembler code for function $main:.*" \
    203  1.1.1.3  christos 		 "[limited_style $hex address].*$func.*"]
    204  1.1.1.3  christos 
    205  1.1.1.3  christos 	set ifield [limited_style int_field variable]
    206  1.1.1.3  christos 	set sfield [limited_style string_field variable]
    207  1.1.1.3  christos 	set efield [limited_style e_field variable]
    208  1.1.1.3  christos 	set evalue [limited_style VALUE_TWO variable]
    209  1.1.1.4  christos 	set lhs [limited_style "\\\$$decimal" variable]
    210  1.1.1.3  christos 	gdb_test "print struct_value" \
    211  1.1.1.4  christos 	    "$lhs = \{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*"
    212  1.1.1.3  christos 
    213  1.1.1.3  christos 	set ffield [limited_style field variable]
    214  1.1.1.3  christos 	set cstart [string_to_regexp "/* XXX "]
    215  1.1.1.3  christos 	set cend [string_to_regexp " */"]
    216  1.1.1.3  christos 	set p1field [limited_style "$cstart.*$decimal.*-bit.*padding.*$cend" \
    217  1.1.1.3  christos 			 highlight]
    218  1.1.1.3  christos 	set p2field [limited_style "$cstart.*$decimal.*-byte.*padding.*$cend" \
    219  1.1.1.3  christos 			 highlight]
    220  1.1.1.3  christos 
    221  1.1.1.3  christos 	gdb_test "ptype/o just_bitfield_value" \
    222  1.1.1.3  christos 	    [multi_line \
    223  1.1.1.3  christos 		 ".* type = struct just_bitfield {" \
    224  1.1.1.3  christos 		 ".* unsigned int $ffield : 3;" \
    225  1.1.1.3  christos 		 "$p1field" \
    226  1.1.1.3  christos 		 "$p2field" \
    227  1.1.1.3  christos 		 "" \
    228  1.1.1.3  christos 		 ".* total size.*: *$decimal *$cend" \
    229  1.1.1.3  christos 		 " *}.*"]
    230  1.1.1.3  christos 
    231  1.1.1.3  christos 	set address_style_expr [limited_style ".*\".*address.*\".*style.*" address]
    232  1.1.1.3  christos 	set color "blue"
    233  1.1.1.3  christos 	if { $currently_disabled_style == "address" } {
    234  1.1.1.3  christos 	    set color "none"
    235  1.1.1.3  christos 	}
    236  1.1.1.3  christos 	gdb_test "show style address foreground" \
    237  1.1.1.3  christos 	    "The ${address_style_expr} foreground color is: ${color}" \
    238  1.1.1.3  christos 	    "style name and style word styled using its own style in show style"
    239  1.1.1.3  christos 
    240  1.1.1.3  christos 	set aliases_expr [limited_style ".*aliases.*" title]
    241  1.1.1.3  christos 	set breakpoints_expr [limited_style ".*breakpoints.*" title]
    242  1.1.1.3  christos 	gdb_test "help" \
    243  1.1.1.3  christos 	    [multi_line \
    244  1.1.1.3  christos 		 "List of classes of commands:" \
    245  1.1.1.3  christos 		 "" \
    246  1.1.1.3  christos 		 "${aliases_expr} -- User-defined aliases of other commands\." \
    247  1.1.1.3  christos 		 "${breakpoints_expr} -- Making program stop at certain points\." \
    248  1.1.1.3  christos 		 ".*" \
    249  1.1.1.3  christos 		] \
    250  1.1.1.3  christos 	    "help classes of commands styled with title"
    251  1.1.1.3  christos 
    252  1.1.1.3  christos 	set taas_expr  [limited_style ".*taas.*" title]
    253  1.1.1.3  christos 	set tfaas_expr  [limited_style ".*tfaas.*" title]
    254  1.1.1.3  christos 	set cut_for_thre_expr [limited_style "cut for 'thre" highlight]
    255  1.1.1.3  christos 	gdb_test "apropos -v cut for 'thre" \
    256  1.1.1.3  christos 	    [multi_line \
    257  1.1.1.3  christos 		 "" \
    258  1.1.1.3  christos 		 "${taas_expr}" \
    259  1.1.1.3  christos 		 "Apply a command to all .*" \
    260  1.1.1.3  christos 		 "Usage:.*" \
    261  1.1.1.3  christos 		 "short${cut_for_thre_expr}ad apply.*" \
    262  1.1.1.3  christos 		 "" \
    263  1.1.1.3  christos 		 "${tfaas_expr}" \
    264  1.1.1.3  christos 		 "Apply a command to all .*" \
    265  1.1.1.3  christos 		 "Usage:.*" \
    266  1.1.1.3  christos 		 "short${cut_for_thre_expr}ad apply.*" \
    267  1.1.1.3  christos 		]
    268  1.1.1.3  christos 
    269  1.1.1.3  christos 	clean_restart_and_disable "restart 2"
    270  1.1.1.3  christos 
    271  1.1.1.3  christos 	set quoted [string_to_regexp $binfile]
    272  1.1.1.3  christos 	set pass_re "Reading symbols from [limited_style $quoted file]\.\.\."
    273  1.1.1.3  christos 	if { $readnow } {
    274  1.1.1.3  christos 	    set pass_re \
    275  1.1.1.3  christos 		[multi_line \
    276  1.1.1.3  christos 		     $pass_re \
    277  1.1.1.3  christos 		     "Expanding full symbols from [limited_style $quoted file]\.\.\."]
    278  1.1.1.3  christos 	}
    279  1.1.1.3  christos 	gdb_test "file $binfile" \
    280  1.1.1.3  christos 	    $pass_re \
    281  1.1.1.3  christos 	    "filename is styled when loading symbol file"
    282  1.1.1.3  christos 
    283  1.1.1.3  christos 	gdb_test "pwd" "Working directory [limited_style .*? file].*"
    284  1.1.1.3  christos 
    285  1.1.1.3  christos 	gdb_test_no_output "set print repeat 3"
    286  1.1.1.3  christos 	gdb_test "print {0,0,0,0,0,0,0,0}" \
    287  1.1.1.3  christos 	    " = \\{0 [limited_style {<repeats.*8.*times>} metadata]\\}"
    288  1.1.1.3  christos 
    289  1.1.1.3  christos 	gdb_test "show logging file" \
    290  1.1.1.3  christos 	    "The current logfile is \"[limited_style .*? file]\"\\..*"
    291  1.1.1.3  christos 
    292  1.1.1.3  christos 	# Check warnings are styled by setting a rubbish data
    293  1.1.1.3  christos 	# directory.
    294  1.1.1.3  christos 	gdb_test "set data-directory Makefile" \
    295  1.1.1.3  christos 	    "warning: [limited_style .*? file] is not a directory\\..*"
    296  1.1.1.3  christos 	gdb_test "show data-directory" \
    297  1.1.1.3  christos 	    "GDB's data directory is \"[limited_style .*? file]\"\\..*"
    298  1.1.1.3  christos 
    299  1.1.1.3  christos 	# Check that deprecation styles command names.
    300  1.1.1.3  christos 	gdb_test_no_output "maintenance deprecate p \"new_p\"" \
    301  1.1.1.3  christos 	    "maintenance deprecate p \"new_p\" /1/"
    302  1.1.1.3  christos 	gdb_test "p 5" \
    303  1.1.1.3  christos 	    "Warning: '[limited_style p title]', an alias for the command '[limited_style print title]', is deprecated.*Use '[limited_style new_p title]'.*" \
    304  1.1.1.3  christos 	    "p deprecated warning, with replacement"
    305  1.1.1.3  christos 
    306  1.1.1.3  christos 	# Check that the version string is styled in the output of 'show
    307  1.1.1.3  christos 	# version', and that this styling can be disabled.
    308  1.1.1.3  christos 	set vers [style "GNU gdb.*" version]
    309  1.1.1.3  christos 	set url [limited_style "http:.*html" file]
    310  1.1.1.3  christos 	gdb_test "show version" "${vers}.*<$url>.*" \
    311  1.1.1.3  christos 	    "'show version' is styled"
    312  1.1.1.3  christos     }
    313  1.1.1.3  christos }
    314  1.1.1.3  christos 
    315  1.1.1.3  christos # Check that disassembler styling can be disabled.  The function that
    316  1.1.1.3  christos # we are disassembling has some minimal styling applied even if the
    317  1.1.1.3  christos # Python pygments module is not available, so, when we disable
    318  1.1.1.3  christos # disassembler styling, we should always see a change in output.
    319  1.1.1.3  christos proc test_disable_disassembler_styling { } {
    320  1.1.1.4  christos     save_vars { env(TERM) env(NO_COLOR) } {
    321  1.1.1.3  christos 	# We need an ANSI-capable terminal to get the output.
    322  1.1.1.3  christos 	setenv TERM ansi
    323  1.1.1.4  christos 	setenv NO_COLOR ""
    324  1.1.1.3  christos 
    325  1.1.1.3  christos 	# Restart GDB with the correct TERM variable setting, this
    326  1.1.1.3  christos 	# means that GDB will enable styling.
    327  1.1.1.3  christos 	clean_restart_and_disable "restart 3" $::binfile
    328  1.1.1.3  christos 
    329  1.1.1.3  christos 	set styled_hex [limited_style $::hex address]
    330  1.1.1.3  christos 	set main [limited_style main function]
    331  1.1.1.3  christos 
    332  1.1.1.3  christos 	foreach_with_prefix libopcodes { on off } {
    333  1.1.1.3  christos 
    334  1.1.1.3  christos 	    set command_failed false
    335  1.1.1.3  christos 	    gdb_test_multiple "maint set libopcodes-styling enabled ${libopcodes}" "" {
    336  1.1.1.3  christos 		-re "^maint set libopcodes-styling enabled ${libopcodes}\r\n" {
    337  1.1.1.3  christos 		    exp_continue
    338  1.1.1.3  christos 		}
    339  1.1.1.3  christos 
    340  1.1.1.3  christos 		-re "Use of libopcodes styling not supported on architecture \[^\r\n\]+\r\n" {
    341  1.1.1.3  christos 		    set command_failed true
    342  1.1.1.3  christos 		    exp_continue
    343  1.1.1.3  christos 		}
    344  1.1.1.3  christos 
    345  1.1.1.3  christos 		-re "^$::gdb_prompt $" {
    346  1.1.1.3  christos 		    gdb_assert { !$command_failed || [string equal $libopcodes "on"] } \
    347  1.1.1.3  christos 			$gdb_test_name
    348  1.1.1.3  christos 		}
    349  1.1.1.3  christos 	    }
    350  1.1.1.3  christos 
    351  1.1.1.3  christos 	    if { $libopcodes == "on" && $command_failed } {
    352  1.1.1.3  christos 		# We tried to turn on libopcodes disassembler styling,
    353  1.1.1.3  christos 		# but this is not supported on this architecture.
    354  1.1.1.3  christos 		continue
    355  1.1.1.3  christos 	    }
    356  1.1.1.3  christos 
    357  1.1.1.3  christos 	    foreach_with_prefix disasm_styling { on off } {
    358  1.1.1.3  christos 		gdb_test_no_output "set style disassembler enabled ${disasm_styling}"
    359  1.1.1.3  christos 
    360  1.1.1.3  christos 		if { $libopcodes == "off" && $disasm_styling == "on" \
    361  1.1.1.3  christos 			 && !$::python_disassembly_styling} {
    362  1.1.1.3  christos 		    # We have libopcodes based styling off, but
    363  1.1.1.3  christos 		    # disassembler styling turned on.  We're expecting
    364  1.1.1.3  christos 		    # Python Pygments to be used to add styling.
    365  1.1.1.3  christos 		    #
    366  1.1.1.3  christos 		    # However, if we get here, then we don't have the
    367  1.1.1.3  christos 		    # Pygments module, so skip this test.
    368  1.1.1.3  christos 		    continue
    369  1.1.1.3  christos 		}
    370  1.1.1.3  christos 
    371  1.1.1.3  christos 		set saw_header_line false
    372  1.1.1.3  christos 		set saw_styled_output_line false
    373  1.1.1.3  christos 		set saw_unstyled_output_line false
    374  1.1.1.3  christos 		gdb_test_multiple "disassemble main" "" {
    375  1.1.1.3  christos 		    -re "disassemble main\r\n" {
    376  1.1.1.3  christos 			exp_continue
    377  1.1.1.3  christos 		    }
    378  1.1.1.3  christos 		    -re "^Dump of assembler code for function $main:" {
    379  1.1.1.3  christos 			set saw_header_line true
    380  1.1.1.3  christos 			exp_continue
    381  1.1.1.3  christos 		    }
    382  1.1.1.3  christos 		    -re "^\\s+${styled_hex}\\s+<\[^>\]+>:\\s+\[^\r\n\033\]+\r\n" {
    383  1.1.1.3  christos 			set saw_unstyled_output_line true
    384  1.1.1.3  christos 			exp_continue
    385  1.1.1.3  christos 		    }
    386  1.1.1.3  christos 		    -re "^\\s+${styled_hex}\\s+<\[^>\]+>:\\s+\[^\r\n\]+\033\[^\r\n\]+\r\n" {
    387  1.1.1.3  christos 			set saw_styled_output_line true
    388  1.1.1.3  christos 			exp_continue
    389  1.1.1.3  christos 		    }
    390  1.1.1.3  christos 		    -re "^End of assembler dump\\.\r\n" {
    391  1.1.1.3  christos 			exp_continue
    392  1.1.1.3  christos 		    }
    393  1.1.1.3  christos 		    -re "^$::gdb_prompt $" {
    394  1.1.1.3  christos 			gdb_assert { $saw_header_line }
    395  1.1.1.3  christos 			if { $disasm_styling } {
    396  1.1.1.3  christos 			    gdb_assert { $saw_styled_output_line }
    397  1.1.1.3  christos 			    gdb_assert { !$saw_unstyled_output_line }
    398  1.1.1.3  christos 			} else {
    399  1.1.1.3  christos 			    gdb_assert { !$saw_styled_output_line }
    400  1.1.1.3  christos 			    gdb_assert { $saw_unstyled_output_line }
    401  1.1.1.3  christos 			}
    402  1.1.1.3  christos 		    }
    403  1.1.1.3  christos 		}
    404  1.1.1.3  christos 	    }
    405  1.1.1.3  christos 	}
    406  1.1.1.3  christos     }
    407  1.1.1.3  christos }
    408  1.1.1.3  christos 
    409  1.1.1.3  christos # Disassemble a single isntruction at the start of main, then strip
    410  1.1.1.3  christos # off the address and symbol information, returning just the
    411  1.1.1.3  christos # disassembled instruction part.
    412  1.1.1.3  christos proc get_single_disassembled_insn {} {
    413  1.1.1.3  christos     set disasm_line [capture_command_output "x/1i *main" ""]
    414  1.1.1.3  christos     regexp "^\[^:\]+:\\s*(.*)$" $disasm_line whole_match insn
    415  1.1.1.3  christos     return $insn
    416  1.1.1.3  christos }
    417  1.1.1.3  christos 
    418  1.1.1.3  christos # Check that, if the user is using Python Pygments for disassembler
    419  1.1.1.3  christos # styling, then the styling correctly switches off when an error is
    420  1.1.1.3  christos # detected in the Python code.
    421  1.1.1.3  christos proc test_disassembler_error_handling { } {
    422  1.1.1.3  christos 
    423  1.1.1.3  christos     # This test requires the Python Pygments module to be installed
    424  1.1.1.3  christos     # and used by GDB.
    425  1.1.1.3  christos     if { !$::python_disassembly_styling } {
    426  1.1.1.3  christos 	return
    427      1.1  christos     }
    428      1.1  christos 
    429  1.1.1.4  christos     save_vars { env(TERM) env(NO_COLOR) } {
    430  1.1.1.3  christos 	# We need an ANSI-capable terminal to get the output.
    431  1.1.1.3  christos 	setenv TERM ansi
    432  1.1.1.4  christos 	setenv NO_COLOR ""
    433  1.1.1.3  christos 
    434  1.1.1.3  christos 	# Restart GDB with the correct TERM variable setting, this
    435  1.1.1.3  christos 	# means that GDB will enable styling.
    436  1.1.1.3  christos 	clean_restart_and_disable "restart 4" $::binfile
    437  1.1.1.3  christos 
    438  1.1.1.3  christos 	# Disable use of libopcodes for styling.  As this function is
    439  1.1.1.3  christos 	# only called when Python Pygments module is available, we
    440  1.1.1.3  christos 	# should now be using that module to style the disassembler
    441  1.1.1.3  christos 	# output.
    442  1.1.1.3  christos 	gdb_test_no_output "maint set libopcodes-styling enabled off"
    443  1.1.1.3  christos 
    444  1.1.1.3  christos 	# Disassemble a single instruction and ensure that the output
    445  1.1.1.3  christos 	# has styling markers in it.
    446  1.1.1.3  christos 	set insn_before [get_single_disassembled_insn]
    447  1.1.1.3  christos 	gdb_assert { [regexp "\033" $insn_before] } \
    448  1.1.1.3  christos 	    "have style markers when Pygments is working fine"
    449  1.1.1.3  christos 
    450  1.1.1.3  christos 	# Now replace the standard function that colorizes the
    451  1.1.1.3  christos 	# disassembler output, with a new function that always returns
    452  1.1.1.3  christos 	# None, this should cause GDB to stop using the Pygments
    453  1.1.1.3  christos 	# module for disassembler styling.
    454  1.1.1.3  christos 	gdb_py_test_silent_cmd \
    455  1.1.1.3  christos 	    [multi_line_input \
    456  1.1.1.3  christos 		 "python" \
    457  1.1.1.3  christos 		 "def replacement_colorize_disasm(content,gdbarch):" \
    458  1.1.1.3  christos 		 "  return None" \
    459  1.1.1.3  christos 		 "gdb.styling.colorize_disasm = replacement_colorize_disasm" \
    460  1.1.1.3  christos 		 "end"] \
    461  1.1.1.3  christos 	    "setup replacement colorize_disasm function" \
    462  1.1.1.3  christos 	    true
    463  1.1.1.3  christos 
    464  1.1.1.3  christos 	set insn_after [get_single_disassembled_insn]
    465  1.1.1.3  christos 	gdb_assert { ![regexp "\033" $insn_after] } \
    466  1.1.1.3  christos 	    "have no style markers when Pygments is broken"
    467  1.1.1.3  christos     }
    468  1.1.1.3  christos }
    469  1.1.1.2  christos 
    470  1.1.1.3  christos # A separate test from the above as the styled text this checks can't
    471  1.1.1.3  christos # currently be disabled (the text is printed too early in GDB's
    472  1.1.1.3  christos # startup process).
    473  1.1.1.3  christos proc test_startup_version_string { } {
    474      1.1  christos     gdb_exit
    475  1.1.1.4  christos 
    476  1.1.1.4  christos     save_vars { ::INTERNAL_GDBFLAGS } {
    477  1.1.1.4  christos 	set ::INTERNAL_GDBFLAGS [string map {"-q" ""} $::INTERNAL_GDBFLAGS]
    478  1.1.1.4  christos 
    479  1.1.1.4  christos 	gdb_spawn
    480  1.1.1.4  christos     }
    481      1.1  christos 
    482  1.1.1.3  christos     # Deliberate use of base STYLE proc here as the style of the
    483  1.1.1.3  christos     # startup version string can't (currently) be controlled.
    484  1.1.1.3  christos     set vers [style "GNU gdb.*" version]
    485  1.1.1.3  christos     gdb_test "" "${vers}.*" "version is styled at startup"
    486  1.1.1.3  christos }
    487  1.1.1.3  christos 
    488  1.1.1.3  christos # Check to see if the Python styling of disassembler output is
    489  1.1.1.3  christos # expected or not, this styling requires Python support in GDB, and
    490  1.1.1.3  christos # the Python pygments module to be available.
    491  1.1.1.3  christos clean_restart ${binfile}
    492  1.1.1.4  christos if {[allow_python_tests] && [gdb_py_module_available "pygments"]} {
    493  1.1.1.3  christos     set python_disassembly_styling true
    494  1.1.1.3  christos } else {
    495  1.1.1.3  christos     set python_disassembly_styling false
    496  1.1.1.3  christos }
    497  1.1.1.3  christos 
    498  1.1.1.3  christos # Run tests with all styles in their default state.
    499  1.1.1.3  christos with_test_prefix "all styles enabled" {
    500  1.1.1.3  christos     run_style_tests
    501  1.1.1.3  christos }
    502  1.1.1.3  christos 
    503  1.1.1.3  christos # Now, for each style in turn.  Disable that style only and run the
    504  1.1.1.3  christos # test again.  Things in that style should NOT now be styled.
    505  1.1.1.3  christos foreach style { title file function highlight variable \
    506  1.1.1.3  christos 		    address metadata } {
    507  1.1.1.3  christos     set currently_disabled_style $style
    508  1.1.1.3  christos     with_test_prefix "disable style $style" {
    509  1.1.1.3  christos 	run_style_tests
    510  1.1.1.2  christos     }
    511      1.1  christos }
    512  1.1.1.3  christos 
    513  1.1.1.3  christos # Check that the disassembler styling can be disabled.
    514  1.1.1.3  christos test_disable_disassembler_styling
    515  1.1.1.3  christos 
    516  1.1.1.3  christos # Check that GDB handles an error in the Python Pygments disassembly
    517  1.1.1.3  christos # styling code.
    518  1.1.1.3  christos test_disassembler_error_handling
    519  1.1.1.3  christos 
    520  1.1.1.3  christos # Finally, check the styling of the version string during startup.
    521  1.1.1.3  christos test_startup_version_string
    522