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