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