access pointer -> address
[libside.git] / src / tracer.c
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6 #include <stdint.h>
7 #include <inttypes.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <stdbool.h>
11 #include <string.h>
12
13 #include <side/trace.h>
14
15 enum tracer_display_base {
16 TRACER_DISPLAY_BASE_2,
17 TRACER_DISPLAY_BASE_8,
18 TRACER_DISPLAY_BASE_10,
19 TRACER_DISPLAY_BASE_16,
20 };
21
22 static struct side_tracer_handle *tracer_handle;
23
24 static
25 void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec);
26 static
27 void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec);
28 static
29 void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec);
30 static
31 void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx);
32 static
33 void tracer_print_array_fixint(const struct side_type *type_desc, const struct side_arg *item);
34 static
35 void tracer_print_vla_fixint(const struct side_type *type_desc, const struct side_arg *item);
36 static
37 void tracer_print_dynamic(const struct side_arg *dynamic_item);
38 static
39 uint32_t tracer_print_gather_byte_type(const struct side_type_gather *type_gather, const void *_ptr);
40 static
41 uint32_t tracer_print_gather_integer_type(const struct side_type_gather *type_gather, const void *_ptr);
42 static
43 uint32_t tracer_print_gather_float_type(const struct side_type_gather *type_gather, const void *_ptr);
44 static
45 uint32_t tracer_print_gather_struct(const struct side_type_gather *type_gather, const void *_ptr);
46 static
47 uint32_t tracer_print_gather_array(const struct side_type_gather *type_gather, const void *_ptr);
48 static
49 uint32_t tracer_print_gather_vla(const struct side_type_gather *type_gather, const void *_ptr);
50 static
51 void tracer_print_type(const struct side_type *type_desc, const struct side_arg *item);
52
53 static
54 int64_t get_attr_integer_value(const struct side_attr *attr)
55 {
56 int64_t val;
57
58 switch (attr->value.type) {
59 case SIDE_ATTR_TYPE_U8:
60 val = attr->value.u.integer_value.side_u8;
61 break;
62 case SIDE_ATTR_TYPE_U16:
63 val = attr->value.u.integer_value.side_u16;
64 break;
65 case SIDE_ATTR_TYPE_U32:
66 val = attr->value.u.integer_value.side_u32;
67 break;
68 case SIDE_ATTR_TYPE_U64:
69 val = attr->value.u.integer_value.side_u64;
70 break;
71 case SIDE_ATTR_TYPE_S8:
72 val = attr->value.u.integer_value.side_s8;
73 break;
74 case SIDE_ATTR_TYPE_S16:
75 val = attr->value.u.integer_value.side_s16;
76 break;
77 case SIDE_ATTR_TYPE_S32:
78 val = attr->value.u.integer_value.side_s32;
79 break;
80 case SIDE_ATTR_TYPE_S64:
81 val = attr->value.u.integer_value.side_s64;
82 break;
83 default:
84 fprintf(stderr, "Unexpected attribute type\n");
85 abort();
86 }
87 return val;
88 }
89
90 static
91 enum tracer_display_base get_attr_display_base(const struct side_attr *_attr, uint32_t nr_attr,
92 enum tracer_display_base default_base)
93 {
94 uint32_t i;
95
96 for (i = 0; i < nr_attr; i++) {
97 const struct side_attr *attr = &_attr[i];
98
99 if (!strcmp(attr->key, "std.integer.base")) {
100 int64_t val = get_attr_integer_value(attr);
101
102 switch (val) {
103 case 2:
104 return TRACER_DISPLAY_BASE_2;
105 case 8:
106 return TRACER_DISPLAY_BASE_8;
107 case 10:
108 return TRACER_DISPLAY_BASE_10;
109 case 16:
110 return TRACER_DISPLAY_BASE_16;
111 default:
112 fprintf(stderr, "Unexpected integer display base: %" PRId64 "\n", val);
113 abort();
114 }
115 }
116 }
117 return default_base; /* Default */
118 }
119
120 static
121 bool type_to_host_reverse_bo(const struct side_type *type_desc)
122 {
123 switch (type_desc->type) {
124 case SIDE_TYPE_U8:
125 case SIDE_TYPE_S8:
126 case SIDE_TYPE_BYTE:
127 return false;
128 case SIDE_TYPE_U16:
129 case SIDE_TYPE_U32:
130 case SIDE_TYPE_U64:
131 case SIDE_TYPE_S16:
132 case SIDE_TYPE_S32:
133 case SIDE_TYPE_S64:
134 case SIDE_TYPE_POINTER32:
135 case SIDE_TYPE_POINTER64:
136 if (type_desc->u.side_integer.byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
137 return true;
138 else
139 return false;
140 break;
141 case SIDE_TYPE_FLOAT_BINARY16:
142 case SIDE_TYPE_FLOAT_BINARY32:
143 case SIDE_TYPE_FLOAT_BINARY64:
144 case SIDE_TYPE_FLOAT_BINARY128:
145 if (type_desc->u.side_float.byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST)
146 return true;
147 else
148 return false;
149 break;
150 default:
151 fprintf(stderr, "Unexpected type\n");
152 abort();
153 }
154 }
155
156 static
157 void tracer_print_attr_type(const char *separator, const struct side_attr *attr)
158 {
159 printf("{ key%s \"%s\", value%s ", separator, attr->key, separator);
160 switch (attr->value.type) {
161 case SIDE_ATTR_TYPE_BOOL:
162 printf("%s", attr->value.u.bool_value ? "true" : "false");
163 break;
164 case SIDE_ATTR_TYPE_U8:
165 printf("%" PRIu8, attr->value.u.integer_value.side_u8);
166 break;
167 case SIDE_ATTR_TYPE_U16:
168 printf("%" PRIu16, attr->value.u.integer_value.side_u16);
169 break;
170 case SIDE_ATTR_TYPE_U32:
171 printf("%" PRIu32, attr->value.u.integer_value.side_u32);
172 break;
173 case SIDE_ATTR_TYPE_U64:
174 printf("%" PRIu64, attr->value.u.integer_value.side_u64);
175 break;
176 case SIDE_ATTR_TYPE_S8:
177 printf("%" PRId8, attr->value.u.integer_value.side_s8);
178 break;
179 case SIDE_ATTR_TYPE_S16:
180 printf("%" PRId16, attr->value.u.integer_value.side_s16);
181 break;
182 case SIDE_ATTR_TYPE_S32:
183 printf("%" PRId32, attr->value.u.integer_value.side_s32);
184 break;
185 case SIDE_ATTR_TYPE_S64:
186 printf("%" PRId64, attr->value.u.integer_value.side_s64);
187 break;
188 case SIDE_ATTR_TYPE_POINTER32:
189 printf("0x%" PRIx32, attr->value.u.integer_value.side_u32);
190 break;
191 case SIDE_ATTR_TYPE_POINTER64:
192 printf("0x%" PRIx64, attr->value.u.integer_value.side_u64);
193 break;
194 case SIDE_ATTR_TYPE_FLOAT_BINARY16:
195 #if __HAVE_FLOAT16
196 printf("%g", (double) attr->value.u.float_value.side_float_binary16);
197 break;
198 #else
199 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
200 abort();
201 #endif
202 case SIDE_ATTR_TYPE_FLOAT_BINARY32:
203 #if __HAVE_FLOAT32
204 printf("%g", (double) attr->value.u.float_value.side_float_binary32);
205 break;
206 #else
207 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
208 abort();
209 #endif
210 case SIDE_ATTR_TYPE_FLOAT_BINARY64:
211 #if __HAVE_FLOAT64
212 printf("%g", (double) attr->value.u.float_value.side_float_binary64);
213 break;
214 #else
215 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
216 abort();
217 #endif
218 case SIDE_ATTR_TYPE_FLOAT_BINARY128:
219 #if __HAVE_FLOAT128
220 printf("%Lg", (long double) attr->value.u.float_value.side_float_binary128);
221 break;
222 #else
223 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
224 abort();
225 #endif
226 case SIDE_ATTR_TYPE_STRING:
227 printf("\"%s\"", (const char *)(uintptr_t) attr->value.u.string_value);
228 break;
229 default:
230 fprintf(stderr, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
231 abort();
232 }
233 printf(" }");
234 }
235
236 static
237 void print_attributes(const char *prefix_str, const char *separator,
238 const struct side_attr *attr, uint32_t nr_attr)
239 {
240 uint32_t i;
241
242 if (!nr_attr)
243 return;
244 printf("%s%s [ ", prefix_str, separator);
245 for (i = 0; i < nr_attr; i++) {
246 printf("%s", i ? ", " : "");
247 tracer_print_attr_type(separator, &attr[i]);
248 }
249 printf(" ]");
250 }
251
252 static
253 void print_enum(const struct side_type *type_desc, const struct side_arg *item)
254 {
255 const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings;
256 const struct side_type *elem_type = type_desc->u.side_enum.elem_type;
257 uint32_t i, print_count = 0;
258 int64_t value;
259
260 if (elem_type->type != item->type) {
261 fprintf(stderr, "ERROR: Unexpected enum element type\n");
262 abort();
263 }
264 switch (item->type) {
265 case SIDE_TYPE_U8:
266 value = (int64_t) item->u.side_static.integer_value.side_u8;
267 break;
268 case SIDE_TYPE_U16:
269 {
270 uint16_t v;
271
272 v = item->u.side_static.integer_value.side_u16;
273 if (type_to_host_reverse_bo(elem_type))
274 v = side_bswap_16(v);
275 value = (int64_t) v;
276 break;
277 }
278 case SIDE_TYPE_U32:
279 {
280 uint32_t v;
281
282 v = item->u.side_static.integer_value.side_u32;
283 if (type_to_host_reverse_bo(elem_type))
284 v = side_bswap_32(v);
285 value = (int64_t) v;
286 break;
287 }
288 case SIDE_TYPE_U64:
289 {
290 uint64_t v;
291
292 v = item->u.side_static.integer_value.side_u64;
293 if (type_to_host_reverse_bo(elem_type))
294 v = side_bswap_64(v);
295 value = (int64_t) v;
296 break;
297 }
298 case SIDE_TYPE_S8:
299 value = (int64_t) item->u.side_static.integer_value.side_s8;
300 break;
301 case SIDE_TYPE_S16:
302 {
303 int16_t v;
304
305 v = item->u.side_static.integer_value.side_s16;
306 if (type_to_host_reverse_bo(elem_type))
307 v = side_bswap_16(v);
308 value = (int64_t) v;
309 break;
310 }
311 case SIDE_TYPE_S32:
312 {
313 int32_t v;
314
315 v = item->u.side_static.integer_value.side_s32;
316 if (type_to_host_reverse_bo(elem_type))
317 v = side_bswap_32(v);
318 value = (int64_t) v;
319 break;
320 }
321 case SIDE_TYPE_S64:
322 {
323 int64_t v;
324
325 v = item->u.side_static.integer_value.side_s64;
326 if (type_to_host_reverse_bo(elem_type))
327 v = side_bswap_64(v);
328 value = v;
329 break;
330 }
331 default:
332 fprintf(stderr, "ERROR: Unexpected enum element type\n");
333 abort();
334 }
335 print_attributes("attr", ":", mappings->attr, mappings->nr_attr);
336 printf("%s", mappings->nr_attr ? ", " : "");
337 tracer_print_type(type_desc->u.side_enum.elem_type, item);
338 printf(", labels: [ ");
339 for (i = 0; i < mappings->nr_mappings; i++) {
340 const struct side_enum_mapping *mapping = &mappings->mappings[i];
341
342 if (mapping->range_end < mapping->range_begin) {
343 fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n",
344 mapping->range_begin, mapping->range_end);
345 abort();
346 }
347 if (value >= mapping->range_begin && value <= mapping->range_end) {
348 printf("%s", print_count++ ? ", " : "");
349 printf("\"%s\"", mapping->label);
350 }
351 }
352 if (!print_count)
353 printf("<NO LABEL>");
354 printf(" ]");
355 }
356
357 static
358 uint32_t enum_elem_type_to_stride(const struct side_type *elem_type)
359 {
360 uint32_t stride_bit;
361
362 switch (elem_type->type) {
363 case SIDE_TYPE_U8: /* Fall-through */
364 case SIDE_TYPE_BYTE:
365 stride_bit = 8;
366 break;
367 case SIDE_TYPE_U16:
368 stride_bit = 16;
369 break;
370 case SIDE_TYPE_U32:
371 stride_bit = 32;
372 break;
373 case SIDE_TYPE_U64:
374 stride_bit = 64;
375 break;
376 default:
377 fprintf(stderr, "ERROR: Unexpected enum element type\n");
378 abort();
379 }
380 return stride_bit;
381 }
382
383 static
384 void print_enum_bitmap(const struct side_type *type_desc,
385 const struct side_arg *item)
386 {
387 const struct side_type *elem_type = type_desc->u.side_enum_bitmap.elem_type;
388 const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings;
389 uint32_t i, print_count = 0, stride_bit, nr_items;
390 bool reverse_byte_order = false;
391 const struct side_arg *array_item;
392
393 switch (elem_type->type) {
394 case SIDE_TYPE_U8: /* Fall-through */
395 case SIDE_TYPE_BYTE: /* Fall-through */
396 case SIDE_TYPE_U16: /* Fall-through */
397 case SIDE_TYPE_U32: /* Fall-through */
398 case SIDE_TYPE_U64:
399 stride_bit = enum_elem_type_to_stride(elem_type);
400 reverse_byte_order = type_to_host_reverse_bo(elem_type);
401 array_item = item;
402 nr_items = 1;
403 break;
404 case SIDE_TYPE_ARRAY:
405 stride_bit = enum_elem_type_to_stride(elem_type->u.side_array.elem_type);
406 reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_array.elem_type);
407 array_item = item->u.side_static.side_array->sav;
408 nr_items = type_desc->u.side_array.length;
409 break;
410 case SIDE_TYPE_VLA:
411 stride_bit = enum_elem_type_to_stride(elem_type->u.side_vla.elem_type);
412 reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_vla.elem_type);
413 array_item = item->u.side_static.side_vla->sav;
414 nr_items = item->u.side_static.side_vla->len;
415 break;
416 default:
417 fprintf(stderr, "ERROR: Unexpected enum element type\n");
418 abort();
419 }
420
421 print_attributes("attr", ":", side_enum_mappings->attr, side_enum_mappings->nr_attr);
422 printf("%s", side_enum_mappings->nr_attr ? ", " : "");
423 printf("labels: [ ");
424 for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
425 const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i];
426 bool match = false;
427 uint64_t bit;
428
429 if (mapping->range_end < mapping->range_begin) {
430 fprintf(stderr, "ERROR: Unexpected enum bitmap range: %" PRIu64 "-%" PRIu64 "\n",
431 mapping->range_begin, mapping->range_end);
432 abort();
433 }
434 for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) {
435 if (bit > (nr_items * stride_bit) - 1)
436 break;
437 switch (stride_bit) {
438 case 8:
439 {
440 uint8_t v = array_item[bit / 8].u.side_static.integer_value.side_u8;
441 if (v & (1ULL << (bit % 8))) {
442 match = true;
443 goto match;
444 }
445 break;
446 }
447 case 16:
448 {
449 uint16_t v = array_item[bit / 16].u.side_static.integer_value.side_u16;
450 if (reverse_byte_order)
451 v = side_bswap_16(v);
452 if (v & (1ULL << (bit % 16))) {
453 match = true;
454 goto match;
455 }
456 break;
457 }
458 case 32:
459 {
460 uint32_t v = array_item[bit / 32].u.side_static.integer_value.side_u32;
461 if (reverse_byte_order)
462 v = side_bswap_32(v);
463 if (v & (1ULL << (bit % 32))) {
464 match = true;
465 goto match;
466 }
467 break;
468 }
469 case 64:
470 {
471 uint64_t v = array_item[bit / 64].u.side_static.integer_value.side_u64;
472 if (reverse_byte_order)
473 v = side_bswap_64(v);
474 if (v & (1ULL << (bit % 64))) {
475 match = true;
476 goto match;
477 }
478 break;
479 }
480 default:
481 abort();
482 }
483 }
484 match:
485 if (match) {
486 printf("%s", print_count++ ? ", " : "");
487 printf("\"%s\"", mapping->label);
488 }
489 }
490 if (!print_count)
491 printf("<NO LABEL>");
492 printf(" ]");
493 }
494
495 static
496 void print_integer_binary(uint64_t v, int bits)
497 {
498 int i;
499
500 printf("0b");
501 v <<= 64 - bits;
502 for (i = 0; i < bits; i++) {
503 printf("%c", v & (1ULL << 63) ? '1' : '0');
504 v <<= 1;
505 }
506 }
507
508 static
509 void tracer_print_type_header(const char *separator,
510 const struct side_attr *attr, uint32_t nr_attr)
511 {
512 print_attributes("attr", separator, attr, nr_attr);
513 printf("%s", nr_attr ? ", " : "");
514 printf("value%s ", separator);
515 }
516
517 static
518 void tracer_print_type_integer(const char *separator,
519 const struct side_type_integer *type_integer,
520 const union side_integer_value *value,
521 uint16_t offset_bits,
522 enum tracer_display_base default_base)
523 {
524 enum tracer_display_base base;
525 bool reverse_bo;
526 union {
527 uint64_t v_unsigned;
528 int64_t v_signed;
529 } v;
530
531 if (!type_integer->len_bits ||
532 type_integer->len_bits + offset_bits > type_integer->integer_size_bits)
533 abort();
534 reverse_bo = type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST;
535 base = get_attr_display_base(type_integer->attr,
536 type_integer->nr_attr,
537 default_base);
538 switch (type_integer->integer_size_bits) {
539 case 8:
540 if (type_integer->signedness)
541 v.v_signed = value->side_s8;
542 else
543 v.v_unsigned = value->side_u8;
544 break;
545 case 16:
546 if (type_integer->signedness) {
547 int16_t side_s16;
548
549 side_s16 = value->side_s16;
550 if (reverse_bo)
551 side_s16 = side_bswap_16(side_s16);
552 v.v_signed = side_s16;
553 } else {
554 uint16_t side_u16;
555
556 side_u16 = value->side_u16;
557 if (reverse_bo)
558 side_u16 = side_bswap_16(side_u16);
559 v.v_unsigned = side_u16;
560 }
561 break;
562 case 32:
563 if (type_integer->signedness) {
564 int32_t side_s32;
565
566 side_s32 = value->side_s32;
567 if (reverse_bo)
568 side_s32 = side_bswap_32(side_s32);
569 v.v_signed = side_s32;
570 } else {
571 uint32_t side_u32;
572
573 side_u32 = value->side_u32;
574 if (reverse_bo)
575 side_u32 = side_bswap_32(side_u32);
576 v.v_unsigned = side_u32;
577 }
578 break;
579 case 64:
580 if (type_integer->signedness) {
581 int64_t side_s64;
582
583 side_s64 = value->side_s64;
584 if (reverse_bo)
585 side_s64 = side_bswap_64(side_s64);
586 v.v_signed = side_s64;
587 } else {
588 uint64_t side_u64;
589
590 side_u64 = value->side_u64;
591 if (reverse_bo)
592 side_u64 = side_bswap_64(side_u64);
593 v.v_unsigned = side_u64;
594 }
595 break;
596 default:
597 abort();
598 }
599 v.v_unsigned >>= offset_bits;
600 if (type_integer->len_bits < 64)
601 v.v_unsigned &= (1ULL << type_integer->len_bits) - 1;
602 tracer_print_type_header(separator, type_integer->attr, type_integer->nr_attr);
603 switch (base) {
604 case TRACER_DISPLAY_BASE_2:
605 print_integer_binary(v.v_unsigned, type_integer->len_bits);
606 break;
607 case TRACER_DISPLAY_BASE_8:
608 printf("0%" PRIo64, v.v_unsigned);
609 break;
610 case TRACER_DISPLAY_BASE_10:
611 if (type_integer->signedness) {
612 /* Sign-extend. */
613 if (type_integer->len_bits < 64) {
614 if (v.v_unsigned & (1ULL << (type_integer->len_bits - 1)))
615 v.v_unsigned |= ~((1ULL << type_integer->len_bits) - 1);
616 }
617 printf("%" PRId64, v.v_signed);
618 } else {
619 printf("%" PRIu64, v.v_unsigned);
620 }
621 break;
622 case TRACER_DISPLAY_BASE_16:
623 printf("0x%" PRIx64, v.v_unsigned);
624 break;
625 default:
626 abort();
627 }
628 }
629
630 static
631 void tracer_print_type_float(const char *separator,
632 const struct side_type_float *type_float,
633 const union side_float_value *value)
634 {
635 bool reverse_bo;
636
637 reverse_bo = type_float->byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST;
638 tracer_print_type_header(separator, type_float->attr, type_float->nr_attr);
639 switch (type_float->float_size_bits) {
640 case 16:
641 {
642 #if __HAVE_FLOAT16
643 union {
644 _Float16 f;
645 uint16_t u;
646 } float16 = {
647 .f = value->side_float_binary16,
648 };
649
650 if (reverse_bo)
651 float16.u = side_bswap_16(float16.u);
652 tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr);
653 printf("%g", (double) float16.f);
654 break;
655 #else
656 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
657 abort();
658 #endif
659 }
660 case 32:
661 {
662 #if __HAVE_FLOAT32
663 union {
664 _Float32 f;
665 uint32_t u;
666 } float32 = {
667 .f = value->side_float_binary32,
668 };
669
670 if (reverse_bo)
671 float32.u = side_bswap_32(float32.u);
672 printf("%g", (double) float32.f);
673 break;
674 #else
675 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
676 abort();
677 #endif
678 }
679 case 64:
680 {
681 #if __HAVE_FLOAT64
682 union {
683 _Float64 f;
684 uint64_t u;
685 } float64 = {
686 .f = value->side_float_binary64,
687 };
688
689 if (reverse_bo)
690 float64.u = side_bswap_64(float64.u);
691 printf("%g", (double) float64.f);
692 break;
693 #else
694 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
695 abort();
696 #endif
697 }
698 case 128:
699 {
700 #if __HAVE_FLOAT128
701 union {
702 _Float128 f;
703 char arr[16];
704 } float128 = {
705 .f = value->side_float_binary128,
706 };
707
708 if (reverse_bo)
709 side_bswap_128p(float128.arr);
710 printf("%Lg", (long double) float128.f);
711 break;
712 #else
713 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
714 abort();
715 #endif
716 }
717 default:
718 fprintf(stderr, "ERROR: Unknown float size\n");
719 abort();
720 }
721 }
722
723 static
724 void tracer_print_type(const struct side_type *type_desc, const struct side_arg *item)
725 {
726 enum side_type_label type;
727
728 switch (type_desc->type) {
729 case SIDE_TYPE_ARRAY:
730 switch (item->type) {
731 case SIDE_TYPE_ARRAY_U8:
732 case SIDE_TYPE_ARRAY_U16:
733 case SIDE_TYPE_ARRAY_U32:
734 case SIDE_TYPE_ARRAY_U64:
735 case SIDE_TYPE_ARRAY_S8:
736 case SIDE_TYPE_ARRAY_S16:
737 case SIDE_TYPE_ARRAY_S32:
738 case SIDE_TYPE_ARRAY_S64:
739 case SIDE_TYPE_ARRAY_POINTER32:
740 case SIDE_TYPE_ARRAY_POINTER64:
741 case SIDE_TYPE_ARRAY_BYTE:
742 case SIDE_TYPE_ARRAY:
743 break;
744 default:
745 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
746 abort();
747 break;
748 }
749 break;
750
751 case SIDE_TYPE_VLA:
752 switch (item->type) {
753 case SIDE_TYPE_VLA_U8:
754 case SIDE_TYPE_VLA_U16:
755 case SIDE_TYPE_VLA_U32:
756 case SIDE_TYPE_VLA_U64:
757 case SIDE_TYPE_VLA_S8:
758 case SIDE_TYPE_VLA_S16:
759 case SIDE_TYPE_VLA_S32:
760 case SIDE_TYPE_VLA_S64:
761 case SIDE_TYPE_VLA_BYTE:
762 case SIDE_TYPE_VLA_POINTER32:
763 case SIDE_TYPE_VLA_POINTER64:
764 case SIDE_TYPE_VLA:
765 break;
766 default:
767 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
768 abort();
769 break;
770 }
771 break;
772
773 case SIDE_TYPE_ENUM:
774 switch (item->type) {
775 case SIDE_TYPE_U8:
776 case SIDE_TYPE_U16:
777 case SIDE_TYPE_U32:
778 case SIDE_TYPE_U64:
779 case SIDE_TYPE_S8:
780 case SIDE_TYPE_S16:
781 case SIDE_TYPE_S32:
782 case SIDE_TYPE_S64:
783 break;
784 default:
785 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
786 abort();
787 break;
788 }
789 break;
790
791 case SIDE_TYPE_ENUM_BITMAP:
792 switch (item->type) {
793 case SIDE_TYPE_U8:
794 case SIDE_TYPE_BYTE:
795 case SIDE_TYPE_U16:
796 case SIDE_TYPE_U32:
797 case SIDE_TYPE_U64:
798 case SIDE_TYPE_ARRAY:
799 case SIDE_TYPE_VLA:
800 break;
801 default:
802 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
803 abort();
804 break;
805 }
806 break;
807
808 case SIDE_TYPE_DYNAMIC:
809 switch (item->type) {
810 case SIDE_TYPE_DYNAMIC_NULL:
811 case SIDE_TYPE_DYNAMIC_BOOL:
812 case SIDE_TYPE_DYNAMIC_U8:
813 case SIDE_TYPE_DYNAMIC_U16:
814 case SIDE_TYPE_DYNAMIC_U32:
815 case SIDE_TYPE_DYNAMIC_U64:
816 case SIDE_TYPE_DYNAMIC_S8:
817 case SIDE_TYPE_DYNAMIC_S16:
818 case SIDE_TYPE_DYNAMIC_S32:
819 case SIDE_TYPE_DYNAMIC_S64:
820 case SIDE_TYPE_DYNAMIC_BYTE:
821 case SIDE_TYPE_DYNAMIC_POINTER32:
822 case SIDE_TYPE_DYNAMIC_POINTER64:
823 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16:
824 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32:
825 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64:
826 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128:
827 case SIDE_TYPE_DYNAMIC_STRING:
828 case SIDE_TYPE_DYNAMIC_STRUCT:
829 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR:
830 case SIDE_TYPE_DYNAMIC_VLA:
831 case SIDE_TYPE_DYNAMIC_VLA_VISITOR:
832 break;
833 default:
834 fprintf(stderr, "ERROR: Unexpected dynamic type\n");
835 abort();
836 break;
837 }
838 break;
839
840 default:
841 if (type_desc->type != item->type) {
842 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
843 abort();
844 }
845 break;
846 }
847
848 if (type_desc->type == SIDE_TYPE_ENUM || type_desc->type == SIDE_TYPE_ENUM_BITMAP)
849 type = (enum side_type_label) type_desc->type;
850 else
851 type = (enum side_type_label) item->type;
852
853 printf("{ ");
854 switch (type) {
855 case SIDE_TYPE_NULL:
856 tracer_print_type_header(":", type_desc->u.side_null.attr, type_desc->u.side_null.nr_attr);
857 printf("<NULL TYPE>");
858 break;
859
860 case SIDE_TYPE_BOOL:
861 tracer_print_type_header(":", type_desc->u.side_bool.attr, type_desc->u.side_bool.nr_attr);
862 printf("%s", item->u.side_static.bool_value ? "true" : "false");
863 break;
864
865 case SIDE_TYPE_U8:
866 case SIDE_TYPE_U16:
867 case SIDE_TYPE_U32:
868 case SIDE_TYPE_U64:
869 case SIDE_TYPE_S8:
870 case SIDE_TYPE_S16:
871 case SIDE_TYPE_S32:
872 case SIDE_TYPE_S64:
873 tracer_print_type_integer(":", &type_desc->u.side_integer, &item->u.side_static.integer_value, 0,
874 TRACER_DISPLAY_BASE_10);
875 break;
876
877 case SIDE_TYPE_POINTER32:
878 case SIDE_TYPE_POINTER64:
879 tracer_print_type_integer(":", &type_desc->u.side_integer, &item->u.side_static.integer_value, 0,
880 TRACER_DISPLAY_BASE_16);
881 break;
882
883 case SIDE_TYPE_BYTE:
884 tracer_print_type_header(":", type_desc->u.side_byte.attr, type_desc->u.side_byte.nr_attr);
885 printf("0x%" PRIx8, item->u.side_static.byte_value);
886 break;
887
888 case SIDE_TYPE_ENUM:
889 print_enum(type_desc, item);
890 break;
891
892 case SIDE_TYPE_ENUM_BITMAP:
893 print_enum_bitmap(type_desc, item);
894 break;
895
896 case SIDE_TYPE_FLOAT_BINARY16:
897 case SIDE_TYPE_FLOAT_BINARY32:
898 case SIDE_TYPE_FLOAT_BINARY64:
899 case SIDE_TYPE_FLOAT_BINARY128:
900 tracer_print_type_float(":", &type_desc->u.side_float, &item->u.side_static.float_value);
901 break;
902
903 case SIDE_TYPE_STRING:
904 tracer_print_type_header(":", type_desc->u.side_string.attr, type_desc->u.side_string.nr_attr);
905 printf("\"%s\"", (const char *)(uintptr_t) item->u.side_static.string_value);
906 break;
907 case SIDE_TYPE_STRUCT:
908 tracer_print_struct(type_desc, item->u.side_static.side_struct);
909 break;
910 case SIDE_TYPE_GATHER_STRUCT:
911 (void) tracer_print_gather_struct(&type_desc->u.side_gather, item->u.side_static.side_struct_gather_ptr);
912 break;
913 case SIDE_TYPE_GATHER_ARRAY:
914 (void) tracer_print_gather_array(&type_desc->u.side_gather, item->u.side_static.side_array_gather_ptr);
915 break;
916 case SIDE_TYPE_GATHER_BYTE:
917 (void) tracer_print_gather_byte_type(&type_desc->u.side_gather, item->u.side_static.side_byte_gather_ptr);
918 break;
919 case SIDE_TYPE_GATHER_UNSIGNED_INT:
920 case SIDE_TYPE_GATHER_SIGNED_INT:
921 (void) tracer_print_gather_integer_type(&type_desc->u.side_gather, item->u.side_static.side_integer_gather_ptr);
922 break;
923 case SIDE_TYPE_GATHER_FLOAT:
924 (void) tracer_print_gather_float_type(&type_desc->u.side_gather, item->u.side_static.side_float_gather_ptr);
925 break;
926 case SIDE_TYPE_ARRAY:
927 tracer_print_array(type_desc, item->u.side_static.side_array);
928 break;
929 case SIDE_TYPE_VLA:
930 tracer_print_vla(type_desc, item->u.side_static.side_vla);
931 break;
932 case SIDE_TYPE_VLA_VISITOR:
933 tracer_print_vla_visitor(type_desc, item->u.side_static.side_vla_app_visitor_ctx);
934 break;
935 case SIDE_TYPE_ARRAY_U8:
936 case SIDE_TYPE_ARRAY_U16:
937 case SIDE_TYPE_ARRAY_U32:
938 case SIDE_TYPE_ARRAY_U64:
939 case SIDE_TYPE_ARRAY_S8:
940 case SIDE_TYPE_ARRAY_S16:
941 case SIDE_TYPE_ARRAY_S32:
942 case SIDE_TYPE_ARRAY_S64:
943 case SIDE_TYPE_ARRAY_BYTE:
944 case SIDE_TYPE_ARRAY_POINTER32:
945 case SIDE_TYPE_ARRAY_POINTER64:
946 tracer_print_array_fixint(type_desc, item);
947 break;
948 case SIDE_TYPE_VLA_U8:
949 case SIDE_TYPE_VLA_U16:
950 case SIDE_TYPE_VLA_U32:
951 case SIDE_TYPE_VLA_U64:
952 case SIDE_TYPE_VLA_S8:
953 case SIDE_TYPE_VLA_S16:
954 case SIDE_TYPE_VLA_S32:
955 case SIDE_TYPE_VLA_S64:
956 case SIDE_TYPE_VLA_BYTE:
957 case SIDE_TYPE_VLA_POINTER32:
958 case SIDE_TYPE_VLA_POINTER64:
959 tracer_print_vla_fixint(type_desc, item);
960 break;
961
962 /* Dynamic types */
963 case SIDE_TYPE_DYNAMIC_NULL:
964 case SIDE_TYPE_DYNAMIC_BOOL:
965 case SIDE_TYPE_DYNAMIC_U8:
966 case SIDE_TYPE_DYNAMIC_U16:
967 case SIDE_TYPE_DYNAMIC_U32:
968 case SIDE_TYPE_DYNAMIC_U64:
969 case SIDE_TYPE_DYNAMIC_S8:
970 case SIDE_TYPE_DYNAMIC_S16:
971 case SIDE_TYPE_DYNAMIC_S32:
972 case SIDE_TYPE_DYNAMIC_S64:
973 case SIDE_TYPE_DYNAMIC_BYTE:
974 case SIDE_TYPE_DYNAMIC_POINTER32:
975 case SIDE_TYPE_DYNAMIC_POINTER64:
976 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16:
977 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32:
978 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64:
979 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128:
980 case SIDE_TYPE_DYNAMIC_STRING:
981 case SIDE_TYPE_DYNAMIC_STRUCT:
982 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR:
983 case SIDE_TYPE_DYNAMIC_VLA:
984 case SIDE_TYPE_DYNAMIC_VLA_VISITOR:
985 tracer_print_dynamic(item);
986 break;
987 case SIDE_TYPE_GATHER_VLA:
988 fprintf(stderr, "<gather VLA only supported within gather structures>\n");
989 abort();
990 default:
991 fprintf(stderr, "<UNKNOWN TYPE>");
992 abort();
993 }
994 printf(" }");
995 }
996
997 static
998 void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg *item)
999 {
1000 printf("%s: ", item_desc->field_name);
1001 tracer_print_type(&item_desc->side_type, item);
1002 }
1003
1004 static
1005 void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec)
1006 {
1007 const struct side_arg *sav = side_arg_vec->sav;
1008 uint32_t i, side_sav_len = side_arg_vec->len;
1009
1010 if (type_desc->u.side_struct->nr_fields != side_sav_len) {
1011 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments of structure\n");
1012 abort();
1013 }
1014 print_attributes("attr", ":", type_desc->u.side_struct->attr, type_desc->u.side_struct->nr_attr);
1015 printf("%s", type_desc->u.side_struct->nr_attr ? ", " : "");
1016 printf("fields: { ");
1017 for (i = 0; i < side_sav_len; i++) {
1018 printf("%s", i ? ", " : "");
1019 tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]);
1020 }
1021 printf(" }");
1022 }
1023
1024 static
1025 void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec)
1026 {
1027 const struct side_arg *sav = side_arg_vec->sav;
1028 uint32_t i, side_sav_len = side_arg_vec->len;
1029
1030 if (type_desc->u.side_array.length != side_sav_len) {
1031 fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n");
1032 abort();
1033 }
1034 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
1035 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
1036 printf("elements: ");
1037 printf("[ ");
1038 for (i = 0; i < side_sav_len; i++) {
1039 printf("%s", i ? ", " : "");
1040 tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]);
1041 }
1042 printf(" ]");
1043 }
1044
1045 static
1046 void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec)
1047 {
1048 const struct side_arg *sav = side_arg_vec->sav;
1049 uint32_t i, side_sav_len = side_arg_vec->len;
1050
1051 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
1052 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
1053 printf("elements: ");
1054 printf("[ ");
1055 for (i = 0; i < side_sav_len; i++) {
1056 printf("%s", i ? ", " : "");
1057 tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]);
1058 }
1059 printf(" ]");
1060 }
1061
1062 static
1063 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode, const char *ptr)
1064 {
1065 switch (access_mode) {
1066 case SIDE_TYPE_GATHER_ACCESS_ADDRESS:
1067 return ptr;
1068 case SIDE_TYPE_GATHER_ACCESS_POINTER:
1069 /* Dereference pointer */
1070 memcpy(&ptr, ptr, sizeof(ptr));
1071 return ptr;
1072 default:
1073 abort();
1074 }
1075 }
1076
1077 static
1078 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode, uint32_t len)
1079 {
1080 switch (access_mode) {
1081 case SIDE_TYPE_GATHER_ACCESS_ADDRESS:
1082 return len;
1083 case SIDE_TYPE_GATHER_ACCESS_POINTER:
1084 return sizeof(void *);
1085 default:
1086 abort();
1087 }
1088 }
1089
1090 static
1091 uint64_t tracer_load_gather_integer_type(const struct side_type_gather *type_gather, const void *_ptr)
1092 {
1093 enum side_type_gather_access_mode access_mode = type_gather->u.side_integer.access_mode;
1094 uint32_t integer_size_bytes = type_gather->u.side_integer.type.integer_size_bits >> 3;
1095 const char *ptr = (const char *) _ptr;
1096 union side_integer_value value;
1097
1098 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_integer.offset);
1099 memcpy(&value, ptr, integer_size_bytes);
1100 switch (type_gather->u.side_integer.type.integer_size_bits) {
1101 case 8:
1102 return (uint64_t) value.side_u8;
1103 case 16:
1104 return (uint64_t) value.side_u16;
1105 case 32:
1106 return (uint64_t) value.side_u32;
1107 case 64:
1108 return (uint64_t) value.side_u64;
1109 default:
1110 abort();
1111 }
1112 }
1113
1114 static
1115 uint32_t tracer_print_gather_byte_type(const struct side_type_gather *type_gather, const void *_ptr)
1116 {
1117 enum side_type_gather_access_mode access_mode = type_gather->u.side_byte.access_mode;
1118 const char *ptr = (const char *) _ptr;
1119 uint8_t value;
1120
1121 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_byte.offset);
1122 memcpy(&value, ptr, 1);
1123 tracer_print_type_header(":", type_gather->u.side_byte.type.attr,
1124 type_gather->u.side_byte.type.nr_attr);
1125 printf("0x%" PRIx8, value);
1126 return tracer_gather_size(access_mode, 1);
1127 }
1128
1129 static
1130 uint32_t tracer_print_gather_integer_type(const struct side_type_gather *type_gather, const void *_ptr)
1131 {
1132 enum side_type_gather_access_mode access_mode = type_gather->u.side_integer.access_mode;
1133 uint32_t integer_size_bytes = type_gather->u.side_integer.type.integer_size_bits >> 3;
1134 const char *ptr = (const char *) _ptr;
1135 union side_integer_value value;
1136
1137 switch (type_gather->u.side_integer.type.integer_size_bits) {
1138 case 8:
1139 case 16:
1140 case 32:
1141 case 64:
1142 break;
1143 default:
1144 abort();
1145 }
1146 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_integer.offset);
1147 memcpy(&value, ptr, integer_size_bytes);
1148 tracer_print_type_integer(":", &type_gather->u.side_integer.type, &value,
1149 type_gather->u.side_integer.offset_bits, TRACER_DISPLAY_BASE_10);
1150 return tracer_gather_size(access_mode, integer_size_bytes);
1151 }
1152
1153 static
1154 uint32_t tracer_print_gather_float_type(const struct side_type_gather *type_gather, const void *_ptr)
1155 {
1156 enum side_type_gather_access_mode access_mode = type_gather->u.side_float.access_mode;
1157 uint32_t float_size_bytes = type_gather->u.side_float.type.float_size_bits >> 3;
1158 const char *ptr = (const char *) _ptr;
1159 union side_float_value value;
1160
1161 switch (type_gather->u.side_float.type.float_size_bits) {
1162 case 16:
1163 case 32:
1164 case 64:
1165 case 128:
1166 break;
1167 default:
1168 abort();
1169 }
1170 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_float.offset);
1171 memcpy(&value, ptr, float_size_bytes);
1172 tracer_print_type_float(":", &type_gather->u.side_float.type, &value);
1173 return tracer_gather_size(access_mode, float_size_bytes);
1174 }
1175
1176 static
1177 uint32_t tracer_print_gather_type(const struct side_type *type_desc, const void *ptr)
1178 {
1179 uint32_t len;
1180
1181 printf("{ ");
1182 switch (type_desc->type) {
1183 case SIDE_TYPE_GATHER_BYTE:
1184 len = tracer_print_gather_byte_type(&type_desc->u.side_gather, ptr);
1185 break;
1186 case SIDE_TYPE_GATHER_UNSIGNED_INT:
1187 case SIDE_TYPE_GATHER_SIGNED_INT:
1188 len = tracer_print_gather_integer_type(&type_desc->u.side_gather, ptr);
1189 break;
1190 case SIDE_TYPE_GATHER_FLOAT:
1191 len = tracer_print_gather_float_type(&type_desc->u.side_gather, ptr);
1192 break;
1193 case SIDE_TYPE_GATHER_STRUCT:
1194 len = tracer_print_gather_struct(&type_desc->u.side_gather, ptr);
1195 break;
1196 case SIDE_TYPE_GATHER_ARRAY:
1197 len = tracer_print_gather_array(&type_desc->u.side_gather, ptr);
1198 break;
1199 case SIDE_TYPE_GATHER_VLA:
1200 len = tracer_print_gather_vla(&type_desc->u.side_gather, ptr);
1201 break;
1202 default:
1203 fprintf(stderr, "<UNKNOWN GATHER TYPE>");
1204 abort();
1205 }
1206 printf(" }");
1207 return len;
1208 }
1209
1210 static
1211 void tracer_print_gather_field(const struct side_event_field *field, const void *ptr)
1212 {
1213 printf("%s: ", field->field_name);
1214 (void) tracer_print_gather_type(&field->side_type, ptr);
1215 }
1216
1217 static
1218 uint32_t tracer_print_gather_struct(const struct side_type_gather *type_gather, const void *_ptr)
1219 {
1220 enum side_type_gather_access_mode access_mode = type_gather->u.side_struct.access_mode;
1221 const char *ptr = (const char *) _ptr;
1222 uint32_t i;
1223
1224 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_struct.offset);
1225 print_attributes("attr", ":", type_gather->u.side_struct.type->attr, type_gather->u.side_struct.type->nr_attr);
1226 printf("%s", type_gather->u.side_struct.type->nr_attr ? ", " : "");
1227 printf("fields: { ");
1228 for (i = 0; i < type_gather->u.side_struct.type->nr_fields; i++) {
1229 printf("%s", i ? ", " : "");
1230 tracer_print_gather_field(&type_gather->u.side_struct.type->fields[i], ptr);
1231 }
1232 printf(" }");
1233 return tracer_gather_size(access_mode, type_gather->u.side_struct.size);
1234 }
1235
1236 static
1237 uint32_t tracer_print_gather_array(const struct side_type_gather *type_gather, const void *_ptr)
1238 {
1239 enum side_type_gather_access_mode access_mode = type_gather->u.side_array.access_mode;
1240 const char *ptr = (const char *) _ptr, *orig_ptr;
1241 uint32_t i;
1242
1243 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_array.offset);
1244 orig_ptr = ptr;
1245 print_attributes("attr", ":", type_gather->u.side_array.type.attr, type_gather->u.side_array.type.nr_attr);
1246 printf("%s", type_gather->u.side_array.type.nr_attr ? ", " : "");
1247 printf("elements: ");
1248 printf("[ ");
1249 for (i = 0; i < type_gather->u.side_array.type.length; i++) {
1250 switch (type_gather->u.side_array.type.elem_type->type) {
1251 case SIDE_TYPE_GATHER_VLA:
1252 fprintf(stderr, "<gather VLA only supported within gather structures>\n");
1253 abort();
1254 default:
1255 break;
1256 }
1257 printf("%s", i ? ", " : "");
1258 ptr += tracer_print_gather_type(type_gather->u.side_array.type.elem_type, ptr);
1259 }
1260 printf(" ]");
1261 return tracer_gather_size(access_mode, ptr - orig_ptr);
1262 }
1263
1264 static
1265 uint32_t tracer_print_gather_vla(const struct side_type_gather *type_gather, const void *_ptr)
1266 {
1267 enum side_type_gather_access_mode access_mode = type_gather->u.side_vla.access_mode;
1268 const char *ptr = (const char *) _ptr, *orig_ptr;
1269 uint32_t i, length;
1270
1271 /* Access length */
1272 switch (type_gather->u.side_vla.length_type->type) {
1273 case SIDE_TYPE_GATHER_UNSIGNED_INT:
1274 case SIDE_TYPE_GATHER_SIGNED_INT:
1275 break;
1276 default:
1277 fprintf(stderr, "<gather VLA expects integer gather length type>\n");
1278 abort();
1279 }
1280 length = (uint32_t) tracer_load_gather_integer_type(&type_gather->u.side_vla.length_type->u.side_gather, ptr);
1281 ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_vla.offset);
1282 orig_ptr = ptr;
1283 print_attributes("attr", ":", type_gather->u.side_vla.type.attr, type_gather->u.side_vla.type.nr_attr);
1284 printf("%s", type_gather->u.side_vla.type.nr_attr ? ", " : "");
1285 printf("elements: ");
1286 printf("[ ");
1287 for (i = 0; i < length; i++) {
1288 switch (type_gather->u.side_vla.type.elem_type->type) {
1289 case SIDE_TYPE_GATHER_VLA:
1290 fprintf(stderr, "<gather VLA only supported within gather structures>\n");
1291 abort();
1292 default:
1293 break;
1294 }
1295 printf("%s", i ? ", " : "");
1296 ptr += tracer_print_gather_type(type_gather->u.side_vla.type.elem_type, ptr);
1297 }
1298 printf(" ]");
1299 return tracer_gather_size(access_mode, ptr - orig_ptr);
1300 }
1301
1302 struct tracer_visitor_priv {
1303 const struct side_type *elem_type;
1304 int i;
1305 };
1306
1307 static
1308 enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx,
1309 const struct side_arg *elem)
1310 {
1311 struct tracer_visitor_priv *tracer_priv = (struct tracer_visitor_priv *) tracer_ctx->priv;
1312
1313 printf("%s", tracer_priv->i++ ? ", " : "");
1314 tracer_print_type(tracer_priv->elem_type, elem);
1315 return SIDE_VISITOR_STATUS_OK;
1316 }
1317
1318 static
1319 void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx)
1320 {
1321 enum side_visitor_status status;
1322 struct tracer_visitor_priv tracer_priv = {
1323 .elem_type = type_desc->u.side_vla_visitor.elem_type,
1324 .i = 0,
1325 };
1326 const struct side_tracer_visitor_ctx tracer_ctx = {
1327 .write_elem = tracer_write_elem_cb,
1328 .priv = &tracer_priv,
1329 };
1330
1331 print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr);
1332 printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : "");
1333 printf("elements: ");
1334 printf("[ ");
1335 status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx);
1336 switch (status) {
1337 case SIDE_VISITOR_STATUS_OK:
1338 break;
1339 case SIDE_VISITOR_STATUS_ERROR:
1340 fprintf(stderr, "ERROR: Visitor error\n");
1341 abort();
1342 }
1343 printf(" ]");
1344 }
1345
1346 void tracer_print_array_fixint(const struct side_type *type_desc, const struct side_arg *item)
1347 {
1348 const struct side_type *elem_type = type_desc->u.side_array.elem_type;
1349 uint32_t i, side_sav_len = type_desc->u.side_array.length;
1350 void *p = item->u.side_static.side_array_fixint;
1351 enum side_type_label side_type;
1352
1353 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
1354 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
1355 printf("elements: ");
1356 switch (item->type) {
1357 case SIDE_TYPE_ARRAY_U8:
1358 if (elem_type->type != SIDE_TYPE_U8)
1359 goto type_error;
1360 break;
1361 case SIDE_TYPE_ARRAY_U16:
1362 if (elem_type->type != SIDE_TYPE_U16)
1363 goto type_error;
1364 break;
1365 case SIDE_TYPE_ARRAY_U32:
1366 if (elem_type->type != SIDE_TYPE_U32)
1367 goto type_error;
1368 break;
1369 case SIDE_TYPE_ARRAY_U64:
1370 if (elem_type->type != SIDE_TYPE_U64)
1371 goto type_error;
1372 break;
1373 case SIDE_TYPE_ARRAY_S8:
1374 if (elem_type->type != SIDE_TYPE_S8)
1375 goto type_error;
1376 break;
1377 case SIDE_TYPE_ARRAY_S16:
1378 if (elem_type->type != SIDE_TYPE_S16)
1379 goto type_error;
1380 break;
1381 case SIDE_TYPE_ARRAY_S32:
1382 if (elem_type->type != SIDE_TYPE_S32)
1383 goto type_error;
1384 break;
1385 case SIDE_TYPE_ARRAY_S64:
1386 if (elem_type->type != SIDE_TYPE_S64)
1387 goto type_error;
1388 break;
1389 case SIDE_TYPE_ARRAY_BYTE:
1390 if (elem_type->type != SIDE_TYPE_BYTE)
1391 goto type_error;
1392 break;
1393 case SIDE_TYPE_ARRAY_POINTER32:
1394 if (elem_type->type != SIDE_TYPE_POINTER32)
1395 goto type_error;
1396 case SIDE_TYPE_ARRAY_POINTER64:
1397 if (elem_type->type != SIDE_TYPE_POINTER64)
1398 goto type_error;
1399 break;
1400 default:
1401 goto type_error;
1402 }
1403 side_type = (enum side_type_label) elem_type->type;
1404
1405 printf("[ ");
1406 for (i = 0; i < side_sav_len; i++) {
1407 struct side_arg sav_elem = {
1408 .type = side_type,
1409 };
1410
1411 switch (side_type) {
1412 case SIDE_TYPE_U8:
1413 sav_elem.u.side_static.integer_value.side_u8 = ((const uint8_t *) p)[i];
1414 break;
1415 case SIDE_TYPE_S8:
1416 sav_elem.u.side_static.integer_value.side_s8 = ((const int8_t *) p)[i];
1417 break;
1418 case SIDE_TYPE_U16:
1419 sav_elem.u.side_static.integer_value.side_u16 = ((const uint16_t *) p)[i];
1420 break;
1421 case SIDE_TYPE_S16:
1422 sav_elem.u.side_static.integer_value.side_s16 = ((const int16_t *) p)[i];
1423 break;
1424 case SIDE_TYPE_U32:
1425 sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i];
1426 break;
1427 case SIDE_TYPE_S32:
1428 sav_elem.u.side_static.integer_value.side_s32 = ((const int32_t *) p)[i];
1429 break;
1430 case SIDE_TYPE_U64:
1431 sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i];
1432 break;
1433 case SIDE_TYPE_S64:
1434 sav_elem.u.side_static.integer_value.side_s64 = ((const int64_t *) p)[i];
1435 break;
1436 case SIDE_TYPE_BYTE:
1437 sav_elem.u.side_static.byte_value = ((const uint8_t *) p)[i];
1438 break;
1439 case SIDE_TYPE_POINTER32:
1440 sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i];
1441 break;
1442 case SIDE_TYPE_POINTER64:
1443 sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i];
1444 break;
1445
1446 default:
1447 fprintf(stderr, "ERROR: Unexpected type\n");
1448 abort();
1449 }
1450
1451 printf("%s", i ? ", " : "");
1452 tracer_print_type(elem_type, &sav_elem);
1453 }
1454 printf(" ]");
1455 return;
1456
1457 type_error:
1458 fprintf(stderr, "ERROR: type mismatch\n");
1459 abort();
1460 }
1461
1462 void tracer_print_vla_fixint(const struct side_type *type_desc, const struct side_arg *item)
1463 {
1464 const struct side_type *elem_type = type_desc->u.side_vla.elem_type;
1465 uint32_t i, side_sav_len = item->u.side_static.side_vla_fixint.length;
1466 void *p = item->u.side_static.side_vla_fixint.p;
1467 enum side_type_label side_type;
1468
1469 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
1470 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
1471 printf("elements: ");
1472 switch (item->type) {
1473 case SIDE_TYPE_VLA_U8:
1474 if (elem_type->type != SIDE_TYPE_U8)
1475 goto type_error;
1476 break;
1477 case SIDE_TYPE_VLA_U16:
1478 if (elem_type->type != SIDE_TYPE_U16)
1479 goto type_error;
1480 break;
1481 case SIDE_TYPE_VLA_U32:
1482 if (elem_type->type != SIDE_TYPE_U32)
1483 goto type_error;
1484 break;
1485 case SIDE_TYPE_VLA_U64:
1486 if (elem_type->type != SIDE_TYPE_U64)
1487 goto type_error;
1488 break;
1489 case SIDE_TYPE_VLA_S8:
1490 if (elem_type->type != SIDE_TYPE_S8)
1491 goto type_error;
1492 break;
1493 case SIDE_TYPE_VLA_S16:
1494 if (elem_type->type != SIDE_TYPE_S16)
1495 goto type_error;
1496 break;
1497 case SIDE_TYPE_VLA_S32:
1498 if (elem_type->type != SIDE_TYPE_S32)
1499 goto type_error;
1500 break;
1501 case SIDE_TYPE_VLA_S64:
1502 if (elem_type->type != SIDE_TYPE_S64)
1503 goto type_error;
1504 break;
1505 case SIDE_TYPE_VLA_BYTE:
1506 if (elem_type->type != SIDE_TYPE_BYTE)
1507 goto type_error;
1508 break;
1509 case SIDE_TYPE_VLA_POINTER32:
1510 if (elem_type->type != SIDE_TYPE_POINTER32)
1511 goto type_error;
1512 case SIDE_TYPE_VLA_POINTER64:
1513 if (elem_type->type != SIDE_TYPE_POINTER64)
1514 goto type_error;
1515 break;
1516 default:
1517 goto type_error;
1518 }
1519 side_type = (enum side_type_label) elem_type->type;
1520
1521 printf("[ ");
1522 for (i = 0; i < side_sav_len; i++) {
1523 struct side_arg sav_elem = {
1524 .type = side_type,
1525 };
1526
1527 switch (side_type) {
1528 case SIDE_TYPE_U8:
1529 sav_elem.u.side_static.integer_value.side_u8 = ((const uint8_t *) p)[i];
1530 break;
1531 case SIDE_TYPE_S8:
1532 sav_elem.u.side_static.integer_value.side_s8 = ((const int8_t *) p)[i];
1533 break;
1534 case SIDE_TYPE_U16:
1535 sav_elem.u.side_static.integer_value.side_u16 = ((const uint16_t *) p)[i];
1536 break;
1537 case SIDE_TYPE_S16:
1538 sav_elem.u.side_static.integer_value.side_s16 = ((const int16_t *) p)[i];
1539 break;
1540 case SIDE_TYPE_U32:
1541 sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i];
1542 break;
1543 case SIDE_TYPE_S32:
1544 sav_elem.u.side_static.integer_value.side_s32 = ((const int32_t *) p)[i];
1545 break;
1546 case SIDE_TYPE_U64:
1547 sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i];
1548 break;
1549 case SIDE_TYPE_S64:
1550 sav_elem.u.side_static.integer_value.side_s64 = ((const int64_t *) p)[i];
1551 break;
1552 case SIDE_TYPE_BYTE:
1553 sav_elem.u.side_static.byte_value = ((const uint8_t *) p)[i];
1554 break;
1555 case SIDE_TYPE_POINTER32:
1556 sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i];
1557 break;
1558 case SIDE_TYPE_POINTER64:
1559 sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i];
1560 break;
1561
1562 default:
1563 fprintf(stderr, "ERROR: Unexpected type\n");
1564 abort();
1565 }
1566
1567 printf("%s", i ? ", " : "");
1568 tracer_print_type(elem_type, &sav_elem);
1569 }
1570 printf(" ]");
1571 return;
1572
1573 type_error:
1574 fprintf(stderr, "ERROR: type mismatch\n");
1575 abort();
1576 }
1577
1578 static
1579 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct *dynamic_struct)
1580 {
1581 const struct side_arg_dynamic_field *fields = dynamic_struct->fields;
1582 uint32_t i, len = dynamic_struct->len;
1583
1584 print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr);
1585 printf("%s", dynamic_struct->nr_attr ? ", " : "");
1586 printf("fields:: ");
1587 printf("[ ");
1588 for (i = 0; i < len; i++) {
1589 printf("%s", i ? ", " : "");
1590 printf("%s:: ", fields[i].field_name);
1591 tracer_print_dynamic(&fields[i].elem);
1592 }
1593 printf(" ]");
1594 }
1595
1596 struct tracer_dynamic_struct_visitor_priv {
1597 int i;
1598 };
1599
1600 static
1601 enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
1602 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
1603 const struct side_arg_dynamic_field *dynamic_field)
1604 {
1605 struct tracer_dynamic_struct_visitor_priv *tracer_priv =
1606 (struct tracer_dynamic_struct_visitor_priv *) tracer_ctx->priv;
1607
1608 printf("%s", tracer_priv->i++ ? ", " : "");
1609 printf("%s:: ", dynamic_field->field_name);
1610 tracer_print_dynamic(&dynamic_field->elem);
1611 return SIDE_VISITOR_STATUS_OK;
1612 }
1613
1614 static
1615 void tracer_print_dynamic_struct_visitor(const struct side_arg *item)
1616 {
1617 enum side_visitor_status status;
1618 struct tracer_dynamic_struct_visitor_priv tracer_priv = {
1619 .i = 0,
1620 };
1621 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = {
1622 .write_field = tracer_dynamic_struct_write_elem_cb,
1623 .priv = &tracer_priv,
1624 };
1625 void *app_ctx = item->u.side_dynamic.side_dynamic_struct_visitor.app_ctx;
1626
1627 print_attributes("attr", "::", item->u.side_dynamic.side_dynamic_struct_visitor.attr, item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr);
1628 printf("%s", item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr ? ", " : "");
1629 printf("fields:: ");
1630 printf("[ ");
1631 status = item->u.side_dynamic.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx);
1632 switch (status) {
1633 case SIDE_VISITOR_STATUS_OK:
1634 break;
1635 case SIDE_VISITOR_STATUS_ERROR:
1636 fprintf(stderr, "ERROR: Visitor error\n");
1637 abort();
1638 }
1639 printf(" ]");
1640 }
1641
1642 static
1643 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla *vla)
1644 {
1645 const struct side_arg *sav = vla->sav;
1646 uint32_t i, side_sav_len = vla->len;
1647
1648 print_attributes("attr", "::", vla->attr, vla->nr_attr);
1649 printf("%s", vla->nr_attr ? ", " : "");
1650 printf("elements:: ");
1651 printf("[ ");
1652 for (i = 0; i < side_sav_len; i++) {
1653 printf("%s", i ? ", " : "");
1654 tracer_print_dynamic(&sav[i]);
1655 }
1656 printf(" ]");
1657 }
1658
1659 struct tracer_dynamic_vla_visitor_priv {
1660 int i;
1661 };
1662
1663 static
1664 enum side_visitor_status tracer_dynamic_vla_write_elem_cb(
1665 const struct side_tracer_visitor_ctx *tracer_ctx,
1666 const struct side_arg *elem)
1667 {
1668 struct tracer_dynamic_vla_visitor_priv *tracer_priv =
1669 (struct tracer_dynamic_vla_visitor_priv *) tracer_ctx->priv;
1670
1671 printf("%s", tracer_priv->i++ ? ", " : "");
1672 tracer_print_dynamic(elem);
1673 return SIDE_VISITOR_STATUS_OK;
1674 }
1675
1676 static
1677 void tracer_print_dynamic_vla_visitor(const struct side_arg *item)
1678 {
1679 enum side_visitor_status status;
1680 struct tracer_dynamic_vla_visitor_priv tracer_priv = {
1681 .i = 0,
1682 };
1683 const struct side_tracer_visitor_ctx tracer_ctx = {
1684 .write_elem = tracer_dynamic_vla_write_elem_cb,
1685 .priv = &tracer_priv,
1686 };
1687 void *app_ctx = item->u.side_dynamic.side_dynamic_vla_visitor.app_ctx;
1688
1689 print_attributes("attr", "::", item->u.side_dynamic.side_dynamic_vla_visitor.attr, item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr);
1690 printf("%s", item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr ? ", " : "");
1691 printf("elements:: ");
1692 printf("[ ");
1693 status = item->u.side_dynamic.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx);
1694 switch (status) {
1695 case SIDE_VISITOR_STATUS_OK:
1696 break;
1697 case SIDE_VISITOR_STATUS_ERROR:
1698 fprintf(stderr, "ERROR: Visitor error\n");
1699 abort();
1700 }
1701 printf(" ]");
1702 }
1703
1704 static
1705 void tracer_print_dynamic(const struct side_arg *item)
1706 {
1707 printf("{ ");
1708 switch (item->type) {
1709 case SIDE_TYPE_DYNAMIC_NULL:
1710 tracer_print_type_header("::", item->u.side_dynamic.side_null.attr, item->u.side_dynamic.side_null.nr_attr);
1711 printf("<NULL TYPE>");
1712 break;
1713 case SIDE_TYPE_DYNAMIC_BOOL:
1714 tracer_print_type_header("::", item->u.side_dynamic.side_bool.type.attr, item->u.side_dynamic.side_bool.type.nr_attr);
1715 printf("%s", item->u.side_dynamic.side_bool.value ? "true" : "false");
1716 break;
1717 case SIDE_TYPE_DYNAMIC_U8:
1718 case SIDE_TYPE_DYNAMIC_U16:
1719 case SIDE_TYPE_DYNAMIC_U32:
1720 case SIDE_TYPE_DYNAMIC_U64:
1721 case SIDE_TYPE_DYNAMIC_S8:
1722 case SIDE_TYPE_DYNAMIC_S16:
1723 case SIDE_TYPE_DYNAMIC_S32:
1724 case SIDE_TYPE_DYNAMIC_S64:
1725 tracer_print_type_integer("::", &item->u.side_dynamic.side_integer.type, &item->u.side_dynamic.side_integer.value, 0,
1726 TRACER_DISPLAY_BASE_10);
1727 break;
1728 case SIDE_TYPE_DYNAMIC_BYTE:
1729 tracer_print_type_header("::", item->u.side_dynamic.side_byte.type.attr, item->u.side_dynamic.side_byte.type.nr_attr);
1730 printf("0x%" PRIx8, item->u.side_dynamic.side_byte.value);
1731 break;
1732
1733 case SIDE_TYPE_DYNAMIC_POINTER32:
1734 case SIDE_TYPE_DYNAMIC_POINTER64:
1735 tracer_print_type_integer("::", &item->u.side_dynamic.side_integer.type, &item->u.side_dynamic.side_integer.value, 0,
1736 TRACER_DISPLAY_BASE_16);
1737 break;
1738
1739 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16:
1740 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32:
1741 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64:
1742 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128:
1743 tracer_print_type_float("::", &item->u.side_dynamic.side_float.type,
1744 &item->u.side_dynamic.side_float.value);
1745 break;
1746
1747 case SIDE_TYPE_DYNAMIC_STRING:
1748 tracer_print_type_header("::", item->u.side_dynamic.side_string.type.attr, item->u.side_dynamic.side_string.type.nr_attr);
1749 printf("\"%s\"", (const char *)(uintptr_t) item->u.side_dynamic.side_string.value);
1750 break;
1751 case SIDE_TYPE_DYNAMIC_STRUCT:
1752 tracer_print_dynamic_struct(item->u.side_dynamic.side_dynamic_struct);
1753 break;
1754 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR:
1755 tracer_print_dynamic_struct_visitor(item);
1756 break;
1757 case SIDE_TYPE_DYNAMIC_VLA:
1758 tracer_print_dynamic_vla(item->u.side_dynamic.side_dynamic_vla);
1759 break;
1760 case SIDE_TYPE_DYNAMIC_VLA_VISITOR:
1761 tracer_print_dynamic_vla_visitor(item);
1762 break;
1763 default:
1764 fprintf(stderr, "<UNKNOWN TYPE>");
1765 abort();
1766 }
1767 printf(" }");
1768 }
1769
1770 static
1771 void tracer_print_static_fields(const struct side_event_description *desc,
1772 const struct side_arg_vec *side_arg_vec,
1773 uint32_t *nr_items)
1774 {
1775 const struct side_arg *sav = side_arg_vec->sav;
1776 uint32_t i, side_sav_len = side_arg_vec->len;
1777
1778 printf("provider: %s, event: %s", desc->provider_name, desc->event_name);
1779 if (desc->nr_fields != side_sav_len) {
1780 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n");
1781 abort();
1782 }
1783 print_attributes(", attr", ":", desc->attr, desc->nr_attr);
1784 printf("%s", side_sav_len ? ", fields: [ " : "");
1785 for (i = 0; i < side_sav_len; i++) {
1786 printf("%s", i ? ", " : "");
1787 tracer_print_field(&desc->fields[i], &sav[i]);
1788 }
1789 if (nr_items)
1790 *nr_items = i;
1791 if (side_sav_len)
1792 printf(" ]");
1793 }
1794
1795 void tracer_call(const struct side_event_description *desc,
1796 const struct side_arg_vec *side_arg_vec,
1797 void *priv __attribute__((unused)))
1798 {
1799 uint32_t nr_fields = 0;
1800
1801 tracer_print_static_fields(desc, side_arg_vec, &nr_fields);
1802 printf("\n");
1803 }
1804
1805 void tracer_call_variadic(const struct side_event_description *desc,
1806 const struct side_arg_vec *side_arg_vec,
1807 const struct side_arg_dynamic_struct *var_struct,
1808 void *priv __attribute__((unused)))
1809 {
1810 uint32_t nr_fields = 0, i, var_struct_len = var_struct->len;
1811
1812 tracer_print_static_fields(desc, side_arg_vec, &nr_fields);
1813
1814 if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) {
1815 fprintf(stderr, "ERROR: unexpected non-variadic event description\n");
1816 abort();
1817 }
1818 print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr);
1819 printf("%s", var_struct_len ? ", fields:: [ " : "");
1820 for (i = 0; i < var_struct_len; i++, nr_fields++) {
1821 printf("%s", i ? ", " : "");
1822 printf("%s:: ", var_struct->fields[i].field_name);
1823 tracer_print_dynamic(&var_struct->fields[i].elem);
1824 }
1825 if (i)
1826 printf(" ]");
1827 printf("\n");
1828 }
1829
1830 void tracer_event_notification(enum side_tracer_notification notif,
1831 struct side_event_description **events, uint32_t nr_events, void *priv)
1832 {
1833 uint32_t i;
1834 int ret;
1835
1836 printf("----------------------------------------------------------\n");
1837 printf("Tracer notified of events %s\n",
1838 notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS ? "inserted" : "removed");
1839 for (i = 0; i < nr_events; i++) {
1840 struct side_event_description *event = events[i];
1841
1842 /* Skip NULL pointers */
1843 if (!event)
1844 continue;
1845 printf("provider: %s, event: %s\n",
1846 event->provider_name, event->event_name);
1847 if (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) {
1848 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
1849 ret = side_tracer_callback_variadic_register(event, tracer_call_variadic, NULL);
1850 if (ret)
1851 abort();
1852 } else {
1853 ret = side_tracer_callback_register(event, tracer_call, NULL);
1854 if (ret)
1855 abort();
1856 }
1857 } else {
1858 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
1859 ret = side_tracer_callback_variadic_unregister(event, tracer_call_variadic, NULL);
1860 if (ret)
1861 abort();
1862 } else {
1863 ret = side_tracer_callback_unregister(event, tracer_call, NULL);
1864 if (ret)
1865 abort();
1866 }
1867 }
1868 }
1869 printf("----------------------------------------------------------\n");
1870 }
1871
1872 static __attribute__((constructor))
1873 void tracer_init(void);
1874 static
1875 void tracer_init(void)
1876 {
1877 tracer_handle = side_tracer_event_notification_register(tracer_event_notification, NULL);
1878 if (!tracer_handle)
1879 abort();
1880 }
1881
1882 static __attribute__((destructor))
1883 void tracer_exit(void);
1884 static
1885 void tracer_exit(void)
1886 {
1887 side_tracer_event_notification_unregister(tracer_handle);
1888 }
This page took 0.153295 seconds and 5 git commands to generate.