Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2018-2020 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 | ||
20 | save_vars { env(TERM) } { | |
21 | # We need an ANSI-capable terminal to get the output. | |
22 | setenv TERM ansi | |
23 | ||
6506371f TT |
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]} { | |
cbe56571 TT |
34 | return -1 |
35 | } | |
36 | ||
71ea2b6b TV |
37 | set readnow [readnow] |
38 | ||
cbe56571 TT |
39 | if {![runto_main]} { |
40 | fail "style tests failed" | |
41 | return | |
42 | } | |
43 | ||
bdfc1e8a TV |
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 | ||
cbe56571 TT |
49 | gdb_test_no_output "set style enabled on" |
50 | ||
18125b16 TT |
51 | set main_expr [style main function] |
52 | set base_file_expr [style ".*style\\.c" file] | |
0bb296cb | 53 | set file_expr "$base_file_expr:\[0-9\]" |
18125b16 | 54 | set arg_expr [style "arg." variable] |
cbe56571 TT |
55 | |
56 | gdb_test "frame" \ | |
80ae2043 | 57 | "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*" |
cbe56571 | 58 | gdb_test "info breakpoints" "$main_expr at $file_expr.*" |
0bb296cb | 59 | |
d085f989 TT |
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 | ||
0bb296cb | 66 | gdb_test "break main" "file $base_file_expr.*" |
af79b68d | 67 | |
18125b16 | 68 | gdb_test "print &main" " = .* [style $hex address] <$main_expr>" |
d47032b7 | 69 | |
a0087920 TT |
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 | ||
6506371f | 88 | if {$test_macros} { |
bdfc1e8a | 89 | set macro_line [gdb_get_line_number "\#define SOME_MACRO"] |
6506371f | 90 | gdb_test "info macro SOME_MACRO" \ |
bdfc1e8a | 91 | "Defined at $base_file_expr:$macro_line\r\n#define SOME_MACRO 23" |
6506371f TT |
92 | } |
93 | ||
046bebe1 TT |
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.*" | |
97 | ||
3f0cbb04 TT |
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.*" | |
104 | ||
d47032b7 TT |
105 | gdb_exit |
106 | gdb_spawn | |
107 | ||
18125b16 TT |
108 | set vers [style "GNU gdb.*" "35;1"] |
109 | gdb_test "" "${vers}.*" \ | |
d47032b7 | 110 | "version is styled" |
47fd17cd | 111 | |
2a3c1174 | 112 | set address_style_expr [style ".*\".*address.*\".*style.*" address] |
206584bd PW |
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" | |
116 | ||
2a3c1174 PA |
117 | set aliases_expr [style ".*aliases.*" title] |
118 | set breakpoints_expr [style ".*breakpoints.*" title] | |
206584bd PW |
119 | gdb_test "help" \ |
120 | [multi_line \ | |
121 | "List of classes of commands:" \ | |
122 | "" \ | |
746ebfe8 | 123 | "${aliases_expr} -- User-defined aliases of other commands\." \ |
590042fc | 124 | "${breakpoints_expr} -- Making program stop at certain points\." \ |
206584bd PW |
125 | ".*" \ |
126 | ] \ | |
127 | "help classes of commands styled with title" | |
128 | ||
2a3c1174 PA |
129 | set taas_expr [style ".*taas.*" title] |
130 | set tfaas_expr [style ".*tfaas.*" title] | |
206584bd PW |
131 | set cut_for_thre_expr [style "cut for 'thre" highlight] |
132 | gdb_test "apropos -v cut for 'thre" \ | |
133 | [multi_line \ | |
134 | "" \ | |
746ebfe8 PW |
135 | "${taas_expr}" \ |
136 | "Apply a command to all .*" \ | |
206584bd PW |
137 | "Usage:.*" \ |
138 | "short${cut_for_thre_expr}ad apply.*" \ | |
139 | "" \ | |
746ebfe8 PW |
140 | "${tfaas_expr}" \ |
141 | "Apply a command to all .*" \ | |
206584bd PW |
142 | "Usage:.*" \ |
143 | "short${cut_for_thre_expr}ad apply.*" \ | |
11af934b | 144 | ] |
206584bd | 145 | |
47fd17cd | 146 | set quoted [string_to_regexp $binfile] |
71ea2b6b TV |
147 | set pass_re "Reading symbols from [style $quoted file]\.\.\." |
148 | if { $readnow } { | |
149 | set pass_re \ | |
150 | [multi_line \ | |
151 | $pass_re \ | |
152 | "Expanding full symbols from [style $quoted file]\.\.\."] | |
153 | } | |
47fd17cd | 154 | gdb_test "file $binfile" \ |
71ea2b6b | 155 | $pass_re \ |
6eb6fb67 | 156 | "filename is styled when loading symbol file" |
14309bb6 TT |
157 | |
158 | gdb_test "pwd" "Working directory [style .*? file].*" | |
7f6aba03 TT |
159 | |
160 | gdb_test_no_output "set print repeat 3" | |
161 | gdb_test "print {0,0,0,0,0,0,0,0}" \ | |
162 | " = \\{0 [style {<repeats.*8.*times>} metadata]\\}" | |
d770d56f TT |
163 | |
164 | gdb_test "show logging file" \ | |
165 | "The current logfile is \"[style .*? file]\"\\..*" | |
6ec1d75e PW |
166 | |
167 | # Check warnings are styled by setting a rubbish data directory. | |
168 | gdb_test "set data-directory Makefile" \ | |
169 | "warning: [style .*? file] is not a directory\\..*" | |
170 | gdb_test "show data-directory" \ | |
171 | "GDB's data directory is \"[style .*? file]\"\\..*" | |
cbe56571 | 172 | } |