1 # Copyright 2018-2021 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 -q 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 main [style main function]
95 set func [style some_called_function function]
96 # Somewhere should see the call to the function.
97 gdb_test "disassemble main" \
98 [concat "Dump of assembler code for function $main:.*" \
99 "[style $hex address].*$func.*"]
101 set ifield [style int_field variable]
102 set sfield [style string_field variable]
103 set efield [style e_field variable]
104 set evalue [style VALUE_TWO variable]
105 gdb_test "print struct_value" \
106 "\{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*"
111 set vers [style "GNU gdb.*" "35;1"]
112 gdb_test "" "${vers}.*" \
115 set address_style_expr [style ".*\".*address.*\".*style.*" address]
116 gdb_test "show style address foreground" \
117 "The ${address_style_expr} foreground color is: blue" \
118 "style name and style word styled using its own style in show style"
120 set aliases_expr [style ".*aliases.*" title]
121 set breakpoints_expr [style ".*breakpoints.*" title]
124 "List of classes of commands:" \
126 "${aliases_expr} -- User-defined aliases of other commands\." \
127 "${breakpoints_expr} -- Making program stop at certain points\." \
130 "help classes of commands styled with title"
132 set taas_expr [style ".*taas.*" title]
133 set tfaas_expr [style ".*tfaas.*" title]
134 set cut_for_thre_expr [style "cut for 'thre" highlight]
135 gdb_test "apropos -v cut for 'thre" \
139 "Apply a command to all .*" \
141 "short${cut_for_thre_expr}ad apply.*" \
144 "Apply a command to all .*" \
146 "short${cut_for_thre_expr}ad apply.*" \
149 set quoted [string_to_regexp $binfile]
150 set pass_re "Reading symbols from [style $quoted file]\.\.\."
155 "Expanding full symbols from [style $quoted file]\.\.\."]
157 gdb_test "file $binfile" \
159 "filename is styled when loading symbol file"
161 gdb_test "pwd" "Working directory [style .*? file].*"
163 gdb_test_no_output "set print repeat 3"
164 gdb_test "print {0,0,0,0,0,0,0,0}" \
165 " = \\{0 [style {<repeats.*8.*times>} metadata]\\}"
167 gdb_test "show logging file" \
168 "The current logfile is \"[style .*? file]\"\\..*"
170 # Check warnings are styled by setting a rubbish data directory.
171 gdb_test "set data-directory Makefile" \
172 "warning: [style .*? file] is not a directory\\..*"
173 gdb_test "show data-directory" \
174 "GDB's data directory is \"[style .*? file]\"\\..*"
176 # Check that deprecation styles command names.
177 gdb_test_no_output "maintenance deprecate p \"new_p\"" \
178 "maintenance deprecate p \"new_p\" /1/"
180 "Warning: '[style p title]', an alias for the command '[style print title]', is deprecated.*Use '[style new_p title]'.*" \
181 "p deprecated warning, with replacement"