38eb35f1df8710049c61ea1e3882a8b034b8d9c5
[binutils-gdb.git] / gdb / testsuite / gdb.base / info-macros.exp
1 # Copyright 2011-2023 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 require !using_fission
20
21 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} {debug macros}] } {
22 return -1
23 }
24
25 if ![runto_main] {
26 return -1
27 }
28
29 # Test various error messages.
30 gdb_test "info macro -- -all" \
31 "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+"
32 gdb_test "info macro -- -all" \
33 "The symbol `-all' has no definition .*\r\nat .*$srcfile:\[0-9\]+"
34
35 gdb_test "info macro -all --" \
36 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
37
38 gdb_test "info macro -all --" \
39 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
40
41 gdb_test "info macro -all --" \
42 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
43
44 gdb_test "info macro --" \
45 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]"
46
47 gdb_test "info macro -- " \
48 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
49 "info macro -- <EOL>"
50 gdb_test "info macro -- " \
51 "You must follow.*with the name.*you want to see.*\[^\r\n\]*\[\r\n\]" \
52 "info macro -- <EOL>"
53
54 gdb_test "info macro -invalid-option" \
55 "Unrecognized option.*Try \"help info macro\"\."
56
57 gdb_test "info macro -invalid-option" \
58 "Unrecognized option.*Try \"help info macro\"\."
59
60 gdb_test "info macro -invalid-option FOO" \
61 "Unrecognized option.*Try \"help info macro\"\."
62 gdb_test "info macro -invalid-option FOO" \
63 "Unrecognized option.*Try \"help info macro\"\."
64
65 # Single macro lookups.
66 gdb_test "info macro -- FOO" \
67 ".*#define FOO \"hello\""
68
69 gdb_test "info macro -- FOO" \
70 ".*#define FOO \"hello\""
71
72 gdb_test "info macro -- FOO" \
73 ".*#define FOO \"hello\""
74
75 gdb_test "info macro FOO" \
76 ".*#define FOO \"hello\""
77
78 gdb_test "info macro FOO" \
79 ".*#define FOO \"hello\""
80
81 # Multiple macro lookups.
82 set test "info macro -a FOO"
83 set r1 ".*#define FOO \"hello\""
84 set r2 ".*#define FOO \" \""
85 set r3 ".*#define FOO \"world\""
86 set r4 ".*#define FOO\\(a\\) foo = a"
87 set testname "$test 1"
88 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
89
90 set test "info macro -a -- FOO"
91 set testname "$test 1"
92 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
93
94 set test "info macro -all -- FOO"
95 set testname "$test 1"
96 gdb_test "$test" "$r1$r2$r3$r4" "$testname"
97
98 set test "info macro -a -- FOO"
99 gdb_test "$test" "$r1$r2$r3$r4"
100
101 set test "info macro -a -- FOO"
102 gdb_test "$test" "$r1$r2$r3$r4"
103
104 set test "info macros"
105 set r1 "#define FOO \"hello\""
106 set r2 "#define ONE"
107 set testname "$test 2"
108 gdb_test_lines $test $testname $r1.*$r2 \
109 -re-not "#define TWO" \
110 -re-not "#define THREE" \
111 -re-not "#define FOUR"
112
113 gdb_test "next" "" "next, 1"
114
115 set r1 "#define FOO \" \""
116 set r2 "#define ONE"
117 set r3 "#define TWO"
118 set testname "$test 3"
119 gdb_test_lines $test $testname $r1.*$r2.*$r3 \
120 -re-not "#define THREE" \
121 -re-not "#define FOUR"
122
123 gdb_test "next" "" "next, 2"
124
125 # in alphabetical order...
126 set r1 "#define FOO \"world\""
127 set r2 "#define ONE"
128 set r3 "#define THREE"
129 set r4 "#define TWO"
130 set testname "$test 4"
131 gdb_test_lines $test $testname $r1.*$r2.*$r3.*$r4 \
132 -re-not "#define FOUR"
133
134 # same as above with a linespec.
135 set test "info macros *\$pc"
136 gdb_test_lines $test "" $r1.*$r2.*$r3.*$r4 \
137 -re-not "#define FOUR"
138 gdb_test "next" "" "next, 3"
139
140 set r1 "#define FOO \" \""
141 set r2 "#define ONE"
142 set r3 "#define TWO."
143 set test "info macros"
144 set testname "$test 5"
145 gdb_test_lines $test $testname $r1.*$r2.*$r3 \
146 -re-not "#define THREE" \
147 -re-not "#define FOUR"
148 gdb_test "next" "" "next, 4"
149 gdb_test "next" "" "next, 5"
150
151 set r1 "#define DEF_MACROS"
152 set testname "$test 6"
153 gdb_test_lines $test $testname $r1 \
154 -re-not "#define FOO" \
155 -re-not "#define ONE" \
156 -re-not "#define TWO" \
157 -re-not "#define THREE" \
158 -re-not "#define FOUR"
159
160 gdb_test "next" "" "next, 6"
161 set r1 "#define DEF_MACROS"
162 set r2 "#define FOO\\(a\\) foo = a"
163 set r3 "#define FOUR"
164 set testname "$test 7"
165 gdb_test_lines $test $testname $r1.*$r2.*$r3 \
166 -re-not "#define FOO \" \"" \
167 -re-not "#define FOO \"hello\"" \
168 -re-not "#define FOO \"world\"" \
169 -re-not "#define ONE" \
170 -re-not "#define TWO" \
171 -re-not "#define THREE"
172
173 set test "info macros info-macros.c:42"
174
175 set r1 "#define DEF_MACROS "
176 set r2 "#define ONE"
177 gdb_test_lines "$test" "" [multi_line \
178 "" \
179 "$r1" \
180 "(.*\r\n)?$r2"]