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
29 typedef struct TEST_STRUCT
{
36 typedef int test_array
[4];
39 * Global variables to be collected
46 test_struct globalstruct
;
52 struct 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
;
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
)
90 test_struct argstruct
;
95 i
= (int) argc
+ argi
+ argf
+ argd
+ argstruct
.memberi
+ argarray
[1];
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
)
112 return (int) argarray
[0] + argarray
[1] + argarray
[2] + argarray
[3];
117 int local_test_func () /* test collecting locals */
126 struct localstruct
{} locdefst
;
130 locst
.memberf
= 17.7;
131 locst
.memberd
= 18.8;
137 i
= /* Set_Tracepoint_Here */
138 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
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];
155 locst
.memberf
= 17.7;
156 locst
.memberd
= 18.8;
162 i
= /* Set_Tracepoint_Here */
163 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
168 int statlocal_test_func () /* test collecting static locals */
174 static test_struct locst
;
184 locst
.memberf
= 17.7;
185 locst
.memberd
= 18.8;
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. */
212 int globals_test_func ()
216 i
+= globalc
+ globali
+ globalf
+ globald
;
217 i
+= globalstruct
.memberc
+ globalstruct
.memberi
;
218 i
+= globalstruct
.memberf
+ globalstruct
.memberd
;
221 return i
; /* Set_Tracepoint_Here */
224 int strings_test_func ()
227 char *locstr
, *longloc
;
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
)
242 char *argv
[], **envp
;
245 test_struct mystruct
;
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;
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
++)
272 for (i
= 0; i
< 4; 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;
287 /* Call test functions, so they can be traced and data collected. */
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. */
318 globalstruct
.memberc
= 0;
319 globalstruct
.memberi
= 0;
320 globalstruct
.memberf
= 0;
321 globalstruct
.memberd
= 0;
323 for (i
= 0; i
< 15; i
++)
325 for (i
= 0; i
< 4; i
++)
327 for (i
= 0; i
< 4; i
++)