[gdb/testsuite] Factor out lib/valgrind.exp
[external/binutils.git] / gdb / testsuite / gdb.base / info-macros.exp
1 # Copyright 2011-2018 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 standard_testfile .c
17
18 # Fission doesn't support macros yet.  Bug 15954.
19 if [using_fission] {
20     untested "fission does not support macros yet"
21     return -1
22 }
23
24 get_compiler_info
25 if ![test_compiler_info gcc*] {
26   untested "no compiler info"
27   return -1
28 }
29
30 # Don't use "debug" here.  Otherwise "-g" would be appended to the gcc
31 # command line, possibly overriding "-g3" (depending on gcc version).
32 set options "additional_flags=-g3"
33
34 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
35     return -1
36 }
37
38 if ![runto_main] {
39     untested "could not run to main"
40     return -1
41 }
42
43 # Test various error messages.
44 gdb_test "info macro -- -all" \
45          "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+" \
46          "info macro -- -all"
47 gdb_test "info macro  -- -all" \
48          "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+" \
49          "info macro  -- -all"
50
51 gdb_test "info macro -all --" \
52          "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
53          "info macro -all --"
54
55 gdb_test "info macro -all  --" \
56          "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
57          "info macro -all  --"
58
59 gdb_test "info macro  -all  --" \
60          "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
61          "info macro  -all  --"
62
63 gdb_test "info macro --" \
64          "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
65          "info macro --"
66
67 gdb_test "info macro -- " \
68          "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
69          "'info macro -- '"
70 gdb_test "info macro  -- " \
71          "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
72          "'info macro  -- '"
73
74 gdb_test "info macro -invalid-option" \
75          "Unrecognized option.*Try \"help info macro\"\." \
76          "info macro -invalid-option 1"
77
78 gdb_test "info macro  -invalid-option" \
79          "Unrecognized option.*Try \"help info macro\"\." \
80          "info macro  -invalid-option"
81
82 gdb_test "info macro -invalid-option FOO" \
83          "Unrecognized option.*Try \"help info macro\"\." \
84          "info macro -invalid-option FOO"
85 gdb_test "info macro  -invalid-option FOO" \
86          "Unrecognized option.*Try \"help info macro\"\." \
87          "info macro  -invalid-option FOO"
88
89 # Single macro lookups.
90 gdb_test "info macro -- FOO" \
91          ".*#define FOO \"hello\"" \
92          "info macro -- FOO"
93
94 gdb_test "info macro  -- FOO" \
95          ".*#define FOO \"hello\"" \
96          "info macro  -- FOO"
97
98 gdb_test "info macro --  FOO" \
99          ".*#define FOO \"hello\"" \
100          "info macro --  FOO"
101
102 gdb_test "info macro FOO" \
103          ".*#define FOO \"hello\"" \
104          "info macro FOO"
105
106 gdb_test "info macro  FOO" \
107          ".*#define FOO \"hello\"" \
108          "info macro  FOO"
109
110 # Multiple macro lookups.
111 set test "info macro -a FOO"
112 set r1 ".*#define FOO \"hello\""
113 set r2 ".*#define FOO \" \""
114 set r3 ".*#define FOO \"world\""
115 set r4 ".*#define FOO\\(a\\) foo = a"
116 set testname "$test 1"
117 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
118
119 set test "info macro -a -- FOO"
120 set testname "$test 1"
121 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
122
123 set test "info macro -all -- FOO"
124 set testname "$test 1"
125 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
126
127 set test "info macro -a  --  FOO"
128 set testname "$test"
129 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
130
131 set test "info macro  -a  --  FOO"
132 set testname "$test"
133 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
134
135 set test "info macros"
136 set r1 ".*#define FOO \"hello\""
137 set r2 ".*#define ONE"
138 set r3 ".*\r\n$gdb_prompt"
139 set testname "$test 2"
140 gdb_test_multiple "$test" $testname {
141   -re "$r1$r2$r3" {
142      pass $testname
143   }
144   -re ".*#define TWO.*\r\n$gdb_prompt" {
145      fail $testname
146   }
147   -re ".*#define THREE.*\r\n$gdb_prompt" {
148      fail $testname
149   }
150   -re ".*#define FOUR.*\r\n$gdb_prompt" {
151      fail $testname
152   }
153 }
154 gdb_test "next" ".*" ""
155
156 set r1 ".*#define FOO \" \""
157 set r2 ".*#define ONE"
158 set r3 ".*#define TWO"
159 set r4 ".*\r\n$gdb_prompt"
160 set testname "$test 3"
161 gdb_test_multiple "$test" $testname {
162   -re ".*#define THREE.*\r\n$gdb_prompt" {
163      fail $testname
164   }
165   -re ".*#define FOUR.*\r\n$gdb_prompt" {
166      fail $testname
167   }
168   -re "$r1$r2$r3$r4" {
169      pass $testname
170   }
171 }
172 gdb_test "next" ".*" ""
173
174 # in alpabetical order...
175 set r1 ".*#define FOO \"world\""
176 set r2 ".*#define ONE"
177 set r3 ".*#define THREE"
178 set r4 ".*#define TWO"
179 set r5 ".*\r\n$gdb_prompt"
180 set testname "$test 4"
181 gdb_test_multiple "$test" $testname {
182   -re ".*#define FOUR.*\r\n$gdb_prompt" {
183      fail $testname
184   }
185   -re "$r1$r2$r3$r4$r5" {
186      pass $testname
187   }
188 }
189 # same as above with a linespec.
190 set test "info macros *\$pc"
191 gdb_test_multiple "$test" $test {
192   -re ".*#define FOUR.*\r\n$gdb_prompt" {
193      fail $test
194   }
195   -re "$r1$r2$r3$r4$r5" {
196      pass $test
197   }
198 }
199 gdb_test "next" ".*" ""
200
201 set r1 ".*#define FOO \" \""
202 set r2 ".*#define ONE"
203 set r3 ".*#define TWO."
204 set r4 ".*\r\n$gdb_prompt"
205 set test "info macros"
206 set testname "$test 5"
207 gdb_test_multiple "$test" $test {
208   -re ".*#define THREE.*\r\n$gdb_prompt" {
209      fail $testname
210   }
211   -re ".*#define FOUR.*\r\n$gdb_prompt" {
212      fail $testname
213   }
214   -re "$r1$r2$r3$r4" {
215      pass $testname
216   }
217 }
218 gdb_test "next" ".*" ""
219 gdb_test "next" ".*" ""
220
221 set r1 ".*#define DEF_MACROS"
222 set r2 ".*\r\n$gdb_prompt"
223 set testname "$test 6"
224 gdb_test_multiple "$test" $testname {
225   -re ".*#define FOO \" \".*\r\n$gdb_prompt" {
226      fail $testname
227   }
228   -re ".*#define FOO \"hello\".*\r\n$gdb_prompt" {
229      fail $testname
230   }
231   -re ".*#define FOO \"world\".*\r\n$gdb_prompt" {
232      fail $testname
233   }
234   -re ".*#define FOO\\(a\\) foo = a.*" {
235      fail $testname
236   }
237   -re ".*#define ONE.*\r\n$gdb_prompt" {
238      fail $testname
239   }
240   -re ".*#define TWO.*\r\n$gdb_prompt" {
241      fail $testname
242   }
243   -re ".*#define THREE.*\r\n$gdb_prompt" {
244      fail $testname
245   }
246   -re ".*#define FOUR.*\r\n$gdb_prompt" {
247      fail $testname
248   }
249   -re "$r1$r2" {
250      pass $testname
251   }
252 }
253
254 gdb_test "next" ".*" ""
255 set r1 ".*#define DEF_MACROS"
256 set r2 ".*#define FOO\\(a\\) foo = a"
257 set r3 ".*#define FOUR"
258 set r4 ".*\r\n$gdb_prompt"
259 set testname "$test 7"
260 gdb_test_multiple "$test" $testname {
261   -re ".*#define FOO \" \".*\r\n$gdb_prompt" {
262      fail $testname
263   }
264   -re ".*#define FOO \"hello\".*\r\n$gdb_prompt" {
265      fail $testname
266   }
267   -re ".*#define FOO \"world\".*\r\n$gdb_prompt" {
268      fail $testname
269   }
270   -re ".*#define ONE.*\r\n$gdb_prompt" {
271      fail $testname
272   }
273   -re ".*#define TWO.*\r\n$gdb_prompt" {
274      fail $testname
275   }
276   -re ".*#define THREE.*\r\n$gdb_prompt" {
277      fail $testname
278   }
279   -re "$r1$r2$r3$r4" {
280      pass $testname
281   }
282 }
283
284 set test "info macros info-macros.c:42"
285
286 set r1 ".*define DEF_MACROS"
287 set r2 ".*define ONE"
288 # info macros on the line where the #define or #include is
289 # fails to find the macro defined (though it works on the next line.)
290 setup_kfail "gdb/NNNN" *-*-*
291 gdb_test "$test" "$r1$r2" "$test"