Home | History | Annotate | Line # | Download | only in gdb.base
style.exp revision 1.1.1.2
      1  1.1.1.2  christos # Copyright 2018-2020 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  christos # Test CLI output styling.
     17      1.1  christos 
     18      1.1  christos standard_testfile
     19      1.1  christos 
     20      1.1  christos save_vars { env(TERM) } {
     21      1.1  christos     # We need an ANSI-capable terminal to get the output.
     22      1.1  christos     setenv TERM ansi
     23      1.1  christos 
     24      1.1  christos     set test_macros 0
     25      1.1  christos     set options debug
     26      1.1  christos     get_compiler_info
     27      1.1  christos     if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
     28      1.1  christos 	lappend options additional_flags=-g3
     29      1.1  christos 	set test_macros 1
     30      1.1  christos     }
     31      1.1  christos 
     32      1.1  christos     if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
     33      1.1  christos 	     $options]} {
     34      1.1  christos 	return -1
     35      1.1  christos     }
     36      1.1  christos 
     37  1.1.1.2  christos     set readnow [readnow]
     38  1.1.1.2  christos 
     39      1.1  christos     if {![runto_main]} {
     40      1.1  christos 	fail "style tests failed"
     41      1.1  christos 	return
     42      1.1  christos     }
     43      1.1  christos 
     44  1.1.1.2  christos     # Check that the source highlighter has not stripped away the leading
     45  1.1.1.2  christos     # newlines.
     46  1.1.1.2  christos     set main_line [gdb_get_line_number "break here"]
     47  1.1.1.2  christos     gdb_test "list $main_line,$main_line" "return.*some_called_function.*"
     48  1.1.1.2  christos 
     49      1.1  christos     gdb_test_no_output "set style enabled on"
     50      1.1  christos 
     51  1.1.1.2  christos     set main_expr [style main function]
     52  1.1.1.2  christos     set base_file_expr [style ".*style\\.c" file]
     53      1.1  christos     set file_expr "$base_file_expr:\[0-9\]"
     54  1.1.1.2  christos     set arg_expr [style "arg." variable]
     55      1.1  christos 
     56      1.1  christos     gdb_test "frame" \
     57      1.1  christos 	"$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
     58      1.1  christos     gdb_test "info breakpoints" "$main_expr at $file_expr.*"
     59      1.1  christos 
     60      1.1  christos     gdb_test_no_output "set style sources off"
     61      1.1  christos     gdb_test "frame" \
     62      1.1  christos 	"\r\n\[^\033\]*break here.*" \
     63      1.1  christos 	"frame without styling"
     64      1.1  christos     gdb_test_no_output "set style sources on"
     65      1.1  christos 
     66      1.1  christos     gdb_test "break main" "file $base_file_expr.*"
     67      1.1  christos 
     68  1.1.1.2  christos     gdb_test "print &main" " = .* [style $hex address] <$main_expr>"
     69      1.1  christos 
     70      1.1  christos     # Regression test for a bug where line-wrapping would occur at the
     71      1.1  christos     # wrong spot with styling.  There were different bugs at different
     72      1.1  christos     # widths, so try two.
     73      1.1  christos     foreach width {20 30} {
     74      1.1  christos 	gdb_test_no_output "set width $width"
     75      1.1  christos 	# There was also a bug where the styling could be wrong in the
     76      1.1  christos 	# line listing; this is why the words from the source code are
     77      1.1  christos 	# spelled out in the final result line of the test.
     78      1.1  christos 	gdb_test "frame" \
     79      1.1  christos 	    [multi_line \
     80      1.1  christos 		 "#0 *$main_expr.*$arg_expr.*" \
     81      1.1  christos 		 ".*$arg_expr.*" \
     82      1.1  christos 		 ".* at .*$file_expr.*" \
     83      1.1  christos 		 "\[0-9\]+.*return.* break here .*"
     84      1.1  christos 	    ] \
     85      1.1  christos 	    "frame when width=$width"
     86      1.1  christos     }
     87      1.1  christos 
     88      1.1  christos     if {$test_macros} {
     89  1.1.1.2  christos 	set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
     90      1.1  christos 	gdb_test "info macro SOME_MACRO" \
     91  1.1.1.2  christos 	    "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
     92      1.1  christos     }
     93      1.1  christos 
     94  1.1.1.2  christos     set func [style some_called_function function]
     95  1.1.1.2  christos     # Somewhere should see the call to the function.
     96  1.1.1.2  christos     gdb_test "disassemble main" "[style $hex address].*$func.*"
     97  1.1.1.2  christos 
     98  1.1.1.2  christos     set ifield [style int_field variable]
     99  1.1.1.2  christos     set sfield [style string_field variable]
    100  1.1.1.2  christos     set efield [style e_field variable]
    101  1.1.1.2  christos     set evalue [style VALUE_TWO variable]
    102  1.1.1.2  christos     gdb_test "print struct_value" \
    103  1.1.1.2  christos 	"\{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*"
    104  1.1.1.2  christos 
    105      1.1  christos     gdb_exit
    106      1.1  christos     gdb_spawn
    107      1.1  christos 
    108  1.1.1.2  christos     set vers [style "GNU gdb.*" "35;1"]
    109  1.1.1.2  christos     gdb_test "" "${vers}.*" \
    110      1.1  christos 	"version is styled"
    111      1.1  christos 
    112  1.1.1.2  christos     set address_style_expr [style ".*\".*address.*\".*style.*" address]
    113  1.1.1.2  christos     gdb_test "show style address foreground" \
    114  1.1.1.2  christos 	"The ${address_style_expr} foreground color is: blue" \
    115  1.1.1.2  christos 	"style name and style word styled using its own style in show style"
    116  1.1.1.2  christos 
    117  1.1.1.2  christos     set aliases_expr [style ".*aliases.*" title]
    118  1.1.1.2  christos     set breakpoints_expr [style ".*breakpoints.*" title]
    119  1.1.1.2  christos     gdb_test "help" \
    120  1.1.1.2  christos 	[multi_line \
    121  1.1.1.2  christos 	     "List of classes of commands:" \
    122  1.1.1.2  christos 	     "" \
    123  1.1.1.2  christos 	     "${aliases_expr} -- User-defined aliases of other commands\." \
    124  1.1.1.2  christos 	     "${breakpoints_expr} -- Making program stop at certain points\." \
    125  1.1.1.2  christos 	     ".*" \
    126  1.1.1.2  christos 	    ] \
    127  1.1.1.2  christos 	"help classes of commands styled with title"
    128  1.1.1.2  christos 
    129  1.1.1.2  christos     set taas_expr  [style ".*taas.*" title]
    130  1.1.1.2  christos     set tfaas_expr  [style ".*tfaas.*" title]
    131  1.1.1.2  christos     set cut_for_thre_expr [style "cut for 'thre" highlight]
    132  1.1.1.2  christos     gdb_test "apropos -v cut for 'thre" \
    133  1.1.1.2  christos 	[multi_line \
    134  1.1.1.2  christos 	     "" \
    135  1.1.1.2  christos 	     "${taas_expr}" \
    136  1.1.1.2  christos 	     "Apply a command to all .*" \
    137  1.1.1.2  christos 	     "Usage:.*" \
    138  1.1.1.2  christos 	     "short${cut_for_thre_expr}ad apply.*" \
    139  1.1.1.2  christos 	     "" \
    140  1.1.1.2  christos 	     "${tfaas_expr}" \
    141  1.1.1.2  christos 	     "Apply a command to all .*" \
    142  1.1.1.2  christos 	     "Usage:.*" \
    143  1.1.1.2  christos 	     "short${cut_for_thre_expr}ad apply.*" \
    144  1.1.1.2  christos 	    ]
    145  1.1.1.2  christos 
    146      1.1  christos     set quoted [string_to_regexp $binfile]
    147  1.1.1.2  christos     set pass_re "Reading symbols from [style $quoted file]\.\.\."
    148  1.1.1.2  christos     if { $readnow } {
    149  1.1.1.2  christos 	set pass_re \
    150  1.1.1.2  christos 	    [multi_line \
    151  1.1.1.2  christos 		 $pass_re \
    152  1.1.1.2  christos 		 "Expanding full symbols from [style $quoted file]\.\.\."]
    153  1.1.1.2  christos     }
    154      1.1  christos     gdb_test "file $binfile" \
    155  1.1.1.2  christos 	$pass_re \
    156      1.1  christos 	"filename is styled when loading symbol file"
    157  1.1.1.2  christos 
    158  1.1.1.2  christos     gdb_test "pwd" "Working directory [style .*? file].*"
    159  1.1.1.2  christos 
    160  1.1.1.2  christos     gdb_test_no_output "set print repeat 3"
    161  1.1.1.2  christos     gdb_test "print {0,0,0,0,0,0,0,0}" \
    162  1.1.1.2  christos 	" = \\{0 [style {<repeats.*8.*times>} metadata]\\}"
    163  1.1.1.2  christos 
    164  1.1.1.2  christos     gdb_test "show logging file" \
    165  1.1.1.2  christos 	"The current logfile is \"[style .*? file]\"\\..*"
    166  1.1.1.2  christos 
    167  1.1.1.2  christos     # Check warnings are styled by setting a rubbish data directory.
    168  1.1.1.2  christos     gdb_test "set data-directory Makefile" \
    169  1.1.1.2  christos 	"warning: [style .*? file] is not a directory\\..*"
    170  1.1.1.2  christos     gdb_test "show data-directory" \
    171  1.1.1.2  christos 	"GDB's data directory is \"[style .*? file]\"\\..*"
    172      1.1  christos }
    173