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