Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.trace / collection.c
blob8379b7d7eaf053f6060e1291e6b10bb646d12fb8
1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 1998-2024 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/>. */
19 * Test program for trace collection
22 #include <string.h>
23 #include <stdlib.h>
26 * Typedefs
29 typedef struct TEST_STRUCT {
30 char memberc;
31 int memberi;
32 float memberf;
33 double memberd;
34 } test_struct;
36 typedef int test_array [4];
38 /*
39 * Global variables to be collected
42 char globalc;
43 int globali;
44 float globalf;
45 double globald;
46 test_struct globalstruct;
47 test_struct *globalp;
48 int globalarr[16];
49 int globalarr2[4];
50 int globalarr3[4];
52 struct global_pieces {
53 unsigned int a;
54 unsigned int b;
55 } global_pieces =
57 0x12345678, 0x87654321
61 * Additional globals used in arithmetic tests
64 signed char c0, c1, c2, c3, c4, c5, c6, c7,
65 c8, c9, c10, c11, c12, c13, c14, c15, cminus;
66 signed short s0, s1, s2, s3, s4, s5, s6, s7,
67 s8, s9, s10, s11, s12, s13, s14, s15, sminus;
68 signed long l0, l1, l2, l3, l4, l5, l6, l7,
69 l8, l9, l10, l11, l12, l13, l14, l15, lminus;
73 * Test functions
76 static void begin () /* called before anything else */
80 static void end () /* called after everything else */
84 /* Test collecting args. */
85 int args_test_func (argc, argi, argf, argd, argstruct, argarray)
86 char argc;
87 int argi;
88 float argf;
89 double argd;
90 test_struct argstruct;
91 int argarray[4];
93 int i;
95 i = (int) argc + argi + argf + argd + argstruct.memberi + argarray[1];
97 return i;
100 /* Test collecting struct args. */
101 int argstruct_test_func (argstruct)
102 test_struct argstruct;
104 return (int) argstruct.memberc + argstruct.memberi +
105 argstruct.memberf + argstruct.memberd;
108 /* Test collecting array args. */
109 int argarray_test_func (argarray)
110 int argarray[4];
112 return (int) argarray[0] + argarray[1] + argarray[2] + argarray[3];
117 int local_test_func () /* test collecting locals */
119 char locc = 11;
120 int loci = 12;
121 float locf = 13.3;
122 double locd = 14.4;
123 test_struct locst;
124 int locar[4];
125 int i;
126 struct localstruct {} locdefst;
128 locst.memberc = 15;
129 locst.memberi = 16;
130 locst.memberf = 17.7;
131 locst.memberd = 18.8;
132 locar[0] = 121;
133 locar[1] = 122;
134 locar[2] = 123;
135 locar[3] = 124;
137 i = /* Set_Tracepoint_Here */
138 (int) locc + loci + locf + locd + locst.memberi + locar[1];
140 return i;
143 int reglocal_test_func () /* test collecting register locals */
145 register char locc = 11;
146 register int loci = 12;
147 register float locf = 13.3;
148 register double locd = 14.4;
149 register test_struct locst;
150 register int locar[4];
151 int i;
153 locst.memberc = 15;
154 locst.memberi = 16;
155 locst.memberf = 17.7;
156 locst.memberd = 18.8;
157 locar[0] = 121;
158 locar[1] = 122;
159 locar[2] = 123;
160 locar[3] = 124;
162 i = /* Set_Tracepoint_Here */
163 (int) locc + loci + locf + locd + locst.memberi + locar[1];
165 return i;
168 int statlocal_test_func () /* test collecting static locals */
170 static char locc;
171 static int loci;
172 static float locf;
173 static double locd;
174 static test_struct locst;
175 static int locar[4];
176 int i;
178 locc = 11;
179 loci = 12;
180 locf = 13.3;
181 locd = 14.4;
182 locst.memberc = 15;
183 locst.memberi = 16;
184 locst.memberf = 17.7;
185 locst.memberd = 18.8;
186 locar[0] = 121;
187 locar[1] = 122;
188 locar[2] = 123;
189 locar[3] = 124;
191 i = /* Set_Tracepoint_Here */
192 (int) locc + loci + locf + locd + locst.memberi + locar[1];
194 /* Set static locals back to zero so collected values are clearly special. */
195 locc = 0;
196 loci = 0;
197 locf = 0;
198 locd = 0;
199 locst.memberc = 0;
200 locst.memberi = 0;
201 locst.memberf = 0;
202 locst.memberd = 0;
203 locar[0] = 0;
204 locar[1] = 0;
205 locar[2] = 0;
206 locar[3] = 0;
208 return i;
212 int globals_test_func ()
214 int i = 0;
216 i += globalc + globali + globalf + globald;
217 i += globalstruct.memberc + globalstruct.memberi;
218 i += globalstruct.memberf + globalstruct.memberd;
219 i += globalarr[1];
221 return i; /* Set_Tracepoint_Here */
224 int strings_test_func ()
226 int i = 0;
227 char *locstr, *longloc;
229 locstr = "abcdef";
230 longloc = malloc(500);
231 strcpy(longloc, "how now brown cow spam spam spam wonderful wonderful spam");
233 i += strlen (locstr);
234 i += strlen (longloc);
236 return i; /* Set_Tracepoint_Here */
240 main (argc, argv, envp)
241 int argc;
242 char *argv[], **envp;
244 int i = 0;
245 test_struct mystruct;
246 int myarray[4];
248 begin ();
249 /* Assign collectable values to global variables. */
250 l0 = s0 = c0 = 0; l1 = s1 = c1 = 1;
251 l2 = s2 = c2 = 2; l3 = s3 = c3 = 3;
252 l4 = s4 = c4 = 4; l5 = s5 = c5 = 5;
253 l6 = s6 = c6 = 6; l7 = s7 = c7 = 7;
254 l8 = s8 = c8 = 8; l9 = s9 = c9 = 9;
255 l10 = s10 = c10 = 10; l11 = s11 = c11 = 11;
256 l12 = s12 = c12 = 12; l13 = s13 = c13 = 13;
257 l14 = s14 = c14 = 14; l15 = s15 = c15 = 15;
258 lminus = sminus = cminus = -2;
259 globalc = 71;
260 globali = 72;
261 globalf = 73.3;
262 globald = 74.4;
263 globalstruct.memberc = 81;
264 globalstruct.memberi = 82;
265 globalstruct.memberf = 83.3;
266 globalstruct.memberd = 84.4;
267 globalp = &globalstruct;
269 for (i = 0; i < 15; i++)
270 globalarr[i] = i;
272 for (i = 0; i < 4; i++)
273 globalarr2[i] = i;
275 for (i = 0; i < 4; i++)
276 globalarr3[3 - i] = i;
278 mystruct.memberc = 101;
279 mystruct.memberi = 102;
280 mystruct.memberf = 103.3;
281 mystruct.memberd = 104.4;
282 myarray[0] = 111;
283 myarray[1] = 112;
284 myarray[2] = 113;
285 myarray[3] = 114;
287 /* Call test functions, so they can be traced and data collected. */
288 i = 0;
289 i += args_test_func (1, 2, 3.3, 4.4, mystruct, myarray);
290 i += argstruct_test_func (mystruct);
291 i += argarray_test_func (myarray);
292 i += local_test_func ();
293 i += reglocal_test_func ();
294 i += statlocal_test_func ();
295 i += globals_test_func ();
296 i += strings_test_func ();
298 /* Values of globals at end of test should be different from
299 values that they had when trace data was captured. */
301 l0 = s0 = c0 = 0; l1 = s1 = c1 = 0;
302 l2 = s2 = c2 = 0; l3 = s3 = c3 = 0;
303 l4 = s4 = c4 = 0; l5 = s5 = c5 = 0;
304 l6 = s6 = c6 = 0; l7 = s7 = c7 = 0;
305 l8 = s8 = c8 = 0; l9 = s9 = c9 = 0;
306 l10 = s10 = c10 = 0; l11 = s11 = c11 = 0;
307 l12 = s12 = c12 = 0; l13 = s13 = c13 = 0;
308 l14 = s14 = c14 = 0; l15 = s15 = c15 = 0;
309 lminus = sminus = cminus = 0;
311 /* Set 'em back to zero, so that the collected values will be
312 distinctly different from the "realtime" (end of test) values. */
314 globalc = 0;
315 globali = 0;
316 globalf = 0;
317 globald = 0;
318 globalstruct.memberc = 0;
319 globalstruct.memberi = 0;
320 globalstruct.memberf = 0;
321 globalstruct.memberd = 0;
322 globalp = 0;
323 for (i = 0; i < 15; i++)
324 globalarr[i] = 0;
325 for (i = 0; i < 4; i++)
326 globalarr2[i] = 0;
327 for (i = 0; i < 4; i++)
328 globalarr3[i] = 0;
330 end ();
331 return 0;