1 # Copyright 2018-2020 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test CLI output styling.
20 save_vars { env(TERM) } {
21 # We need an ANSI-capable terminal to get the output.
27 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
28 lappend options additional_flags=-g3
32 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
40 fail "style tests failed"
44 # Check that the source highlighter has not stripped away the leading
46 set main_line [gdb_get_line_number "break here"]
47 gdb_test "list $main_line,$main_line" "return.*some_called_function.*"
49 gdb_test_no_output "set style enabled on"
51 set main_expr [style main function]
52 set base_file_expr [style ".*style\\.c" file]
53 set file_expr "$base_file_expr:\[0-9\]"
54 set arg_expr [style "arg." variable]
57 "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
58 gdb_test "info breakpoints" "$main_expr at $file_expr.*"
60 gdb_test_no_output "set style sources off"
62 "\r\n\[^\033\]*break here.*" \
63 "frame without styling"
64 gdb_test_no_output "set style sources on"
66 gdb_test "break main" "file $base_file_expr.*"
68 gdb_test "print &main" " = .* [style $hex address] <$main_expr>"
70 # Regression test for a bug where line-wrapping would occur at the
71 # wrong spot with styling. There were different bugs at different
73 foreach width {20 30} {
74 gdb_test_no_output "set width $width"
75 # There was also a bug where the styling could be wrong in the
76 # line listing; this is why the words from the source code are
77 # spelled out in the final result line of the test.
80 "#0 *$main_expr.*$arg_expr.*" \
82 ".* at .*$file_expr.*" \
83 "\[0-9\]+.*return.* break here .*"
85 "frame when width=$width"
89 set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
90 gdb_test "info macro SOME_MACRO" \
91 "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
94 set func [style some_called_function function]
95 # Somewhere should see the call to the function.
96 gdb_test "disassemble main" "[style $hex address].*$func.*"
98 set ifield [style int_field variable]
99 set sfield [style string_field variable]
100 set efield [style e_field variable]
101 set evalue [style VALUE_TWO variable]
102 gdb_test "print struct_value" \
103 "\{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*"
108 set vers [style "GNU gdb.*" "35;1"]
109 gdb_test "" "${vers}.*" \
112 set address_style_expr [style ".*\".*address.*\".*style.*" address]
113 gdb_test "show style address foreground" \
114 "The ${address_style_expr} foreground color is: blue" \
115 "style name and style word styled using its own style in show style"
117 set aliases_expr [style ".*aliases.*" title]
118 set breakpoints_expr [style ".*breakpoints.*" title]
121 "List of classes of commands:" \
123 "${aliases_expr} -- Aliases of other commands\." \
124 "${breakpoints_expr} -- Making program stop at certain points\." \
127 "help classes of commands styled with title"
129 set taas_expr [style ".*taas.*" title]
130 set tfaas_expr [style ".*tfaas.*" title]
131 set cut_for_thre_expr [style "cut for 'thre" highlight]
132 gdb_test "apropos -v cut for 'thre" \
135 "${taas_expr} --.*" \
137 "short${cut_for_thre_expr}ad apply.*" \
139 "${tfaas_expr} --.*" \
141 "short${cut_for_thre_expr}ad apply.*" \
144 set quoted [string_to_regexp $binfile]
145 set pass_re "Reading symbols from [style $quoted file]\.\.\."
150 "Expanding full symbols from [style $quoted file]\.\.\."]
152 gdb_test "file $binfile" \
154 "filename is styled when loading symbol file"
156 gdb_test "pwd" "Working directory [style .*? file].*"
158 gdb_test_no_output "set print repeat 3"
159 gdb_test "print {0,0,0,0,0,0,0,0}" \
160 " = \\{0 [style {<repeats.*8.*times>} metadata]\\}"
162 gdb_test "show logging file" \
163 "The current logfile is \"[style .*? file]\"\\..*"
165 # Check warnings are styled by setting a rubbish data directory.
166 gdb_test "set data-directory Makefile" \
167 "warning: [style .*? file] is not a directory\\..*"
168 gdb_test "show data-directory" \
169 "GDB's data directory is \"[style .*? file]\"\\..*"