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