import gdb-1999-06-28 snapshot
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / call-rt-st.c
CommitLineData
c906108c
SS
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5/**************************************************************************
6 * TESTS :
7 * function returning large structures, which go on the stack
8 * functions returning varied sized structs which go on in the registers.
9 ***************************************************************************/
10
11
12/* A large structure (> 64 bits) used to test passing large structures as
13 * parameters
14 */
15
16struct array_rep_info_t {
17 int next_index[10];
18 int values[10];
19 int head;
20};
21
22/*****************************************************************************
23 * Small structures ( <= 64 bits). These are used to test passing small
24 * structures as parameters and test argument size promotion.
25 *****************************************************************************/
26
27 /* 64 bits
28 */
29struct small_rep_info_t {
30 int value;
31 int head;
32};
33
34/* 6 bits : really fits in 8 bits and is promoted to 32 bits
35 */
36struct bit_flags_t {
37 unsigned alpha :1;
38 unsigned beta :1;
39 unsigned gamma :1;
40 unsigned delta :1;
41 unsigned epsilon :1;
42 unsigned omega :1;
43};
44
45/* 22 bits : really fits in 40 bits and is promoted to 64 bits
46 */
47struct bit_flags_combo_t {
48 unsigned alpha :1;
49 unsigned beta :1;
50 char ch1;
51 unsigned gamma :1;
52 unsigned delta :1;
53 char ch2;
54 unsigned epsilon :1;
55 unsigned omega :1;
56};
57
58/* 64 bits
59 */
60struct one_double_t {
61 double double1;
62};
63
64/* 64 bits
65 */
66struct two_floats_t {
67 float float1;
68 float float2;
69};
70
71
72/* 24 bits : promoted to 32 bits
73 */
74struct three_char_t {
75 char ch1;
76 char ch2;
77 char ch3;
78};
79
80/* 40 bits : promoted to 64 bits
81 */
82struct five_char_t {
83 char ch1;
84 char ch2;
85 char ch3;
86 char ch4;
87 char ch5;
88};
89
90/* 40 bits : promoted to 64 bits
91 */
92struct int_char_combo_t {
93 int int1;
94 char ch1;
95};
96
97
98/*****************************************************************
99 * LOOP_COUNT :
100 * A do nothing function. Used to provide a point at which calls can be made.
101 *****************************************************************/
102void loop_count () {
103
104 int index;
105
106 for (index=0; index<4; index++);
107}
108
109/*****************************************************************
110 * INIT_BIT_FLAGS :
111 * Initializes a bit_flags_t structure. Can call this function see
112 * the call command behavior when integer arguments do not fit into
113 * registers and must be placed on the stack.
114 * OUT struct bit_flags_t *bit_flags -- structure to be filled
115 * IN unsigned a -- 0 or 1
116 * IN unsigned b -- 0 or 1
117 * IN unsigned g -- 0 or 1
118 * IN unsigned d -- 0 or 1
119 * IN unsigned e -- 0 or 1
120 * IN unsigned o -- 0 or 1
121 *****************************************************************/
085dd6e6
JM
122#ifdef PROTOTYPES
123void init_bit_flags (
124struct bit_flags_t *bit_flags,
125unsigned a,
126unsigned b,
127unsigned g,
128unsigned d,
129unsigned e,
130unsigned o)
131#else
c906108c
SS
132void init_bit_flags (bit_flags,a,b,g,d,e,o)
133struct bit_flags_t *bit_flags;
134unsigned a;
135unsigned b;
136unsigned g;
137unsigned d;
138unsigned e;
139unsigned o;
085dd6e6 140#endif
c906108c
SS
141{
142
143 bit_flags->alpha = a;
144 bit_flags->beta = b;
145 bit_flags->gamma = g;
146 bit_flags->delta = d;
147 bit_flags->epsilon = e;
148 bit_flags->omega = o;
149}
150
151/*****************************************************************
152 * INIT_BIT_FLAGS_COMBO :
153 * Initializes a bit_flags_combo_t structure. Can call this function
154 * to see the call command behavior when integer and character arguments
155 * do not fit into registers and must be placed on the stack.
156 * OUT struct bit_flags_combo_t *bit_flags_combo -- structure to fill
157 * IN unsigned a -- 0 or 1
158 * IN unsigned b -- 0 or 1
159 * IN char ch1
160 * IN unsigned g -- 0 or 1
161 * IN unsigned d -- 0 or 1
162 * IN char ch2
163 * IN unsigned e -- 0 or 1
164 * IN unsigned o -- 0 or 1
165 *****************************************************************/
085dd6e6
JM
166#ifdef PROTOTYPES
167void init_bit_flags_combo (
168struct bit_flags_combo_t *bit_flags_combo,
169unsigned a,
170unsigned b,
171char ch1,
172unsigned g,
173unsigned d,
174char ch2,
175unsigned e,
176unsigned o)
177#else
c906108c
SS
178void init_bit_flags_combo (bit_flags_combo, a, b, ch1, g, d, ch2, e, o)
179struct bit_flags_combo_t *bit_flags_combo;
180unsigned a;
181unsigned b;
182char ch1;
183unsigned g;
184unsigned d;
185char ch2;
186unsigned e;
187unsigned o;
085dd6e6 188#endif
c906108c
SS
189{
190
191 bit_flags_combo->alpha = a;
192 bit_flags_combo->beta = b;
193 bit_flags_combo->ch1 = ch1;
194 bit_flags_combo->gamma = g;
195 bit_flags_combo->delta = d;
196 bit_flags_combo->ch2 = ch2;
197 bit_flags_combo->epsilon = e;
198 bit_flags_combo->omega = o;
199}
200
201
202/*****************************************************************
203 * INIT_ONE_DOUBLE :
204 * OUT struct one_double_t *one_double -- structure to fill
205 * IN double init_val
206 *****************************************************************/
085dd6e6
JM
207#ifdef PROTOTYPES
208void init_one_double ( struct one_double_t *one_double, double init_val)
209#else
c906108c
SS
210void init_one_double (one_double, init_val)
211struct one_double_t *one_double;
212double init_val;
085dd6e6 213#endif
c906108c
SS
214{
215
216 one_double->double1 = init_val;
217}
218
219/*****************************************************************
220 * INIT_TWO_FLOATS :
221 * OUT struct two_floats_t *two_floats -- structure to be filled
222 * IN float init_val1
223 * IN float init_val2
224 *****************************************************************/
085dd6e6
JM
225#ifdef PROTOTYPES
226void init_two_floats (
227 struct two_floats_t *two_floats,
228 float init_val1,
229 float init_val2)
230#else
c906108c
SS
231void init_two_floats (two_floats, init_val1, init_val2)
232struct two_floats_t *two_floats;
233float init_val1;
234float init_val2;
085dd6e6 235#endif
c906108c
SS
236{
237
238 two_floats->float1 = init_val1;
239 two_floats->float2 = init_val2;
240}
241
242/*****************************************************************
243 * INIT_THREE_CHARS :
244 * OUT struct three_char_t *three_char -- structure to be filled
245 * IN char init_val1
246 * IN char init_val2
247 * IN char init_val3
248 *****************************************************************/
085dd6e6
JM
249#ifdef PROTOTYPES
250void init_three_chars (
251struct three_char_t *three_char,
252char init_val1,
253char init_val2,
254char init_val3)
255#else
c906108c
SS
256void init_three_chars ( three_char, init_val1, init_val2, init_val3)
257struct three_char_t *three_char;
258char init_val1;
259char init_val2;
260char init_val3;
085dd6e6 261#endif
c906108c
SS
262{
263
264 three_char->ch1 = init_val1;
265 three_char->ch2 = init_val2;
266 three_char->ch3 = init_val3;
267}
268
269/*****************************************************************
270 * INIT_FIVE_CHARS :
271 * OUT struct five_char_t *five_char -- structure to be filled
272 * IN char init_val1
273 * IN char init_val2
274 * IN char init_val3
275 * IN char init_val4
276 * IN char init_val5
277 *****************************************************************/
085dd6e6
JM
278#ifdef PROTOTYPES
279void init_five_chars (
280struct five_char_t *five_char,
281char init_val1,
282char init_val2,
283char init_val3,
284char init_val4,
285char init_val5)
286#else
c906108c
SS
287void init_five_chars ( five_char, init_val1, init_val2, init_val3, init_val4, init_val5)
288struct five_char_t *five_char;
289char init_val1;
290char init_val2;
291char init_val3;
292char init_val4;
293char init_val5;
085dd6e6 294#endif
c906108c
SS
295{
296
297 five_char->ch1 = init_val1;
298 five_char->ch2 = init_val2;
299 five_char->ch3 = init_val3;
300 five_char->ch4 = init_val4;
301 five_char->ch5 = init_val5;
302}
303
304/*****************************************************************
305 * INIT_INT_CHAR_COMBO :
306 * OUT struct int_char_combo_t *combo -- structure to be filled
307 * IN int init_val1
308 * IN char init_val2
309 *****************************************************************/
085dd6e6
JM
310#ifdef PROTOTYPES
311void init_int_char_combo (
312struct int_char_combo_t *combo,
313int init_val1,
314char init_val2)
315#else
c906108c
SS
316void init_int_char_combo ( combo, init_val1, init_val2)
317struct int_char_combo_t *combo;
318int init_val1;
319char init_val2;
085dd6e6 320#endif
c906108c
SS
321{
322
323 combo->int1 = init_val1;
324 combo->ch1 = init_val2;
325}
326
327/*****************************************************************
328 * INIT_STRUCT_REP :
329 * OUT struct small_rep_into_t *small_struct -- structure to be filled
330 * IN int seed
331 *****************************************************************/
085dd6e6
JM
332#ifdef PROTOTYPES
333void init_struct_rep(
334 struct small_rep_info_t *small_struct,
335 int seed)
336#else
c906108c
SS
337void init_struct_rep( small_struct, seed)
338struct small_rep_info_t *small_struct;
339int seed;
085dd6e6 340#endif
c906108c
SS
341{
342
343 small_struct->value = 2 + (seed*2);
344 small_struct->head = 0;
345}
346
347/*****************************************************************
348 * PRINT_BIT_FLAGS :
349 * IN struct bit_flags_t bit_flags
350 ****************************************************************/
085dd6e6
JM
351#ifdef PROTOTYPES
352struct bit_flags_t print_bit_flags (struct bit_flags_t bit_flags)
353#else
c906108c
SS
354struct bit_flags_t print_bit_flags ( bit_flags)
355struct bit_flags_t bit_flags;
085dd6e6 356#endif
c906108c
SS
357{
358
359 if (bit_flags.alpha) printf("alpha\n");
360 if (bit_flags.beta) printf("beta\n");
361 if (bit_flags.gamma) printf("gamma\n");
362 if (bit_flags.delta) printf("delta\n");
363 if (bit_flags.epsilon) printf("epsilon\n");
364 if (bit_flags.omega) printf("omega\n");
365 return bit_flags;
366
367}
368
369/*****************************************************************
370 * PRINT_BIT_FLAGS_COMBO :
371 * IN struct bit_flags_combo_t bit_flags_combo
372 ****************************************************************/
085dd6e6
JM
373#ifdef PROTOTYPES
374struct bit_flags_combo_t print_bit_flags_combo (struct bit_flags_combo_t bit_flags_combo)
375#else
c906108c
SS
376struct bit_flags_combo_t print_bit_flags_combo ( bit_flags_combo )
377struct bit_flags_combo_t bit_flags_combo;
085dd6e6 378#endif
c906108c
SS
379{
380
381 if (bit_flags_combo.alpha) printf("alpha\n");
382 if (bit_flags_combo.beta) printf("beta\n");
383 if (bit_flags_combo.gamma) printf("gamma\n");
384 if (bit_flags_combo.delta) printf("delta\n");
385 if (bit_flags_combo.epsilon) printf("epsilon\n");
386 if (bit_flags_combo.omega) printf("omega\n");
387 printf("ch1: %c\tch2: %c\n", bit_flags_combo.ch1, bit_flags_combo.ch2);
388 return bit_flags_combo;
389
390}
391
392/*****************************************************************
393 * PRINT_ONE_DOUBLE :
394 * IN struct one_double_t one_double
395 ****************************************************************/
085dd6e6
JM
396#ifdef PROTOTYPES
397struct one_double_t print_one_double (struct one_double_t one_double)
398#else
c906108c
SS
399struct one_double_t print_one_double ( one_double )
400struct one_double_t one_double;
085dd6e6 401#endif
c906108c
SS
402{
403
404 printf("Contents of one_double_t: \n\n");
405 printf("%f\n", one_double.double1);
406 return one_double;
407
408}
409
410/*****************************************************************
411 * PRINT_TWO_FLOATS :
412 * IN struct two_floats_t two_floats
413 ****************************************************************/
085dd6e6
JM
414#ifdef PROTOTYPES
415struct two_floats_t print_two_floats (struct two_floats_t two_floats)
416#else
c906108c
SS
417struct two_floats_t print_two_floats ( two_floats )
418struct two_floats_t two_floats;
085dd6e6 419#endif
c906108c
SS
420{
421
422 printf("Contents of two_floats_t: \n\n");
423 printf("%f\t%f\n", two_floats.float1, two_floats.float2);
424 return two_floats;
425
426}
427
428/*****************************************************************
429 * PRINT_THREE_CHARS :
430 * IN struct three_char_t three_char
431 ****************************************************************/
085dd6e6
JM
432#ifdef PROTOTYPES
433struct three_char_t print_three_chars (struct three_char_t three_char)
434#else
c906108c
SS
435struct three_char_t print_three_chars ( three_char )
436struct three_char_t three_char;
085dd6e6 437#endif
c906108c
SS
438{
439
440 printf("Contents of three_char_t: \n\n");
441 printf("%c\t%c\t%c\n", three_char.ch1, three_char.ch2, three_char.ch3);
442 return three_char;
443
444}
445
446/*****************************************************************
447 * PRINT_FIVE_CHARS :
448 * IN struct five_char_t five_char
449 ****************************************************************/
085dd6e6
JM
450#ifdef PROTOTYPES
451struct five_char_t print_five_chars (struct five_char_t five_char)
452#else
c906108c
SS
453struct five_char_t print_five_chars ( five_char )
454struct five_char_t five_char;
085dd6e6 455#endif
c906108c
SS
456{
457
458 printf("Contents of five_char_t: \n\n");
459 printf("%c\t%c\t%c\t%c\t%c\n", five_char.ch1, five_char.ch2,
460 five_char.ch3, five_char.ch4,
461 five_char.ch5);
462 return five_char;
463
464}
465
466/*****************************************************************
467 * PRINT_INT_CHAR_COMBO :
468 * IN struct int_char_combo_t int_char_combo
469 ****************************************************************/
085dd6e6
JM
470#ifdef PROTOTYPES
471struct int_char_combo_t print_int_char_combo (struct int_char_combo_t int_char_combo)
472#else
c906108c
SS
473struct int_char_combo_t print_int_char_combo ( int_char_combo )
474struct int_char_combo_t int_char_combo;
085dd6e6 475#endif
c906108c
SS
476{
477
478 printf("Contents of int_char_combo_t: \n\n");
479 printf("%d\t%c\n", int_char_combo.int1, int_char_combo.ch1);
480 return int_char_combo;
481
482}
483
484/*****************************************************************
485 * PRINT_STRUCT_REP :
486 ****************************************************************/
085dd6e6
JM
487#ifdef PROTOTYPES
488struct small_rep_info_t print_struct_rep(struct small_rep_info_t struct1)
489#else
c906108c
SS
490struct small_rep_info_t print_struct_rep( struct1 )
491struct small_rep_info_t struct1;
085dd6e6 492#endif
c906108c
SS
493{
494
495 printf("Contents of struct1: \n\n");
496 printf("%10d%10d\n", struct1.value, struct1.head);
497 struct1.value =+5;
498
499 return struct1;
500
501
502}
503
504
085dd6e6
JM
505#ifdef PROTOTYPES
506struct array_rep_info_t print_one_large_struct(struct array_rep_info_t linked_list1)
507#else
c906108c
SS
508struct array_rep_info_t print_one_large_struct( linked_list1 )
509struct array_rep_info_t linked_list1;
085dd6e6 510#endif
c906108c
SS
511{
512
513
514 printf("%10d%10d\n", linked_list1.values[0],
515 linked_list1.next_index[0]);
516
517 return linked_list1;
518
519}
520
521/*****************************************************************
522 * INIT_ARRAY_REP :
523 * IN struct array_rep_info_t *linked_list
524 * IN int seed
525 ****************************************************************/
085dd6e6
JM
526#ifdef PROTOTYPES
527void init_array_rep(struct array_rep_info_t *linked_list, int seed)
528#else
c906108c
SS
529void init_array_rep( linked_list, seed )
530struct array_rep_info_t *linked_list;
531int seed;
085dd6e6 532#endif
c906108c
SS
533{
534
535 int index;
536
537 for (index = 0; index < 10; index++) {
538
539 linked_list->values[index] = (2*index) + (seed*2);
540 linked_list->next_index[index] = index + 1;
541 }
542 linked_list->head = 0;
543}
544
545
546int main () {
547
548 /* variables for large structure testing
549 */
550 int number = 10;
551 struct array_rep_info_t *list1;
552
553 /* variables for testing a small structures and a very long argument list
554 */
555 struct small_rep_info_t *struct1;
556 struct bit_flags_t *flags;
557 struct bit_flags_combo_t *flags_combo;
558 struct three_char_t *three_char;
559 struct five_char_t *five_char;
560 struct int_char_combo_t *int_char_combo;
561 struct one_double_t *d1;
562 struct two_floats_t *f3;
563
564
565 /* Allocate space for large structures
566 */
567 list1 = (struct array_rep_info_t *)malloc(sizeof(struct array_rep_info_t));
568
569 /* Initialize large structures
570 */
571 init_array_rep(list1, 2);
572
573 /* Print large structures
574 */
575 print_one_large_struct(*list1);
576
577 /* Allocate space for small structures
578 */
579 struct1 = (struct small_rep_info_t *)malloc(sizeof(struct small_rep_info_t));
580 flags = (struct bit_flags_t *)malloc(sizeof(struct bit_flags_t));
581 flags_combo = (struct bit_flags_combo_t *)malloc(sizeof(struct bit_flags_combo_t));
582 three_char = (struct three_char_t *)malloc(sizeof(struct three_char_t));
583 five_char = (struct five_char_t *)malloc(sizeof(struct five_char_t));
584 int_char_combo = (struct int_char_combo_t *)malloc(sizeof(struct int_char_combo_t));
585
586 d1 = (struct one_double_t *)malloc(sizeof(struct one_double_t));
587 f3 = (struct two_floats_t *)malloc(sizeof(struct two_floats_t));
588
589 /* Initialize small structures
590 */
591 init_one_double ( d1, 1.11111);
592 init_two_floats ( f3, -2.345, 1.0);
593 init_bit_flags(flags, (unsigned)1, (unsigned)0, (unsigned)1,
594 (unsigned)0, (unsigned)1, (unsigned)0 );
595 init_bit_flags_combo(flags_combo, (unsigned)1, (unsigned)0, 'y',
596 (unsigned)1, (unsigned)0, 'n',
597 (unsigned)1, (unsigned)0 );
598 init_three_chars(three_char, 'x', 'y', 'z');
599 init_five_chars(five_char, 'h', 'e', 'l', 'l', 'o');
600 init_int_char_combo(int_char_combo, 13, '!');
601 init_struct_rep(struct1, 10);
602
603
604 /* Print small structures
605 */
606 print_one_double(*d1);
607 print_two_floats(*f3);
608 print_bit_flags(*flags);
609 print_bit_flags_combo(*flags_combo);
610 print_three_chars(*three_char);
611 print_five_chars(*five_char);
612 print_int_char_combo(*int_char_combo);
613 print_struct_rep(*struct1);
614
615 loop_count();
616
617 return 0;
618}
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
This page took 0.070539 seconds and 4 git commands to generate.