Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / style.exp
CommitLineData
88b9d363 1# Copyright 2018-2022 Free Software Foundation, Inc.
cbe56571
TT
2
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.
7#
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.
12#
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/>.
15
16# Test CLI output styling.
17
18standard_testfile
19
e7b43072
AB
20# Compile the test executable.
21set test_macros 0
22set options debug
23get_compiler_info
a088215a 24if { [test_compiler_info "gcc-*"] } {
e7b43072
AB
25 lappend options additional_flags=-g3
26 set test_macros 1
a088215a
SST
27} elseif { [test_compiler_info "clang-*"] } {
28 lappend options additional_flags=-fdebug-macro
29 set test_macros 1
e7b43072 30}
6506371f 31
e7b43072
AB
32if {[build_executable "failed to build" $testfile $srcfile $options]} {
33 return -1
34}
cbe56571 35
e7b43072
AB
36# The tests in this file are run multiple times with GDB's styles
37# disabled one at a time. This variable is the style that is
38# currently disabled.
39set currently_disabled_style ""
71ea2b6b 40
e7b43072
AB
41# A wrapper around the 'style' function found in gdb-utils.exp,
42# filter out requests for the disabled style.
43proc limited_style { str style } {
44 global currently_disabled_style
45
46 if { $style != $currently_disabled_style } {
47 return [style $str $style]
cbe56571
TT
48 }
49
e7b43072
AB
50 return $str
51}
bdfc1e8a 52
e7b43072
AB
53# A wrapper around 'clean_restart' from gdb.exp, this performs the
54# normal clean_restart, but then disables the currently disabled
55# style.
56proc clean_restart_and_disable { args } {
57 global currently_disabled_style
116d0cf1 58
e7b43072 59 eval "clean_restart $args"
116d0cf1 60
e7b43072
AB
61 if { $currently_disabled_style != "" } {
62 set st $currently_disabled_style
63 gdb_test_no_output "set style $st background none" ""
64 gdb_test_no_output "set style $st foreground none" ""
65 gdb_test_no_output "set style $st intensity normal" ""
66 }
67}
cbe56571 68
e7b43072
AB
69# The core of this test script. Run some tests of different aspects
70# of GDB's styling.
71#
72# Within this proc always use LIMITED_STYLE instead of STYLE, and
73# CLEAN_RESTART_AND_DISABLE instead of CLEAN_RESTART, this ensures
74# that the test operates as expected as styles are disabled.
75proc run_style_tests { } {
76 global testfile srcfile hex binfile test_macros
77 global currently_disabled_style decimal hex
78
79 save_vars { env(TERM) } {
80 # We need an ANSI-capable terminal to get the output.
81 setenv TERM ansi
82
83 # Restart GDB with the correct TERM variable setting, this
84 # means that GDB will enable styling.
85 clean_restart_and_disable ${binfile}
86
87 set readnow [readnow]
88
89 if {![runto_main]} {
90 fail "style tests failed"
91 return
92 }
cbe56571 93
e7b43072
AB
94 # Check that the source highlighter has not stripped away the
95 # leading newlines.
96 set main_line [gdb_get_line_number "break here"]
97 gdb_test "list $main_line,$main_line" "return.*some_called_function.*"
0bb296cb 98
e7b43072 99 gdb_test_no_output "set style enabled off"
d085f989 100
e7b43072
AB
101 set argv ""
102 gdb_test_multiple "frame" "frame without styling" {
103 -re -wrap "main \\(argc=.*, (argv=$hex)\\).*style\\.c:\[0-9\].*" {
104 set argv $expect_out(1,string)
105 pass $gdb_test_name
106 }
107 }
af79b68d 108
e7b43072 109 gdb_test_no_output "set style enabled on"
d47032b7 110
e7b43072
AB
111 set main_expr [limited_style main function]
112 set base_file_expr [limited_style ".*style\\.c" file]
113 set file_expr "$base_file_expr:\[0-9\]+"
114 set arg_expr [limited_style "arg." variable]
116d0cf1 115
e7b43072 116 gdb_test "frame" \
a0087920 117 [multi_line \
e7b43072
AB
118 "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+$arg_expr=$hex\\)\\s+at\\s+$file_expr" \
119 "\[0-9\]+\\s+.*return.* break here .*"]
120 gdb_test "info breakpoints" "$main_expr at $file_expr.*"
121
122 gdb_test_no_output "set style sources off"
123 gdb_test "frame" \
124 "\r\n\[^\033\]*break here.*" \
125 "frame without sources styling"
126 gdb_test_no_output "set style sources on"
127
128 gdb_test "break -q main" "file $base_file_expr.*"
129
130 gdb_test "print &main" " = .* [limited_style $hex address] <$main_expr>"
131
132 # Regression test for a bug where line-wrapping would occur at
133 # the wrong spot with styling. There were different bugs at
134 # different widths, so try two.
135 foreach width {20 30} {
136 set argv_len [string length $argv]
137 if { $argv_len == 0 } {
138 continue
139 }
140
141 # There was also a bug where the styling could be wrong in
142 # the line listing; this is why the words from the source
143 # code are spelled out in the final result line of the
144 # test.
145 set re1_styled \
146 [multi_line \
147 "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+" \
148 "\\s+$arg_expr=$hex\\)" \
149 "\\s+at\\s+$file_expr" \
150 "\[0-9\]+\\s+.*return.* break here .*"]
151 set re2_styled \
152 [multi_line \
153 "#0\\s+$main_expr\\s+\\($arg_expr=.*" \
154 "\\s+$arg_expr=$hex\\)\\s+at\\s+$file_expr" \
155 "\[0-9\]+\\s+.*return.* break here .*"]
156
157 # The length of the line containing argv containing:
158 # - 4 leading spaces
159 # - argv string
160 # - closing parenthesis
161 set line_len [expr 4 + $argv_len + 1]
162
163 if { $line_len > $width } {
164 # At on the next line.
165 set re_styled $re1_styled
166 } else {
167 # At on the same line as argv.
168 set re_styled $re2_styled
169 }
170
171 gdb_test_no_output "set width $width"
172 gdb_test "frame" $re_styled "frame when width=$width"
116d0cf1
TV
173 }
174
e7b43072
AB
175 # Reset width back to 0.
176 gdb_test_no_output "set width 0" ""
116d0cf1 177
e7b43072
AB
178 if {$test_macros} {
179 set macro_line [gdb_get_line_number "\#define SOME_MACRO"]
180 gdb_test "info macro SOME_MACRO" \
181 "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23"
182 }
6506371f 183
e7b43072
AB
184 gdb_test_no_output "set width 0"
185
186 set main [limited_style main function]
187 set func [limited_style some_called_function function]
188 # Somewhere should see the call to the function.
189 gdb_test "disassemble main" \
190 [concat "Dump of assembler code for function $main:.*" \
191 "[limited_style $hex address].*$func.*"]
192
193 set ifield [limited_style int_field variable]
194 set sfield [limited_style string_field variable]
195 set efield [limited_style e_field variable]
196 set evalue [limited_style VALUE_TWO variable]
197 gdb_test "print struct_value" \
198 "\{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*"
199
200 set address_style_expr [limited_style ".*\".*address.*\".*style.*" address]
201 set color "blue"
202 if { $currently_disabled_style == "address" } {
203 set color "none"
204 }
205 gdb_test "show style address foreground" \
206 "The ${address_style_expr} foreground color is: ${color}" \
207 "style name and style word styled using its own style in show style"
046bebe1 208
e7b43072
AB
209 set aliases_expr [limited_style ".*aliases.*" title]
210 set breakpoints_expr [limited_style ".*breakpoints.*" title]
211 gdb_test "help" \
212 [multi_line \
213 "List of classes of commands:" \
214 "" \
215 "${aliases_expr} -- User-defined aliases of other commands\." \
216 "${breakpoints_expr} -- Making program stop at certain points\." \
217 ".*" \
218 ] \
219 "help classes of commands styled with title"
220
221 set taas_expr [limited_style ".*taas.*" title]
222 set tfaas_expr [limited_style ".*tfaas.*" title]
223 set cut_for_thre_expr [limited_style "cut for 'thre" highlight]
224 gdb_test "apropos -v cut for 'thre" \
225 [multi_line \
226 "" \
227 "${taas_expr}" \
228 "Apply a command to all .*" \
229 "Usage:.*" \
230 "short${cut_for_thre_expr}ad apply.*" \
231 "" \
232 "${tfaas_expr}" \
233 "Apply a command to all .*" \
234 "Usage:.*" \
235 "short${cut_for_thre_expr}ad apply.*" \
236 ]
237
238 clean_restart_and_disable
239
240 set quoted [string_to_regexp $binfile]
241 set pass_re "Reading symbols from [limited_style $quoted file]\.\.\."
242 if { $readnow } {
243 set pass_re \
244 [multi_line \
245 $pass_re \
246 "Expanding full symbols from [limited_style $quoted file]\.\.\."]
247 }
248 gdb_test "file $binfile" \
249 $pass_re \
250 "filename is styled when loading symbol file" \
251 "Are you sure you want to change the file.*" \
252 "y"
253
254 gdb_test "pwd" "Working directory [limited_style .*? file].*"
255
256 gdb_test_no_output "set print repeat 3"
257 gdb_test "print {0,0,0,0,0,0,0,0}" \
258 " = \\{0 [limited_style {<repeats.*8.*times>} metadata]\\}"
259
260 gdb_test "show logging file" \
261 "The current logfile is \"[limited_style .*? file]\"\\..*"
262
263 # Check warnings are styled by setting a rubbish data
264 # directory.
265 gdb_test "set data-directory Makefile" \
266 "warning: [limited_style .*? file] is not a directory\\..*"
267 gdb_test "show data-directory" \
268 "GDB's data directory is \"[limited_style .*? file]\"\\..*"
269
270 # Check that deprecation styles command names.
271 gdb_test_no_output "maintenance deprecate p \"new_p\"" \
272 "maintenance deprecate p \"new_p\" /1/"
273 gdb_test "p 5" \
274 "Warning: '[limited_style p title]', an alias for the command '[limited_style print title]', is deprecated.*Use '[limited_style new_p title]'.*" \
275 "p deprecated warning, with replacement"
9d2d8a16
AB
276
277 # Check that the version string is styled in the output of 'show
278 # version', and that this styling can be disabled.
279 set vers [style "GNU gdb.*" version]
280 gdb_test "show version" "${vers}.*" \
281 "version is styled in 'show version'"
e7b43072
AB
282 }
283}
3f0cbb04 284
e7b43072
AB
285# A separate test from the above as the styled text this checks can't
286# currently be disabled (the text is printed too early in GDB's
287# startup process).
288proc test_startup_version_string { } {
d47032b7
TT
289 gdb_exit
290 gdb_spawn
291
e7b43072
AB
292 # Deliberate use of base STYLE proc here as the style of the
293 # startup version string can't (currently) be controlled.
9d2d8a16 294 set vers [style "GNU gdb.*" version]
e7b43072
AB
295 gdb_test "" "${vers}.*" "version is styled at startup"
296}
297
298
299# Run tests with all styles in their default state.
300with_test_prefix "all styles enabled" {
301 run_style_tests
302}
303
304# Now, for each style in turn. Disable that style only and run the
305# test again. Things in that style should NOT now be styled.
306foreach style { title file function highlight variable \
307 address metadata } {
308 set currently_disabled_style $style
309 with_test_prefix "disable style $style" {
310 run_style_tests
71ea2b6b 311 }
cbe56571 312}
e7b43072
AB
313
314# Finally, check the styling of the version string during startup.
315test_startup_version_string
This page took 0.434812 seconds and 4 git commands to generate.