1 # Copyright 2011-2022 Free Software Foundation, Inc.
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.
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.
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/>.
18 # Fission doesn't support macros yet. Bug 15954.
20 untested "fission does not support macros yet"
25 if { [test_compiler_info gcc*] } {
26 # Don't use "debug" here. Otherwise "-g" would be appended to the gcc
27 # command line, possibly overriding "-g3" (depending on gcc version).
28 set options "additional_flags=-g3"
29 } elseif { [test_compiler_info clang*] } {
30 set options "additional_flags=-fdebug-macro"
32 untested "no compiler info"
36 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
41 untested "could not run to main"
45 # Test various error messages.
46 gdb_test "info macro -- -all" \
47 "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+"
48 gdb_test "info macro -- -all" \
49 "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+"
51 gdb_test "info macro -all --" \
52 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
54 gdb_test "info macro -all --" \
55 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
57 gdb_test "info macro -all --" \
58 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
60 gdb_test "info macro --" \
61 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
63 gdb_test "info macro -- " \
64 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
66 gdb_test "info macro -- " \
67 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
70 gdb_test "info macro -invalid-option" \
71 "Unrecognized option.*Try \"help info macro\"\."
73 gdb_test "info macro -invalid-option" \
74 "Unrecognized option.*Try \"help info macro\"\."
76 gdb_test "info macro -invalid-option FOO" \
77 "Unrecognized option.*Try \"help info macro\"\."
78 gdb_test "info macro -invalid-option FOO" \
79 "Unrecognized option.*Try \"help info macro\"\."
81 # Single macro lookups.
82 gdb_test "info macro -- FOO" \
83 ".*#define FOO \"hello\""
85 gdb_test "info macro -- FOO" \
86 ".*#define FOO \"hello\""
88 gdb_test "info macro -- FOO" \
89 ".*#define FOO \"hello\""
91 gdb_test "info macro FOO" \
92 ".*#define FOO \"hello\""
94 gdb_test "info macro FOO" \
95 ".*#define FOO \"hello\""
97 # Multiple macro lookups.
98 set test "info macro -a FOO"
99 set r1 ".*#define FOO \"hello\""
100 set r2 ".*#define FOO \" \""
101 set r3 ".*#define FOO \"world\""
102 set r4 ".*#define FOO\\(a\\) foo = a"
103 set testname "$test 1"
104 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
106 set test "info macro -a -- FOO"
107 set testname "$test 1"
108 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
110 set test "info macro -all -- FOO"
111 set testname "$test 1"
112 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
114 set test "info macro -a -- FOO"
115 gdb_test "$test" "$r1$r2$r3$r4"
117 set test "info macro -a -- FOO"
118 gdb_test "$test" "$r1$r2$r3$r4"
120 proc gdb_test_multiple_with_read1_timeout_factor { factor command message \
122 with_read1_timeout_factor $factor {
123 uplevel [list gdb_test_multiple $command $message $user_code]
127 set test "info macros"
128 set r1 ".*#define FOO \"hello\""
129 set r2 ".*#define ONE"
130 set r3 ".*\r\n$gdb_prompt"
131 set testname "$test 2"
132 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $testname {
136 -re ".*#define TWO.*\r\n$gdb_prompt" {
139 -re ".*#define THREE.*\r\n$gdb_prompt" {
142 -re ".*#define FOUR.*\r\n$gdb_prompt" {
146 gdb_test "next" ".*" ""
148 set r1 ".*#define FOO \" \""
149 set r2 ".*#define ONE"
150 set r3 ".*#define TWO"
151 set r4 ".*\r\n$gdb_prompt"
152 set testname "$test 3"
153 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $testname {
154 -re ".*#define THREE.*\r\n$gdb_prompt" {
157 -re ".*#define FOUR.*\r\n$gdb_prompt" {
164 gdb_test "next" ".*" ""
166 # in alpabetical order...
167 set r1 ".*#define FOO \"world\""
168 set r2 ".*#define ONE"
169 set r3 ".*#define THREE"
170 set r4 ".*#define TWO"
171 set r5 ".*\r\n$gdb_prompt"
172 set testname "$test 4"
173 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $testname {
174 -re ".*#define FOUR.*\r\n$gdb_prompt" {
177 -re "$r1$r2$r3$r4$r5" {
181 # same as above with a linespec.
182 set test "info macros *\$pc"
183 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $test {
184 -re ".*#define FOUR.*\r\n$gdb_prompt" {
187 -re "$r1$r2$r3$r4$r5" {
191 gdb_test "next" ".*" ""
193 set r1 ".*#define FOO \" \""
194 set r2 ".*#define ONE"
195 set r3 ".*#define TWO."
196 set r4 ".*\r\n$gdb_prompt"
197 set test "info macros"
198 set testname "$test 5"
199 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $test {
200 -re ".*#define THREE.*\r\n$gdb_prompt" {
203 -re ".*#define FOUR.*\r\n$gdb_prompt" {
210 gdb_test "next" ".*" ""
211 gdb_test "next" ".*" ""
213 set r1 ".*#define DEF_MACROS"
214 set r2 ".*\r\n$gdb_prompt"
215 set testname "$test 6"
216 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $testname {
217 -re ".*#define FOO \" \".*\r\n$gdb_prompt" {
220 -re ".*#define FOO \"hello\".*\r\n$gdb_prompt" {
223 -re ".*#define FOO \"world\".*\r\n$gdb_prompt" {
226 -re ".*#define FOO\\(a\\) foo = a.*" {
229 -re ".*#define ONE.*\r\n$gdb_prompt" {
232 -re ".*#define TWO.*\r\n$gdb_prompt" {
235 -re ".*#define THREE.*\r\n$gdb_prompt" {
238 -re ".*#define FOUR.*\r\n$gdb_prompt" {
246 gdb_test "next" ".*" ""
247 set r1 ".*#define DEF_MACROS"
248 set r2 ".*#define FOO\\(a\\) foo = a"
249 set r3 ".*#define FOUR"
250 set r4 ".*\r\n$gdb_prompt"
251 set testname "$test 7"
252 gdb_test_multiple_with_read1_timeout_factor 10 "$test" $testname {
253 -re ".*#define FOO \" \".*\r\n$gdb_prompt" {
256 -re ".*#define FOO \"hello\".*\r\n$gdb_prompt" {
259 -re ".*#define FOO \"world\".*\r\n$gdb_prompt" {
262 -re ".*#define ONE.*\r\n$gdb_prompt" {
265 -re ".*#define TWO.*\r\n$gdb_prompt" {
268 -re ".*#define THREE.*\r\n$gdb_prompt" {
276 set test "info macros info-macros.c:42"
278 set r1 "#define DEF_MACROS "
280 gdb_test_lines "$test" "" [multi_line \