parameters.c revision 1bcd05943ebff28c1537d61d584c7f874d963d27
1/* Ltrace Test : parameters.c.
2   Objectives  : Verify that Ltrace can handle all the different
3   parameter types
4
5   This file was written by Steve Fink <sphink@gmail.com>. */
6
7#include <stdio.h>
8#include <unistd.h>
9#include <sys/syscall.h>
10#include <sys/stat.h>
11#include <errno.h>
12#include <string.h>
13#include <stdlib.h>
14
15void func_intptr(int *i);
16void func_intptr_ret(int *i);
17int func_strlen(char*);
18void func_strfixed(char*);
19void func_ppp(int***);
20void func_stringp(char**);
21void func_short(short, short);
22void func_ushort(unsigned short, unsigned short);
23float func_float(float, float);
24double func_double(double, double);
25void func_arrayi(int*, int);
26void func_arrayf(float*, int);
27void func_struct(void*);
28
29typedef enum {
30  RED,
31  GREEN,
32  BLUE,
33  CHARTREUSE,
34  PETUNIA
35} color_t;
36void func_enum(color_t);
37void func_typedef(color_t);
38
39void func_work(char *x);
40void func_call(char *x, char *y, void (*cb)(char *));
41
42void
43call_func_work (char *x)
44{
45	func_work(x);
46}
47
48int
49main ()
50{
51  int x = 17;
52  int *xP, **xPP;
53  char buf[200];
54  char *s;
55  int *ai;
56  float *af;
57
58  func_intptr(&x);
59
60  func_intptr_ret(&x);
61
62  func_strlen(buf);
63  printf("%s\n", buf);
64
65  func_strfixed(buf);
66  printf("%s\n", buf);
67
68  x = 80;
69  xP = &x;
70  xPP = &xP;
71  func_ppp(&xPP);
72
73  s = (char*) malloc(100);
74  strcpy(s, "Dude");
75  func_stringp(&s);
76
77  func_enum(BLUE);
78
79  func_short(-8, -9);
80  func_ushort(33, 34);
81  float f = func_float(3.4, -3.4);
82  double d = func_double(3.4, -3.4);
83
84  func_typedef(BLUE);
85
86  ai = (int*) calloc(sizeof(int), 8);
87  for (x = 0; x < 8; x++)
88    ai[x] = 10 + x;
89  func_arrayi(ai, 8);
90  func_arrayi(ai, 2);
91
92  af = (float*) calloc(sizeof(float), 8);
93  for (x = 0; x < 8; x++)
94    af[x] = 10.1 + x;
95  func_arrayf(af, 8);
96  func_arrayf(af, 2);
97
98  {
99    struct {
100      int simple;
101      int alen;
102      int slen;
103      struct { int a; int b; }* array;
104      struct { int a; int b; } seq[3];
105      char* str;
106    } x;
107
108    x.simple = 89;
109
110    x.alen = 2;
111    x.array = malloc(800);
112    x.array[0].a = 1;
113    x.array[0].b = 10;
114    x.array[1].a = 3;
115    x.array[1].b = 30;
116
117    x.seq[0].a = 4;
118    x.seq[0].b = 40;
119    x.seq[1].a = 5;
120    x.seq[1].b = 50;
121    x.seq[2].a = 6;
122    x.seq[2].b = 60;
123
124    x.slen = 3;
125    x.str = "123junk";
126
127    func_struct(&x);
128  }
129
130  {
131    char x[10] = {};
132    char y[10] = {};
133    func_call(x, y, call_func_work);
134  }
135
136  return 0;
137}
138