1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include <side/trace.h>
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
,
22 static struct side_tracer_handle
*tracer_handle
;
25 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
27 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
29 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
31 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
);
33 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
35 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
37 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*dynamic_item
);
39 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
42 int64_t get_attr_integer_value(const struct side_attr
*attr
)
46 switch (attr
->value
.type
) {
47 case SIDE_ATTR_TYPE_U8
:
48 val
= attr
->value
.u
.side_u8
;
50 case SIDE_ATTR_TYPE_U16
:
51 val
= attr
->value
.u
.side_u16
;
53 case SIDE_ATTR_TYPE_U32
:
54 val
= attr
->value
.u
.side_u32
;
56 case SIDE_ATTR_TYPE_U64
:
57 val
= attr
->value
.u
.side_u64
;
59 case SIDE_ATTR_TYPE_S8
:
60 val
= attr
->value
.u
.side_s8
;
62 case SIDE_ATTR_TYPE_S16
:
63 val
= attr
->value
.u
.side_s16
;
65 case SIDE_ATTR_TYPE_S32
:
66 val
= attr
->value
.u
.side_s32
;
68 case SIDE_ATTR_TYPE_S64
:
69 val
= attr
->value
.u
.side_s64
;
72 fprintf(stderr
, "Unexpected attribute type\n");
79 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
)
83 for (i
= 0; i
< nr_attr
; i
++) {
84 const struct side_attr
*attr
= &_attr
[i
];
86 if (!strcmp(attr
->key
, "std.integer.base")) {
87 int64_t val
= get_attr_integer_value(attr
);
91 return TRACER_DISPLAY_BASE_2
;
93 return TRACER_DISPLAY_BASE_8
;
95 return TRACER_DISPLAY_BASE_10
;
97 return TRACER_DISPLAY_BASE_16
;
99 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
104 return TRACER_DISPLAY_BASE_10
; /* Default */
108 bool type_to_host_reverse_bo(const struct side_type_description
*type_desc
)
110 switch (type_desc
->type
) {
121 case SIDE_TYPE_POINTER32
:
122 case SIDE_TYPE_POINTER64
:
123 if (type_desc
->u
.side_basic
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
128 case SIDE_TYPE_FLOAT_BINARY16
:
129 case SIDE_TYPE_FLOAT_BINARY32
:
130 case SIDE_TYPE_FLOAT_BINARY64
:
131 case SIDE_TYPE_FLOAT_BINARY128
:
132 if (type_desc
->u
.side_basic
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
138 fprintf(stderr
, "Unexpected type\n");
144 bool dynamic_type_to_host_reverse_bo(const struct side_arg_dynamic_vec
*item
)
146 switch (item
->dynamic_type
) {
147 case SIDE_DYNAMIC_TYPE_U8
:
148 case SIDE_DYNAMIC_TYPE_S8
:
149 case SIDE_DYNAMIC_TYPE_BYTE
:
151 case SIDE_DYNAMIC_TYPE_U16
:
152 case SIDE_DYNAMIC_TYPE_U32
:
153 case SIDE_DYNAMIC_TYPE_U64
:
154 case SIDE_DYNAMIC_TYPE_S16
:
155 case SIDE_DYNAMIC_TYPE_S32
:
156 case SIDE_DYNAMIC_TYPE_S64
:
157 case SIDE_DYNAMIC_TYPE_POINTER32
:
158 case SIDE_DYNAMIC_TYPE_POINTER64
:
159 if (item
->u
.side_basic
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
164 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
165 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
166 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
167 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
168 if (item
->u
.side_basic
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
174 fprintf(stderr
, "Unexpected type\n");
180 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
182 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
183 switch (attr
->value
.type
) {
184 case SIDE_ATTR_TYPE_BOOL
:
185 printf("%s", attr
->value
.u
.side_bool
? "true" : "false");
187 case SIDE_ATTR_TYPE_U8
:
188 printf("%" PRIu8
, attr
->value
.u
.side_u8
);
190 case SIDE_ATTR_TYPE_U16
:
191 printf("%" PRIu16
, attr
->value
.u
.side_u16
);
193 case SIDE_ATTR_TYPE_U32
:
194 printf("%" PRIu32
, attr
->value
.u
.side_u32
);
196 case SIDE_ATTR_TYPE_U64
:
197 printf("%" PRIu64
, attr
->value
.u
.side_u64
);
199 case SIDE_ATTR_TYPE_S8
:
200 printf("%" PRId8
, attr
->value
.u
.side_s8
);
202 case SIDE_ATTR_TYPE_S16
:
203 printf("%" PRId16
, attr
->value
.u
.side_s16
);
205 case SIDE_ATTR_TYPE_S32
:
206 printf("%" PRId32
, attr
->value
.u
.side_s32
);
208 case SIDE_ATTR_TYPE_S64
:
209 printf("%" PRId64
, attr
->value
.u
.side_s64
);
211 case SIDE_ATTR_TYPE_POINTER32
:
212 printf("0x%" PRIx32
, attr
->value
.u
.side_u32
);
214 case SIDE_ATTR_TYPE_POINTER64
:
215 printf("0x%" PRIx64
, attr
->value
.u
.side_u64
);
217 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
219 printf("%g", (double) attr
->value
.u
.side_float_binary16
);
222 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
225 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
227 printf("%g", (double) attr
->value
.u
.side_float_binary32
);
230 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
233 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
235 printf("%g", (double) attr
->value
.u
.side_float_binary64
);
238 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
241 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
243 printf("%Lg", (long double) attr
->value
.u
.side_float_binary128
);
246 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
249 case SIDE_ATTR_TYPE_STRING
:
250 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string
);
253 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
260 void print_attributes(const char *prefix_str
, const char *separator
,
261 const struct side_attr
*attr
, uint32_t nr_attr
)
267 printf("%s%s [ ", prefix_str
, separator
);
268 for (i
= 0; i
< nr_attr
; i
++) {
269 printf("%s", i
? ", " : "");
270 tracer_print_attr_type(separator
, &attr
[i
]);
276 void print_enum(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
278 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
279 const struct side_type_description
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
280 int i
, print_count
= 0;
283 if (elem_type
->type
!= item
->type
) {
284 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
287 switch (item
->type
) {
289 value
= (int64_t) item
->u
.side_u8
;
295 v
= item
->u
.side_u16
;
296 if (type_to_host_reverse_bo(elem_type
))
297 v
= side_bswap_16(v
);
305 v
= item
->u
.side_u32
;
306 if (type_to_host_reverse_bo(elem_type
))
307 v
= side_bswap_32(v
);
315 v
= item
->u
.side_u64
;
316 if (type_to_host_reverse_bo(elem_type
))
317 v
= side_bswap_64(v
);
322 value
= (int64_t) item
->u
.side_s8
;
328 v
= item
->u
.side_s16
;
329 if (type_to_host_reverse_bo(elem_type
))
330 v
= side_bswap_16(v
);
338 v
= item
->u
.side_s32
;
339 if (type_to_host_reverse_bo(elem_type
))
340 v
= side_bswap_32(v
);
348 v
= item
->u
.side_s64
;
349 if (type_to_host_reverse_bo(elem_type
))
350 v
= side_bswap_64(v
);
355 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
358 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
359 printf("%s", mappings
->nr_attr
? ", " : "");
360 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
361 printf(", labels: [ ");
362 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
363 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
365 if (mapping
->range_end
< mapping
->range_begin
) {
366 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
367 mapping
->range_begin
, mapping
->range_end
);
370 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
371 printf("%s", print_count
++ ? ", " : "");
372 printf("\"%s\"", mapping
->label
);
376 printf("<NO LABEL>");
381 uint32_t enum_elem_type_to_stride(const struct side_type_description
*elem_type
)
385 switch (elem_type
->type
) {
386 case SIDE_TYPE_U8
: /* Fall-through */
400 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
407 void print_enum_bitmap(const struct side_type_description
*type_desc
,
408 const struct side_arg_vec
*item
)
410 const struct side_type_description
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
411 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
412 int i
, print_count
= 0;
413 uint32_t stride_bit
, nr_items
;
414 bool reverse_byte_order
= false;
415 const struct side_arg_vec
*array_item
;
417 switch (elem_type
->type
) {
418 case SIDE_TYPE_U8
: /* Fall-through */
419 case SIDE_TYPE_BYTE
: /* Fall-through */
420 case SIDE_TYPE_U16
: /* Fall-through */
421 case SIDE_TYPE_U32
: /* Fall-through */
423 stride_bit
= enum_elem_type_to_stride(elem_type
);
424 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
428 case SIDE_TYPE_ARRAY
:
429 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
430 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
431 array_item
= item
->u
.side_array
->sav
;
432 nr_items
= type_desc
->u
.side_array
.length
;
435 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
436 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
437 array_item
= item
->u
.side_vla
->sav
;
438 nr_items
= item
->u
.side_vla
->len
;
441 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
445 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
446 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
447 printf("labels: [ ");
448 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
449 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
453 if (mapping
->range_end
< mapping
->range_begin
) {
454 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
455 mapping
->range_begin
, mapping
->range_end
);
458 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
459 if (bit
> (nr_items
* stride_bit
) - 1)
461 switch (stride_bit
) {
464 uint8_t v
= array_item
[bit
/ 8].u
.side_u8
;
465 if (v
& (1ULL << (bit
% 8))) {
473 uint16_t v
= array_item
[bit
/ 16].u
.side_u16
;
474 if (reverse_byte_order
)
475 v
= side_bswap_16(v
);
476 if (v
& (1ULL << (bit
% 16))) {
484 uint32_t v
= array_item
[bit
/ 32].u
.side_u32
;
485 if (reverse_byte_order
)
486 v
= side_bswap_32(v
);
487 if (v
& (1ULL << (bit
% 32))) {
495 uint64_t v
= array_item
[bit
/ 64].u
.side_u64
;
496 if (reverse_byte_order
)
497 v
= side_bswap_64(v
);
498 if (v
& (1ULL << (bit
% 64))) {
510 printf("%s", print_count
++ ? ", " : "");
511 printf("\"%s\"", mapping
->label
);
515 printf("<NO LABEL>");
520 void print_integer_binary(uint64_t v
, int bits
)
526 for (i
= 0; i
< bits
; i
++) {
527 printf("%c", v
& (1ULL << 63) ? '1' : '0');
533 void tracer_print_basic_type_header(const struct side_type_description
*type_desc
)
535 print_attributes("attr", ":", type_desc
->u
.side_basic
.attr
, type_desc
->u
.side_basic
.nr_attr
);
536 printf("%s", type_desc
->u
.side_basic
.nr_attr
? ", " : "");
541 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
544 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
546 switch (type_desc
->type
) {
547 case SIDE_TYPE_ARRAY
:
548 switch (item
->type
) {
549 case SIDE_TYPE_ARRAY_U8
:
550 case SIDE_TYPE_ARRAY_U16
:
551 case SIDE_TYPE_ARRAY_U32
:
552 case SIDE_TYPE_ARRAY_U64
:
553 case SIDE_TYPE_ARRAY_S8
:
554 case SIDE_TYPE_ARRAY_S16
:
555 case SIDE_TYPE_ARRAY_S32
:
556 case SIDE_TYPE_ARRAY_S64
:
557 case SIDE_TYPE_ARRAY_POINTER32
:
558 case SIDE_TYPE_ARRAY_POINTER64
:
559 case SIDE_TYPE_ARRAY_BYTE
:
560 case SIDE_TYPE_ARRAY
:
563 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
570 switch (item
->type
) {
571 case SIDE_TYPE_VLA_U8
:
572 case SIDE_TYPE_VLA_U16
:
573 case SIDE_TYPE_VLA_U32
:
574 case SIDE_TYPE_VLA_U64
:
575 case SIDE_TYPE_VLA_S8
:
576 case SIDE_TYPE_VLA_S16
:
577 case SIDE_TYPE_VLA_S32
:
578 case SIDE_TYPE_VLA_S64
:
579 case SIDE_TYPE_VLA_BYTE
:
580 case SIDE_TYPE_VLA_POINTER32
:
581 case SIDE_TYPE_VLA_POINTER64
:
585 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
592 switch (item
->type
) {
603 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
609 case SIDE_TYPE_ENUM_BITMAP
:
610 switch (item
->type
) {
616 case SIDE_TYPE_ARRAY
:
620 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
627 if (type_desc
->type
!= item
->type
) {
628 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
634 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
635 type
= type_desc
->type
;
648 base
= get_attr_display_base(type_desc
->u
.side_basic
.attr
,
649 type_desc
->u
.side_basic
.nr_attr
);
658 tracer_print_basic_type_header(type_desc
);
659 printf("%s", item
->u
.side_bool
? "true" : "false");
666 tracer_print_basic_type_header(type_desc
);
668 case TRACER_DISPLAY_BASE_2
:
669 print_integer_binary(v
, 8);
671 case TRACER_DISPLAY_BASE_8
:
672 printf("0%" PRIo8
, v
);
674 case TRACER_DISPLAY_BASE_10
:
675 printf("%" PRIu8
, v
);
677 case TRACER_DISPLAY_BASE_16
:
678 printf("0x%" PRIx8
, v
);
689 v
= item
->u
.side_u16
;
690 if (type_to_host_reverse_bo(type_desc
))
691 v
= side_bswap_16(v
);
692 tracer_print_basic_type_header(type_desc
);
694 case TRACER_DISPLAY_BASE_2
:
695 print_integer_binary(v
, 16);
697 case TRACER_DISPLAY_BASE_8
:
698 printf("0%" PRIo16
, v
);
700 case TRACER_DISPLAY_BASE_10
:
701 printf("%" PRIu16
, v
);
703 case TRACER_DISPLAY_BASE_16
:
704 printf("0x%" PRIx16
, v
);
715 v
= item
->u
.side_u32
;
716 if (type_to_host_reverse_bo(type_desc
))
717 v
= side_bswap_32(v
);
718 tracer_print_basic_type_header(type_desc
);
720 case TRACER_DISPLAY_BASE_2
:
721 print_integer_binary(v
, 32);
723 case TRACER_DISPLAY_BASE_8
:
724 printf("0%" PRIo32
, v
);
726 case TRACER_DISPLAY_BASE_10
:
727 printf("%" PRIu32
, v
);
729 case TRACER_DISPLAY_BASE_16
:
730 printf("0x%" PRIx32
, v
);
741 v
= item
->u
.side_u64
;
742 if (type_to_host_reverse_bo(type_desc
))
743 v
= side_bswap_64(v
);
744 tracer_print_basic_type_header(type_desc
);
746 case TRACER_DISPLAY_BASE_2
:
747 print_integer_binary(v
, 64);
749 case TRACER_DISPLAY_BASE_8
:
750 printf("0%" PRIo64
, v
);
752 case TRACER_DISPLAY_BASE_10
:
753 printf("%" PRIu64
, v
);
755 case TRACER_DISPLAY_BASE_16
:
756 printf("0x%" PRIx64
, v
);
768 tracer_print_basic_type_header(type_desc
);
770 case TRACER_DISPLAY_BASE_2
:
771 print_integer_binary(v
, 8);
773 case TRACER_DISPLAY_BASE_8
:
774 printf("0%" PRIo8
, v
);
776 case TRACER_DISPLAY_BASE_10
:
777 printf("%" PRId8
, v
);
779 case TRACER_DISPLAY_BASE_16
:
780 printf("0x%" PRIx8
, v
);
791 v
= item
->u
.side_s16
;
792 if (type_to_host_reverse_bo(type_desc
))
793 v
= side_bswap_16(v
);
794 tracer_print_basic_type_header(type_desc
);
796 case TRACER_DISPLAY_BASE_2
:
797 print_integer_binary(v
, 16);
799 case TRACER_DISPLAY_BASE_8
:
800 printf("0%" PRIo16
, v
);
802 case TRACER_DISPLAY_BASE_10
:
803 printf("%" PRId16
, v
);
805 case TRACER_DISPLAY_BASE_16
:
806 printf("0x%" PRIx16
, v
);
817 v
= item
->u
.side_s32
;
818 if (type_to_host_reverse_bo(type_desc
))
819 v
= side_bswap_32(v
);
820 tracer_print_basic_type_header(type_desc
);
822 case TRACER_DISPLAY_BASE_2
:
823 print_integer_binary(v
, 32);
825 case TRACER_DISPLAY_BASE_8
:
826 printf("0%" PRIo32
, v
);
828 case TRACER_DISPLAY_BASE_10
:
829 printf("%" PRId32
, v
);
831 case TRACER_DISPLAY_BASE_16
:
832 printf("0x%" PRIx32
, v
);
843 v
= item
->u
.side_s64
;
844 if (type_to_host_reverse_bo(type_desc
))
845 v
= side_bswap_64(v
);
846 tracer_print_basic_type_header(type_desc
);
848 case TRACER_DISPLAY_BASE_2
:
849 print_integer_binary(v
, 64);
851 case TRACER_DISPLAY_BASE_8
:
852 printf("0%" PRIo64
, v
);
854 case TRACER_DISPLAY_BASE_10
:
855 printf("%" PRId64
, v
);
857 case TRACER_DISPLAY_BASE_16
:
858 printf("0x%" PRIx64
, v
);
865 case SIDE_TYPE_POINTER32
:
869 v
= item
->u
.side_u32
;
870 if (type_to_host_reverse_bo(type_desc
))
871 v
= side_bswap_32(v
);
872 tracer_print_basic_type_header(type_desc
);
873 printf("0x%" PRIx32
, v
);
876 case SIDE_TYPE_POINTER64
:
880 v
= item
->u
.side_u64
;
881 if (type_to_host_reverse_bo(type_desc
))
882 v
= side_bswap_64(v
);
883 tracer_print_basic_type_header(type_desc
);
884 printf("0x%" PRIx64
, v
);
888 tracer_print_basic_type_header(type_desc
);
889 printf("0x%" PRIx8
, item
->u
.side_byte
);
893 print_enum(type_desc
, item
);
896 case SIDE_TYPE_ENUM_BITMAP
:
897 print_enum_bitmap(type_desc
, item
);
900 case SIDE_TYPE_FLOAT_BINARY16
:
907 .f
= item
->u
.side_float_binary16
,
910 if (type_to_host_reverse_bo(type_desc
))
911 float16
.u
= side_bswap_16(float16
.u
);
912 tracer_print_basic_type_header(type_desc
);
913 printf("%g", (double) float16
.f
);
916 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
920 case SIDE_TYPE_FLOAT_BINARY32
:
927 .f
= item
->u
.side_float_binary32
,
930 if (type_to_host_reverse_bo(type_desc
))
931 float32
.u
= side_bswap_32(float32
.u
);
932 tracer_print_basic_type_header(type_desc
);
933 printf("%g", (double) float32
.f
);
936 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
940 case SIDE_TYPE_FLOAT_BINARY64
:
947 .f
= item
->u
.side_float_binary64
,
950 if (type_to_host_reverse_bo(type_desc
))
951 float64
.u
= side_bswap_64(float64
.u
);
952 tracer_print_basic_type_header(type_desc
);
953 printf("%g", (double) float64
.f
);
956 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
960 case SIDE_TYPE_FLOAT_BINARY128
:
967 .f
= item
->u
.side_float_binary128
,
970 if (type_to_host_reverse_bo(type_desc
))
971 side_bswap_128p(float128
.arr
);
972 tracer_print_basic_type_header(type_desc
);
973 printf("%Lg", (long double) float128
.f
);
976 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
980 case SIDE_TYPE_STRING
:
981 tracer_print_basic_type_header(type_desc
);
982 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.string
);
984 case SIDE_TYPE_STRUCT
:
985 tracer_print_struct(type_desc
, item
->u
.side_struct
);
987 case SIDE_TYPE_ARRAY
:
988 tracer_print_array(type_desc
, item
->u
.side_array
);
991 tracer_print_vla(type_desc
, item
->u
.side_vla
);
993 case SIDE_TYPE_VLA_VISITOR
:
994 tracer_print_vla_visitor(type_desc
, item
->u
.side_vla_app_visitor_ctx
);
996 case SIDE_TYPE_ARRAY_U8
:
997 case SIDE_TYPE_ARRAY_U16
:
998 case SIDE_TYPE_ARRAY_U32
:
999 case SIDE_TYPE_ARRAY_U64
:
1000 case SIDE_TYPE_ARRAY_S8
:
1001 case SIDE_TYPE_ARRAY_S16
:
1002 case SIDE_TYPE_ARRAY_S32
:
1003 case SIDE_TYPE_ARRAY_S64
:
1004 case SIDE_TYPE_ARRAY_BYTE
:
1005 case SIDE_TYPE_ARRAY_POINTER32
:
1006 case SIDE_TYPE_ARRAY_POINTER64
:
1007 tracer_print_array_fixint(type_desc
, item
);
1009 case SIDE_TYPE_VLA_U8
:
1010 case SIDE_TYPE_VLA_U16
:
1011 case SIDE_TYPE_VLA_U32
:
1012 case SIDE_TYPE_VLA_U64
:
1013 case SIDE_TYPE_VLA_S8
:
1014 case SIDE_TYPE_VLA_S16
:
1015 case SIDE_TYPE_VLA_S32
:
1016 case SIDE_TYPE_VLA_S64
:
1017 case SIDE_TYPE_VLA_BYTE
:
1018 case SIDE_TYPE_VLA_POINTER32
:
1019 case SIDE_TYPE_VLA_POINTER64
:
1020 tracer_print_vla_fixint(type_desc
, item
);
1022 case SIDE_TYPE_DYNAMIC
:
1023 tracer_print_basic_type_header(type_desc
);
1024 tracer_print_dynamic(&item
->u
.dynamic
);
1027 fprintf(stderr
, "<UNKNOWN TYPE>");
1034 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg_vec
*item
)
1036 printf("%s: ", item_desc
->field_name
);
1037 tracer_print_type(&item_desc
->side_type
, item
);
1041 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1043 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1044 uint32_t side_sav_len
= sav_desc
->len
;
1047 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
1048 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
1051 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1052 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1053 printf("fields: { ");
1054 for (i
= 0; i
< side_sav_len
; i
++) {
1055 printf("%s", i
? ", " : "");
1056 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1062 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1064 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1065 uint32_t side_sav_len
= sav_desc
->len
;
1068 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1069 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1072 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1073 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1074 printf("elements: ");
1076 for (i
= 0; i
< side_sav_len
; i
++) {
1077 printf("%s", i
? ", " : "");
1078 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1084 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1086 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1087 uint32_t side_sav_len
= sav_desc
->len
;
1090 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1091 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1092 printf("elements: ");
1094 for (i
= 0; i
< side_sav_len
; i
++) {
1095 printf("%s", i
? ", " : "");
1096 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1101 struct tracer_visitor_priv
{
1102 const struct side_type_description
*elem_type
;
1107 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1108 const struct side_arg_vec
*elem
)
1110 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1112 printf("%s", tracer_priv
->i
++ ? ", " : "");
1113 tracer_print_type(tracer_priv
->elem_type
, elem
);
1114 return SIDE_VISITOR_STATUS_OK
;
1118 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
)
1120 enum side_visitor_status status
;
1121 struct tracer_visitor_priv tracer_priv
= {
1122 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1125 const struct side_tracer_visitor_ctx tracer_ctx
= {
1126 .write_elem
= tracer_write_elem_cb
,
1127 .priv
= &tracer_priv
,
1130 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1131 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1132 printf("elements: ");
1134 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1136 case SIDE_VISITOR_STATUS_OK
:
1138 case SIDE_VISITOR_STATUS_ERROR
:
1139 fprintf(stderr
, "ERROR: Visitor error\n");
1145 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1147 const struct side_type_description
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1148 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
1149 void *p
= item
->u
.side_array_fixint
;
1150 enum side_type side_type
;
1153 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1154 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1155 printf("elements: ");
1156 switch (item
->type
) {
1157 case SIDE_TYPE_ARRAY_U8
:
1158 if (elem_type
->type
!= SIDE_TYPE_U8
)
1161 case SIDE_TYPE_ARRAY_U16
:
1162 if (elem_type
->type
!= SIDE_TYPE_U16
)
1165 case SIDE_TYPE_ARRAY_U32
:
1166 if (elem_type
->type
!= SIDE_TYPE_U32
)
1169 case SIDE_TYPE_ARRAY_U64
:
1170 if (elem_type
->type
!= SIDE_TYPE_U64
)
1173 case SIDE_TYPE_ARRAY_S8
:
1174 if (elem_type
->type
!= SIDE_TYPE_S8
)
1177 case SIDE_TYPE_ARRAY_S16
:
1178 if (elem_type
->type
!= SIDE_TYPE_S16
)
1181 case SIDE_TYPE_ARRAY_S32
:
1182 if (elem_type
->type
!= SIDE_TYPE_S32
)
1185 case SIDE_TYPE_ARRAY_S64
:
1186 if (elem_type
->type
!= SIDE_TYPE_S64
)
1189 case SIDE_TYPE_ARRAY_BYTE
:
1190 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1193 case SIDE_TYPE_ARRAY_POINTER32
:
1194 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1196 case SIDE_TYPE_ARRAY_POINTER64
:
1197 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1203 side_type
= elem_type
->type
;
1206 for (i
= 0; i
< side_sav_len
; i
++) {
1207 struct side_arg_vec sav_elem
= {
1211 switch (side_type
) {
1213 sav_elem
.u
.side_u8
= ((const uint8_t *) p
)[i
];
1216 sav_elem
.u
.side_s8
= ((const int8_t *) p
)[i
];
1219 sav_elem
.u
.side_u16
= ((const uint16_t *) p
)[i
];
1222 sav_elem
.u
.side_s16
= ((const int16_t *) p
)[i
];
1225 sav_elem
.u
.side_u32
= ((const uint32_t *) p
)[i
];
1228 sav_elem
.u
.side_s32
= ((const int32_t *) p
)[i
];
1231 sav_elem
.u
.side_u64
= ((const uint64_t *) p
)[i
];
1234 sav_elem
.u
.side_s64
= ((const int64_t *) p
)[i
];
1236 case SIDE_TYPE_BYTE
:
1237 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1239 case SIDE_TYPE_POINTER32
:
1240 sav_elem
.u
.side_u32
= ((const uint32_t *) p
)[i
];
1242 case SIDE_TYPE_POINTER64
:
1243 sav_elem
.u
.side_u64
= ((const uint64_t *) p
)[i
];
1247 fprintf(stderr
, "ERROR: Unexpected type\n");
1251 printf("%s", i
? ", " : "");
1252 tracer_print_type(elem_type
, &sav_elem
);
1258 fprintf(stderr
, "ERROR: type mismatch\n");
1262 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1264 const struct side_type_description
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1265 uint32_t side_sav_len
= item
->u
.side_vla_fixint
.length
;
1266 void *p
= item
->u
.side_vla_fixint
.p
;
1267 enum side_type side_type
;
1270 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1271 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1272 printf("elements: ");
1273 switch (item
->type
) {
1274 case SIDE_TYPE_VLA_U8
:
1275 if (elem_type
->type
!= SIDE_TYPE_U8
)
1278 case SIDE_TYPE_VLA_U16
:
1279 if (elem_type
->type
!= SIDE_TYPE_U16
)
1282 case SIDE_TYPE_VLA_U32
:
1283 if (elem_type
->type
!= SIDE_TYPE_U32
)
1286 case SIDE_TYPE_VLA_U64
:
1287 if (elem_type
->type
!= SIDE_TYPE_U64
)
1290 case SIDE_TYPE_VLA_S8
:
1291 if (elem_type
->type
!= SIDE_TYPE_S8
)
1294 case SIDE_TYPE_VLA_S16
:
1295 if (elem_type
->type
!= SIDE_TYPE_S16
)
1298 case SIDE_TYPE_VLA_S32
:
1299 if (elem_type
->type
!= SIDE_TYPE_S32
)
1302 case SIDE_TYPE_VLA_S64
:
1303 if (elem_type
->type
!= SIDE_TYPE_S64
)
1306 case SIDE_TYPE_VLA_BYTE
:
1307 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1310 case SIDE_TYPE_VLA_POINTER32
:
1311 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1313 case SIDE_TYPE_VLA_POINTER64
:
1314 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1320 side_type
= elem_type
->type
;
1323 for (i
= 0; i
< side_sav_len
; i
++) {
1324 struct side_arg_vec sav_elem
= {
1328 switch (side_type
) {
1330 sav_elem
.u
.side_u8
= ((const uint8_t *) p
)[i
];
1333 sav_elem
.u
.side_s8
= ((const int8_t *) p
)[i
];
1336 sav_elem
.u
.side_u16
= ((const uint16_t *) p
)[i
];
1339 sav_elem
.u
.side_s16
= ((const int16_t *) p
)[i
];
1342 sav_elem
.u
.side_u32
= ((const uint32_t *) p
)[i
];
1345 sav_elem
.u
.side_s32
= ((const int32_t *) p
)[i
];
1348 sav_elem
.u
.side_u64
= ((const uint64_t *) p
)[i
];
1351 sav_elem
.u
.side_s64
= ((const int64_t *) p
)[i
];
1353 case SIDE_TYPE_BYTE
:
1354 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1356 case SIDE_TYPE_POINTER32
:
1357 sav_elem
.u
.side_u32
= ((const uint32_t *) p
)[i
];
1359 case SIDE_TYPE_POINTER64
:
1360 sav_elem
.u
.side_u64
= ((const uint64_t *) p
)[i
];
1364 fprintf(stderr
, "ERROR: Unexpected type\n");
1368 printf("%s", i
? ", " : "");
1369 tracer_print_type(elem_type
, &sav_elem
);
1375 fprintf(stderr
, "ERROR: type mismatch\n");
1380 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
1382 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
1383 uint32_t len
= dynamic_struct
->len
;
1386 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1387 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1388 printf("fields:: ");
1390 for (i
= 0; i
< len
; i
++) {
1391 printf("%s", i
? ", " : "");
1392 printf("%s:: ", fields
[i
].field_name
);
1393 tracer_print_dynamic(&fields
[i
].elem
);
1398 struct tracer_dynamic_struct_visitor_priv
{
1403 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1404 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1405 const struct side_arg_dynamic_event_field
*dynamic_field
)
1407 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1409 printf("%s", tracer_priv
->i
++ ? ", " : "");
1410 printf("%s:: ", dynamic_field
->field_name
);
1411 tracer_print_dynamic(&dynamic_field
->elem
);
1412 return SIDE_VISITOR_STATUS_OK
;
1416 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec
*item
)
1418 enum side_visitor_status status
;
1419 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1422 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1423 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1424 .priv
= &tracer_priv
,
1426 void *app_ctx
= item
->u
.side_dynamic_struct_visitor
.app_ctx
;
1428 print_attributes("attr", "::", item
->u
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic_struct_visitor
.nr_attr
);
1429 printf("%s", item
->u
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1430 printf("fields:: ");
1432 status
= item
->u
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1434 case SIDE_VISITOR_STATUS_OK
:
1436 case SIDE_VISITOR_STATUS_ERROR
:
1437 fprintf(stderr
, "ERROR: Visitor error\n");
1444 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla
*vla
)
1446 const struct side_arg_dynamic_vec
*sav
= vla
->sav
;
1447 uint32_t side_sav_len
= vla
->len
;
1450 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1451 printf("%s", vla
->nr_attr
? ", " : "");
1452 printf("elements:: ");
1454 for (i
= 0; i
< side_sav_len
; i
++) {
1455 printf("%s", i
? ", " : "");
1456 tracer_print_dynamic(&sav
[i
]);
1461 struct tracer_dynamic_vla_visitor_priv
{
1466 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1467 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
1468 const struct side_arg_dynamic_vec
*elem
)
1470 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1472 printf("%s", tracer_priv
->i
++ ? ", " : "");
1473 tracer_print_dynamic(elem
);
1474 return SIDE_VISITOR_STATUS_OK
;
1478 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec
*item
)
1480 enum side_visitor_status status
;
1481 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1484 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
1485 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1486 .priv
= &tracer_priv
,
1488 void *app_ctx
= item
->u
.side_dynamic_vla_visitor
.app_ctx
;
1490 print_attributes("attr", "::", item
->u
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic_vla_visitor
.nr_attr
);
1491 printf("%s", item
->u
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1492 printf("elements:: ");
1494 status
= item
->u
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1496 case SIDE_VISITOR_STATUS_OK
:
1498 case SIDE_VISITOR_STATUS_ERROR
:
1499 fprintf(stderr
, "ERROR: Visitor error\n");
1506 void tracer_print_dynamic_basic_type_header(const struct side_arg_dynamic_vec
*item
)
1508 print_attributes("attr", "::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1509 printf("%s", item
->u
.side_basic
.nr_attr
? ", " : "");
1514 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*item
)
1516 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
1518 switch (item
->dynamic_type
) {
1519 case SIDE_DYNAMIC_TYPE_U8
:
1520 case SIDE_DYNAMIC_TYPE_U16
:
1521 case SIDE_DYNAMIC_TYPE_U32
:
1522 case SIDE_DYNAMIC_TYPE_U64
:
1523 case SIDE_DYNAMIC_TYPE_S8
:
1524 case SIDE_DYNAMIC_TYPE_S16
:
1525 case SIDE_DYNAMIC_TYPE_S32
:
1526 case SIDE_DYNAMIC_TYPE_S64
:
1527 base
= get_attr_display_base(item
->u
.side_basic
.attr
,
1528 item
->u
.side_basic
.nr_attr
);
1536 switch (item
->dynamic_type
) {
1537 case SIDE_DYNAMIC_TYPE_NULL
:
1538 tracer_print_dynamic_basic_type_header(item
);
1539 printf("<NULL TYPE>");
1541 case SIDE_DYNAMIC_TYPE_BOOL
:
1542 tracer_print_dynamic_basic_type_header(item
);
1543 printf("%s", item
->u
.side_basic
.u
.side_bool
? "true" : "false");
1545 case SIDE_DYNAMIC_TYPE_U8
:
1549 v
= item
->u
.side_basic
.u
.side_u8
;
1550 tracer_print_dynamic_basic_type_header(item
);
1552 case TRACER_DISPLAY_BASE_2
:
1553 print_integer_binary(v
, 8);
1555 case TRACER_DISPLAY_BASE_8
:
1556 printf("0%" PRIo8
, v
);
1558 case TRACER_DISPLAY_BASE_10
:
1559 printf("%" PRIu8
, v
);
1561 case TRACER_DISPLAY_BASE_16
:
1562 printf("0x%" PRIx8
, v
);
1569 case SIDE_DYNAMIC_TYPE_U16
:
1573 v
= item
->u
.side_basic
.u
.side_u16
;
1574 if (dynamic_type_to_host_reverse_bo(item
))
1575 v
= side_bswap_16(v
);
1576 tracer_print_dynamic_basic_type_header(item
);
1578 case TRACER_DISPLAY_BASE_2
:
1579 print_integer_binary(v
, 16);
1581 case TRACER_DISPLAY_BASE_8
:
1582 printf("0%" PRIo16
, v
);
1584 case TRACER_DISPLAY_BASE_10
:
1585 printf("%" PRIu16
, v
);
1587 case TRACER_DISPLAY_BASE_16
:
1588 printf("0x%" PRIx16
, v
);
1595 case SIDE_DYNAMIC_TYPE_U32
:
1599 v
= item
->u
.side_basic
.u
.side_u32
;
1600 if (dynamic_type_to_host_reverse_bo(item
))
1601 v
= side_bswap_32(v
);
1602 tracer_print_dynamic_basic_type_header(item
);
1604 case TRACER_DISPLAY_BASE_2
:
1605 print_integer_binary(v
, 32);
1607 case TRACER_DISPLAY_BASE_8
:
1608 printf("0%" PRIo32
, v
);
1610 case TRACER_DISPLAY_BASE_10
:
1611 printf("%" PRIu32
, v
);
1613 case TRACER_DISPLAY_BASE_16
:
1614 printf("0x%" PRIx32
, v
);
1621 case SIDE_DYNAMIC_TYPE_U64
:
1625 v
= item
->u
.side_basic
.u
.side_u64
;
1626 if (dynamic_type_to_host_reverse_bo(item
))
1627 v
= side_bswap_64(v
);
1628 tracer_print_dynamic_basic_type_header(item
);
1630 case TRACER_DISPLAY_BASE_2
:
1631 print_integer_binary(v
, 64);
1633 case TRACER_DISPLAY_BASE_8
:
1634 printf("0%" PRIo64
, v
);
1636 case TRACER_DISPLAY_BASE_10
:
1637 printf("%" PRIu64
, v
);
1639 case TRACER_DISPLAY_BASE_16
:
1640 printf("0x%" PRIx64
, v
);
1647 case SIDE_DYNAMIC_TYPE_S8
:
1651 v
= item
->u
.side_basic
.u
.side_s8
;
1652 tracer_print_dynamic_basic_type_header(item
);
1654 case TRACER_DISPLAY_BASE_2
:
1655 print_integer_binary(v
, 8);
1657 case TRACER_DISPLAY_BASE_8
:
1658 printf("0%" PRIo8
, v
);
1660 case TRACER_DISPLAY_BASE_10
:
1661 printf("%" PRId8
, v
);
1663 case TRACER_DISPLAY_BASE_16
:
1664 printf("0x%" PRIx8
, v
);
1671 case SIDE_DYNAMIC_TYPE_S16
:
1675 v
= item
->u
.side_basic
.u
.side_u16
;
1676 if (dynamic_type_to_host_reverse_bo(item
))
1677 v
= side_bswap_16(v
);
1678 tracer_print_dynamic_basic_type_header(item
);
1680 case TRACER_DISPLAY_BASE_2
:
1681 print_integer_binary(v
, 16);
1683 case TRACER_DISPLAY_BASE_8
:
1684 printf("0%" PRIo16
, v
);
1686 case TRACER_DISPLAY_BASE_10
:
1687 printf("%" PRId16
, v
);
1689 case TRACER_DISPLAY_BASE_16
:
1690 printf("0x%" PRIx16
, v
);
1697 case SIDE_DYNAMIC_TYPE_S32
:
1701 v
= item
->u
.side_basic
.u
.side_u32
;
1702 if (dynamic_type_to_host_reverse_bo(item
))
1703 v
= side_bswap_32(v
);
1704 tracer_print_dynamic_basic_type_header(item
);
1706 case TRACER_DISPLAY_BASE_2
:
1707 print_integer_binary(v
, 32);
1709 case TRACER_DISPLAY_BASE_8
:
1710 printf("0%" PRIo32
, v
);
1712 case TRACER_DISPLAY_BASE_10
:
1713 printf("%" PRId32
, v
);
1715 case TRACER_DISPLAY_BASE_16
:
1716 printf("0x%" PRIx32
, v
);
1723 case SIDE_DYNAMIC_TYPE_S64
:
1727 v
= item
->u
.side_basic
.u
.side_u64
;
1728 if (dynamic_type_to_host_reverse_bo(item
))
1729 v
= side_bswap_64(v
);
1730 tracer_print_dynamic_basic_type_header(item
);
1732 case TRACER_DISPLAY_BASE_2
:
1733 print_integer_binary(v
, 64);
1735 case TRACER_DISPLAY_BASE_8
:
1736 printf("0%" PRIo64
, v
);
1738 case TRACER_DISPLAY_BASE_10
:
1739 printf("%" PRId64
, v
);
1741 case TRACER_DISPLAY_BASE_16
:
1742 printf("0x%" PRIx64
, v
);
1749 case SIDE_DYNAMIC_TYPE_BYTE
:
1750 tracer_print_dynamic_basic_type_header(item
);
1751 printf("0x%" PRIx8
, item
->u
.side_basic
.u
.side_byte
);
1753 case SIDE_DYNAMIC_TYPE_POINTER32
:
1757 v
= item
->u
.side_basic
.u
.side_u32
;
1758 if (dynamic_type_to_host_reverse_bo(item
))
1759 v
= side_bswap_32(v
);
1760 tracer_print_dynamic_basic_type_header(item
);
1761 printf("0x%" PRIx32
, v
);
1765 case SIDE_DYNAMIC_TYPE_POINTER64
:
1769 v
= item
->u
.side_basic
.u
.side_u64
;
1770 if (dynamic_type_to_host_reverse_bo(item
))
1771 v
= side_bswap_64(v
);
1772 tracer_print_dynamic_basic_type_header(item
);
1773 printf("0x%" PRIx64
, v
);
1777 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
1784 .f
= item
->u
.side_basic
.u
.side_float_binary16
,
1787 if (dynamic_type_to_host_reverse_bo(item
))
1788 float16
.u
= side_bswap_16(float16
.u
);
1789 tracer_print_dynamic_basic_type_header(item
);
1790 printf("%g", (double) float16
.f
);
1793 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
1797 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
1804 .f
= item
->u
.side_basic
.u
.side_float_binary32
,
1807 if (dynamic_type_to_host_reverse_bo(item
))
1808 float32
.u
= side_bswap_32(float32
.u
);
1809 tracer_print_dynamic_basic_type_header(item
);
1810 printf("%g", (double) float32
.f
);
1813 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
1817 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
1824 .f
= item
->u
.side_basic
.u
.side_float_binary64
,
1827 if (dynamic_type_to_host_reverse_bo(item
))
1828 float64
.u
= side_bswap_64(float64
.u
);
1829 tracer_print_dynamic_basic_type_header(item
);
1830 printf("%g", (double) float64
.f
);
1833 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
1837 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
1844 .f
= item
->u
.side_basic
.u
.side_float_binary128
,
1847 if (dynamic_type_to_host_reverse_bo(item
))
1848 side_bswap_128p(float128
.arr
);
1849 tracer_print_dynamic_basic_type_header(item
);
1850 printf("%Lg", (long double) float128
.f
);
1853 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
1857 case SIDE_DYNAMIC_TYPE_STRING
:
1858 tracer_print_dynamic_basic_type_header(item
);
1859 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_basic
.u
.string
);
1861 case SIDE_DYNAMIC_TYPE_STRUCT
:
1862 tracer_print_dynamic_struct(item
->u
.side_dynamic_struct
);
1864 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
:
1865 tracer_print_dynamic_struct_visitor(item
);
1867 case SIDE_DYNAMIC_TYPE_VLA
:
1868 tracer_print_dynamic_vla(item
->u
.side_dynamic_vla
);
1870 case SIDE_DYNAMIC_TYPE_VLA_VISITOR
:
1871 tracer_print_dynamic_vla_visitor(item
);
1874 fprintf(stderr
, "<UNKNOWN TYPE>");
1881 void tracer_print_static_fields(const struct side_event_description
*desc
,
1882 const struct side_arg_vec_description
*sav_desc
,
1885 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1886 uint32_t side_sav_len
= sav_desc
->len
;
1889 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1890 if (desc
->nr_fields
!= side_sav_len
) {
1891 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1894 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1895 printf("%s", side_sav_len
? ", fields: [ " : "");
1896 for (i
= 0; i
< side_sav_len
; i
++) {
1897 printf("%s", i
? ", " : "");
1898 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1906 void tracer_call(const struct side_event_description
*desc
,
1907 const struct side_arg_vec_description
*sav_desc
,
1908 void *priv
__attribute__((unused
)))
1912 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
1916 void tracer_call_variadic(const struct side_event_description
*desc
,
1917 const struct side_arg_vec_description
*sav_desc
,
1918 const struct side_arg_dynamic_event_struct
*var_struct
,
1919 void *priv
__attribute__((unused
)))
1921 uint32_t var_struct_len
= var_struct
->len
;
1922 int nr_fields
= 0, i
;
1924 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
1926 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1927 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1930 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1931 printf("%s", var_struct_len
? ", fields:: [ " : "");
1932 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1933 printf("%s", i
? ", " : "");
1934 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1935 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1942 void tracer_event_notification(enum side_tracer_notification notif
,
1943 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1948 printf("----------------------------------------------------------\n");
1949 printf("Tracer notified of events %s\n",
1950 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1951 for (i
= 0; i
< nr_events
; i
++) {
1952 struct side_event_description
*event
= events
[i
];
1954 /* Skip NULL pointers */
1957 printf("provider: %s, event: %s\n",
1958 event
->provider_name
, event
->event_name
);
1959 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1960 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1961 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1965 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1970 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1971 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1975 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1981 printf("----------------------------------------------------------\n");
1984 static __attribute__((constructor
))
1985 void tracer_init(void);
1987 void tracer_init(void)
1989 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1994 static __attribute__((destructor
))
1995 void tracer_exit(void);
1997 void tracer_exit(void)
1999 side_tracer_event_notification_unregister(tracer_handle
);