parameters.c revision 3a8a91ca57f66d664b3fbd19882e6d163c7ad496
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_string("zero\0xxxxxxxxxxxxxx"); 63 func_strlen(buf); 64 65 extern int func_arg0(char *); 66 func_arg0(buf); 67 68 printf("%s\n", buf); 69 70 func_strfixed(buf); 71 printf("%s\n", buf); 72 73 x = 80; 74 xP = &x; 75 xPP = &xP; 76 func_ppp(&xPP); 77 78 s = (char*) malloc(100); 79 strcpy(s, "Dude"); 80 func_stringp(&s); 81 82 func_enum(BLUE); 83 84 func_short(-8, -9); 85 func_ushort(33, 34); 86 float f = func_float(3.4, -3.4); 87 double d = func_double(3.4, -3.4); 88 89 func_typedef(BLUE); 90 91 ai = (int*) calloc(sizeof(int), 8); 92 for (x = 0; x < 8; x++) 93 ai[x] = 10 + x; 94 func_arrayi(ai, 8); 95 func_arrayi(ai, 2); 96 97 af = (float*) calloc(sizeof(float), 8); 98 for (x = 0; x < 8; x++) 99 af[x] = 10.1 + x; 100 func_arrayf(af, 8); 101 func_arrayf(af, 2); 102 103 { 104 struct { 105 int simple; 106 int alen; 107 int slen; 108 struct { int a; int b; }* array; 109 struct { int a; int b; } seq[3]; 110 char* str; 111 } x; 112 113 x.simple = 89; 114 115 x.alen = 2; 116 x.array = malloc(800); 117 x.array[0].a = 1; 118 x.array[0].b = 10; 119 x.array[1].a = 3; 120 x.array[1].b = 30; 121 122 x.seq[0].a = 4; 123 x.seq[0].b = 40; 124 x.seq[1].a = 5; 125 x.seq[1].b = 50; 126 x.seq[2].a = 6; 127 x.seq[2].b = 60; 128 129 x.slen = 3; 130 x.str = "123junk"; 131 132 func_struct(&x); 133 } 134 135 { 136 char x[10] = {}; 137 char y[10] = {}; 138 func_call(x, y, call_func_work); 139 } 140 141 struct S2 { 142 float f; 143 char a; 144 char b; 145 }; 146 struct S3 { 147 char a[6]; 148 float f; 149 }; 150 struct S2 func_struct_2(int, struct S3 s3, double d); 151 func_struct_2(17, (struct S3){ "ABCDE", 0.25 }, 0.5); 152 153 struct S4 { 154 long a; 155 long b; 156 long c; 157 long d; 158 }; 159 struct S4 func_struct_large(struct S4 a, struct S4 b); 160 func_struct_large((struct S4){ 1, 2, 3, 4 }, (struct S4){ 5, 6, 7, 8 }); 161 162 struct S5 { 163 char a; 164 char b; 165 long c; 166 long d; 167 }; 168 struct S5 func_struct_large2(struct S5 a, struct S5 b); 169 func_struct_large2((struct S5){ '0', '1', 3, 4 }, (struct S5){ '2', '3', 7, 8 }); 170 171 struct S6 { 172 long a; 173 long b; 174 char c; 175 char d; 176 }; 177 struct S6 func_struct_large3(struct S6 a, struct S6 b); 178 func_struct_large3((struct S6){ 3, 4, '0', '1' }, (struct S6){ 7, 8 ,'2', '3' }); 179 180 void func_many_args(int a, int b, long c, double d, char e, int f, float g, 181 char h, int i, double j, int k, double l, char m, int n, 182 short o, int p, char q, float r, float s, double t, 183 long u, float v, float w, float x, float y); 184 func_many_args(1, 2, 3, 4.0, '5', 6, 7.0, 185 '8', 9, 10.0, 11, 12.0, 'A', 14, 186 15, 16, 'B', 18.0, 19.0, 20.0, 187 21, 22.0, 23.0, 24.0, 25.0); 188 189 void func_printf(char *format, ...); 190 func_printf("sotnuh %d %ld %g %c\n", 5, 6L, 1.5, 'X'); 191 func_printf("sotnuh1 %d %ld %hd\n", 5, 6L, (short)7); 192 func_printf("sotnuh2 %s %10s %10s\n", "a string", "a trimmed string", "short"); 193 func_printf("many_args" 194 "%d %d %ld %g %c %d %g " 195 "%c %d %g %d %g %c %d " 196 "%hd %d %c %g %g %g " 197 "%ld %g %g %g %g", 198 1, 2, 3L, 4.0, '5', 6, 7.0, 199 '8', 9, 10.0, 11, 12.0, 'A', 14, 200 (short)15, 16, 'B', 18.0, 19.0, 20.0, 201 21L, 22.0, 23.0, 24.0, 25.0); 202 203 func_printf("sotnuh3 %*s\n", 4, "a trimmed string"); 204 205 void func_sprintf(char *str, char *format, ...); 206 func_sprintf(NULL, "test %d %d %d %d\n", 1, 2, 3, 4); 207 208 void func_lens(int, long, short, long); 209 func_lens(22, 23, 24, 25); 210 211 int func_bool(int a, int b); 212 func_bool(1, 10); 213 func_bool(2, 0); 214 215 void func_hide(int a, int b, int c, int d, int e, int f); 216 func_hide(1, 2, 3, 4, 5, 6); 217 218 enum ab { A, B }; 219 long *func_short_enums(short abs[]); 220 func_short_enums((short[]){ A, B, A, A }); 221 222 long func_negative_enum(short a, unsigned short b, int c, unsigned d, 223 long e, unsigned long f); 224 func_negative_enum(-1, -1, -1, -1, -1, -1); 225 226 void func_charp_string(char *p); 227 func_charp_string("null-terminated string"); 228 229 struct dbl_eqv1 { double d; }; 230 struct dbl_eqv2 { struct dbl_eqv1 d; }; 231 struct dbl_eqv3 { struct dbl_eqv2 d; }; 232 struct dbl_eqv4 { struct dbl_eqv3 d; }; 233 234 struct flt_eqv1 { float d; }; 235 struct flt_eqv2 { struct flt_eqv1 d; }; 236 struct flt_eqv3 { struct flt_eqv2 d; }; 237 struct flt_eqv4 { struct flt_eqv3 d; }; 238 239 struct dbl_eqv1 func_dbl_eqv(struct dbl_eqv1 a, struct dbl_eqv2 b, 240 struct dbl_eqv3 c, struct dbl_eqv4 d); 241 func_dbl_eqv((struct dbl_eqv1){ 2.5 }, 242 (struct dbl_eqv2){ { 1.5 } }, 243 (struct dbl_eqv3){ { { 0.5 } } }, 244 (struct dbl_eqv4){ { { { -0.5 } } } }); 245 246 struct flt_eqv1 func_flt_eqv(struct flt_eqv1 a, struct flt_eqv2 b, 247 struct flt_eqv3 c, struct flt_eqv4 d); 248 func_flt_eqv((struct flt_eqv1){ 2.5 }, 249 (struct flt_eqv2){ { 1.5 } }, 250 (struct flt_eqv3){ { { 0.5 } } }, 251 (struct flt_eqv4){ { { { -0.5 } } } }); 252 253 struct struct_empty {}; 254 struct struct_empty func_struct_empty(struct struct_empty e); 255 func_struct_empty((struct struct_empty) {}); 256 257 struct struct_size1 { char a; }; 258 struct struct_size1 func_struct_size1(struct struct_size1 e); 259 func_struct_size1((struct struct_size1){ '5' }); 260 261 struct struct_size2 { short a; }; 262 struct struct_size2 func_struct_size2(struct struct_size2 e); 263 func_struct_size2((struct struct_size2){ 5 }); 264 265 struct struct_size4 { int a; }; 266 struct struct_size4 func_struct_size4(struct struct_size4 e); 267 func_struct_size4((struct struct_size4){ 5 }); 268 269 struct struct_size8 { int a; int b; }; 270 struct struct_size8 func_struct_size8(struct struct_size8 e); 271 func_struct_size8((struct struct_size8){ 5, 6 }); 272 273 /* Test Itanium Homogeneous Floating-point Aggregates. */ 274 275 struct struct_hfa_f2 { float a; struct flt_eqv1 b; }; 276 struct struct_hfa_f2 func_hfa_f2(struct struct_hfa_f2 e); 277 func_hfa_f2((struct struct_hfa_f2){ 1, { 2 } }); 278 279 struct struct_hfa_f3 { float a; struct struct_hfa_f2 b; }; 280 struct struct_hfa_f3 func_hfa_f3(struct struct_hfa_f3 e); 281 func_hfa_f3((struct struct_hfa_f3){ 3, { 1, { 2 } } }); 282 283 struct struct_hfa_f4 { float a; struct struct_hfa_f3 b; }; 284 struct struct_hfa_f4 func_hfa_f4(struct struct_hfa_f4 e); 285 func_hfa_f4((struct struct_hfa_f4){ 4, { 3, { 1, { 2 } } } }); 286 287 struct struct_hfa_f5 { float a; struct struct_hfa_f4 b; }; 288 struct struct_hfa_f5 func_hfa_f5(struct struct_hfa_f5 e); 289 func_hfa_f5((struct struct_hfa_f5){ 5, { 4, { 3, { 1, { 2 } } } } }); 290 291 struct struct_hfa_f6 { float a; struct struct_hfa_f5 b; }; 292 struct struct_hfa_f6 func_hfa_f6(struct struct_hfa_f6 e); 293 func_hfa_f6((struct struct_hfa_f6){ 6, { 5, { 4, { 3, { 1, { 2 } } } } } }); 294 295 struct struct_hfa_f7 { float a; struct struct_hfa_f6 b; }; 296 struct struct_hfa_f7 func_hfa_f7(struct struct_hfa_f7 e); 297 func_hfa_f7((struct struct_hfa_f7){ 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } }); 298 299 struct struct_hfa_f8 { float a; struct struct_hfa_f7 b; }; 300 struct struct_hfa_f8 func_hfa_f8(struct struct_hfa_f8 e); 301 func_hfa_f8((struct struct_hfa_f8){ 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } }); 302 303 struct struct_hfa_f9 { float a; struct struct_hfa_f8 b; }; 304 struct struct_hfa_f9 func_hfa_f9(struct struct_hfa_f9 e); 305 func_hfa_f9((struct struct_hfa_f9){ 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } }); 306 307 struct struct_hfa_f10 { float a; struct struct_hfa_f9 b; }; 308 struct struct_hfa_f10 func_hfa_f10(struct struct_hfa_f10 e); 309 func_hfa_f10((struct struct_hfa_f10){ 10, { 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } } }); 310 311 struct struct_hfa_f11 { float a; struct struct_hfa_f10 b; }; 312 struct struct_hfa_f11 func_hfa_f11(struct struct_hfa_f11 e); 313 func_hfa_f11((struct struct_hfa_f11){ 11, { 10, { 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } } } }); 314 315 struct struct_hfa_f12 { float a; struct struct_hfa_f11 b; }; 316 struct struct_hfa_f12 func_hfa_f12(struct struct_hfa_f12 e); 317 func_hfa_f12((struct struct_hfa_f12){ 12, { 11, { 10, { 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } } } } }); 318 319 320 struct struct_hfa_d2 { double a; struct dbl_eqv1 b; }; 321 struct struct_hfa_d2 func_hfa_d2(struct struct_hfa_d2 e); 322 func_hfa_d2((struct struct_hfa_d2){ 1, { 2 } }); 323 324 struct struct_hfa_d3 { double a; struct struct_hfa_d2 b; }; 325 struct struct_hfa_d3 func_hfa_d3(struct struct_hfa_d3 e); 326 func_hfa_d3((struct struct_hfa_d3){ 3, { 1, { 2 } } }); 327 328 struct struct_hfa_d4 { double a; struct struct_hfa_d3 b; }; 329 struct struct_hfa_d4 func_hfa_d4(struct struct_hfa_d4 e); 330 func_hfa_d4((struct struct_hfa_d4){ 4, { 3, { 1, { 2 } } } }); 331 332 struct struct_hfa_d5 { double a; struct struct_hfa_d4 b; }; 333 struct struct_hfa_d5 func_hfa_d5(struct struct_hfa_d5 e); 334 func_hfa_d5((struct struct_hfa_d5){ 5, { 4, { 3, { 1, { 2 } } } } }); 335 336 struct struct_hfa_d6 { double a; struct struct_hfa_d5 b; }; 337 struct struct_hfa_d6 func_hfa_d6(struct struct_hfa_d6 e); 338 func_hfa_d6((struct struct_hfa_d6){ 6, { 5, { 4, { 3, { 1, { 2 } } } } } }); 339 340 struct struct_hfa_d7 { double a; struct struct_hfa_d6 b; }; 341 struct struct_hfa_d7 func_hfa_d7(struct struct_hfa_d7 e); 342 func_hfa_d7((struct struct_hfa_d7){ 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } }); 343 344 struct struct_hfa_d8 { double a; struct struct_hfa_d7 b; }; 345 struct struct_hfa_d8 func_hfa_d8(struct struct_hfa_d8 e); 346 func_hfa_d8((struct struct_hfa_d8){ 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } }); 347 348 struct struct_hfa_d9 { double a; struct struct_hfa_d8 b; }; 349 struct struct_hfa_d9 func_hfa_d9(struct struct_hfa_d9 e); 350 func_hfa_d9((struct struct_hfa_d9){ 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } }); 351 352 struct struct_hfa_d10 { double a; struct struct_hfa_d9 b; }; 353 struct struct_hfa_d10 func_hfa_d10(struct struct_hfa_d10 e); 354 func_hfa_d10((struct struct_hfa_d10){ 10, { 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } } }); 355 356 struct struct_hfa_d11 { double a; struct struct_hfa_d10 b; }; 357 struct struct_hfa_d11 func_hfa_d11(struct struct_hfa_d11 e); 358 func_hfa_d11((struct struct_hfa_d11){ 11, { 10, { 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } } } }); 359 360 struct struct_hfa_d12 { double a; struct struct_hfa_d11 b; }; 361 struct struct_hfa_d12 func_hfa_d12(struct struct_hfa_d12 e); 362 func_hfa_d12((struct struct_hfa_d12){ 12, { 11, { 10, { 9, { 8, { 7, { 6, { 5, { 4, { 3, { 1, { 2 } } } } } } } } } } } }); 363 364 return 0; 365} 366