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