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
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
27 void tracer_print_sg_struct(const struct side_type_sg
*type_sg
, const void *_ptr
);
29 void tracer_print_sg_integer_type(const struct side_type_sg
*type_sg
, const void *_ptr
);
31 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
33 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
35 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
);
37 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
39 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
41 void tracer_print_dynamic(const struct side_arg
*dynamic_item
);
43 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
46 int64_t get_attr_integer_value(const struct side_attr
*attr
)
50 switch (attr
->value
.type
) {
51 case SIDE_ATTR_TYPE_U8
:
52 val
= attr
->value
.u
.integer_value
.side_u8
;
54 case SIDE_ATTR_TYPE_U16
:
55 val
= attr
->value
.u
.integer_value
.side_u16
;
57 case SIDE_ATTR_TYPE_U32
:
58 val
= attr
->value
.u
.integer_value
.side_u32
;
60 case SIDE_ATTR_TYPE_U64
:
61 val
= attr
->value
.u
.integer_value
.side_u64
;
63 case SIDE_ATTR_TYPE_S8
:
64 val
= attr
->value
.u
.integer_value
.side_s8
;
66 case SIDE_ATTR_TYPE_S16
:
67 val
= attr
->value
.u
.integer_value
.side_s16
;
69 case SIDE_ATTR_TYPE_S32
:
70 val
= attr
->value
.u
.integer_value
.side_s32
;
72 case SIDE_ATTR_TYPE_S64
:
73 val
= attr
->value
.u
.integer_value
.side_s64
;
76 fprintf(stderr
, "Unexpected attribute type\n");
83 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
84 enum tracer_display_base default_base
)
88 for (i
= 0; i
< nr_attr
; i
++) {
89 const struct side_attr
*attr
= &_attr
[i
];
91 if (!strcmp(attr
->key
, "std.integer.base")) {
92 int64_t val
= get_attr_integer_value(attr
);
96 return TRACER_DISPLAY_BASE_2
;
98 return TRACER_DISPLAY_BASE_8
;
100 return TRACER_DISPLAY_BASE_10
;
102 return TRACER_DISPLAY_BASE_16
;
104 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
109 return default_base
; /* Default */
113 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
115 switch (type_desc
->type
) {
126 case SIDE_TYPE_POINTER32
:
127 case SIDE_TYPE_POINTER64
:
128 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
133 case SIDE_TYPE_FLOAT_BINARY16
:
134 case SIDE_TYPE_FLOAT_BINARY32
:
135 case SIDE_TYPE_FLOAT_BINARY64
:
136 case SIDE_TYPE_FLOAT_BINARY128
:
137 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
143 fprintf(stderr
, "Unexpected type\n");
149 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
151 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
152 switch (attr
->value
.type
) {
153 case SIDE_ATTR_TYPE_BOOL
:
154 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
156 case SIDE_ATTR_TYPE_U8
:
157 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
159 case SIDE_ATTR_TYPE_U16
:
160 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
162 case SIDE_ATTR_TYPE_U32
:
163 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
165 case SIDE_ATTR_TYPE_U64
:
166 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
168 case SIDE_ATTR_TYPE_S8
:
169 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
171 case SIDE_ATTR_TYPE_S16
:
172 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
174 case SIDE_ATTR_TYPE_S32
:
175 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
177 case SIDE_ATTR_TYPE_S64
:
178 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
180 case SIDE_ATTR_TYPE_POINTER32
:
181 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
183 case SIDE_ATTR_TYPE_POINTER64
:
184 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
186 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
188 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
191 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
194 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
196 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
199 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
202 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
204 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
207 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
210 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
212 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
215 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
218 case SIDE_ATTR_TYPE_STRING
:
219 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
222 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
229 void print_attributes(const char *prefix_str
, const char *separator
,
230 const struct side_attr
*attr
, uint32_t nr_attr
)
236 printf("%s%s [ ", prefix_str
, separator
);
237 for (i
= 0; i
< nr_attr
; i
++) {
238 printf("%s", i
? ", " : "");
239 tracer_print_attr_type(separator
, &attr
[i
]);
245 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
247 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
248 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
249 int i
, print_count
= 0;
252 if (elem_type
->type
!= item
->type
) {
253 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
256 switch (item
->type
) {
258 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
264 v
= item
->u
.side_static
.integer_value
.side_u16
;
265 if (type_to_host_reverse_bo(elem_type
))
266 v
= side_bswap_16(v
);
274 v
= item
->u
.side_static
.integer_value
.side_u32
;
275 if (type_to_host_reverse_bo(elem_type
))
276 v
= side_bswap_32(v
);
284 v
= item
->u
.side_static
.integer_value
.side_u64
;
285 if (type_to_host_reverse_bo(elem_type
))
286 v
= side_bswap_64(v
);
291 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
297 v
= item
->u
.side_static
.integer_value
.side_s16
;
298 if (type_to_host_reverse_bo(elem_type
))
299 v
= side_bswap_16(v
);
307 v
= item
->u
.side_static
.integer_value
.side_s32
;
308 if (type_to_host_reverse_bo(elem_type
))
309 v
= side_bswap_32(v
);
317 v
= item
->u
.side_static
.integer_value
.side_s64
;
318 if (type_to_host_reverse_bo(elem_type
))
319 v
= side_bswap_64(v
);
324 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
327 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
328 printf("%s", mappings
->nr_attr
? ", " : "");
329 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
330 printf(", labels: [ ");
331 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
332 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
334 if (mapping
->range_end
< mapping
->range_begin
) {
335 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
336 mapping
->range_begin
, mapping
->range_end
);
339 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
340 printf("%s", print_count
++ ? ", " : "");
341 printf("\"%s\"", mapping
->label
);
345 printf("<NO LABEL>");
350 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
354 switch (elem_type
->type
) {
355 case SIDE_TYPE_U8
: /* Fall-through */
369 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
376 void print_enum_bitmap(const struct side_type
*type_desc
,
377 const struct side_arg
*item
)
379 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
380 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
381 int i
, print_count
= 0;
382 uint32_t stride_bit
, nr_items
;
383 bool reverse_byte_order
= false;
384 const struct side_arg
*array_item
;
386 switch (elem_type
->type
) {
387 case SIDE_TYPE_U8
: /* Fall-through */
388 case SIDE_TYPE_BYTE
: /* Fall-through */
389 case SIDE_TYPE_U16
: /* Fall-through */
390 case SIDE_TYPE_U32
: /* Fall-through */
392 stride_bit
= enum_elem_type_to_stride(elem_type
);
393 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
397 case SIDE_TYPE_ARRAY
:
398 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
399 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
400 array_item
= item
->u
.side_static
.side_array
->sav
;
401 nr_items
= type_desc
->u
.side_array
.length
;
404 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
405 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
406 array_item
= item
->u
.side_static
.side_vla
->sav
;
407 nr_items
= item
->u
.side_static
.side_vla
->len
;
410 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
414 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
415 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
416 printf("labels: [ ");
417 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
418 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
422 if (mapping
->range_end
< mapping
->range_begin
) {
423 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
424 mapping
->range_begin
, mapping
->range_end
);
427 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
428 if (bit
> (nr_items
* stride_bit
) - 1)
430 switch (stride_bit
) {
433 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
434 if (v
& (1ULL << (bit
% 8))) {
442 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
443 if (reverse_byte_order
)
444 v
= side_bswap_16(v
);
445 if (v
& (1ULL << (bit
% 16))) {
453 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
454 if (reverse_byte_order
)
455 v
= side_bswap_32(v
);
456 if (v
& (1ULL << (bit
% 32))) {
464 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
465 if (reverse_byte_order
)
466 v
= side_bswap_64(v
);
467 if (v
& (1ULL << (bit
% 64))) {
479 printf("%s", print_count
++ ? ", " : "");
480 printf("\"%s\"", mapping
->label
);
484 printf("<NO LABEL>");
489 void print_integer_binary(uint64_t v
, int bits
)
495 for (i
= 0; i
< bits
; i
++) {
496 printf("%c", v
& (1ULL << 63) ? '1' : '0');
502 void tracer_print_type_header(const char *separator
,
503 const struct side_attr
*attr
, uint32_t nr_attr
)
505 print_attributes("attr", separator
, attr
, nr_attr
);
506 printf("%s", nr_attr
? ", " : "");
507 printf("value%s ", separator
);
511 void tracer_print_type_integer(const char *separator
,
512 const struct side_type_integer
*type_integer
,
513 const union side_integer_value
*value
,
514 uint16_t offset_bits
,
515 enum tracer_display_base default_base
)
517 enum tracer_display_base base
;
524 if (!type_integer
->len_bits
||
525 type_integer
->len_bits
+ offset_bits
> type_integer
->integer_size_bits
)
527 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
528 base
= get_attr_display_base(type_integer
->attr
,
529 type_integer
->nr_attr
,
531 switch (type_integer
->integer_size_bits
) {
533 if (type_integer
->signedness
)
534 v
.v_signed
= value
->side_s8
;
536 v
.v_unsigned
= value
->side_u8
;
539 if (type_integer
->signedness
) {
542 side_s16
= value
->side_s16
;
544 side_s16
= side_bswap_16(side_s16
);
545 v
.v_signed
= side_s16
;
549 side_u16
= value
->side_u16
;
551 side_u16
= side_bswap_16(side_u16
);
552 v
.v_unsigned
= side_u16
;
556 if (type_integer
->signedness
) {
559 side_s32
= value
->side_s32
;
561 side_s32
= side_bswap_32(side_s32
);
562 v
.v_signed
= side_s32
;
566 side_u32
= value
->side_u32
;
568 side_u32
= side_bswap_32(side_u32
);
569 v
.v_unsigned
= side_u32
;
573 if (type_integer
->signedness
) {
576 side_s64
= value
->side_s64
;
578 side_s64
= side_bswap_64(side_s64
);
579 v
.v_signed
= side_s64
;
583 side_u64
= value
->side_u64
;
585 side_u64
= side_bswap_64(side_u64
);
586 v
.v_unsigned
= side_u64
;
592 v
.v_unsigned
>>= offset_bits
;
593 if (type_integer
->len_bits
< 64)
594 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
595 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
597 case TRACER_DISPLAY_BASE_2
:
598 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
600 case TRACER_DISPLAY_BASE_8
:
601 printf("0%" PRIo64
, v
.v_unsigned
);
603 case TRACER_DISPLAY_BASE_10
:
604 if (type_integer
->signedness
) {
606 if (type_integer
->len_bits
< 64) {
607 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
608 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
610 printf("%" PRId64
, v
.v_signed
);
612 printf("%" PRIu64
, v
.v_unsigned
);
615 case TRACER_DISPLAY_BASE_16
:
616 printf("0x%" PRIx64
, v
.v_unsigned
);
624 void tracer_print_type_float(const char *separator
,
625 const struct side_type_float
*type_float
,
626 const union side_float_value
*value
)
630 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
631 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
632 switch (type_float
->float_size_bits
) {
640 .f
= value
->side_float_binary16
,
644 float16
.u
= side_bswap_16(float16
.u
);
645 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
646 printf("%g", (double) float16
.f
);
649 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
660 .f
= value
->side_float_binary32
,
664 float32
.u
= side_bswap_32(float32
.u
);
665 printf("%g", (double) float32
.f
);
668 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
679 .f
= value
->side_float_binary64
,
683 float64
.u
= side_bswap_64(float64
.u
);
684 printf("%g", (double) float64
.f
);
687 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
698 .f
= value
->side_float_binary128
,
702 side_bswap_128p(float128
.arr
);
703 printf("%Lg", (long double) float128
.f
);
706 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
711 fprintf(stderr
, "ERROR: Unknown float size\n");
717 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
719 enum side_type_label type
;
721 switch (type_desc
->type
) {
722 case SIDE_TYPE_ARRAY
:
723 switch (item
->type
) {
724 case SIDE_TYPE_ARRAY_U8
:
725 case SIDE_TYPE_ARRAY_U16
:
726 case SIDE_TYPE_ARRAY_U32
:
727 case SIDE_TYPE_ARRAY_U64
:
728 case SIDE_TYPE_ARRAY_S8
:
729 case SIDE_TYPE_ARRAY_S16
:
730 case SIDE_TYPE_ARRAY_S32
:
731 case SIDE_TYPE_ARRAY_S64
:
732 case SIDE_TYPE_ARRAY_POINTER32
:
733 case SIDE_TYPE_ARRAY_POINTER64
:
734 case SIDE_TYPE_ARRAY_BYTE
:
735 case SIDE_TYPE_ARRAY
:
738 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
745 switch (item
->type
) {
746 case SIDE_TYPE_VLA_U8
:
747 case SIDE_TYPE_VLA_U16
:
748 case SIDE_TYPE_VLA_U32
:
749 case SIDE_TYPE_VLA_U64
:
750 case SIDE_TYPE_VLA_S8
:
751 case SIDE_TYPE_VLA_S16
:
752 case SIDE_TYPE_VLA_S32
:
753 case SIDE_TYPE_VLA_S64
:
754 case SIDE_TYPE_VLA_BYTE
:
755 case SIDE_TYPE_VLA_POINTER32
:
756 case SIDE_TYPE_VLA_POINTER64
:
760 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
767 switch (item
->type
) {
778 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
784 case SIDE_TYPE_ENUM_BITMAP
:
785 switch (item
->type
) {
791 case SIDE_TYPE_ARRAY
:
795 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
801 case SIDE_TYPE_DYNAMIC
:
802 switch (item
->type
) {
803 case SIDE_TYPE_DYNAMIC_NULL
:
804 case SIDE_TYPE_DYNAMIC_BOOL
:
805 case SIDE_TYPE_DYNAMIC_U8
:
806 case SIDE_TYPE_DYNAMIC_U16
:
807 case SIDE_TYPE_DYNAMIC_U32
:
808 case SIDE_TYPE_DYNAMIC_U64
:
809 case SIDE_TYPE_DYNAMIC_S8
:
810 case SIDE_TYPE_DYNAMIC_S16
:
811 case SIDE_TYPE_DYNAMIC_S32
:
812 case SIDE_TYPE_DYNAMIC_S64
:
813 case SIDE_TYPE_DYNAMIC_BYTE
:
814 case SIDE_TYPE_DYNAMIC_POINTER32
:
815 case SIDE_TYPE_DYNAMIC_POINTER64
:
816 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
817 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
818 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
819 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
820 case SIDE_TYPE_DYNAMIC_STRING
:
821 case SIDE_TYPE_DYNAMIC_STRUCT
:
822 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
823 case SIDE_TYPE_DYNAMIC_VLA
:
824 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
827 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
834 if (type_desc
->type
!= item
->type
) {
835 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
841 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
842 type
= type_desc
->type
;
849 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
850 printf("<NULL TYPE>");
854 tracer_print_type_header(":", type_desc
->u
.side_bool
.attr
, type_desc
->u
.side_bool
.nr_attr
);
855 printf("%s", item
->u
.side_static
.bool_value
? "true" : "false");
866 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
867 TRACER_DISPLAY_BASE_10
);
870 case SIDE_TYPE_POINTER32
:
871 case SIDE_TYPE_POINTER64
:
872 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
873 TRACER_DISPLAY_BASE_16
);
877 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
878 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
882 print_enum(type_desc
, item
);
885 case SIDE_TYPE_ENUM_BITMAP
:
886 print_enum_bitmap(type_desc
, item
);
889 case SIDE_TYPE_FLOAT_BINARY16
:
890 case SIDE_TYPE_FLOAT_BINARY32
:
891 case SIDE_TYPE_FLOAT_BINARY64
:
892 case SIDE_TYPE_FLOAT_BINARY128
:
893 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
896 case SIDE_TYPE_STRING
:
897 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
898 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
900 case SIDE_TYPE_STRUCT
:
901 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
903 case SIDE_TYPE_SG_STRUCT
:
904 tracer_print_sg_struct(&type_desc
->u
.side_sg
, &item
->u
.side_static
.side_struct_sg_ptr
);
906 case SIDE_TYPE_SG_UNSIGNED_INT
:
907 case SIDE_TYPE_SG_SIGNED_INT
:
908 tracer_print_sg_integer_type(&type_desc
->u
.side_sg
, item
->u
.side_static
.side_integer_sg_ptr
);
910 case SIDE_TYPE_ARRAY
:
911 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
914 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
916 case SIDE_TYPE_VLA_VISITOR
:
917 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
919 case SIDE_TYPE_ARRAY_U8
:
920 case SIDE_TYPE_ARRAY_U16
:
921 case SIDE_TYPE_ARRAY_U32
:
922 case SIDE_TYPE_ARRAY_U64
:
923 case SIDE_TYPE_ARRAY_S8
:
924 case SIDE_TYPE_ARRAY_S16
:
925 case SIDE_TYPE_ARRAY_S32
:
926 case SIDE_TYPE_ARRAY_S64
:
927 case SIDE_TYPE_ARRAY_BYTE
:
928 case SIDE_TYPE_ARRAY_POINTER32
:
929 case SIDE_TYPE_ARRAY_POINTER64
:
930 tracer_print_array_fixint(type_desc
, item
);
932 case SIDE_TYPE_VLA_U8
:
933 case SIDE_TYPE_VLA_U16
:
934 case SIDE_TYPE_VLA_U32
:
935 case SIDE_TYPE_VLA_U64
:
936 case SIDE_TYPE_VLA_S8
:
937 case SIDE_TYPE_VLA_S16
:
938 case SIDE_TYPE_VLA_S32
:
939 case SIDE_TYPE_VLA_S64
:
940 case SIDE_TYPE_VLA_BYTE
:
941 case SIDE_TYPE_VLA_POINTER32
:
942 case SIDE_TYPE_VLA_POINTER64
:
943 tracer_print_vla_fixint(type_desc
, item
);
947 case SIDE_TYPE_DYNAMIC_NULL
:
948 case SIDE_TYPE_DYNAMIC_BOOL
:
949 case SIDE_TYPE_DYNAMIC_U8
:
950 case SIDE_TYPE_DYNAMIC_U16
:
951 case SIDE_TYPE_DYNAMIC_U32
:
952 case SIDE_TYPE_DYNAMIC_U64
:
953 case SIDE_TYPE_DYNAMIC_S8
:
954 case SIDE_TYPE_DYNAMIC_S16
:
955 case SIDE_TYPE_DYNAMIC_S32
:
956 case SIDE_TYPE_DYNAMIC_S64
:
957 case SIDE_TYPE_DYNAMIC_BYTE
:
958 case SIDE_TYPE_DYNAMIC_POINTER32
:
959 case SIDE_TYPE_DYNAMIC_POINTER64
:
960 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
961 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
962 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
963 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
964 case SIDE_TYPE_DYNAMIC_STRING
:
965 case SIDE_TYPE_DYNAMIC_STRUCT
:
966 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
967 case SIDE_TYPE_DYNAMIC_VLA
:
968 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
969 tracer_print_dynamic(item
);
972 fprintf(stderr
, "<UNKNOWN TYPE>");
979 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
981 printf("%s: ", item_desc
->field_name
);
982 tracer_print_type(&item_desc
->side_type
, item
);
986 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
988 const struct side_arg
*sav
= side_arg_vec
->sav
;
989 uint32_t side_sav_len
= side_arg_vec
->len
;
992 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
993 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
996 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
997 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
998 printf("fields: { ");
999 for (i
= 0; i
< side_sav_len
; i
++) {
1000 printf("%s", i
? ", " : "");
1001 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1007 void tracer_print_sg_integer_type(const struct side_type_sg
*type_sg
, const void *_ptr
)
1009 const char *ptr
= (const char *) _ptr
;
1010 union side_integer_value value
;
1012 switch (type_sg
->u
.side_integer
.type
.integer_size_bits
) {
1021 memcpy(&value
, ptr
+ type_sg
->offset
, type_sg
->u
.side_integer
.type
.integer_size_bits
>> 3);
1022 tracer_print_type_integer(":", &type_sg
->u
.side_integer
.type
, &value
,
1023 type_sg
->u
.side_integer
.offset_bits
, TRACER_DISPLAY_BASE_10
);
1027 void tracer_print_sg_type(const struct side_type
*type_desc
, void *ptr
)
1030 switch (type_desc
->type
) {
1031 case SIDE_TYPE_SG_UNSIGNED_INT
:
1032 case SIDE_TYPE_SG_SIGNED_INT
:
1033 tracer_print_sg_integer_type(&type_desc
->u
.side_sg
, ptr
);
1035 case SIDE_TYPE_SG_STRUCT
:
1036 tracer_print_sg_struct(&type_desc
->u
.side_sg
, ptr
);
1039 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER TYPE>");
1046 void tracer_print_sg_field(const struct side_event_field
*field
, void *ptr
)
1048 printf("%s: ", field
->field_name
);
1049 tracer_print_sg_type(&field
->side_type
, ptr
);
1053 void tracer_print_sg_struct(const struct side_type_sg
*type_sg
, const void *_ptr
)
1055 char *ptr
= (char *) _ptr
;
1058 memcpy(&ptr
, ptr
+ type_sg
->offset
, sizeof(ptr
));
1059 print_attributes("attr", ":", type_sg
->u
.side_struct
->attr
, type_sg
->u
.side_struct
->nr_attr
);
1060 printf("%s", type_sg
->u
.side_struct
->nr_attr
? ", " : "");
1061 printf("fields: { ");
1062 for (i
= 0; i
< type_sg
->u
.side_struct
->nr_fields
; i
++) {
1063 printf("%s", i
? ", " : "");
1064 tracer_print_sg_field(&type_sg
->u
.side_struct
->fields
[i
], ptr
);
1070 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1072 const struct side_arg
*sav
= side_arg_vec
->sav
;
1073 uint32_t side_sav_len
= side_arg_vec
->len
;
1076 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1077 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1080 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1081 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1082 printf("elements: ");
1084 for (i
= 0; i
< side_sav_len
; i
++) {
1085 printf("%s", i
? ", " : "");
1086 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1092 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1094 const struct side_arg
*sav
= side_arg_vec
->sav
;
1095 uint32_t side_sav_len
= side_arg_vec
->len
;
1098 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1099 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1100 printf("elements: ");
1102 for (i
= 0; i
< side_sav_len
; i
++) {
1103 printf("%s", i
? ", " : "");
1104 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1109 struct tracer_visitor_priv
{
1110 const struct side_type
*elem_type
;
1115 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1116 const struct side_arg
*elem
)
1118 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1120 printf("%s", tracer_priv
->i
++ ? ", " : "");
1121 tracer_print_type(tracer_priv
->elem_type
, elem
);
1122 return SIDE_VISITOR_STATUS_OK
;
1126 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1128 enum side_visitor_status status
;
1129 struct tracer_visitor_priv tracer_priv
= {
1130 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1133 const struct side_tracer_visitor_ctx tracer_ctx
= {
1134 .write_elem
= tracer_write_elem_cb
,
1135 .priv
= &tracer_priv
,
1138 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1139 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1140 printf("elements: ");
1142 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1144 case SIDE_VISITOR_STATUS_OK
:
1146 case SIDE_VISITOR_STATUS_ERROR
:
1147 fprintf(stderr
, "ERROR: Visitor error\n");
1153 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1155 const struct side_type
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1156 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
1157 void *p
= item
->u
.side_static
.side_array_fixint
;
1158 enum side_type_label side_type
;
1161 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1162 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1163 printf("elements: ");
1164 switch (item
->type
) {
1165 case SIDE_TYPE_ARRAY_U8
:
1166 if (elem_type
->type
!= SIDE_TYPE_U8
)
1169 case SIDE_TYPE_ARRAY_U16
:
1170 if (elem_type
->type
!= SIDE_TYPE_U16
)
1173 case SIDE_TYPE_ARRAY_U32
:
1174 if (elem_type
->type
!= SIDE_TYPE_U32
)
1177 case SIDE_TYPE_ARRAY_U64
:
1178 if (elem_type
->type
!= SIDE_TYPE_U64
)
1181 case SIDE_TYPE_ARRAY_S8
:
1182 if (elem_type
->type
!= SIDE_TYPE_S8
)
1185 case SIDE_TYPE_ARRAY_S16
:
1186 if (elem_type
->type
!= SIDE_TYPE_S16
)
1189 case SIDE_TYPE_ARRAY_S32
:
1190 if (elem_type
->type
!= SIDE_TYPE_S32
)
1193 case SIDE_TYPE_ARRAY_S64
:
1194 if (elem_type
->type
!= SIDE_TYPE_S64
)
1197 case SIDE_TYPE_ARRAY_BYTE
:
1198 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1201 case SIDE_TYPE_ARRAY_POINTER32
:
1202 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1204 case SIDE_TYPE_ARRAY_POINTER64
:
1205 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1211 side_type
= elem_type
->type
;
1214 for (i
= 0; i
< side_sav_len
; i
++) {
1215 struct side_arg sav_elem
= {
1219 switch (side_type
) {
1221 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1224 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1227 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1230 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1233 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1236 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1239 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1242 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1244 case SIDE_TYPE_BYTE
:
1245 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1247 case SIDE_TYPE_POINTER32
:
1248 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1250 case SIDE_TYPE_POINTER64
:
1251 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1255 fprintf(stderr
, "ERROR: Unexpected type\n");
1259 printf("%s", i
? ", " : "");
1260 tracer_print_type(elem_type
, &sav_elem
);
1266 fprintf(stderr
, "ERROR: type mismatch\n");
1270 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1272 const struct side_type
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1273 uint32_t side_sav_len
= item
->u
.side_static
.side_vla_fixint
.length
;
1274 void *p
= item
->u
.side_static
.side_vla_fixint
.p
;
1275 enum side_type_label side_type
;
1278 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1279 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1280 printf("elements: ");
1281 switch (item
->type
) {
1282 case SIDE_TYPE_VLA_U8
:
1283 if (elem_type
->type
!= SIDE_TYPE_U8
)
1286 case SIDE_TYPE_VLA_U16
:
1287 if (elem_type
->type
!= SIDE_TYPE_U16
)
1290 case SIDE_TYPE_VLA_U32
:
1291 if (elem_type
->type
!= SIDE_TYPE_U32
)
1294 case SIDE_TYPE_VLA_U64
:
1295 if (elem_type
->type
!= SIDE_TYPE_U64
)
1298 case SIDE_TYPE_VLA_S8
:
1299 if (elem_type
->type
!= SIDE_TYPE_S8
)
1302 case SIDE_TYPE_VLA_S16
:
1303 if (elem_type
->type
!= SIDE_TYPE_S16
)
1306 case SIDE_TYPE_VLA_S32
:
1307 if (elem_type
->type
!= SIDE_TYPE_S32
)
1310 case SIDE_TYPE_VLA_S64
:
1311 if (elem_type
->type
!= SIDE_TYPE_S64
)
1314 case SIDE_TYPE_VLA_BYTE
:
1315 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1318 case SIDE_TYPE_VLA_POINTER32
:
1319 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1321 case SIDE_TYPE_VLA_POINTER64
:
1322 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1328 side_type
= elem_type
->type
;
1331 for (i
= 0; i
< side_sav_len
; i
++) {
1332 struct side_arg sav_elem
= {
1336 switch (side_type
) {
1338 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1341 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1344 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1347 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1350 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1353 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1356 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1359 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1361 case SIDE_TYPE_BYTE
:
1362 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1364 case SIDE_TYPE_POINTER32
:
1365 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1367 case SIDE_TYPE_POINTER64
:
1368 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1372 fprintf(stderr
, "ERROR: Unexpected type\n");
1376 printf("%s", i
? ", " : "");
1377 tracer_print_type(elem_type
, &sav_elem
);
1383 fprintf(stderr
, "ERROR: type mismatch\n");
1388 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
1390 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
1391 uint32_t len
= dynamic_struct
->len
;
1394 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1395 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1396 printf("fields:: ");
1398 for (i
= 0; i
< len
; i
++) {
1399 printf("%s", i
? ", " : "");
1400 printf("%s:: ", fields
[i
].field_name
);
1401 tracer_print_dynamic(&fields
[i
].elem
);
1406 struct tracer_dynamic_struct_visitor_priv
{
1411 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1412 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1413 const struct side_arg_dynamic_event_field
*dynamic_field
)
1415 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1417 printf("%s", tracer_priv
->i
++ ? ", " : "");
1418 printf("%s:: ", dynamic_field
->field_name
);
1419 tracer_print_dynamic(&dynamic_field
->elem
);
1420 return SIDE_VISITOR_STATUS_OK
;
1424 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1426 enum side_visitor_status status
;
1427 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1430 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1431 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1432 .priv
= &tracer_priv
,
1434 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1436 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1437 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1438 printf("fields:: ");
1440 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1442 case SIDE_VISITOR_STATUS_OK
:
1444 case SIDE_VISITOR_STATUS_ERROR
:
1445 fprintf(stderr
, "ERROR: Visitor error\n");
1452 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1454 const struct side_arg
*sav
= vla
->sav
;
1455 uint32_t side_sav_len
= vla
->len
;
1458 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1459 printf("%s", vla
->nr_attr
? ", " : "");
1460 printf("elements:: ");
1462 for (i
= 0; i
< side_sav_len
; i
++) {
1463 printf("%s", i
? ", " : "");
1464 tracer_print_dynamic(&sav
[i
]);
1469 struct tracer_dynamic_vla_visitor_priv
{
1474 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1475 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
1476 const struct side_arg
*elem
)
1478 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1480 printf("%s", tracer_priv
->i
++ ? ", " : "");
1481 tracer_print_dynamic(elem
);
1482 return SIDE_VISITOR_STATUS_OK
;
1486 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1488 enum side_visitor_status status
;
1489 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1492 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
1493 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1494 .priv
= &tracer_priv
,
1496 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1498 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1499 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1500 printf("elements:: ");
1502 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1504 case SIDE_VISITOR_STATUS_OK
:
1506 case SIDE_VISITOR_STATUS_ERROR
:
1507 fprintf(stderr
, "ERROR: Visitor error\n");
1514 void tracer_print_dynamic(const struct side_arg
*item
)
1517 switch (item
->type
) {
1518 case SIDE_TYPE_DYNAMIC_NULL
:
1519 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1520 printf("<NULL TYPE>");
1522 case SIDE_TYPE_DYNAMIC_BOOL
:
1523 tracer_print_type_header("::", item
->u
.side_dynamic
.side_bool
.type
.attr
, item
->u
.side_dynamic
.side_bool
.type
.nr_attr
);
1524 printf("%s", item
->u
.side_dynamic
.side_bool
.value
? "true" : "false");
1526 case SIDE_TYPE_DYNAMIC_U8
:
1527 case SIDE_TYPE_DYNAMIC_U16
:
1528 case SIDE_TYPE_DYNAMIC_U32
:
1529 case SIDE_TYPE_DYNAMIC_U64
:
1530 case SIDE_TYPE_DYNAMIC_S8
:
1531 case SIDE_TYPE_DYNAMIC_S16
:
1532 case SIDE_TYPE_DYNAMIC_S32
:
1533 case SIDE_TYPE_DYNAMIC_S64
:
1534 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1535 TRACER_DISPLAY_BASE_10
);
1537 case SIDE_TYPE_DYNAMIC_BYTE
:
1538 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1539 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1542 case SIDE_TYPE_DYNAMIC_POINTER32
:
1543 case SIDE_TYPE_DYNAMIC_POINTER64
:
1544 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1545 TRACER_DISPLAY_BASE_16
);
1548 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
1549 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
1550 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
1551 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
1552 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1553 &item
->u
.side_dynamic
.side_float
.value
);
1556 case SIDE_TYPE_DYNAMIC_STRING
:
1557 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1558 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1560 case SIDE_TYPE_DYNAMIC_STRUCT
:
1561 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1563 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1564 tracer_print_dynamic_struct_visitor(item
);
1566 case SIDE_TYPE_DYNAMIC_VLA
:
1567 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1569 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1570 tracer_print_dynamic_vla_visitor(item
);
1573 fprintf(stderr
, "<UNKNOWN TYPE>");
1580 void tracer_print_static_fields(const struct side_event_description
*desc
,
1581 const struct side_arg_vec
*side_arg_vec
,
1584 const struct side_arg
*sav
= side_arg_vec
->sav
;
1585 uint32_t side_sav_len
= side_arg_vec
->len
;
1588 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1589 if (desc
->nr_fields
!= side_sav_len
) {
1590 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1593 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1594 printf("%s", side_sav_len
? ", fields: [ " : "");
1595 for (i
= 0; i
< side_sav_len
; i
++) {
1596 printf("%s", i
? ", " : "");
1597 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1605 void tracer_call(const struct side_event_description
*desc
,
1606 const struct side_arg_vec
*side_arg_vec
,
1607 void *priv
__attribute__((unused
)))
1611 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1615 void tracer_call_variadic(const struct side_event_description
*desc
,
1616 const struct side_arg_vec
*side_arg_vec
,
1617 const struct side_arg_dynamic_event_struct
*var_struct
,
1618 void *priv
__attribute__((unused
)))
1620 uint32_t var_struct_len
= var_struct
->len
;
1621 int nr_fields
= 0, i
;
1623 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1625 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1626 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1629 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1630 printf("%s", var_struct_len
? ", fields:: [ " : "");
1631 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1632 printf("%s", i
? ", " : "");
1633 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1634 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1641 void tracer_event_notification(enum side_tracer_notification notif
,
1642 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1647 printf("----------------------------------------------------------\n");
1648 printf("Tracer notified of events %s\n",
1649 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1650 for (i
= 0; i
< nr_events
; i
++) {
1651 struct side_event_description
*event
= events
[i
];
1653 /* Skip NULL pointers */
1656 printf("provider: %s, event: %s\n",
1657 event
->provider_name
, event
->event_name
);
1658 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1659 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1660 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1664 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1669 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1670 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1674 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1680 printf("----------------------------------------------------------\n");
1683 static __attribute__((constructor
))
1684 void tracer_init(void);
1686 void tracer_init(void)
1688 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1693 static __attribute__((destructor
))
1694 void tracer_exit(void);
1696 void tracer_exit(void)
1698 side_tracer_event_notification_unregister(tracer_handle
);