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