1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 1998-2021 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
26 typedef struct TEST_STRUCT
{
33 typedef int test_array
[4];
36 * Global variables to be collected
43 test_struct globalstruct
;
49 struct global_pieces
{
54 0x12345678, 0x87654321
58 * Additional globals used in arithmetic tests
61 signed char c0
, c1
, c2
, c3
, c4
, c5
, c6
, c7
,
62 c8
, c9
, c10
, c11
, c12
, c13
, c14
, c15
, cminus
;
63 signed short s0
, s1
, s2
, s3
, s4
, s5
, s6
, s7
,
64 s8
, s9
, s10
, s11
, s12
, s13
, s14
, s15
, sminus
;
65 signed long l0
, l1
, l2
, l3
, l4
, l5
, l6
, l7
,
66 l8
, l9
, l10
, l11
, l12
, l13
, l14
, l15
, lminus
;
73 static void begin () /* called before anything else */
77 static void end () /* called after everything else */
81 /* Test collecting args. */
82 int args_test_func (argc
, argi
, argf
, argd
, argstruct
, argarray
)
87 test_struct argstruct
;
92 i
= (int) argc
+ argi
+ argf
+ argd
+ argstruct
.memberi
+ argarray
[1];
97 /* Test collecting struct args. */
98 int argstruct_test_func (argstruct
)
99 test_struct argstruct
;
101 return (int) argstruct
.memberc
+ argstruct
.memberi
+
102 argstruct
.memberf
+ argstruct
.memberd
;
105 /* Test collecting array args. */
106 int argarray_test_func (argarray
)
109 return (int) argarray
[0] + argarray
[1] + argarray
[2] + argarray
[3];
114 int local_test_func () /* test collecting locals */
123 struct localstruct
{} locdefst
;
127 locst
.memberf
= 17.7;
128 locst
.memberd
= 18.8;
134 i
= /* Set_Tracepoint_Here */
135 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
140 int reglocal_test_func () /* test collecting register locals */
142 register char locc
= 11;
143 register int loci
= 12;
144 register float locf
= 13.3;
145 register double locd
= 14.4;
146 register test_struct locst
;
147 register int locar
[4];
152 locst
.memberf
= 17.7;
153 locst
.memberd
= 18.8;
159 i
= /* Set_Tracepoint_Here */
160 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
165 int statlocal_test_func () /* test collecting static locals */
171 static test_struct locst
;
181 locst
.memberf
= 17.7;
182 locst
.memberd
= 18.8;
188 i
= /* Set_Tracepoint_Here */
189 (int) locc
+ loci
+ locf
+ locd
+ locst
.memberi
+ locar
[1];
191 /* Set static locals back to zero so collected values are clearly special. */
209 int globals_test_func ()
213 i
+= globalc
+ globali
+ globalf
+ globald
;
214 i
+= globalstruct
.memberc
+ globalstruct
.memberi
;
215 i
+= globalstruct
.memberf
+ globalstruct
.memberd
;
218 return i
; /* Set_Tracepoint_Here */
221 int strings_test_func ()
224 char *locstr
, *longloc
;
227 longloc
= malloc(500);
228 strcpy(longloc
, "how now brown cow spam spam spam wonderful wonderful spam");
230 i
+= strlen (locstr
);
231 i
+= strlen (longloc
);
233 return i
; /* Set_Tracepoint_Here */
237 main (argc
, argv
, envp
)
239 char *argv
[], **envp
;
242 test_struct mystruct
;
246 /* Assign collectable values to global variables. */
247 l0
= s0
= c0
= 0; l1
= s1
= c1
= 1;
248 l2
= s2
= c2
= 2; l3
= s3
= c3
= 3;
249 l4
= s4
= c4
= 4; l5
= s5
= c5
= 5;
250 l6
= s6
= c6
= 6; l7
= s7
= c7
= 7;
251 l8
= s8
= c8
= 8; l9
= s9
= c9
= 9;
252 l10
= s10
= c10
= 10; l11
= s11
= c11
= 11;
253 l12
= s12
= c12
= 12; l13
= s13
= c13
= 13;
254 l14
= s14
= c14
= 14; l15
= s15
= c15
= 15;
255 lminus
= sminus
= cminus
= -2;
260 globalstruct
.memberc
= 81;
261 globalstruct
.memberi
= 82;
262 globalstruct
.memberf
= 83.3;
263 globalstruct
.memberd
= 84.4;
264 globalp
= &globalstruct
;
266 for (i
= 0; i
< 15; i
++)
269 for (i
= 0; i
< 4; i
++)
272 for (i
= 0; i
< 4; i
++)
273 globalarr3
[3 - i
] = i
;
275 mystruct
.memberc
= 101;
276 mystruct
.memberi
= 102;
277 mystruct
.memberf
= 103.3;
278 mystruct
.memberd
= 104.4;
284 /* Call test functions, so they can be traced and data collected. */
286 i
+= args_test_func (1, 2, 3.3, 4.4, mystruct
, myarray
);
287 i
+= argstruct_test_func (mystruct
);
288 i
+= argarray_test_func (myarray
);
289 i
+= local_test_func ();
290 i
+= reglocal_test_func ();
291 i
+= statlocal_test_func ();
292 i
+= globals_test_func ();
293 i
+= strings_test_func ();
295 /* Values of globals at end of test should be different from
296 values that they had when trace data was captured. */
298 l0
= s0
= c0
= 0; l1
= s1
= c1
= 0;
299 l2
= s2
= c2
= 0; l3
= s3
= c3
= 0;
300 l4
= s4
= c4
= 0; l5
= s5
= c5
= 0;
301 l6
= s6
= c6
= 0; l7
= s7
= c7
= 0;
302 l8
= s8
= c8
= 0; l9
= s9
= c9
= 0;
303 l10
= s10
= c10
= 0; l11
= s11
= c11
= 0;
304 l12
= s12
= c12
= 0; l13
= s13
= c13
= 0;
305 l14
= s14
= c14
= 0; l15
= s15
= c15
= 0;
306 lminus
= sminus
= cminus
= 0;
308 /* Set 'em back to zero, so that the collected values will be
309 distinctly different from the "realtime" (end of test) values. */
315 globalstruct
.memberc
= 0;
316 globalstruct
.memberi
= 0;
317 globalstruct
.memberf
= 0;
318 globalstruct
.memberd
= 0;
320 for (i
= 0; i
< 15; i
++)
322 for (i
= 0; i
< 4; i
++)
324 for (i
= 0; i
< 4; i
++)