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_sg_float_type(const struct side_type_sg
*type_sg
, const void *_ptr
);
33 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
35 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
37 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
);
39 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
41 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
43 void tracer_print_dynamic(const struct side_arg
*dynamic_item
);
45 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
48 int64_t get_attr_integer_value(const struct side_attr
*attr
)
52 switch (attr
->value
.type
) {
53 case SIDE_ATTR_TYPE_U8
:
54 val
= attr
->value
.u
.integer_value
.side_u8
;
56 case SIDE_ATTR_TYPE_U16
:
57 val
= attr
->value
.u
.integer_value
.side_u16
;
59 case SIDE_ATTR_TYPE_U32
:
60 val
= attr
->value
.u
.integer_value
.side_u32
;
62 case SIDE_ATTR_TYPE_U64
:
63 val
= attr
->value
.u
.integer_value
.side_u64
;
65 case SIDE_ATTR_TYPE_S8
:
66 val
= attr
->value
.u
.integer_value
.side_s8
;
68 case SIDE_ATTR_TYPE_S16
:
69 val
= attr
->value
.u
.integer_value
.side_s16
;
71 case SIDE_ATTR_TYPE_S32
:
72 val
= attr
->value
.u
.integer_value
.side_s32
;
74 case SIDE_ATTR_TYPE_S64
:
75 val
= attr
->value
.u
.integer_value
.side_s64
;
78 fprintf(stderr
, "Unexpected attribute type\n");
85 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
86 enum tracer_display_base default_base
)
90 for (i
= 0; i
< nr_attr
; i
++) {
91 const struct side_attr
*attr
= &_attr
[i
];
93 if (!strcmp(attr
->key
, "std.integer.base")) {
94 int64_t val
= get_attr_integer_value(attr
);
98 return TRACER_DISPLAY_BASE_2
;
100 return TRACER_DISPLAY_BASE_8
;
102 return TRACER_DISPLAY_BASE_10
;
104 return TRACER_DISPLAY_BASE_16
;
106 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
111 return default_base
; /* Default */
115 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
117 switch (type_desc
->type
) {
128 case SIDE_TYPE_POINTER32
:
129 case SIDE_TYPE_POINTER64
:
130 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
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_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
145 fprintf(stderr
, "Unexpected type\n");
151 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
153 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
154 switch (attr
->value
.type
) {
155 case SIDE_ATTR_TYPE_BOOL
:
156 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
158 case SIDE_ATTR_TYPE_U8
:
159 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
161 case SIDE_ATTR_TYPE_U16
:
162 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
164 case SIDE_ATTR_TYPE_U32
:
165 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
167 case SIDE_ATTR_TYPE_U64
:
168 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
170 case SIDE_ATTR_TYPE_S8
:
171 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
173 case SIDE_ATTR_TYPE_S16
:
174 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
176 case SIDE_ATTR_TYPE_S32
:
177 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
179 case SIDE_ATTR_TYPE_S64
:
180 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
182 case SIDE_ATTR_TYPE_POINTER32
:
183 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
185 case SIDE_ATTR_TYPE_POINTER64
:
186 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
188 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
190 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
193 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
196 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
198 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
201 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
204 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
206 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
209 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
212 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
214 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
217 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
220 case SIDE_ATTR_TYPE_STRING
:
221 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
224 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
231 void print_attributes(const char *prefix_str
, const char *separator
,
232 const struct side_attr
*attr
, uint32_t nr_attr
)
238 printf("%s%s [ ", prefix_str
, separator
);
239 for (i
= 0; i
< nr_attr
; i
++) {
240 printf("%s", i
? ", " : "");
241 tracer_print_attr_type(separator
, &attr
[i
]);
247 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
249 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
250 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
251 uint32_t i
, print_count
= 0;
254 if (elem_type
->type
!= item
->type
) {
255 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
258 switch (item
->type
) {
260 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
266 v
= item
->u
.side_static
.integer_value
.side_u16
;
267 if (type_to_host_reverse_bo(elem_type
))
268 v
= side_bswap_16(v
);
276 v
= item
->u
.side_static
.integer_value
.side_u32
;
277 if (type_to_host_reverse_bo(elem_type
))
278 v
= side_bswap_32(v
);
286 v
= item
->u
.side_static
.integer_value
.side_u64
;
287 if (type_to_host_reverse_bo(elem_type
))
288 v
= side_bswap_64(v
);
293 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
299 v
= item
->u
.side_static
.integer_value
.side_s16
;
300 if (type_to_host_reverse_bo(elem_type
))
301 v
= side_bswap_16(v
);
309 v
= item
->u
.side_static
.integer_value
.side_s32
;
310 if (type_to_host_reverse_bo(elem_type
))
311 v
= side_bswap_32(v
);
319 v
= item
->u
.side_static
.integer_value
.side_s64
;
320 if (type_to_host_reverse_bo(elem_type
))
321 v
= side_bswap_64(v
);
326 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
329 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
330 printf("%s", mappings
->nr_attr
? ", " : "");
331 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
332 printf(", labels: [ ");
333 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
334 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
336 if (mapping
->range_end
< mapping
->range_begin
) {
337 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
338 mapping
->range_begin
, mapping
->range_end
);
341 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
342 printf("%s", print_count
++ ? ", " : "");
343 printf("\"%s\"", mapping
->label
);
347 printf("<NO LABEL>");
352 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
356 switch (elem_type
->type
) {
357 case SIDE_TYPE_U8
: /* Fall-through */
371 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
378 void print_enum_bitmap(const struct side_type
*type_desc
,
379 const struct side_arg
*item
)
381 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
382 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
383 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
384 bool reverse_byte_order
= false;
385 const struct side_arg
*array_item
;
387 switch (elem_type
->type
) {
388 case SIDE_TYPE_U8
: /* Fall-through */
389 case SIDE_TYPE_BYTE
: /* Fall-through */
390 case SIDE_TYPE_U16
: /* Fall-through */
391 case SIDE_TYPE_U32
: /* Fall-through */
393 stride_bit
= enum_elem_type_to_stride(elem_type
);
394 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
398 case SIDE_TYPE_ARRAY
:
399 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
400 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
401 array_item
= item
->u
.side_static
.side_array
->sav
;
402 nr_items
= type_desc
->u
.side_array
.length
;
405 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
406 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
407 array_item
= item
->u
.side_static
.side_vla
->sav
;
408 nr_items
= item
->u
.side_static
.side_vla
->len
;
411 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
415 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
416 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
417 printf("labels: [ ");
418 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
419 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
423 if (mapping
->range_end
< mapping
->range_begin
) {
424 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
425 mapping
->range_begin
, mapping
->range_end
);
428 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
429 if (bit
> (nr_items
* stride_bit
) - 1)
431 switch (stride_bit
) {
434 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
435 if (v
& (1ULL << (bit
% 8))) {
443 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
444 if (reverse_byte_order
)
445 v
= side_bswap_16(v
);
446 if (v
& (1ULL << (bit
% 16))) {
454 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
455 if (reverse_byte_order
)
456 v
= side_bswap_32(v
);
457 if (v
& (1ULL << (bit
% 32))) {
465 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
466 if (reverse_byte_order
)
467 v
= side_bswap_64(v
);
468 if (v
& (1ULL << (bit
% 64))) {
480 printf("%s", print_count
++ ? ", " : "");
481 printf("\"%s\"", mapping
->label
);
485 printf("<NO LABEL>");
490 void print_integer_binary(uint64_t v
, int bits
)
496 for (i
= 0; i
< bits
; i
++) {
497 printf("%c", v
& (1ULL << 63) ? '1' : '0');
503 void tracer_print_type_header(const char *separator
,
504 const struct side_attr
*attr
, uint32_t nr_attr
)
506 print_attributes("attr", separator
, attr
, nr_attr
);
507 printf("%s", nr_attr
? ", " : "");
508 printf("value%s ", separator
);
512 void tracer_print_type_integer(const char *separator
,
513 const struct side_type_integer
*type_integer
,
514 const union side_integer_value
*value
,
515 uint16_t offset_bits
,
516 enum tracer_display_base default_base
)
518 enum tracer_display_base base
;
525 if (!type_integer
->len_bits
||
526 type_integer
->len_bits
+ offset_bits
> type_integer
->integer_size_bits
)
528 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
529 base
= get_attr_display_base(type_integer
->attr
,
530 type_integer
->nr_attr
,
532 switch (type_integer
->integer_size_bits
) {
534 if (type_integer
->signedness
)
535 v
.v_signed
= value
->side_s8
;
537 v
.v_unsigned
= value
->side_u8
;
540 if (type_integer
->signedness
) {
543 side_s16
= value
->side_s16
;
545 side_s16
= side_bswap_16(side_s16
);
546 v
.v_signed
= side_s16
;
550 side_u16
= value
->side_u16
;
552 side_u16
= side_bswap_16(side_u16
);
553 v
.v_unsigned
= side_u16
;
557 if (type_integer
->signedness
) {
560 side_s32
= value
->side_s32
;
562 side_s32
= side_bswap_32(side_s32
);
563 v
.v_signed
= side_s32
;
567 side_u32
= value
->side_u32
;
569 side_u32
= side_bswap_32(side_u32
);
570 v
.v_unsigned
= side_u32
;
574 if (type_integer
->signedness
) {
577 side_s64
= value
->side_s64
;
579 side_s64
= side_bswap_64(side_s64
);
580 v
.v_signed
= side_s64
;
584 side_u64
= value
->side_u64
;
586 side_u64
= side_bswap_64(side_u64
);
587 v
.v_unsigned
= side_u64
;
593 v
.v_unsigned
>>= offset_bits
;
594 if (type_integer
->len_bits
< 64)
595 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
596 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
598 case TRACER_DISPLAY_BASE_2
:
599 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
601 case TRACER_DISPLAY_BASE_8
:
602 printf("0%" PRIo64
, v
.v_unsigned
);
604 case TRACER_DISPLAY_BASE_10
:
605 if (type_integer
->signedness
) {
607 if (type_integer
->len_bits
< 64) {
608 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
609 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
611 printf("%" PRId64
, v
.v_signed
);
613 printf("%" PRIu64
, v
.v_unsigned
);
616 case TRACER_DISPLAY_BASE_16
:
617 printf("0x%" PRIx64
, v
.v_unsigned
);
625 void tracer_print_type_float(const char *separator
,
626 const struct side_type_float
*type_float
,
627 const union side_float_value
*value
)
631 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
632 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
633 switch (type_float
->float_size_bits
) {
641 .f
= value
->side_float_binary16
,
645 float16
.u
= side_bswap_16(float16
.u
);
646 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
647 printf("%g", (double) float16
.f
);
650 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
661 .f
= value
->side_float_binary32
,
665 float32
.u
= side_bswap_32(float32
.u
);
666 printf("%g", (double) float32
.f
);
669 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
680 .f
= value
->side_float_binary64
,
684 float64
.u
= side_bswap_64(float64
.u
);
685 printf("%g", (double) float64
.f
);
688 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
699 .f
= value
->side_float_binary128
,
703 side_bswap_128p(float128
.arr
);
704 printf("%Lg", (long double) float128
.f
);
707 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
712 fprintf(stderr
, "ERROR: Unknown float size\n");
718 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
720 enum side_type_label type
;
722 switch (type_desc
->type
) {
723 case SIDE_TYPE_ARRAY
:
724 switch (item
->type
) {
725 case SIDE_TYPE_ARRAY_U8
:
726 case SIDE_TYPE_ARRAY_U16
:
727 case SIDE_TYPE_ARRAY_U32
:
728 case SIDE_TYPE_ARRAY_U64
:
729 case SIDE_TYPE_ARRAY_S8
:
730 case SIDE_TYPE_ARRAY_S16
:
731 case SIDE_TYPE_ARRAY_S32
:
732 case SIDE_TYPE_ARRAY_S64
:
733 case SIDE_TYPE_ARRAY_POINTER32
:
734 case SIDE_TYPE_ARRAY_POINTER64
:
735 case SIDE_TYPE_ARRAY_BYTE
:
736 case SIDE_TYPE_ARRAY
:
739 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
746 switch (item
->type
) {
747 case SIDE_TYPE_VLA_U8
:
748 case SIDE_TYPE_VLA_U16
:
749 case SIDE_TYPE_VLA_U32
:
750 case SIDE_TYPE_VLA_U64
:
751 case SIDE_TYPE_VLA_S8
:
752 case SIDE_TYPE_VLA_S16
:
753 case SIDE_TYPE_VLA_S32
:
754 case SIDE_TYPE_VLA_S64
:
755 case SIDE_TYPE_VLA_BYTE
:
756 case SIDE_TYPE_VLA_POINTER32
:
757 case SIDE_TYPE_VLA_POINTER64
:
761 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
768 switch (item
->type
) {
779 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
785 case SIDE_TYPE_ENUM_BITMAP
:
786 switch (item
->type
) {
792 case SIDE_TYPE_ARRAY
:
796 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
802 case SIDE_TYPE_DYNAMIC
:
803 switch (item
->type
) {
804 case SIDE_TYPE_DYNAMIC_NULL
:
805 case SIDE_TYPE_DYNAMIC_BOOL
:
806 case SIDE_TYPE_DYNAMIC_U8
:
807 case SIDE_TYPE_DYNAMIC_U16
:
808 case SIDE_TYPE_DYNAMIC_U32
:
809 case SIDE_TYPE_DYNAMIC_U64
:
810 case SIDE_TYPE_DYNAMIC_S8
:
811 case SIDE_TYPE_DYNAMIC_S16
:
812 case SIDE_TYPE_DYNAMIC_S32
:
813 case SIDE_TYPE_DYNAMIC_S64
:
814 case SIDE_TYPE_DYNAMIC_BYTE
:
815 case SIDE_TYPE_DYNAMIC_POINTER32
:
816 case SIDE_TYPE_DYNAMIC_POINTER64
:
817 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
818 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
819 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
820 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
821 case SIDE_TYPE_DYNAMIC_STRING
:
822 case SIDE_TYPE_DYNAMIC_STRUCT
:
823 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
824 case SIDE_TYPE_DYNAMIC_VLA
:
825 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
828 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
835 if (type_desc
->type
!= item
->type
) {
836 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
842 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
843 type
= (enum side_type_label
) type_desc
->type
;
845 type
= (enum side_type_label
) item
->type
;
850 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
851 printf("<NULL TYPE>");
855 tracer_print_type_header(":", type_desc
->u
.side_bool
.attr
, type_desc
->u
.side_bool
.nr_attr
);
856 printf("%s", item
->u
.side_static
.bool_value
? "true" : "false");
867 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
868 TRACER_DISPLAY_BASE_10
);
871 case SIDE_TYPE_POINTER32
:
872 case SIDE_TYPE_POINTER64
:
873 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
874 TRACER_DISPLAY_BASE_16
);
878 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
879 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
883 print_enum(type_desc
, item
);
886 case SIDE_TYPE_ENUM_BITMAP
:
887 print_enum_bitmap(type_desc
, item
);
890 case SIDE_TYPE_FLOAT_BINARY16
:
891 case SIDE_TYPE_FLOAT_BINARY32
:
892 case SIDE_TYPE_FLOAT_BINARY64
:
893 case SIDE_TYPE_FLOAT_BINARY128
:
894 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
897 case SIDE_TYPE_STRING
:
898 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
899 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
901 case SIDE_TYPE_STRUCT
:
902 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
904 case SIDE_TYPE_SG_STRUCT
:
905 tracer_print_sg_struct(&type_desc
->u
.side_sg
, &item
->u
.side_static
.side_struct_sg_ptr
);
907 case SIDE_TYPE_SG_UNSIGNED_INT
:
908 case SIDE_TYPE_SG_SIGNED_INT
:
909 tracer_print_sg_integer_type(&type_desc
->u
.side_sg
, item
->u
.side_static
.side_integer_sg_ptr
);
911 case SIDE_TYPE_SG_FLOAT
:
912 tracer_print_sg_float_type(&type_desc
->u
.side_sg
, item
->u
.side_static
.side_float_sg_ptr
);
914 case SIDE_TYPE_ARRAY
:
915 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
918 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
920 case SIDE_TYPE_VLA_VISITOR
:
921 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
923 case SIDE_TYPE_ARRAY_U8
:
924 case SIDE_TYPE_ARRAY_U16
:
925 case SIDE_TYPE_ARRAY_U32
:
926 case SIDE_TYPE_ARRAY_U64
:
927 case SIDE_TYPE_ARRAY_S8
:
928 case SIDE_TYPE_ARRAY_S16
:
929 case SIDE_TYPE_ARRAY_S32
:
930 case SIDE_TYPE_ARRAY_S64
:
931 case SIDE_TYPE_ARRAY_BYTE
:
932 case SIDE_TYPE_ARRAY_POINTER32
:
933 case SIDE_TYPE_ARRAY_POINTER64
:
934 tracer_print_array_fixint(type_desc
, item
);
936 case SIDE_TYPE_VLA_U8
:
937 case SIDE_TYPE_VLA_U16
:
938 case SIDE_TYPE_VLA_U32
:
939 case SIDE_TYPE_VLA_U64
:
940 case SIDE_TYPE_VLA_S8
:
941 case SIDE_TYPE_VLA_S16
:
942 case SIDE_TYPE_VLA_S32
:
943 case SIDE_TYPE_VLA_S64
:
944 case SIDE_TYPE_VLA_BYTE
:
945 case SIDE_TYPE_VLA_POINTER32
:
946 case SIDE_TYPE_VLA_POINTER64
:
947 tracer_print_vla_fixint(type_desc
, item
);
951 case SIDE_TYPE_DYNAMIC_NULL
:
952 case SIDE_TYPE_DYNAMIC_BOOL
:
953 case SIDE_TYPE_DYNAMIC_U8
:
954 case SIDE_TYPE_DYNAMIC_U16
:
955 case SIDE_TYPE_DYNAMIC_U32
:
956 case SIDE_TYPE_DYNAMIC_U64
:
957 case SIDE_TYPE_DYNAMIC_S8
:
958 case SIDE_TYPE_DYNAMIC_S16
:
959 case SIDE_TYPE_DYNAMIC_S32
:
960 case SIDE_TYPE_DYNAMIC_S64
:
961 case SIDE_TYPE_DYNAMIC_BYTE
:
962 case SIDE_TYPE_DYNAMIC_POINTER32
:
963 case SIDE_TYPE_DYNAMIC_POINTER64
:
964 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
965 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
966 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
967 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
968 case SIDE_TYPE_DYNAMIC_STRING
:
969 case SIDE_TYPE_DYNAMIC_STRUCT
:
970 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
971 case SIDE_TYPE_DYNAMIC_VLA
:
972 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
973 tracer_print_dynamic(item
);
976 fprintf(stderr
, "<UNKNOWN TYPE>");
983 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
985 printf("%s: ", item_desc
->field_name
);
986 tracer_print_type(&item_desc
->side_type
, item
);
990 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
992 const struct side_arg
*sav
= side_arg_vec
->sav
;
993 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
995 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
996 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
999 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1000 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1001 printf("fields: { ");
1002 for (i
= 0; i
< side_sav_len
; i
++) {
1003 printf("%s", i
? ", " : "");
1004 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1010 void tracer_print_sg_integer_type(const struct side_type_sg
*type_sg
, const void *_ptr
)
1012 const char *ptr
= (const char *) _ptr
;
1013 union side_integer_value value
;
1015 switch (type_sg
->u
.side_integer
.type
.integer_size_bits
) {
1024 memcpy(&value
, ptr
+ type_sg
->offset
, type_sg
->u
.side_integer
.type
.integer_size_bits
>> 3);
1025 tracer_print_type_integer(":", &type_sg
->u
.side_integer
.type
, &value
,
1026 type_sg
->u
.side_integer
.offset_bits
, TRACER_DISPLAY_BASE_10
);
1030 void tracer_print_sg_float_type(const struct side_type_sg
*type_sg
, const void *_ptr
)
1032 const char *ptr
= (const char *) _ptr
;
1033 union side_float_value value
;
1035 switch (type_sg
->u
.side_float
.float_size_bits
) {
1044 memcpy(&value
, ptr
+ type_sg
->offset
, type_sg
->u
.side_float
.float_size_bits
>> 3);
1045 tracer_print_type_float(":", &type_sg
->u
.side_float
, &value
);
1049 void tracer_print_sg_type(const struct side_type
*type_desc
, void *ptr
)
1052 switch (type_desc
->type
) {
1053 case SIDE_TYPE_SG_UNSIGNED_INT
:
1054 case SIDE_TYPE_SG_SIGNED_INT
:
1055 tracer_print_sg_integer_type(&type_desc
->u
.side_sg
, ptr
);
1057 case SIDE_TYPE_SG_FLOAT
:
1058 tracer_print_sg_float_type(&type_desc
->u
.side_sg
, ptr
);
1060 case SIDE_TYPE_SG_STRUCT
:
1061 tracer_print_sg_struct(&type_desc
->u
.side_sg
, ptr
);
1064 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER TYPE>");
1071 void tracer_print_sg_field(const struct side_event_field
*field
, void *ptr
)
1073 printf("%s: ", field
->field_name
);
1074 tracer_print_sg_type(&field
->side_type
, ptr
);
1078 void tracer_print_sg_struct(const struct side_type_sg
*type_sg
, const void *_ptr
)
1080 char *ptr
= (char *) _ptr
;
1083 memcpy(&ptr
, ptr
+ type_sg
->offset
, sizeof(ptr
));
1084 print_attributes("attr", ":", type_sg
->u
.side_struct
->attr
, type_sg
->u
.side_struct
->nr_attr
);
1085 printf("%s", type_sg
->u
.side_struct
->nr_attr
? ", " : "");
1086 printf("fields: { ");
1087 for (i
= 0; i
< type_sg
->u
.side_struct
->nr_fields
; i
++) {
1088 printf("%s", i
? ", " : "");
1089 tracer_print_sg_field(&type_sg
->u
.side_struct
->fields
[i
], ptr
);
1095 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1097 const struct side_arg
*sav
= side_arg_vec
->sav
;
1098 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1100 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1101 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1104 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1105 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1106 printf("elements: ");
1108 for (i
= 0; i
< side_sav_len
; i
++) {
1109 printf("%s", i
? ", " : "");
1110 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1116 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1118 const struct side_arg
*sav
= side_arg_vec
->sav
;
1119 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1121 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1122 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1123 printf("elements: ");
1125 for (i
= 0; i
< side_sav_len
; i
++) {
1126 printf("%s", i
? ", " : "");
1127 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1132 struct tracer_visitor_priv
{
1133 const struct side_type
*elem_type
;
1138 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1139 const struct side_arg
*elem
)
1141 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1143 printf("%s", tracer_priv
->i
++ ? ", " : "");
1144 tracer_print_type(tracer_priv
->elem_type
, elem
);
1145 return SIDE_VISITOR_STATUS_OK
;
1149 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1151 enum side_visitor_status status
;
1152 struct tracer_visitor_priv tracer_priv
= {
1153 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1156 const struct side_tracer_visitor_ctx tracer_ctx
= {
1157 .write_elem
= tracer_write_elem_cb
,
1158 .priv
= &tracer_priv
,
1161 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1162 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1163 printf("elements: ");
1165 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1167 case SIDE_VISITOR_STATUS_OK
:
1169 case SIDE_VISITOR_STATUS_ERROR
:
1170 fprintf(stderr
, "ERROR: Visitor error\n");
1176 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1178 const struct side_type
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1179 uint32_t i
, side_sav_len
= type_desc
->u
.side_array
.length
;
1180 void *p
= item
->u
.side_static
.side_array_fixint
;
1181 enum side_type_label side_type
;
1183 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1184 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1185 printf("elements: ");
1186 switch (item
->type
) {
1187 case SIDE_TYPE_ARRAY_U8
:
1188 if (elem_type
->type
!= SIDE_TYPE_U8
)
1191 case SIDE_TYPE_ARRAY_U16
:
1192 if (elem_type
->type
!= SIDE_TYPE_U16
)
1195 case SIDE_TYPE_ARRAY_U32
:
1196 if (elem_type
->type
!= SIDE_TYPE_U32
)
1199 case SIDE_TYPE_ARRAY_U64
:
1200 if (elem_type
->type
!= SIDE_TYPE_U64
)
1203 case SIDE_TYPE_ARRAY_S8
:
1204 if (elem_type
->type
!= SIDE_TYPE_S8
)
1207 case SIDE_TYPE_ARRAY_S16
:
1208 if (elem_type
->type
!= SIDE_TYPE_S16
)
1211 case SIDE_TYPE_ARRAY_S32
:
1212 if (elem_type
->type
!= SIDE_TYPE_S32
)
1215 case SIDE_TYPE_ARRAY_S64
:
1216 if (elem_type
->type
!= SIDE_TYPE_S64
)
1219 case SIDE_TYPE_ARRAY_BYTE
:
1220 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1223 case SIDE_TYPE_ARRAY_POINTER32
:
1224 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1226 case SIDE_TYPE_ARRAY_POINTER64
:
1227 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1233 side_type
= (enum side_type_label
) elem_type
->type
;
1236 for (i
= 0; i
< side_sav_len
; i
++) {
1237 struct side_arg sav_elem
= {
1241 switch (side_type
) {
1243 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1246 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1249 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1252 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1255 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1258 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1261 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1264 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1266 case SIDE_TYPE_BYTE
:
1267 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1269 case SIDE_TYPE_POINTER32
:
1270 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1272 case SIDE_TYPE_POINTER64
:
1273 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1277 fprintf(stderr
, "ERROR: Unexpected type\n");
1281 printf("%s", i
? ", " : "");
1282 tracer_print_type(elem_type
, &sav_elem
);
1288 fprintf(stderr
, "ERROR: type mismatch\n");
1292 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1294 const struct side_type
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1295 uint32_t i
, side_sav_len
= item
->u
.side_static
.side_vla_fixint
.length
;
1296 void *p
= item
->u
.side_static
.side_vla_fixint
.p
;
1297 enum side_type_label side_type
;
1299 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1300 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1301 printf("elements: ");
1302 switch (item
->type
) {
1303 case SIDE_TYPE_VLA_U8
:
1304 if (elem_type
->type
!= SIDE_TYPE_U8
)
1307 case SIDE_TYPE_VLA_U16
:
1308 if (elem_type
->type
!= SIDE_TYPE_U16
)
1311 case SIDE_TYPE_VLA_U32
:
1312 if (elem_type
->type
!= SIDE_TYPE_U32
)
1315 case SIDE_TYPE_VLA_U64
:
1316 if (elem_type
->type
!= SIDE_TYPE_U64
)
1319 case SIDE_TYPE_VLA_S8
:
1320 if (elem_type
->type
!= SIDE_TYPE_S8
)
1323 case SIDE_TYPE_VLA_S16
:
1324 if (elem_type
->type
!= SIDE_TYPE_S16
)
1327 case SIDE_TYPE_VLA_S32
:
1328 if (elem_type
->type
!= SIDE_TYPE_S32
)
1331 case SIDE_TYPE_VLA_S64
:
1332 if (elem_type
->type
!= SIDE_TYPE_S64
)
1335 case SIDE_TYPE_VLA_BYTE
:
1336 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1339 case SIDE_TYPE_VLA_POINTER32
:
1340 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1342 case SIDE_TYPE_VLA_POINTER64
:
1343 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1349 side_type
= (enum side_type_label
) elem_type
->type
;
1352 for (i
= 0; i
< side_sav_len
; i
++) {
1353 struct side_arg sav_elem
= {
1357 switch (side_type
) {
1359 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1362 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1365 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1368 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1371 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1374 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1377 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1380 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1382 case SIDE_TYPE_BYTE
:
1383 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1385 case SIDE_TYPE_POINTER32
:
1386 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1388 case SIDE_TYPE_POINTER64
:
1389 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1393 fprintf(stderr
, "ERROR: Unexpected type\n");
1397 printf("%s", i
? ", " : "");
1398 tracer_print_type(elem_type
, &sav_elem
);
1404 fprintf(stderr
, "ERROR: type mismatch\n");
1409 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1411 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1412 uint32_t i
, len
= dynamic_struct
->len
;
1414 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1415 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1416 printf("fields:: ");
1418 for (i
= 0; i
< len
; i
++) {
1419 printf("%s", i
? ", " : "");
1420 printf("%s:: ", fields
[i
].field_name
);
1421 tracer_print_dynamic(&fields
[i
].elem
);
1426 struct tracer_dynamic_struct_visitor_priv
{
1431 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1432 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1433 const struct side_arg_dynamic_field
*dynamic_field
)
1435 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1436 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1438 printf("%s", tracer_priv
->i
++ ? ", " : "");
1439 printf("%s:: ", dynamic_field
->field_name
);
1440 tracer_print_dynamic(&dynamic_field
->elem
);
1441 return SIDE_VISITOR_STATUS_OK
;
1445 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1447 enum side_visitor_status status
;
1448 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1451 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1452 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1453 .priv
= &tracer_priv
,
1455 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1457 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1458 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1459 printf("fields:: ");
1461 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1463 case SIDE_VISITOR_STATUS_OK
:
1465 case SIDE_VISITOR_STATUS_ERROR
:
1466 fprintf(stderr
, "ERROR: Visitor error\n");
1473 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1475 const struct side_arg
*sav
= vla
->sav
;
1476 uint32_t i
, side_sav_len
= vla
->len
;
1478 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1479 printf("%s", vla
->nr_attr
? ", " : "");
1480 printf("elements:: ");
1482 for (i
= 0; i
< side_sav_len
; i
++) {
1483 printf("%s", i
? ", " : "");
1484 tracer_print_dynamic(&sav
[i
]);
1489 struct tracer_dynamic_vla_visitor_priv
{
1494 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1495 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1496 const struct side_arg
*elem
)
1498 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1499 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1501 printf("%s", tracer_priv
->i
++ ? ", " : "");
1502 tracer_print_dynamic(elem
);
1503 return SIDE_VISITOR_STATUS_OK
;
1507 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1509 enum side_visitor_status status
;
1510 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1513 const struct side_tracer_visitor_ctx tracer_ctx
= {
1514 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1515 .priv
= &tracer_priv
,
1517 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1519 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1520 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1521 printf("elements:: ");
1523 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1525 case SIDE_VISITOR_STATUS_OK
:
1527 case SIDE_VISITOR_STATUS_ERROR
:
1528 fprintf(stderr
, "ERROR: Visitor error\n");
1535 void tracer_print_dynamic(const struct side_arg
*item
)
1538 switch (item
->type
) {
1539 case SIDE_TYPE_DYNAMIC_NULL
:
1540 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1541 printf("<NULL TYPE>");
1543 case SIDE_TYPE_DYNAMIC_BOOL
:
1544 tracer_print_type_header("::", item
->u
.side_dynamic
.side_bool
.type
.attr
, item
->u
.side_dynamic
.side_bool
.type
.nr_attr
);
1545 printf("%s", item
->u
.side_dynamic
.side_bool
.value
? "true" : "false");
1547 case SIDE_TYPE_DYNAMIC_U8
:
1548 case SIDE_TYPE_DYNAMIC_U16
:
1549 case SIDE_TYPE_DYNAMIC_U32
:
1550 case SIDE_TYPE_DYNAMIC_U64
:
1551 case SIDE_TYPE_DYNAMIC_S8
:
1552 case SIDE_TYPE_DYNAMIC_S16
:
1553 case SIDE_TYPE_DYNAMIC_S32
:
1554 case SIDE_TYPE_DYNAMIC_S64
:
1555 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1556 TRACER_DISPLAY_BASE_10
);
1558 case SIDE_TYPE_DYNAMIC_BYTE
:
1559 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1560 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1563 case SIDE_TYPE_DYNAMIC_POINTER32
:
1564 case SIDE_TYPE_DYNAMIC_POINTER64
:
1565 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1566 TRACER_DISPLAY_BASE_16
);
1569 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
1570 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
1571 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
1572 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
1573 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1574 &item
->u
.side_dynamic
.side_float
.value
);
1577 case SIDE_TYPE_DYNAMIC_STRING
:
1578 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1579 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1581 case SIDE_TYPE_DYNAMIC_STRUCT
:
1582 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1584 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1585 tracer_print_dynamic_struct_visitor(item
);
1587 case SIDE_TYPE_DYNAMIC_VLA
:
1588 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1590 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1591 tracer_print_dynamic_vla_visitor(item
);
1594 fprintf(stderr
, "<UNKNOWN TYPE>");
1601 void tracer_print_static_fields(const struct side_event_description
*desc
,
1602 const struct side_arg_vec
*side_arg_vec
,
1605 const struct side_arg
*sav
= side_arg_vec
->sav
;
1606 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1608 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1609 if (desc
->nr_fields
!= side_sav_len
) {
1610 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1613 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1614 printf("%s", side_sav_len
? ", fields: [ " : "");
1615 for (i
= 0; i
< side_sav_len
; i
++) {
1616 printf("%s", i
? ", " : "");
1617 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1625 void tracer_call(const struct side_event_description
*desc
,
1626 const struct side_arg_vec
*side_arg_vec
,
1627 void *priv
__attribute__((unused
)))
1629 uint32_t nr_fields
= 0;
1631 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1635 void tracer_call_variadic(const struct side_event_description
*desc
,
1636 const struct side_arg_vec
*side_arg_vec
,
1637 const struct side_arg_dynamic_struct
*var_struct
,
1638 void *priv
__attribute__((unused
)))
1640 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1642 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1644 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1645 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1648 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1649 printf("%s", var_struct_len
? ", fields:: [ " : "");
1650 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1651 printf("%s", i
? ", " : "");
1652 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1653 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1660 void tracer_event_notification(enum side_tracer_notification notif
,
1661 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1666 printf("----------------------------------------------------------\n");
1667 printf("Tracer notified of events %s\n",
1668 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1669 for (i
= 0; i
< nr_events
; i
++) {
1670 struct side_event_description
*event
= events
[i
];
1672 /* Skip NULL pointers */
1675 printf("provider: %s, event: %s\n",
1676 event
->provider_name
, event
->event_name
);
1677 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1678 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1679 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1683 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1688 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1689 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1693 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1699 printf("----------------------------------------------------------\n");
1702 static __attribute__((constructor
))
1703 void tracer_init(void);
1705 void tracer_init(void)
1707 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1712 static __attribute__((destructor
))
1713 void tracer_exit(void);
1715 void tracer_exit(void)
1717 side_tracer_event_notification_unregister(tracer_handle
);