cc143b432923964bca1d8d00980f2bdb754650ac
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / style.exp
1 # Copyright 2018-2021 Free Software Foundation, Inc.
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
20 save_vars { env(TERM) } {
21 # We need an ANSI-capable terminal to get the output.
22 setenv TERM ansi
23
24 set test_macros 0
25 set options debug
26 get_compiler_info
27 if { [test_compiler_info "gcc-*"] || [test_compiler_info "clang-*"] } {
28 lappend options additional_flags=-g3
29 set test_macros 1
30 }
31
32 if {[prepare_for_testing "failed to prepare" $testfile $srcfile \
33 $options]} {
34 return -1
35 }
36
37 set readnow [readnow]
38
39 if {![runto_main]} {
40 fail "style tests failed"
41 return
42 }
43
44 # Check that the source highlighter has not stripped away the leading
45 # newlines.
46 set main_line [gdb_get_line_number "break here"]
47 gdb_test "list $main_line,$main_line" "return.*some_called_function.*"
48
49 gdb_test_no_output "set style enabled on"
50
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]
55
56 gdb_test "frame" \
57 "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*"
58 gdb_test "info breakpoints" "$main_expr at $file_expr.*"
59
60 gdb_test_no_output "set style sources off"
61 gdb_test "frame" \
62 "\r\n\[^\033\]*break here.*" \
63 "frame without styling"
64 gdb_test_no_output "set style sources on"
65
66 gdb_test "break -q main" "file $base_file_expr.*"
67
68 gdb_test "print &main" " = .* [style $hex address] <$main_expr>"
69
70 # Regression test for a bug where line-wrapping would occur at the
71 # wrong spot with styling. There were different bugs at different
72 # widths, so try two.
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.
78 gdb_test "frame" \
79 [multi_line \
80 "#0 *$main_expr.*$arg_expr.*" \
81 ".*$arg_expr.*" \
82 ".* at .*$file_expr.*" \
83 "\[0-9\]+.*return.* break here .*"
84 ] \
85 "frame when width=$width"
86 }
87
88 if {$test_macros} {
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"
92 }
93
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.*"]
100
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.*"
107
108 gdb_exit
109 gdb_spawn
110
111 set vers [style "GNU gdb.*" "35;1"]
112 gdb_test "" "${vers}.*" \
113 "version is styled"
114
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"
119
120 set aliases_expr [style ".*aliases.*" title]
121 set breakpoints_expr [style ".*breakpoints.*" title]
122 gdb_test "help" \
123 [multi_line \
124 "List of classes of commands:" \
125 "" \
126 "${aliases_expr} -- User-defined aliases of other commands\." \
127 "${breakpoints_expr} -- Making program stop at certain points\." \
128 ".*" \
129 ] \
130 "help classes of commands styled with title"
131
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" \
136 [multi_line \
137 "" \
138 "${taas_expr}" \
139 "Apply a command to all .*" \
140 "Usage:.*" \
141 "short${cut_for_thre_expr}ad apply.*" \
142 "" \
143 "${tfaas_expr}" \
144 "Apply a command to all .*" \
145 "Usage:.*" \
146 "short${cut_for_thre_expr}ad apply.*" \
147 ]
148
149 set quoted [string_to_regexp $binfile]
150 set pass_re "Reading symbols from [style $quoted file]\.\.\."
151 if { $readnow } {
152 set pass_re \
153 [multi_line \
154 $pass_re \
155 "Expanding full symbols from [style $quoted file]\.\.\."]
156 }
157 gdb_test "file $binfile" \
158 $pass_re \
159 "filename is styled when loading symbol file"
160
161 gdb_test "pwd" "Working directory [style .*? file].*"
162
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]\\}"
166
167 gdb_test "show logging file" \
168 "The current logfile is \"[style .*? file]\"\\..*"
169
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]\"\\..*"
175
176 # Check that deprecation styles command names.
177 gdb_test_no_output "maintenance deprecate p \"new_p\"" \
178 "maintenance deprecate p \"new_p\" /1/"
179 gdb_test "p 5" \
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"
182 }
This page took 0.038073 seconds and 3 git commands to generate.