* elf32-mips.c (MIPS_ELF_SRDATA_SECTION_NAME): New macro.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / funcargs.c
CommitLineData
c906108c
SS
1/* Test passing of arguments to functions. Use various sorts of arguments,
2 including basic types, pointers to those types, structures, lots of
3 args, etc, in various combinations. */
4
5/* AIX requires this to be the first thing in the file. */
6#ifdef __GNUC__
7# define alloca __builtin_alloca
8# define HAVE_STACK_ALLOCA 1
9#else /* not __GNUC__ */
10# ifdef _AIX
11 #pragma alloca
12# define HAVE_STACK_ALLOCA 1
13# else /* Not AIX */
14# ifdef sparc
15# include <alloca.h>
16# define HAVE_STACK_ALLOCA 1
17# ifdef __STDC__
18 void *alloca ();
19# else
20 char *alloca ();
21# endif /* __STDC__ */
22# endif /* sparc */
23# endif /* Not AIX */
24#endif /* not __GNUC__ */
25
26char c = 'a';
27char *cp = &c;
28
29unsigned char uc = 'b';
30unsigned char *ucp = &uc;
31
32short s = 1;
33short *sp = &s;
34
35unsigned short us = 6;
36unsigned short *usp = &us;
37
38int i = 2;
39int *ip = &i;
40
41unsigned int ui = 7;
42unsigned int *uip = &ui;
43
44long l = 3;
45long *lp = &l;
46
47unsigned long ul = 8;
48unsigned long *ulp = &ul;
49
50float f = 4.0;
51float *fp = &f;
52
53double d = 5.0;
54double *dp = &d;
55
56struct stag {
57 int s1;
58 int s2;
59} st = { 101, 102 };
60struct stag *stp = &st;
61
62union utag {
63 int u1;
64 long u2;
65} un;
66union utag *unp = &un;
67
68char carray[] = {'a', 'n', ' ', 'a', 'r', 'r', 'a', 'y', '\0'};
69
70
71/* Test various permutations and interleaving of integral arguments */
72
73
74call0a (c, s, i, l)
75char c; short s; int i; long l;
76{
77 c = 'a';
78 s = 5;
79 i = 6;
80 l = 7;
81}
82
83call0b (s, i, l, c)
84short s; int i; long l; char c;
85{
86 s = 6; i = 7; l = 8; c = 'j';
87}
88
89call0c (i, l, c, s)
90int i; long l; char c; short s;
91{
92 i = 3; l = 4; c = 'k'; s = 5;
93}
94
95call0d (l, c, s, i)
96long l; char c; short s; int i;
97{
98 l = 7; c = 'z'; s = 8; i = 9;
99}
100
101call0e (c1, l, c2, i, c3, s, c4, c5)
102char c1; long l; char c2; int i; char c3; short s; char c4; char c5;
103{
104 c1 = 'a'; l = 5; c2 = 'b'; i = 7; c3 = 'c'; s = 7; c4 = 'f'; c5 = 'g';
105}
106
107
108/* Test various permutations and interleaving of unsigned integral arguments */
109
110
111call1a (uc, us, ui, ul)
112unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
113{
114 uc = 5; us = 6; ui = 7; ul = 8;
115}
116
117call1b (us, ui, ul, uc)
118unsigned short us; unsigned int ui; unsigned long ul; unsigned char uc;
119{
120 uc = 5; us = 6; ui = 7; ul = 8;
121}
122
123call1c (ui, ul, uc, us)
124unsigned int ui; unsigned long ul; unsigned char uc; unsigned short us;
125{
126 uc = 5; us = 6; ui = 7; ul = 8;
127}
128
129call1d (ul, uc, us, ui)
130unsigned long ul; unsigned char uc; unsigned short us; unsigned int ui;
131{
132 uc = 5; us = 6; ui = 7; ul = 8;
133}
134
135call1e (uc1, ul, uc2, ui, uc3, us, uc4, uc5)
136unsigned char uc1; unsigned long ul; unsigned char uc2; unsigned int ui;
137unsigned char uc3; unsigned short us; unsigned char uc4; unsigned char uc5;
138{
139 uc1 = 5; ul = 7; uc2 = 8; ui = 9; uc3 = 10; us = 11; uc4 = 12; uc5 = 55;
140}
141
142/* Test various permutations and interleaving of integral arguments with
143 floating point arguments. */
144
145
146call2a (c, f1, s, d1, i, f2, l, d2)
147char c; float f1; short s; double d1; int i; float f2; long l; double d2;
148{
149 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
150}
151
152call2b (f1, s, d1, i, f2, l, d2, c)
153float f1; short s; double d1; int i; float f2; long l; double d2; char c;
154{
155 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
156}
157
158call2c (s, d1, i, f2, l, d2, c, f1)
159short s; double d1; int i; float f2; long l; double d2; char c; float f1;
160{
161 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
162}
163
164call2d (d1, i, f2, l, d2, c, f1, s)
165double d1; int i; float f2; long l; double d2; char c; float f1; short s;
166{
167 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
168}
169
170call2e (i, f2, l, d2, c, f1, s, d1)
171int i; float f2; long l; double d2; char c; float f1; short s; double d1;
172{
173 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
174}
175
176call2f (f2, l, d2, c, f1, s, d1, i)
177float f2; long l; double d2; char c; float f1; short s; double d1; int i;
178{
179 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
180}
181
182call2g (l, d2, c, f1, s, d1, i, f2)
183long l; double d2; char c; float f1; short s; double d1; int i; float f2;
184{
185 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
186}
187
188call2h (d2, c, f1, s, d1, i, f2, l)
189double d2; char c; float f1; short s; double d1; int i; float f2; long l;
190{
191 c = 'a'; f1 = 0.0; s = 5; d1 = 0.0; i = 6; f2 = 0.1; l = 7; d2 = 0.2;
192}
193
194call2i (c1, f1, c2, c3, d1, c4, c5, c6, f2, s, c7, d2)
195char c1; float f1; char c2; char c3; double d1; char c4; char c5; char c6;
196float f2; short s; char c7; double d2;
197{
198 c1 = 'a'; f1 = 0.0; c2 = 5; d1 = 0.0; c3 = 6; f2 = 0.1; c4 = 7; d2 = 0.2;
199 c5 = 's'; c6 = 'f'; c7 = 'z'; s = 77;
200}
201
202
203/* Test pointers to various integral and floating types. */
204
205
206call3a (cp, sp, ip, lp)
207char *cp; short *sp; int *ip; long *lp;
208{
209 cp = 0; sp = 0; ip = 0; lp = 0;
210}
211
212call3b (ucp, usp, uip, ulp)
213unsigned char *ucp; unsigned short *usp; unsigned int *uip;
214unsigned long *ulp;
215{
216 ucp = 0; usp = 0; uip = 0; ulp = 0;
217}
218
219call3c (fp, dp)
220float *fp; double *dp;
221{
222 fp = 0; dp = 0;
223}
224
225
226/* Test passing structures and unions by reference. */
227
228
229call4a (stp)
230struct stag *stp; {
231stp = 0;}
232
233call4b (unp)
234union utag *unp;
235{
236 unp = 0;
237}
238
239
240/* Test passing structures and unions by value. */
241
242
243call5a (st)
244struct stag st; {st.s1 = 5;}
245
246call5b (un)
247union utag un; {un.u1 = 7;}
248
249
250/* Test shuffling of args */
251
252
253call6a (c, s, i, l, f, d, uc, us, ui, ul)
254char c; short s; int i; long l; float f; double d;
255unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
256{
257 c = c;
258 call6b (s, i, l, f, d, uc, us, ui, ul);
259}
260
261call6b (s, i, l, f, d, uc, us, ui, ul)
262short s; int i; long l; float f; double d;
263unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
264{
265 s = s;
266 call6c (i, l, f, d, uc, us, ui, ul);
267}
268
269call6c (i, l, f, d, uc, us, ui, ul)
270int i; long l; float f; double d;
271unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
272{
273 i = i;
274 call6d (l, f, d, uc, us, ui, ul);
275}
276
277call6d (l, f, d, uc, us, ui, ul)
278long l; float f; double d;
279unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
280{
281 l = l;
282 call6e (f, d, uc, us, ui, ul);
283}
284
285call6e (f, d, uc, us, ui, ul)
286float f; double d;
287unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
288{
289 f = f;
290 call6f (d, uc, us, ui, ul);
291}
292
293call6f (d, uc, us, ui, ul)
294double d;
295unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
296{
297 d = d;
298 call6g (uc, us, ui, ul);
299}
300
301call6g (uc, us, ui, ul)
302unsigned char uc; unsigned short us; unsigned int ui; unsigned long ul;
303{
304 uc = uc;
305 call6h (us, ui, ul);
306}
307
308call6h (us, ui, ul)
309unsigned short us; unsigned int ui; unsigned long ul;
310{
311 us = us;
312 call6i (ui, ul);
313}
314
315call6i (ui, ul)
316unsigned int ui; unsigned long ul;
317{
318 ui = ui;
319 call6j (ul);
320}
321
322call6j (ul)
323unsigned long ul;
324{
325 ul = ul;
326 call6k ();
327}
328
329call6k ()
330{
331}
332
333
334/* Test shuffling of args, round robin */
335
336
337call7a (c, i, s, l, f, uc, d, us, ul, ui)
338char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
339{
340 call7b (i, s, l, f, uc, d, us, ul, ui, c);
341}
342
343call7b (i, s, l, f, uc, d, us, ul, ui, c)
344int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c;
345{
346 call7c (s, l, f, uc, d, us, ul, ui, c, i);
347}
348
349call7c (s, l, f, uc, d, us, ul, ui, c, i)
350short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i;
351{
352 call7d (l, f, uc, d, us, ul, ui, c, i, s);
353}
354
355call7d (l, f, uc, d, us, ul, ui, c, i, s)
356long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s;
357{
358 call7e (f, uc, d, us, ul, ui, c, i, s, l);
359}
360
361call7e (f, uc, d, us, ul, ui, c, i, s, l)
362float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l;
363{
364 call7f (uc, d, us, ul, ui, c, i, s, l, f);
365}
366
367call7f (uc, d, us, ul, ui, c, i, s, l, f)
368unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f;
369{
370 call7g (d, us, ul, ui, c, i, s, l, f, uc);
371}
372
373call7g (d, us, ul, ui, c, i, s, l, f, uc)
374double d; unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc;
375{
376 call7h (us, ul, ui, c, i, s, l, f, uc, d);
377}
378
379call7h (us, ul, ui, c, i, s, l, f, uc, d)
380unsigned short us; unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d;
381{
382 call7i (ul, ui, c, i, s, l, f, uc, d, us);
383}
384
385call7i (ul, ui, c, i, s, l, f, uc, d, us)
386unsigned long ul; unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us;
387{
388 call7j (ui, c, i, s, l, f, uc, d, us, ul);
389}
390
391call7j (ui, c, i, s, l, f, uc, d, us, ul)
392unsigned int ui; char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul;
393{
394 call7k (c, i, s, l, f, uc, d, us, ul, ui);
395}
396
397call7k (c, i, s, l, f, uc, d, us, ul, ui)
398char c; int i; short s; long l; float f; unsigned char uc; double d; unsigned short us; unsigned long ul; unsigned int ui;
399{
400 c = 'a'; i = 7; s = 8; l = 7; f = 0.3; uc = 44; d = 0.44; us = 77;
401 ul = 43; ui = 33;
402}
403
404
405/* Test printing of structures passed as arguments to recursive functions. */
406
407
408typedef struct s
409{
410 short s;
411 int i;
412 long l;
413} SVAL;
414
415hitbottom ()
416{
417}
418
419void recurse (a, depth)
420SVAL a;
421int depth;
422{
423 a.s = a.i = a.l = --depth;
424 if (depth == 0)
425 hitbottom ();
426 else
427 recurse (a, depth);
428}
429
430test_struct_args ()
431{
432 SVAL s; s.s = 5; s.i = 5; s.l = 5;
433
434 recurse (s, 5);
435}
436
437/* On various machines (pa, 29k, and rs/6000, at least), a function which
438 calls alloca may do things differently with respect to frames. So give
439 it a try. */
440
441int
442localvars_after_alloca (c, s, i, l)
443 char c;
444 short s;
445 int i;
446 long l;
447{
448#ifdef HAVE_STACK_ALLOCA
449 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
450 test what we are looking for, so if we don't have an alloca which
451 allocates on the stack, just don't bother to call alloca at all. */
452
453 char *z = alloca (s + 50);
454#endif
455 c = 'a';
456 s = 5;
457 i = 6;
458 l = 7;
459}
460
461void
462call_after_alloca_subr (c, s, i, l, uc, us, ui, ul)
463char c; int i; short s; long l; unsigned char uc; unsigned short us; unsigned long ul; unsigned int ui;
464{
465 c = 'a';
466 i = 7; s = 8; l = 7; uc = 44; us = 77;
467 ul = 43; ui = 33;
468}
469
470int
471call_after_alloca (c, s, i, l)
472 char c;
473 short s;
474 int i;
475 long l;
476{
477#ifdef HAVE_STACK_ALLOCA
478 /* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
479 test what we are looking for, so if we don't have an alloca which
480 allocates on the stack, just don't bother to call alloca at all. */
481
482 char *z = alloca (s + 50);
483#endif
484 call_after_alloca_subr (c, s, i, l, 'b', 11, 12, (unsigned long)13);
485}
486
487\f
488
489/* The point behind this test is the PA will call this indirectly
490 through dyncall. Unlike the indirect calls to call0a, this test
491 will require a trampoline between dyncall and this function on the
492 call path, then another trampoline on between this function and main
493 on the return path. */
494double
495call_with_trampolines (d1)
496double d1;
497{
498 return d1;
499} /* End of call_with_trampolines, this comment is needed by funcargs.exp */
500
501/* Dummy functions which the testsuite can use to run to, etc. */
502
503void
504marker_indirect_call () {}
505
506void
507marker_call_with_trampolines () {}
508\f
509main ()
510{
511 int (*pointer_to_call0a) () = call0a;
512 double (*pointer_to_call_with_trampolines) () = call_with_trampolines;
513
514#ifdef usestubs
515 set_debug_traps();
516 breakpoint();
517#endif
518 /* Test calling with basic integer types */
519 call0a (c, s, i, l);
520 call0b (s, i, l, c);
521 call0c (i, l, c, s);
522 call0d (l, c, s, i);
523 call0e (c, l, c, i, c, s, c, c);
524
525 /* Test calling with unsigned integer types */
526 call1a (uc, us, ui, ul);
527 call1b (us, ui, ul, uc);
528 call1c (ui, ul, uc, us);
529 call1d (ul, uc, us, ui);
530 call1e (uc, ul, uc, ui, uc, us, uc, uc);
531
532 /* Test calling with integral types mixed with floating point types */
533 call2a (c, f, s, d, i, f, l, d);
534 call2b (f, s, d, i, f, l, d, c);
535 call2c (s, d, i, f, l, d, c, f);
536 call2d (d, i, f, l, d, c, f, s);
537 call2e (i, f, l, d, c, f, s, d);
538 call2f (f, l, d, c, f, s, d, i);
539 call2g (l, d, c, f, s, d, i, f);
540 call2h (d, c, f, s, d, i, f, l);
541 call2i (c, f, c, c, d, c, c, c, f, s, c, d);;
542
543 /* Test dereferencing pointers to various integral and floating types */
544
545 call3a (cp, sp, ip, lp);
546 call3b (ucp, usp, uip, ulp);
547 call3c (fp, dp);
548
549 /* Test dereferencing pointers to structs and unions */
550
551 call4a (stp);
552 un.u1 = 1;
553 call4b (unp);
554
555 /* Test calling with structures and unions. */
556
557 call5a (st);
558 un.u1 = 2;
559 call5b (un);
560
561 /* Test shuffling of args */
562
563 call6a (c, s, i, l, f, d, uc, us, ui, ul);
564 call7a (c, i, s, l, f, uc, d, us, ul, ui);
565
566 /* Test passing structures recursively. */
567
568 test_struct_args ();
569
570 localvars_after_alloca (c, s, i, l);
571
572 call_after_alloca (c, s, i, l);
573
574 /* This is for localvars_in_indirect_call. */
575 marker_indirect_call ();
576 /* The comment on the following two lines is used by funcargs.exp,
577 don't change it. */
578 (*pointer_to_call0a) (c, s, i, l); /* First step into call0a. */
579 (*pointer_to_call0a) (c, s, i, l); /* Second step into call0a. */
580 marker_call_with_trampolines ();
581 (*pointer_to_call_with_trampolines) (d); /* Test multiple trampolines. */
582}
This page took 0.047079 seconds and 4 git commands to generate.