1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2018 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* This file is used for testing GDBs ability to pass structures to, and
19 return structures from, functions. All of the structures in this test
20 are special in that they are small structures containing from 1 up to 5
21 scalar fields, the fields can be inside nested structures, and there can
22 be empty structures around too.
24 This test is specifically written for RiscV and Aarch64, which both have
25 special ABI rules for structures like these, however, there should be no harm
26 in running these tests on other targets, though in many cases the
27 structures will treated no differently to the structures already covered
28 in the structs.exp test script. */
32 /* Useful abreviations. */
37 typedef long long tll;
40 typedef long double tld;
43 typedef float _Complex tfc;
44 typedef double _Complex tdc;
45 typedef long double _Complex tldc;
46 #endif /* TEST_COMPLEX */
48 #define MAKE_CHECK_FUNCS(TYPE) \
50 check_arg_ ## TYPE (struct TYPE arg) \
52 return cmp_ ## TYPE (arg, ref_val_ ## TYPE); \
56 rtn_str_ ## TYPE (void) \
58 return (ref_val_ ## TYPE); \
61 #define REF_VAL(NAME) struct NAME ref_val_ ## NAME
62 #define ES(NAME) struct { } NAME
64 /* Test is either for a single type or two differing types. */
65 #if defined tA && ! defined tB
69 #error "Incorrect configuration of tA and tB defines"
72 /* Structures with a single field nested to various depths, along with
73 some empty structures. */
74 struct struct_01_01 { ES(es1); struct { struct { tA a; } s1; } s2; };
75 struct struct_01_02 { tA a; struct { struct { ES(es1); } s1; } s2; };
76 struct struct_01_03 { struct { struct { ES(es1); } s1; } s2; ES(es1); struct { struct { tA a; } s3; } s4;};
77 struct struct_01_04 { ES(es1); ES(es2); tA a; ES(es3); };
79 /* Structures with two fields nested to various depths, along with
80 some empty structures. */
81 struct struct_02_01 { ES(es1); struct { struct { tA a; tB b; } s1; } s2; };
82 struct struct_02_02 { tA a; struct { struct { ES(es1); } s1; } s2; tB b; };
83 struct struct_02_03 { struct { struct { ES(es1); } s1; } s2; ES(es1); struct { struct { tA a; } s3; } s4; struct { struct { tB b; } s5; } s6;};
84 struct struct_02_04 { ES(es1); ES(es2); tA a; ES(es3); tB b; };
86 /* Structures with four fields nested to various depths, along with
87 some empty structures. */
88 struct struct_04_01 { ES(es1); struct { struct { tA a; tB b; tA c; tB d; } s1; } s2; };
89 struct struct_04_02 { tA a; struct { struct { ES(es1); } s1; } s2; tB b; struct { struct { ES(es1); } s2; } s3; tA c; struct { struct { ES(es2); } s4; } s5; tB d;};
90 struct struct_04_03 { struct { struct { ES(es1); } s1; } s2; ES(es1); struct { struct { tA a; } s3; } s4; struct { struct { tB b; } s5; } s6; struct { struct { tA c; } s7; } s8; struct { struct { tB d; } s9; } s10;};
91 struct struct_04_04 { ES(es1); ES(es2); tA a; ES(es3); tB b; ES(es4); tA c; ES(es5); tB d; };
93 /* Structures with five fields nested to various depths, along with
94 some empty structures. */
95 struct struct_05_01 { ES(es1); struct { struct { tA a; tB b; tA c; tB d; tA e; } s1; } s2; };
96 struct struct_05_02 { tA a; struct { struct { ES(es1); } s1; } s2; tB b; struct { struct { ES(es1); } s2; } s3; tA c; struct { struct { ES(es2); } s4; } s5; tB d; struct { struct { ES(es2); } s6; } s7; tB e;};
97 struct struct_05_03 { struct { struct { ES(es1); } s1; } s2; ES(es1); struct { struct { tA a; } s3; } s4; struct { struct { tB b; } s5; } s6; struct { struct { tA c; } s7; } s8; struct { struct { tB d; } s9; } s10; struct { struct { tA e; } s11; } s12;};
98 struct struct_05_04 { ES(es1); ES(es2); tA a; ES(es3); tB b; ES(es4); tA c; ES(es5); tB d; ES(es6); tA e; };
100 int cmp_struct_01_01 (struct struct_01_01 a, struct struct_01_01 b)
101 { return a.s2.s1.a == b.s2.s1.a; }
103 int cmp_struct_01_02 (struct struct_01_02 a, struct struct_01_02 b)
104 { return a.a == b.a; }
106 int cmp_struct_01_03 (struct struct_01_03 a, struct struct_01_03 b)
107 { return a.s4.s3.a == b.s4.s3.a; }
109 int cmp_struct_01_04 (struct struct_01_04 a, struct struct_01_04 b)
110 { return a.a == b.a; }
112 int cmp_struct_02_01 (struct struct_02_01 a, struct struct_02_01 b)
113 { return a.s2.s1.a == b.s2.s1.a && a.s2.s1.b == a.s2.s1.b; }
115 int cmp_struct_02_02 (struct struct_02_02 a, struct struct_02_02 b)
116 { return a.a == b.a && a.b == b.b; }
118 int cmp_struct_02_03 (struct struct_02_03 a, struct struct_02_03 b)
119 { return a.s4.s3.a == b.s4.s3.a && a.s6.s5.b == b.s6.s5.b; }
121 int cmp_struct_02_04 (struct struct_02_04 a, struct struct_02_04 b)
122 { return a.a == b.a && a.b == b.b; }
124 int cmp_struct_04_01 (struct struct_04_01 a, struct struct_04_01 b)
125 { return a.s2.s1.a == b.s2.s1.a && a.s2.s1.b == a.s2.s1.b
126 && a.s2.s1.c == b.s2.s1.c && a.s2.s1.d == a.s2.s1.d; }
128 int cmp_struct_04_02 (struct struct_04_02 a, struct struct_04_02 b)
129 { return a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d; }
131 int cmp_struct_04_03 (struct struct_04_03 a, struct struct_04_03 b)
132 { return a.s4.s3.a == b.s4.s3.a && a.s6.s5.b == b.s6.s5.b
133 && a.s8.s7.c == b.s8.s7.c && a.s10.s9.d == b.s10.s9.d; }
135 int cmp_struct_04_04 (struct struct_04_04 a, struct struct_04_04 b)
136 { return a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d; }
138 int cmp_struct_05_01 (struct struct_05_01 a, struct struct_05_01 b)
139 { return a.s2.s1.a == b.s2.s1.a && a.s2.s1.b == a.s2.s1.b
140 && a.s2.s1.c == b.s2.s1.c && a.s2.s1.d == a.s2.s1.d
141 && a.s2.s1.e == b.s2.s1.e; }
143 int cmp_struct_05_02 (struct struct_05_02 a, struct struct_05_02 b)
144 { return a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d && a.e == b.e; }
146 int cmp_struct_05_03 (struct struct_05_03 a, struct struct_05_03 b)
147 { return a.s4.s3.a == b.s4.s3.a && a.s6.s5.b == b.s6.s5.b
148 && a.s8.s7.c == b.s8.s7.c && a.s10.s9.d == b.s10.s9.d
149 && a.s12.s11.e == b.s12.s11.e; }
151 int cmp_struct_05_04 (struct struct_05_04 a, struct struct_05_04 b)
152 { return a.a == b.a && a.b == b.b && a.c == b.c && a.d == b.d && a.e == b.e; }
154 REF_VAL(struct_01_01) = { {}, { { 'a' } } };
155 REF_VAL(struct_01_02) = { 'a', { { {} } } };
156 REF_VAL(struct_01_03) = { { { {} } }, {}, { { 'a' } } };
157 REF_VAL(struct_01_04) = { {}, {}, 'a', {} };
159 REF_VAL(struct_02_01) = { {}, { { 'a', 'b' } } };
160 REF_VAL(struct_02_02) = { 'a', { { {} } }, 'b' };
161 REF_VAL(struct_02_03) = { { { {} } }, {}, { { 'a' } }, { { 'b' } } };
162 REF_VAL(struct_02_04) = { {}, {}, 'a', {}, 'b' };
164 REF_VAL(struct_04_01) = { {}, { { 'a', 'b', 'c', 'd' } } };
165 REF_VAL(struct_04_02) = { 'a', { { {} } }, 'b', { { {} } }, 'c', { { {} } }, 'd' };
166 REF_VAL(struct_04_03) = { { { {} } }, {}, { { 'a' } }, { { 'b' } }, { { 'c' } }, { { 'd' } } };
167 REF_VAL(struct_04_04) = { {}, {}, 'a', {}, 'b', {}, 'c', {}, 'd' };
169 REF_VAL(struct_05_01) = { {}, { { 'a', 'b', 'c', 'd', 'e' } } };
170 REF_VAL(struct_05_02) = { 'a', { { {} } }, 'b', { { {} } }, 'c', { { {} } }, 'd', { { {} } }, 'e' };
171 REF_VAL(struct_05_03) = { { { {} } }, {}, { { 'a' } }, { { 'b' } }, { { 'c' } }, { { 'd' } }, { { 'e' } } };
172 REF_VAL(struct_05_04) = { {}, {}, 'a', {}, 'b', {}, 'c', {}, 'd', {}, 'e' };
174 /* Create all of the functions GDB will call to check functionality. */
175 MAKE_CHECK_FUNCS(struct_01_01)
176 MAKE_CHECK_FUNCS(struct_01_02)
177 MAKE_CHECK_FUNCS(struct_01_03)
178 MAKE_CHECK_FUNCS(struct_01_04)
179 MAKE_CHECK_FUNCS(struct_02_01)
180 MAKE_CHECK_FUNCS(struct_02_02)
181 MAKE_CHECK_FUNCS(struct_02_03)
182 MAKE_CHECK_FUNCS(struct_02_04)
183 MAKE_CHECK_FUNCS(struct_04_01)
184 MAKE_CHECK_FUNCS(struct_04_02)
185 MAKE_CHECK_FUNCS(struct_04_03)
186 MAKE_CHECK_FUNCS(struct_04_04)
187 MAKE_CHECK_FUNCS(struct_05_01)
188 MAKE_CHECK_FUNCS(struct_05_02)
189 MAKE_CHECK_FUNCS(struct_05_03)
190 MAKE_CHECK_FUNCS(struct_05_04)
192 #define CALL_LINE(NAME) val += check_arg_ ## NAME (rtn_str_ ## NAME ())
199 CALL_LINE(struct_01_01);
200 CALL_LINE(struct_01_02);
201 CALL_LINE(struct_01_03);
202 CALL_LINE(struct_01_04);
203 CALL_LINE(struct_02_01);
204 CALL_LINE(struct_02_02);
205 CALL_LINE(struct_02_03);
206 CALL_LINE(struct_02_04);
207 CALL_LINE(struct_04_01);
208 CALL_LINE(struct_04_02);
209 CALL_LINE(struct_04_03);
210 CALL_LINE(struct_04_04);
211 CALL_LINE(struct_05_01);
212 CALL_LINE(struct_05_02);
213 CALL_LINE(struct_05_03);
214 CALL_LINE(struct_05_04);
231 breakpt (); /* Break Here. */