]>
Commit | Line | Data |
---|---|---|
4a94e368 | 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 | ||
18 | standard_testfile | |
19 | ||
e7b43072 AB |
20 | # Compile the test executable. |
21 | set test_macros 0 | |
22 | set options debug | |
23 | get_compiler_info | |
a088215a | 24 | if { [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 |
32 | if {[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. | |
39 | set 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. | |
43 | proc 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. | |
56 | proc 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. | |
75 | proc 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]} { | |
e7b43072 AB |
90 | return |
91 | } | |
cbe56571 | 92 | |
e7b43072 AB |
93 | # Check that the source highlighter has not stripped away the |
94 | # leading newlines. | |
95 | set main_line [gdb_get_line_number "break here"] | |
96 | gdb_test "list $main_line,$main_line" "return.*some_called_function.*" | |
0bb296cb | 97 | |
e7b43072 | 98 | gdb_test_no_output "set style enabled off" |
d085f989 | 99 | |
e7b43072 AB |
100 | set argv "" |
101 | gdb_test_multiple "frame" "frame without styling" { | |
102 | -re -wrap "main \\(argc=.*, (argv=$hex)\\).*style\\.c:\[0-9\].*" { | |
103 | set argv $expect_out(1,string) | |
104 | pass $gdb_test_name | |
105 | } | |
106 | } | |
af79b68d | 107 | |
e7b43072 | 108 | gdb_test_no_output "set style enabled on" |
d47032b7 | 109 | |
e7b43072 AB |
110 | set main_expr [limited_style main function] |
111 | set base_file_expr [limited_style ".*style\\.c" file] | |
112 | set file_expr "$base_file_expr:\[0-9\]+" | |
113 | set arg_expr [limited_style "arg." variable] | |
116d0cf1 | 114 | |
e7b43072 | 115 | gdb_test "frame" \ |
a0087920 | 116 | [multi_line \ |
e7b43072 AB |
117 | "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+$arg_expr=$hex\\)\\s+at\\s+$file_expr" \ |
118 | "\[0-9\]+\\s+.*return.* break here .*"] | |
119 | gdb_test "info breakpoints" "$main_expr at $file_expr.*" | |
120 | ||
121 | gdb_test_no_output "set style sources off" | |
122 | gdb_test "frame" \ | |
123 | "\r\n\[^\033\]*break here.*" \ | |
124 | "frame without sources styling" | |
125 | gdb_test_no_output "set style sources on" | |
126 | ||
127 | gdb_test "break -q main" "file $base_file_expr.*" | |
128 | ||
129 | gdb_test "print &main" " = .* [limited_style $hex address] <$main_expr>" | |
130 | ||
131 | # Regression test for a bug where line-wrapping would occur at | |
132 | # the wrong spot with styling. There were different bugs at | |
133 | # different widths, so try two. | |
134 | foreach width {20 30} { | |
135 | set argv_len [string length $argv] | |
136 | if { $argv_len == 0 } { | |
137 | continue | |
138 | } | |
139 | ||
140 | # There was also a bug where the styling could be wrong in | |
141 | # the line listing; this is why the words from the source | |
142 | # code are spelled out in the final result line of the | |
143 | # test. | |
144 | set re1_styled \ | |
145 | [multi_line \ | |
146 | "#0\\s+$main_expr\\s+\\($arg_expr=$decimal,\\s+" \ | |
147 | "\\s+$arg_expr=$hex\\)" \ | |
148 | "\\s+at\\s+$file_expr" \ | |
149 | "\[0-9\]+\\s+.*return.* break here .*"] | |
150 | set re2_styled \ | |
151 | [multi_line \ | |
152 | "#0\\s+$main_expr\\s+\\($arg_expr=.*" \ | |
153 | "\\s+$arg_expr=$hex\\)\\s+at\\s+$file_expr" \ | |
154 | "\[0-9\]+\\s+.*return.* break here .*"] | |
155 | ||
156 | # The length of the line containing argv containing: | |
157 | # - 4 leading spaces | |
158 | # - argv string | |
159 | # - closing parenthesis | |
160 | set line_len [expr 4 + $argv_len + 1] | |
161 | ||
162 | if { $line_len > $width } { | |
163 | # At on the next line. | |
164 | set re_styled $re1_styled | |
165 | } else { | |
166 | # At on the same line as argv. | |
167 | set re_styled $re2_styled | |
168 | } | |
169 | ||
170 | gdb_test_no_output "set width $width" | |
171 | gdb_test "frame" $re_styled "frame when width=$width" | |
116d0cf1 | 172 | |
d0b39fc4 TV |
173 | # Reset width back to 0. Doing this in the loop rather than |
174 | # after, avoids trying to do "set width 30" while width is 20, | |
175 | # which causes horizontal scrolling in the case that the fallback | |
176 | # stub-termcap.c is used: | |
177 | # ^M<et width 30^M | |
178 | # (gdb) FAIL: gdb.base/style.exp: all styles enabled: set width 30 | |
179 | gdb_test_no_output "set width 0" "" | |
180 | } | |
116d0cf1 | 181 | |
e7b43072 AB |
182 | if {$test_macros} { |
183 | set macro_line [gdb_get_line_number "\#define SOME_MACRO"] | |
184 | gdb_test "info macro SOME_MACRO" \ | |
185 | "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23" | |
186 | } | |
6506371f | 187 | |
e7b43072 AB |
188 | gdb_test_no_output "set width 0" |
189 | ||
190 | set main [limited_style main function] | |
191 | set func [limited_style some_called_function function] | |
192 | # Somewhere should see the call to the function. | |
193 | gdb_test "disassemble main" \ | |
194 | [concat "Dump of assembler code for function $main:.*" \ | |
195 | "[limited_style $hex address].*$func.*"] | |
196 | ||
197 | set ifield [limited_style int_field variable] | |
198 | set sfield [limited_style string_field variable] | |
199 | set efield [limited_style e_field variable] | |
200 | set evalue [limited_style VALUE_TWO variable] | |
201 | gdb_test "print struct_value" \ | |
202 | "\{$ifield = 23,.*$sfield = .*,.*$efield = $evalue.*" | |
203 | ||
334381ea TT |
204 | set ffield [limited_style field variable] |
205 | set cstart [string_to_regexp "/* XXX "] | |
206 | set cend [string_to_regexp " */"] | |
207 | set p1field [limited_style "$cstart.*$decimal.*-bit.*padding.*$cend" \ | |
208 | highlight] | |
209 | set p2field [limited_style "$cstart.*$decimal.*-byte.*padding.*$cend" \ | |
210 | highlight] | |
211 | ||
212 | gdb_test "ptype/o just_bitfield_value" \ | |
213 | [multi_line \ | |
214 | ".* type = struct just_bitfield {" \ | |
215 | ".* unsigned int $ffield : 3;" \ | |
216 | "$p1field" \ | |
217 | "$p2field" \ | |
218 | "" \ | |
219 | ".* total size.*: *$decimal *$cend" \ | |
220 | " *}.*"] | |
221 | ||
e7b43072 AB |
222 | set address_style_expr [limited_style ".*\".*address.*\".*style.*" address] |
223 | set color "blue" | |
224 | if { $currently_disabled_style == "address" } { | |
225 | set color "none" | |
226 | } | |
227 | gdb_test "show style address foreground" \ | |
228 | "The ${address_style_expr} foreground color is: ${color}" \ | |
229 | "style name and style word styled using its own style in show style" | |
046bebe1 | 230 | |
e7b43072 AB |
231 | set aliases_expr [limited_style ".*aliases.*" title] |
232 | set breakpoints_expr [limited_style ".*breakpoints.*" title] | |
233 | gdb_test "help" \ | |
234 | [multi_line \ | |
235 | "List of classes of commands:" \ | |
236 | "" \ | |
237 | "${aliases_expr} -- User-defined aliases of other commands\." \ | |
238 | "${breakpoints_expr} -- Making program stop at certain points\." \ | |
239 | ".*" \ | |
240 | ] \ | |
241 | "help classes of commands styled with title" | |
242 | ||
243 | set taas_expr [limited_style ".*taas.*" title] | |
244 | set tfaas_expr [limited_style ".*tfaas.*" title] | |
245 | set cut_for_thre_expr [limited_style "cut for 'thre" highlight] | |
246 | gdb_test "apropos -v cut for 'thre" \ | |
247 | [multi_line \ | |
248 | "" \ | |
249 | "${taas_expr}" \ | |
250 | "Apply a command to all .*" \ | |
251 | "Usage:.*" \ | |
252 | "short${cut_for_thre_expr}ad apply.*" \ | |
253 | "" \ | |
254 | "${tfaas_expr}" \ | |
255 | "Apply a command to all .*" \ | |
256 | "Usage:.*" \ | |
257 | "short${cut_for_thre_expr}ad apply.*" \ | |
258 | ] | |
259 | ||
260 | clean_restart_and_disable | |
261 | ||
262 | set quoted [string_to_regexp $binfile] | |
263 | set pass_re "Reading symbols from [limited_style $quoted file]\.\.\." | |
264 | if { $readnow } { | |
265 | set pass_re \ | |
266 | [multi_line \ | |
267 | $pass_re \ | |
268 | "Expanding full symbols from [limited_style $quoted file]\.\.\."] | |
269 | } | |
270 | gdb_test "file $binfile" \ | |
271 | $pass_re \ | |
272 | "filename is styled when loading symbol file" \ | |
273 | "Are you sure you want to change the file.*" \ | |
274 | "y" | |
275 | ||
276 | gdb_test "pwd" "Working directory [limited_style .*? file].*" | |
277 | ||
278 | gdb_test_no_output "set print repeat 3" | |
279 | gdb_test "print {0,0,0,0,0,0,0,0}" \ | |
280 | " = \\{0 [limited_style {<repeats.*8.*times>} metadata]\\}" | |
281 | ||
282 | gdb_test "show logging file" \ | |
283 | "The current logfile is \"[limited_style .*? file]\"\\..*" | |
284 | ||
285 | # Check warnings are styled by setting a rubbish data | |
286 | # directory. | |
287 | gdb_test "set data-directory Makefile" \ | |
288 | "warning: [limited_style .*? file] is not a directory\\..*" | |
289 | gdb_test "show data-directory" \ | |
290 | "GDB's data directory is \"[limited_style .*? file]\"\\..*" | |
291 | ||
292 | # Check that deprecation styles command names. | |
293 | gdb_test_no_output "maintenance deprecate p \"new_p\"" \ | |
294 | "maintenance deprecate p \"new_p\" /1/" | |
295 | gdb_test "p 5" \ | |
296 | "Warning: '[limited_style p title]', an alias for the command '[limited_style print title]', is deprecated.*Use '[limited_style new_p title]'.*" \ | |
297 | "p deprecated warning, with replacement" | |
9d2d8a16 AB |
298 | |
299 | # Check that the version string is styled in the output of 'show | |
300 | # version', and that this styling can be disabled. | |
301 | set vers [style "GNU gdb.*" version] | |
302 | gdb_test "show version" "${vers}.*" \ | |
303 | "version is styled in 'show version'" | |
e7b43072 AB |
304 | } |
305 | } | |
3f0cbb04 | 306 | |
e7b43072 AB |
307 | # A separate test from the above as the styled text this checks can't |
308 | # currently be disabled (the text is printed too early in GDB's | |
309 | # startup process). | |
310 | proc test_startup_version_string { } { | |
d47032b7 TT |
311 | gdb_exit |
312 | gdb_spawn | |
313 | ||
e7b43072 AB |
314 | # Deliberate use of base STYLE proc here as the style of the |
315 | # startup version string can't (currently) be controlled. | |
9d2d8a16 | 316 | set vers [style "GNU gdb.*" version] |
e7b43072 AB |
317 | gdb_test "" "${vers}.*" "version is styled at startup" |
318 | } | |
319 | ||
320 | ||
321 | # Run tests with all styles in their default state. | |
322 | with_test_prefix "all styles enabled" { | |
323 | run_style_tests | |
324 | } | |
325 | ||
326 | # Now, for each style in turn. Disable that style only and run the | |
327 | # test again. Things in that style should NOT now be styled. | |
328 | foreach style { title file function highlight variable \ | |
329 | address metadata } { | |
330 | set currently_disabled_style $style | |
331 | with_test_prefix "disable style $style" { | |
332 | run_style_tests | |
71ea2b6b | 333 | } |
cbe56571 | 334 | } |
e7b43072 AB |
335 | |
336 | # Finally, check the styling of the version string during startup. | |
337 | test_startup_version_string |