scatter-gather integer: sign-extend signed types
[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 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 8)
1118 abort();
1119 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1120 v >>= sg_type->u.side_basic.offset_bits;
1121 if (sg_type->u.side_basic.len_bits < 8)
1122 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1123 switch (base) {
1124 case TRACER_DISPLAY_BASE_2:
1125 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1126 break;
1127 case TRACER_DISPLAY_BASE_8:
1128 printf("0%" PRIo8, v);
1129 break;
1130 case TRACER_DISPLAY_BASE_10:
1131 printf("%" PRIu8, v);
1132 break;
1133 case TRACER_DISPLAY_BASE_16:
1134 printf("0x%" PRIx8, v);
1135 break;
1136 default:
1137 abort();
1138 }
1139 break;
1140 }
1141 case 16:
1142 {
1143 uint16_t v;
1144
1145 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 16)
1146 abort();
1147 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1148 if (sg_type_to_host_reverse_bo(sg_type))
1149 v = side_bswap_16(v);
1150 v >>= sg_type->u.side_basic.offset_bits;
1151 if (sg_type->u.side_basic.len_bits < 16)
1152 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1153 switch (base) {
1154 case TRACER_DISPLAY_BASE_2:
1155 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1156 break;
1157 case TRACER_DISPLAY_BASE_8:
1158 printf("0%" PRIo16, v);
1159 break;
1160 case TRACER_DISPLAY_BASE_10:
1161 printf("%" PRIu16, v);
1162 break;
1163 case TRACER_DISPLAY_BASE_16:
1164 printf("0x%" PRIx16, v);
1165 break;
1166 default:
1167 abort();
1168 }
1169 break;
1170 }
1171 case 32:
1172 {
1173 uint32_t v;
1174
1175 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 32)
1176 abort();
1177 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1178 if (sg_type_to_host_reverse_bo(sg_type))
1179 v = side_bswap_32(v);
1180 v >>= sg_type->u.side_basic.offset_bits;
1181 if (sg_type->u.side_basic.len_bits < 32)
1182 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1183 switch (base) {
1184 case TRACER_DISPLAY_BASE_2:
1185 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1186 break;
1187 case TRACER_DISPLAY_BASE_8:
1188 printf("0%" PRIo32, v);
1189 break;
1190 case TRACER_DISPLAY_BASE_10:
1191 printf("%" PRIu32, v);
1192 break;
1193 case TRACER_DISPLAY_BASE_16:
1194 printf("0x%" PRIx32, v);
1195 break;
1196 default:
1197 abort();
1198 }
1199 break;
1200 }
1201 case 64:
1202 {
1203 uint64_t v;
1204
1205 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 64)
1206 abort();
1207 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1208 if (sg_type_to_host_reverse_bo(sg_type))
1209 v = side_bswap_64(v);
1210 v >>= sg_type->u.side_basic.offset_bits;
1211 if (sg_type->u.side_basic.len_bits < 64)
1212 v &= (1ULL << sg_type->u.side_basic.len_bits) - 1;
1213 switch (base) {
1214 case TRACER_DISPLAY_BASE_2:
1215 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1216 break;
1217 case TRACER_DISPLAY_BASE_8:
1218 printf("0%" PRIo64, v);
1219 break;
1220 case TRACER_DISPLAY_BASE_10:
1221 printf("%" PRIu64, v);
1222 break;
1223 case TRACER_DISPLAY_BASE_16:
1224 printf("0x%" PRIx64, v);
1225 break;
1226 default:
1227 abort();
1228 }
1229 break;
1230 }
1231 default:
1232 fprintf(stderr, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1233 abort();
1234 }
1235 break;
1236 }
1237 case SIDE_TYPE_SG_SIGNED_INT:
1238 {
1239 tracer_print_sg_integer_type_header(sg_type);
1240 switch (sg_type->u.side_basic.integer_size_bits) {
1241 case 8:
1242 {
1243 int8_t v;
1244
1245 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 8)
1246 abort();
1247 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1248 v >>= sg_type->u.side_basic.offset_bits;
1249 if (sg_type->u.side_basic.len_bits < 8)
1250 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1251 switch (base) {
1252 case TRACER_DISPLAY_BASE_2:
1253 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1254 break;
1255 case TRACER_DISPLAY_BASE_8:
1256 printf("0%" PRIo8, v);
1257 break;
1258 case TRACER_DISPLAY_BASE_10:
1259 /* Sign-extend. */
1260 if (sg_type->u.side_basic.len_bits < 8) {
1261 if (v & (1U << (sg_type->u.side_basic.len_bits - 1)))
1262 v |= ~((1U << sg_type->u.side_basic.len_bits) - 1);
1263 }
1264 printf("%" PRId8, v);
1265 break;
1266 case TRACER_DISPLAY_BASE_16:
1267 printf("0x%" PRIx8, v);
1268 break;
1269 default:
1270 abort();
1271 }
1272 break;
1273 }
1274 case 16:
1275 {
1276 int16_t v;
1277
1278 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 16)
1279 abort();
1280 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1281 if (sg_type_to_host_reverse_bo(sg_type))
1282 v = side_bswap_16(v);
1283 v >>= sg_type->u.side_basic.offset_bits;
1284 if (sg_type->u.side_basic.len_bits < 16)
1285 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1286 switch (base) {
1287 case TRACER_DISPLAY_BASE_2:
1288 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1289 break;
1290 case TRACER_DISPLAY_BASE_8:
1291 printf("0%" PRIo16, v);
1292 break;
1293 case TRACER_DISPLAY_BASE_10:
1294 /* Sign-extend. */
1295 if (sg_type->u.side_basic.len_bits < 16) {
1296 if (v & (1U << (sg_type->u.side_basic.len_bits - 1)))
1297 v |= ~((1U << sg_type->u.side_basic.len_bits) - 1);
1298 }
1299 printf("%" PRId16, v);
1300 break;
1301 case TRACER_DISPLAY_BASE_16:
1302 printf("0x%" PRIx16, v);
1303 break;
1304 default:
1305 abort();
1306 }
1307 break;
1308 }
1309 case 32:
1310 {
1311 uint32_t v;
1312
1313 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 32)
1314 abort();
1315 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1316 if (sg_type_to_host_reverse_bo(sg_type))
1317 v = side_bswap_32(v);
1318 v >>= sg_type->u.side_basic.offset_bits;
1319 if (sg_type->u.side_basic.len_bits < 32)
1320 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1321 switch (base) {
1322 case TRACER_DISPLAY_BASE_2:
1323 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1324 break;
1325 case TRACER_DISPLAY_BASE_8:
1326 printf("0%" PRIo32, v);
1327 break;
1328 case TRACER_DISPLAY_BASE_10:
1329 /* Sign-extend. */
1330 if (sg_type->u.side_basic.len_bits < 32) {
1331 if (v & (1U << (sg_type->u.side_basic.len_bits - 1)))
1332 v |= ~((1U << sg_type->u.side_basic.len_bits) - 1);
1333 }
1334 printf("%" PRId32, v);
1335 break;
1336 case TRACER_DISPLAY_BASE_16:
1337 printf("0x%" PRIx32, v);
1338 break;
1339 default:
1340 abort();
1341 }
1342 break;
1343 }
1344 case 64:
1345 {
1346 uint64_t v;
1347
1348 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 64)
1349 abort();
1350 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1351 if (sg_type_to_host_reverse_bo(sg_type))
1352 v = side_bswap_64(v);
1353 v >>= sg_type->u.side_basic.offset_bits;
1354 if (sg_type->u.side_basic.len_bits < 64)
1355 v &= (1ULL << sg_type->u.side_basic.len_bits) - 1;
1356 switch (base) {
1357 case TRACER_DISPLAY_BASE_2:
1358 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1359 break;
1360 case TRACER_DISPLAY_BASE_8:
1361 printf("0%" PRIo64, v);
1362 break;
1363 case TRACER_DISPLAY_BASE_10:
1364 /* Sign-extend. */
1365 if (sg_type->u.side_basic.len_bits < 64) {
1366 if (v & (1ULL << (sg_type->u.side_basic.len_bits - 1)))
1367 v |= ~((1ULL << sg_type->u.side_basic.len_bits) - 1);
1368 }
1369 printf("%" PRId64, v);
1370 break;
1371 case TRACER_DISPLAY_BASE_16:
1372 printf("0x%" PRIx64, v);
1373 break;
1374 default:
1375 abort();
1376 }
1377 break;
1378 }
1379 default:
1380 fprintf(stderr, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1381 abort();
1382 }
1383 break;
1384 }
1385 default:
1386 fprintf(stderr, "<UNKNOWN SCATTER-GATHER TYPE>");
1387 abort();
1388 }
1389 printf(" }");
1390 }
1391
1392 static
1393 void tracer_print_sg_field(const struct side_struct_field_sg *field_sg, void *ptr)
1394 {
1395 printf("%s: ", field_sg->field_name);
1396 tracer_print_sg_type(&field_sg->side_type, ptr);
1397 }
1398
1399 static
1400 void tracer_print_struct_sg(const struct side_type_description *type_desc, void *ptr)
1401 {
1402 const struct side_type_struct_sg *struct_sg = type_desc->u.side_struct_sg;
1403 int i;
1404
1405 print_attributes("attr", ":", struct_sg->attr, struct_sg->nr_attr);
1406 printf("%s", struct_sg->nr_attr ? ", " : "");
1407 printf("fields: { ");
1408 for (i = 0; i < struct_sg->nr_fields; i++) {
1409 printf("%s", i ? ", " : "");
1410 tracer_print_sg_field(&struct_sg->fields_sg[i], ptr);
1411 }
1412 printf(" }");
1413 }
1414
1415 static
1416 void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
1417 {
1418 const struct side_arg_vec *sav = sav_desc->sav;
1419 uint32_t side_sav_len = sav_desc->len;
1420 int i;
1421
1422 if (type_desc->u.side_array.length != side_sav_len) {
1423 fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n");
1424 abort();
1425 }
1426 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
1427 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
1428 printf("elements: ");
1429 printf("[ ");
1430 for (i = 0; i < side_sav_len; i++) {
1431 printf("%s", i ? ", " : "");
1432 tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]);
1433 }
1434 printf(" ]");
1435 }
1436
1437 static
1438 void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
1439 {
1440 const struct side_arg_vec *sav = sav_desc->sav;
1441 uint32_t side_sav_len = sav_desc->len;
1442 int i;
1443
1444 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
1445 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
1446 printf("elements: ");
1447 printf("[ ");
1448 for (i = 0; i < side_sav_len; i++) {
1449 printf("%s", i ? ", " : "");
1450 tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]);
1451 }
1452 printf(" ]");
1453 }
1454
1455 struct tracer_visitor_priv {
1456 const struct side_type_description *elem_type;
1457 int i;
1458 };
1459
1460 static
1461 enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx,
1462 const struct side_arg_vec *elem)
1463 {
1464 struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv;
1465
1466 printf("%s", tracer_priv->i++ ? ", " : "");
1467 tracer_print_type(tracer_priv->elem_type, elem);
1468 return SIDE_VISITOR_STATUS_OK;
1469 }
1470
1471 static
1472 void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx)
1473 {
1474 enum side_visitor_status status;
1475 struct tracer_visitor_priv tracer_priv = {
1476 .elem_type = type_desc->u.side_vla_visitor.elem_type,
1477 .i = 0,
1478 };
1479 const struct side_tracer_visitor_ctx tracer_ctx = {
1480 .write_elem = tracer_write_elem_cb,
1481 .priv = &tracer_priv,
1482 };
1483
1484 print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr);
1485 printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : "");
1486 printf("elements: ");
1487 printf("[ ");
1488 status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx);
1489 switch (status) {
1490 case SIDE_VISITOR_STATUS_OK:
1491 break;
1492 case SIDE_VISITOR_STATUS_ERROR:
1493 fprintf(stderr, "ERROR: Visitor error\n");
1494 abort();
1495 }
1496 printf(" ]");
1497 }
1498
1499 void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
1500 {
1501 const struct side_type_description *elem_type = type_desc->u.side_array.elem_type;
1502 uint32_t side_sav_len = type_desc->u.side_array.length;
1503 void *p = item->u.side_array_fixint;
1504 enum side_type side_type;
1505 int i;
1506
1507 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
1508 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
1509 printf("elements: ");
1510 switch (item->type) {
1511 case SIDE_TYPE_ARRAY_U8:
1512 if (elem_type->type != SIDE_TYPE_U8)
1513 goto type_error;
1514 break;
1515 case SIDE_TYPE_ARRAY_U16:
1516 if (elem_type->type != SIDE_TYPE_U16)
1517 goto type_error;
1518 break;
1519 case SIDE_TYPE_ARRAY_U32:
1520 if (elem_type->type != SIDE_TYPE_U32)
1521 goto type_error;
1522 break;
1523 case SIDE_TYPE_ARRAY_U64:
1524 if (elem_type->type != SIDE_TYPE_U64)
1525 goto type_error;
1526 break;
1527 case SIDE_TYPE_ARRAY_S8:
1528 if (elem_type->type != SIDE_TYPE_S8)
1529 goto type_error;
1530 break;
1531 case SIDE_TYPE_ARRAY_S16:
1532 if (elem_type->type != SIDE_TYPE_S16)
1533 goto type_error;
1534 break;
1535 case SIDE_TYPE_ARRAY_S32:
1536 if (elem_type->type != SIDE_TYPE_S32)
1537 goto type_error;
1538 break;
1539 case SIDE_TYPE_ARRAY_S64:
1540 if (elem_type->type != SIDE_TYPE_S64)
1541 goto type_error;
1542 break;
1543 case SIDE_TYPE_ARRAY_BYTE:
1544 if (elem_type->type != SIDE_TYPE_BYTE)
1545 goto type_error;
1546 break;
1547 case SIDE_TYPE_ARRAY_POINTER32:
1548 if (elem_type->type != SIDE_TYPE_POINTER32)
1549 goto type_error;
1550 case SIDE_TYPE_ARRAY_POINTER64:
1551 if (elem_type->type != SIDE_TYPE_POINTER64)
1552 goto type_error;
1553 break;
1554 default:
1555 goto type_error;
1556 }
1557 side_type = elem_type->type;
1558
1559 printf("[ ");
1560 for (i = 0; i < side_sav_len; i++) {
1561 struct side_arg_vec sav_elem = {
1562 .type = side_type,
1563 };
1564
1565 switch (side_type) {
1566 case SIDE_TYPE_U8:
1567 sav_elem.u.side_u8 = ((const uint8_t *) p)[i];
1568 break;
1569 case SIDE_TYPE_S8:
1570 sav_elem.u.side_s8 = ((const int8_t *) p)[i];
1571 break;
1572 case SIDE_TYPE_U16:
1573 sav_elem.u.side_u16 = ((const uint16_t *) p)[i];
1574 break;
1575 case SIDE_TYPE_S16:
1576 sav_elem.u.side_s16 = ((const int16_t *) p)[i];
1577 break;
1578 case SIDE_TYPE_U32:
1579 sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
1580 break;
1581 case SIDE_TYPE_S32:
1582 sav_elem.u.side_s32 = ((const int32_t *) p)[i];
1583 break;
1584 case SIDE_TYPE_U64:
1585 sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
1586 break;
1587 case SIDE_TYPE_S64:
1588 sav_elem.u.side_s64 = ((const int64_t *) p)[i];
1589 break;
1590 case SIDE_TYPE_BYTE:
1591 sav_elem.u.side_byte = ((const uint8_t *) p)[i];
1592 break;
1593 case SIDE_TYPE_POINTER32:
1594 sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
1595 break;
1596 case SIDE_TYPE_POINTER64:
1597 sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
1598 break;
1599
1600 default:
1601 fprintf(stderr, "ERROR: Unexpected type\n");
1602 abort();
1603 }
1604
1605 printf("%s", i ? ", " : "");
1606 tracer_print_type(elem_type, &sav_elem);
1607 }
1608 printf(" ]");
1609 return;
1610
1611 type_error:
1612 fprintf(stderr, "ERROR: type mismatch\n");
1613 abort();
1614 }
1615
1616 void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
1617 {
1618 const struct side_type_description *elem_type = type_desc->u.side_vla.elem_type;
1619 uint32_t side_sav_len = item->u.side_vla_fixint.length;
1620 void *p = item->u.side_vla_fixint.p;
1621 enum side_type side_type;
1622 int i;
1623
1624 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
1625 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
1626 printf("elements: ");
1627 switch (item->type) {
1628 case SIDE_TYPE_VLA_U8:
1629 if (elem_type->type != SIDE_TYPE_U8)
1630 goto type_error;
1631 break;
1632 case SIDE_TYPE_VLA_U16:
1633 if (elem_type->type != SIDE_TYPE_U16)
1634 goto type_error;
1635 break;
1636 case SIDE_TYPE_VLA_U32:
1637 if (elem_type->type != SIDE_TYPE_U32)
1638 goto type_error;
1639 break;
1640 case SIDE_TYPE_VLA_U64:
1641 if (elem_type->type != SIDE_TYPE_U64)
1642 goto type_error;
1643 break;
1644 case SIDE_TYPE_VLA_S8:
1645 if (elem_type->type != SIDE_TYPE_S8)
1646 goto type_error;
1647 break;
1648 case SIDE_TYPE_VLA_S16:
1649 if (elem_type->type != SIDE_TYPE_S16)
1650 goto type_error;
1651 break;
1652 case SIDE_TYPE_VLA_S32:
1653 if (elem_type->type != SIDE_TYPE_S32)
1654 goto type_error;
1655 break;
1656 case SIDE_TYPE_VLA_S64:
1657 if (elem_type->type != SIDE_TYPE_S64)
1658 goto type_error;
1659 break;
1660 case SIDE_TYPE_VLA_BYTE:
1661 if (elem_type->type != SIDE_TYPE_BYTE)
1662 goto type_error;
1663 break;
1664 case SIDE_TYPE_VLA_POINTER32:
1665 if (elem_type->type != SIDE_TYPE_POINTER32)
1666 goto type_error;
1667 case SIDE_TYPE_VLA_POINTER64:
1668 if (elem_type->type != SIDE_TYPE_POINTER64)
1669 goto type_error;
1670 break;
1671 default:
1672 goto type_error;
1673 }
1674 side_type = elem_type->type;
1675
1676 printf("[ ");
1677 for (i = 0; i < side_sav_len; i++) {
1678 struct side_arg_vec sav_elem = {
1679 .type = side_type,
1680 };
1681
1682 switch (side_type) {
1683 case SIDE_TYPE_U8:
1684 sav_elem.u.side_u8 = ((const uint8_t *) p)[i];
1685 break;
1686 case SIDE_TYPE_S8:
1687 sav_elem.u.side_s8 = ((const int8_t *) p)[i];
1688 break;
1689 case SIDE_TYPE_U16:
1690 sav_elem.u.side_u16 = ((const uint16_t *) p)[i];
1691 break;
1692 case SIDE_TYPE_S16:
1693 sav_elem.u.side_s16 = ((const int16_t *) p)[i];
1694 break;
1695 case SIDE_TYPE_U32:
1696 sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
1697 break;
1698 case SIDE_TYPE_S32:
1699 sav_elem.u.side_s32 = ((const int32_t *) p)[i];
1700 break;
1701 case SIDE_TYPE_U64:
1702 sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
1703 break;
1704 case SIDE_TYPE_S64:
1705 sav_elem.u.side_s64 = ((const int64_t *) p)[i];
1706 break;
1707 case SIDE_TYPE_BYTE:
1708 sav_elem.u.side_byte = ((const uint8_t *) p)[i];
1709 break;
1710 case SIDE_TYPE_POINTER32:
1711 sav_elem.u.side_u32 = ((const uint32_t *) p)[i];
1712 break;
1713 case SIDE_TYPE_POINTER64:
1714 sav_elem.u.side_u64 = ((const uint64_t *) p)[i];
1715 break;
1716
1717 default:
1718 fprintf(stderr, "ERROR: Unexpected type\n");
1719 abort();
1720 }
1721
1722 printf("%s", i ? ", " : "");
1723 tracer_print_type(elem_type, &sav_elem);
1724 }
1725 printf(" ]");
1726 return;
1727
1728 type_error:
1729 fprintf(stderr, "ERROR: type mismatch\n");
1730 abort();
1731 }
1732
1733 static
1734 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct)
1735 {
1736 const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields;
1737 uint32_t len = dynamic_struct->len;
1738 int i;
1739
1740 print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr);
1741 printf("%s", dynamic_struct->nr_attr ? ", " : "");
1742 printf("fields:: ");
1743 printf("[ ");
1744 for (i = 0; i < len; i++) {
1745 printf("%s", i ? ", " : "");
1746 printf("%s:: ", fields[i].field_name);
1747 tracer_print_dynamic(&fields[i].elem);
1748 }
1749 printf(" ]");
1750 }
1751
1752 struct tracer_dynamic_struct_visitor_priv {
1753 int i;
1754 };
1755
1756 static
1757 enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
1758 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
1759 const struct side_arg_dynamic_event_field *dynamic_field)
1760 {
1761 struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv;
1762
1763 printf("%s", tracer_priv->i++ ? ", " : "");
1764 printf("%s:: ", dynamic_field->field_name);
1765 tracer_print_dynamic(&dynamic_field->elem);
1766 return SIDE_VISITOR_STATUS_OK;
1767 }
1768
1769 static
1770 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item)
1771 {
1772 enum side_visitor_status status;
1773 struct tracer_dynamic_struct_visitor_priv tracer_priv = {
1774 .i = 0,
1775 };
1776 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = {
1777 .write_field = tracer_dynamic_struct_write_elem_cb,
1778 .priv = &tracer_priv,
1779 };
1780 void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx;
1781
1782 print_attributes("attr", "::", item->u.side_dynamic_struct_visitor.attr, item->u.side_dynamic_struct_visitor.nr_attr);
1783 printf("%s", item->u.side_dynamic_struct_visitor.nr_attr ? ", " : "");
1784 printf("fields:: ");
1785 printf("[ ");
1786 status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx);
1787 switch (status) {
1788 case SIDE_VISITOR_STATUS_OK:
1789 break;
1790 case SIDE_VISITOR_STATUS_ERROR:
1791 fprintf(stderr, "ERROR: Visitor error\n");
1792 abort();
1793 }
1794 printf(" ]");
1795 }
1796
1797 static
1798 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla *vla)
1799 {
1800 const struct side_arg_dynamic_vec *sav = vla->sav;
1801 uint32_t side_sav_len = vla->len;
1802 int i;
1803
1804 print_attributes("attr", "::", vla->attr, vla->nr_attr);
1805 printf("%s", vla->nr_attr ? ", " : "");
1806 printf("elements:: ");
1807 printf("[ ");
1808 for (i = 0; i < side_sav_len; i++) {
1809 printf("%s", i ? ", " : "");
1810 tracer_print_dynamic(&sav[i]);
1811 }
1812 printf(" ]");
1813 }
1814
1815 struct tracer_dynamic_vla_visitor_priv {
1816 int i;
1817 };
1818
1819 static
1820 enum side_visitor_status tracer_dynamic_vla_write_elem_cb(
1821 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
1822 const struct side_arg_dynamic_vec *elem)
1823 {
1824 struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv;
1825
1826 printf("%s", tracer_priv->i++ ? ", " : "");
1827 tracer_print_dynamic(elem);
1828 return SIDE_VISITOR_STATUS_OK;
1829 }
1830
1831 static
1832 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec *item)
1833 {
1834 enum side_visitor_status status;
1835 struct tracer_dynamic_vla_visitor_priv tracer_priv = {
1836 .i = 0,
1837 };
1838 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = {
1839 .write_elem = tracer_dynamic_vla_write_elem_cb,
1840 .priv = &tracer_priv,
1841 };
1842 void *app_ctx = item->u.side_dynamic_vla_visitor.app_ctx;
1843
1844 print_attributes("attr", "::", item->u.side_dynamic_vla_visitor.attr, item->u.side_dynamic_vla_visitor.nr_attr);
1845 printf("%s", item->u.side_dynamic_vla_visitor.nr_attr ? ", " : "");
1846 printf("elements:: ");
1847 printf("[ ");
1848 status = item->u.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx);
1849 switch (status) {
1850 case SIDE_VISITOR_STATUS_OK:
1851 break;
1852 case SIDE_VISITOR_STATUS_ERROR:
1853 fprintf(stderr, "ERROR: Visitor error\n");
1854 abort();
1855 }
1856 printf(" ]");
1857 }
1858
1859 static
1860 void tracer_print_dynamic_basic_type_header(const struct side_arg_dynamic_vec *item)
1861 {
1862 print_attributes("attr", "::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
1863 printf("%s", item->u.side_basic.nr_attr ? ", " : "");
1864 printf("value:: ");
1865 }
1866
1867 static
1868 void tracer_print_dynamic(const struct side_arg_dynamic_vec *item)
1869 {
1870 enum tracer_display_base base = TRACER_DISPLAY_BASE_10;
1871
1872 switch (item->dynamic_type) {
1873 case SIDE_DYNAMIC_TYPE_U8:
1874 case SIDE_DYNAMIC_TYPE_U16:
1875 case SIDE_DYNAMIC_TYPE_U32:
1876 case SIDE_DYNAMIC_TYPE_U64:
1877 case SIDE_DYNAMIC_TYPE_S8:
1878 case SIDE_DYNAMIC_TYPE_S16:
1879 case SIDE_DYNAMIC_TYPE_S32:
1880 case SIDE_DYNAMIC_TYPE_S64:
1881 base = get_attr_display_base(item->u.side_basic.attr,
1882 item->u.side_basic.nr_attr);
1883 break;
1884 default:
1885 break;
1886 }
1887
1888
1889 printf("{ ");
1890 switch (item->dynamic_type) {
1891 case SIDE_DYNAMIC_TYPE_NULL:
1892 tracer_print_dynamic_basic_type_header(item);
1893 printf("<NULL TYPE>");
1894 break;
1895 case SIDE_DYNAMIC_TYPE_BOOL:
1896 tracer_print_dynamic_basic_type_header(item);
1897 printf("%s", item->u.side_basic.u.side_bool ? "true" : "false");
1898 break;
1899 case SIDE_DYNAMIC_TYPE_U8:
1900 {
1901 uint8_t v;
1902
1903 v = item->u.side_basic.u.side_u8;
1904 tracer_print_dynamic_basic_type_header(item);
1905 switch (base) {
1906 case TRACER_DISPLAY_BASE_2:
1907 print_integer_binary(v, 8);
1908 break;
1909 case TRACER_DISPLAY_BASE_8:
1910 printf("0%" PRIo8, v);
1911 break;
1912 case TRACER_DISPLAY_BASE_10:
1913 printf("%" PRIu8, v);
1914 break;
1915 case TRACER_DISPLAY_BASE_16:
1916 printf("0x%" PRIx8, v);
1917 break;
1918 default:
1919 abort();
1920 }
1921 break;
1922 }
1923 case SIDE_DYNAMIC_TYPE_U16:
1924 {
1925 uint16_t v;
1926
1927 v = item->u.side_basic.u.side_u16;
1928 if (dynamic_type_to_host_reverse_bo(item))
1929 v = side_bswap_16(v);
1930 tracer_print_dynamic_basic_type_header(item);
1931 switch (base) {
1932 case TRACER_DISPLAY_BASE_2:
1933 print_integer_binary(v, 16);
1934 break;
1935 case TRACER_DISPLAY_BASE_8:
1936 printf("0%" PRIo16, v);
1937 break;
1938 case TRACER_DISPLAY_BASE_10:
1939 printf("%" PRIu16, v);
1940 break;
1941 case TRACER_DISPLAY_BASE_16:
1942 printf("0x%" PRIx16, v);
1943 break;
1944 default:
1945 abort();
1946 }
1947 break;
1948 }
1949 case SIDE_DYNAMIC_TYPE_U32:
1950 {
1951 uint32_t v;
1952
1953 v = item->u.side_basic.u.side_u32;
1954 if (dynamic_type_to_host_reverse_bo(item))
1955 v = side_bswap_32(v);
1956 tracer_print_dynamic_basic_type_header(item);
1957 switch (base) {
1958 case TRACER_DISPLAY_BASE_2:
1959 print_integer_binary(v, 32);
1960 break;
1961 case TRACER_DISPLAY_BASE_8:
1962 printf("0%" PRIo32, v);
1963 break;
1964 case TRACER_DISPLAY_BASE_10:
1965 printf("%" PRIu32, v);
1966 break;
1967 case TRACER_DISPLAY_BASE_16:
1968 printf("0x%" PRIx32, v);
1969 break;
1970 default:
1971 abort();
1972 }
1973 break;
1974 }
1975 case SIDE_DYNAMIC_TYPE_U64:
1976 {
1977 uint64_t v;
1978
1979 v = item->u.side_basic.u.side_u64;
1980 if (dynamic_type_to_host_reverse_bo(item))
1981 v = side_bswap_64(v);
1982 tracer_print_dynamic_basic_type_header(item);
1983 switch (base) {
1984 case TRACER_DISPLAY_BASE_2:
1985 print_integer_binary(v, 64);
1986 break;
1987 case TRACER_DISPLAY_BASE_8:
1988 printf("0%" PRIo64, v);
1989 break;
1990 case TRACER_DISPLAY_BASE_10:
1991 printf("%" PRIu64, v);
1992 break;
1993 case TRACER_DISPLAY_BASE_16:
1994 printf("0x%" PRIx64, v);
1995 break;
1996 default:
1997 abort();
1998 }
1999 break;
2000 }
2001 case SIDE_DYNAMIC_TYPE_S8:
2002 {
2003 int8_t v;
2004
2005 v = item->u.side_basic.u.side_s8;
2006 tracer_print_dynamic_basic_type_header(item);
2007 switch (base) {
2008 case TRACER_DISPLAY_BASE_2:
2009 print_integer_binary(v, 8);
2010 break;
2011 case TRACER_DISPLAY_BASE_8:
2012 printf("0%" PRIo8, v);
2013 break;
2014 case TRACER_DISPLAY_BASE_10:
2015 printf("%" PRId8, v);
2016 break;
2017 case TRACER_DISPLAY_BASE_16:
2018 printf("0x%" PRIx8, v);
2019 break;
2020 default:
2021 abort();
2022 }
2023 break;
2024 }
2025 case SIDE_DYNAMIC_TYPE_S16:
2026 {
2027 int16_t v;
2028
2029 v = item->u.side_basic.u.side_u16;
2030 if (dynamic_type_to_host_reverse_bo(item))
2031 v = side_bswap_16(v);
2032 tracer_print_dynamic_basic_type_header(item);
2033 switch (base) {
2034 case TRACER_DISPLAY_BASE_2:
2035 print_integer_binary(v, 16);
2036 break;
2037 case TRACER_DISPLAY_BASE_8:
2038 printf("0%" PRIo16, v);
2039 break;
2040 case TRACER_DISPLAY_BASE_10:
2041 printf("%" PRId16, v);
2042 break;
2043 case TRACER_DISPLAY_BASE_16:
2044 printf("0x%" PRIx16, v);
2045 break;
2046 default:
2047 abort();
2048 }
2049 break;
2050 }
2051 case SIDE_DYNAMIC_TYPE_S32:
2052 {
2053 int32_t v;
2054
2055 v = item->u.side_basic.u.side_u32;
2056 if (dynamic_type_to_host_reverse_bo(item))
2057 v = side_bswap_32(v);
2058 tracer_print_dynamic_basic_type_header(item);
2059 switch (base) {
2060 case TRACER_DISPLAY_BASE_2:
2061 print_integer_binary(v, 32);
2062 break;
2063 case TRACER_DISPLAY_BASE_8:
2064 printf("0%" PRIo32, v);
2065 break;
2066 case TRACER_DISPLAY_BASE_10:
2067 printf("%" PRId32, v);
2068 break;
2069 case TRACER_DISPLAY_BASE_16:
2070 printf("0x%" PRIx32, v);
2071 break;
2072 default:
2073 abort();
2074 }
2075 break;
2076 }
2077 case SIDE_DYNAMIC_TYPE_S64:
2078 {
2079 int64_t v;
2080
2081 v = item->u.side_basic.u.side_u64;
2082 if (dynamic_type_to_host_reverse_bo(item))
2083 v = side_bswap_64(v);
2084 tracer_print_dynamic_basic_type_header(item);
2085 switch (base) {
2086 case TRACER_DISPLAY_BASE_2:
2087 print_integer_binary(v, 64);
2088 break;
2089 case TRACER_DISPLAY_BASE_8:
2090 printf("0%" PRIo64, v);
2091 break;
2092 case TRACER_DISPLAY_BASE_10:
2093 printf("%" PRId64, v);
2094 break;
2095 case TRACER_DISPLAY_BASE_16:
2096 printf("0x%" PRIx64, v);
2097 break;
2098 default:
2099 abort();
2100 }
2101 break;
2102 }
2103 case SIDE_DYNAMIC_TYPE_BYTE:
2104 tracer_print_dynamic_basic_type_header(item);
2105 printf("0x%" PRIx8, item->u.side_basic.u.side_byte);
2106 break;
2107 case SIDE_DYNAMIC_TYPE_POINTER32:
2108 {
2109 uint32_t v;
2110
2111 v = item->u.side_basic.u.side_u32;
2112 if (dynamic_type_to_host_reverse_bo(item))
2113 v = side_bswap_32(v);
2114 tracer_print_dynamic_basic_type_header(item);
2115 printf("0x%" PRIx32, v);
2116 break;
2117 }
2118
2119 case SIDE_DYNAMIC_TYPE_POINTER64:
2120 {
2121 uint64_t v;
2122
2123 v = item->u.side_basic.u.side_u64;
2124 if (dynamic_type_to_host_reverse_bo(item))
2125 v = side_bswap_64(v);
2126 tracer_print_dynamic_basic_type_header(item);
2127 printf("0x%" PRIx64, v);
2128 break;
2129 }
2130
2131 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
2132 {
2133 #if __HAVE_FLOAT16
2134 union {
2135 _Float16 f;
2136 uint16_t u;
2137 } float16 = {
2138 .f = item->u.side_basic.u.side_float_binary16,
2139 };
2140
2141 if (dynamic_type_to_host_reverse_bo(item))
2142 float16.u = side_bswap_16(float16.u);
2143 tracer_print_dynamic_basic_type_header(item);
2144 printf("%g", (double) float16.f);
2145 break;
2146 #else
2147 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
2148 abort();
2149 #endif
2150 }
2151 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
2152 {
2153 #if __HAVE_FLOAT32
2154 union {
2155 _Float32 f;
2156 uint32_t u;
2157 } float32 = {
2158 .f = item->u.side_basic.u.side_float_binary32,
2159 };
2160
2161 if (dynamic_type_to_host_reverse_bo(item))
2162 float32.u = side_bswap_32(float32.u);
2163 tracer_print_dynamic_basic_type_header(item);
2164 printf("%g", (double) float32.f);
2165 break;
2166 #else
2167 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
2168 abort();
2169 #endif
2170 }
2171 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
2172 {
2173 #if __HAVE_FLOAT64
2174 union {
2175 _Float64 f;
2176 uint64_t u;
2177 } float64 = {
2178 .f = item->u.side_basic.u.side_float_binary64,
2179 };
2180
2181 if (dynamic_type_to_host_reverse_bo(item))
2182 float64.u = side_bswap_64(float64.u);
2183 tracer_print_dynamic_basic_type_header(item);
2184 printf("%g", (double) float64.f);
2185 break;
2186 #else
2187 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
2188 abort();
2189 #endif
2190 }
2191 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
2192 {
2193 #if __HAVE_FLOAT128
2194 union {
2195 _Float128 f;
2196 char arr[16];
2197 } float128 = {
2198 .f = item->u.side_basic.u.side_float_binary128,
2199 };
2200
2201 if (dynamic_type_to_host_reverse_bo(item))
2202 side_bswap_128p(float128.arr);
2203 tracer_print_dynamic_basic_type_header(item);
2204 printf("%Lg", (long double) float128.f);
2205 break;
2206 #else
2207 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
2208 abort();
2209 #endif
2210 }
2211 case SIDE_DYNAMIC_TYPE_STRING:
2212 tracer_print_dynamic_basic_type_header(item);
2213 printf("\"%s\"", (const char *)(uintptr_t) item->u.side_basic.u.string);
2214 break;
2215 case SIDE_DYNAMIC_TYPE_STRUCT:
2216 tracer_print_dynamic_struct(item->u.side_dynamic_struct);
2217 break;
2218 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR:
2219 tracer_print_dynamic_struct_visitor(item);
2220 break;
2221 case SIDE_DYNAMIC_TYPE_VLA:
2222 tracer_print_dynamic_vla(item->u.side_dynamic_vla);
2223 break;
2224 case SIDE_DYNAMIC_TYPE_VLA_VISITOR:
2225 tracer_print_dynamic_vla_visitor(item);
2226 break;
2227 default:
2228 fprintf(stderr, "<UNKNOWN TYPE>");
2229 abort();
2230 }
2231 printf(" }");
2232 }
2233
2234 static
2235 void tracer_print_static_fields(const struct side_event_description *desc,
2236 const struct side_arg_vec_description *sav_desc,
2237 int *nr_items)
2238 {
2239 const struct side_arg_vec *sav = sav_desc->sav;
2240 uint32_t side_sav_len = sav_desc->len;
2241 int i;
2242
2243 printf("provider: %s, event: %s", desc->provider_name, desc->event_name);
2244 if (desc->nr_fields != side_sav_len) {
2245 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n");
2246 abort();
2247 }
2248 print_attributes(", attr", ":", desc->attr, desc->nr_attr);
2249 printf("%s", side_sav_len ? ", fields: [ " : "");
2250 for (i = 0; i < side_sav_len; i++) {
2251 printf("%s", i ? ", " : "");
2252 tracer_print_field(&desc->fields[i], &sav[i]);
2253 }
2254 if (nr_items)
2255 *nr_items = i;
2256 if (side_sav_len)
2257 printf(" ]");
2258 }
2259
2260 void tracer_call(const struct side_event_description *desc,
2261 const struct side_arg_vec_description *sav_desc,
2262 void *priv __attribute__((unused)))
2263 {
2264 int nr_fields = 0;
2265
2266 tracer_print_static_fields(desc, sav_desc, &nr_fields);
2267 printf("\n");
2268 }
2269
2270 void tracer_call_variadic(const struct side_event_description *desc,
2271 const struct side_arg_vec_description *sav_desc,
2272 const struct side_arg_dynamic_event_struct *var_struct,
2273 void *priv __attribute__((unused)))
2274 {
2275 uint32_t var_struct_len = var_struct->len;
2276 int nr_fields = 0, i;
2277
2278 tracer_print_static_fields(desc, sav_desc, &nr_fields);
2279
2280 if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) {
2281 fprintf(stderr, "ERROR: unexpected non-variadic event description\n");
2282 abort();
2283 }
2284 print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr);
2285 printf("%s", var_struct_len ? ", fields:: [ " : "");
2286 for (i = 0; i < var_struct_len; i++, nr_fields++) {
2287 printf("%s", i ? ", " : "");
2288 printf("%s:: ", var_struct->fields[i].field_name);
2289 tracer_print_dynamic(&var_struct->fields[i].elem);
2290 }
2291 if (i)
2292 printf(" ]");
2293 printf("\n");
2294 }
2295
2296 void tracer_event_notification(enum side_tracer_notification notif,
2297 struct side_event_description **events, uint32_t nr_events, void *priv)
2298 {
2299 uint32_t i;
2300 int ret;
2301
2302 printf("----------------------------------------------------------\n");
2303 printf("Tracer notified of events %s\n",
2304 notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS ? "inserted" : "removed");
2305 for (i = 0; i < nr_events; i++) {
2306 struct side_event_description *event = events[i];
2307
2308 /* Skip NULL pointers */
2309 if (!event)
2310 continue;
2311 printf("provider: %s, event: %s\n",
2312 event->provider_name, event->event_name);
2313 if (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) {
2314 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
2315 ret = side_tracer_callback_variadic_register(event, tracer_call_variadic, NULL);
2316 if (ret)
2317 abort();
2318 } else {
2319 ret = side_tracer_callback_register(event, tracer_call, NULL);
2320 if (ret)
2321 abort();
2322 }
2323 } else {
2324 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
2325 ret = side_tracer_callback_variadic_unregister(event, tracer_call_variadic, NULL);
2326 if (ret)
2327 abort();
2328 } else {
2329 ret = side_tracer_callback_unregister(event, tracer_call, NULL);
2330 if (ret)
2331 abort();
2332 }
2333 }
2334 }
2335 printf("----------------------------------------------------------\n");
2336 }
2337
2338 static __attribute__((constructor))
2339 void tracer_init(void);
2340 static
2341 void tracer_init(void)
2342 {
2343 tracer_handle = side_tracer_event_notification_register(tracer_event_notification, NULL);
2344 if (!tracer_handle)
2345 abort();
2346 }
2347
2348 static __attribute__((destructor))
2349 void tracer_exit(void);
2350 static
2351 void tracer_exit(void)
2352 {
2353 side_tracer_event_notification_unregister(tracer_handle);
2354 }
This page took 0.077944 seconds and 5 git commands to generate.