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_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
29 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
31 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
);
33 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
35 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
37 void tracer_print_dynamic(const struct side_arg
*dynamic_item
);
39 uint32_t tracer_print_sg_struct(const struct side_type_sg
*type_sg
, const void *_ptr
);
41 uint32_t tracer_print_sg_integer_type(const struct side_type_sg
*type_sg
, const void *_ptr
);
43 uint32_t tracer_print_sg_float_type(const struct side_type_sg
*type_sg
, const void *_ptr
);
45 uint32_t tracer_print_sg_array(const struct side_type_sg
*type_sg
, const void *_ptr
);
47 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
50 int64_t get_attr_integer_value(const struct side_attr
*attr
)
54 switch (attr
->value
.type
) {
55 case SIDE_ATTR_TYPE_U8
:
56 val
= attr
->value
.u
.integer_value
.side_u8
;
58 case SIDE_ATTR_TYPE_U16
:
59 val
= attr
->value
.u
.integer_value
.side_u16
;
61 case SIDE_ATTR_TYPE_U32
:
62 val
= attr
->value
.u
.integer_value
.side_u32
;
64 case SIDE_ATTR_TYPE_U64
:
65 val
= attr
->value
.u
.integer_value
.side_u64
;
67 case SIDE_ATTR_TYPE_S8
:
68 val
= attr
->value
.u
.integer_value
.side_s8
;
70 case SIDE_ATTR_TYPE_S16
:
71 val
= attr
->value
.u
.integer_value
.side_s16
;
73 case SIDE_ATTR_TYPE_S32
:
74 val
= attr
->value
.u
.integer_value
.side_s32
;
76 case SIDE_ATTR_TYPE_S64
:
77 val
= attr
->value
.u
.integer_value
.side_s64
;
80 fprintf(stderr
, "Unexpected attribute type\n");
87 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
88 enum tracer_display_base default_base
)
92 for (i
= 0; i
< nr_attr
; i
++) {
93 const struct side_attr
*attr
= &_attr
[i
];
95 if (!strcmp(attr
->key
, "std.integer.base")) {
96 int64_t val
= get_attr_integer_value(attr
);
100 return TRACER_DISPLAY_BASE_2
;
102 return TRACER_DISPLAY_BASE_8
;
104 return TRACER_DISPLAY_BASE_10
;
106 return TRACER_DISPLAY_BASE_16
;
108 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
113 return default_base
; /* Default */
117 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
119 switch (type_desc
->type
) {
130 case SIDE_TYPE_POINTER32
:
131 case SIDE_TYPE_POINTER64
:
132 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
137 case SIDE_TYPE_FLOAT_BINARY16
:
138 case SIDE_TYPE_FLOAT_BINARY32
:
139 case SIDE_TYPE_FLOAT_BINARY64
:
140 case SIDE_TYPE_FLOAT_BINARY128
:
141 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
147 fprintf(stderr
, "Unexpected type\n");
153 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
155 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
156 switch (attr
->value
.type
) {
157 case SIDE_ATTR_TYPE_BOOL
:
158 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
160 case SIDE_ATTR_TYPE_U8
:
161 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
163 case SIDE_ATTR_TYPE_U16
:
164 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
166 case SIDE_ATTR_TYPE_U32
:
167 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
169 case SIDE_ATTR_TYPE_U64
:
170 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
172 case SIDE_ATTR_TYPE_S8
:
173 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
175 case SIDE_ATTR_TYPE_S16
:
176 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
178 case SIDE_ATTR_TYPE_S32
:
179 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
181 case SIDE_ATTR_TYPE_S64
:
182 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
184 case SIDE_ATTR_TYPE_POINTER32
:
185 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
187 case SIDE_ATTR_TYPE_POINTER64
:
188 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
190 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
192 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
195 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
198 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
200 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
203 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
206 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
208 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
211 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
214 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
216 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
219 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
222 case SIDE_ATTR_TYPE_STRING
:
223 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
226 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
233 void print_attributes(const char *prefix_str
, const char *separator
,
234 const struct side_attr
*attr
, uint32_t nr_attr
)
240 printf("%s%s [ ", prefix_str
, separator
);
241 for (i
= 0; i
< nr_attr
; i
++) {
242 printf("%s", i
? ", " : "");
243 tracer_print_attr_type(separator
, &attr
[i
]);
249 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
251 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
252 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
253 uint32_t i
, print_count
= 0;
256 if (elem_type
->type
!= item
->type
) {
257 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
260 switch (item
->type
) {
262 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
268 v
= item
->u
.side_static
.integer_value
.side_u16
;
269 if (type_to_host_reverse_bo(elem_type
))
270 v
= side_bswap_16(v
);
278 v
= item
->u
.side_static
.integer_value
.side_u32
;
279 if (type_to_host_reverse_bo(elem_type
))
280 v
= side_bswap_32(v
);
288 v
= item
->u
.side_static
.integer_value
.side_u64
;
289 if (type_to_host_reverse_bo(elem_type
))
290 v
= side_bswap_64(v
);
295 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
301 v
= item
->u
.side_static
.integer_value
.side_s16
;
302 if (type_to_host_reverse_bo(elem_type
))
303 v
= side_bswap_16(v
);
311 v
= item
->u
.side_static
.integer_value
.side_s32
;
312 if (type_to_host_reverse_bo(elem_type
))
313 v
= side_bswap_32(v
);
321 v
= item
->u
.side_static
.integer_value
.side_s64
;
322 if (type_to_host_reverse_bo(elem_type
))
323 v
= side_bswap_64(v
);
328 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
331 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
332 printf("%s", mappings
->nr_attr
? ", " : "");
333 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
334 printf(", labels: [ ");
335 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
336 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
338 if (mapping
->range_end
< mapping
->range_begin
) {
339 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
340 mapping
->range_begin
, mapping
->range_end
);
343 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
344 printf("%s", print_count
++ ? ", " : "");
345 printf("\"%s\"", mapping
->label
);
349 printf("<NO LABEL>");
354 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
358 switch (elem_type
->type
) {
359 case SIDE_TYPE_U8
: /* Fall-through */
373 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
380 void print_enum_bitmap(const struct side_type
*type_desc
,
381 const struct side_arg
*item
)
383 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
384 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
385 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
386 bool reverse_byte_order
= false;
387 const struct side_arg
*array_item
;
389 switch (elem_type
->type
) {
390 case SIDE_TYPE_U8
: /* Fall-through */
391 case SIDE_TYPE_BYTE
: /* Fall-through */
392 case SIDE_TYPE_U16
: /* Fall-through */
393 case SIDE_TYPE_U32
: /* Fall-through */
395 stride_bit
= enum_elem_type_to_stride(elem_type
);
396 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
400 case SIDE_TYPE_ARRAY
:
401 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
402 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
403 array_item
= item
->u
.side_static
.side_array
->sav
;
404 nr_items
= type_desc
->u
.side_array
.length
;
407 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
408 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
409 array_item
= item
->u
.side_static
.side_vla
->sav
;
410 nr_items
= item
->u
.side_static
.side_vla
->len
;
413 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
417 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
418 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
419 printf("labels: [ ");
420 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
421 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
425 if (mapping
->range_end
< mapping
->range_begin
) {
426 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
427 mapping
->range_begin
, mapping
->range_end
);
430 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
431 if (bit
> (nr_items
* stride_bit
) - 1)
433 switch (stride_bit
) {
436 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
437 if (v
& (1ULL << (bit
% 8))) {
445 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
446 if (reverse_byte_order
)
447 v
= side_bswap_16(v
);
448 if (v
& (1ULL << (bit
% 16))) {
456 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
457 if (reverse_byte_order
)
458 v
= side_bswap_32(v
);
459 if (v
& (1ULL << (bit
% 32))) {
467 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
468 if (reverse_byte_order
)
469 v
= side_bswap_64(v
);
470 if (v
& (1ULL << (bit
% 64))) {
482 printf("%s", print_count
++ ? ", " : "");
483 printf("\"%s\"", mapping
->label
);
487 printf("<NO LABEL>");
492 void print_integer_binary(uint64_t v
, int bits
)
498 for (i
= 0; i
< bits
; i
++) {
499 printf("%c", v
& (1ULL << 63) ? '1' : '0');
505 void tracer_print_type_header(const char *separator
,
506 const struct side_attr
*attr
, uint32_t nr_attr
)
508 print_attributes("attr", separator
, attr
, nr_attr
);
509 printf("%s", nr_attr
? ", " : "");
510 printf("value%s ", separator
);
514 void tracer_print_type_integer(const char *separator
,
515 const struct side_type_integer
*type_integer
,
516 const union side_integer_value
*value
,
517 uint16_t offset_bits
,
518 enum tracer_display_base default_base
)
520 enum tracer_display_base base
;
527 if (!type_integer
->len_bits
||
528 type_integer
->len_bits
+ offset_bits
> type_integer
->integer_size_bits
)
530 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
531 base
= get_attr_display_base(type_integer
->attr
,
532 type_integer
->nr_attr
,
534 switch (type_integer
->integer_size_bits
) {
536 if (type_integer
->signedness
)
537 v
.v_signed
= value
->side_s8
;
539 v
.v_unsigned
= value
->side_u8
;
542 if (type_integer
->signedness
) {
545 side_s16
= value
->side_s16
;
547 side_s16
= side_bswap_16(side_s16
);
548 v
.v_signed
= side_s16
;
552 side_u16
= value
->side_u16
;
554 side_u16
= side_bswap_16(side_u16
);
555 v
.v_unsigned
= side_u16
;
559 if (type_integer
->signedness
) {
562 side_s32
= value
->side_s32
;
564 side_s32
= side_bswap_32(side_s32
);
565 v
.v_signed
= side_s32
;
569 side_u32
= value
->side_u32
;
571 side_u32
= side_bswap_32(side_u32
);
572 v
.v_unsigned
= side_u32
;
576 if (type_integer
->signedness
) {
579 side_s64
= value
->side_s64
;
581 side_s64
= side_bswap_64(side_s64
);
582 v
.v_signed
= side_s64
;
586 side_u64
= value
->side_u64
;
588 side_u64
= side_bswap_64(side_u64
);
589 v
.v_unsigned
= side_u64
;
595 v
.v_unsigned
>>= offset_bits
;
596 if (type_integer
->len_bits
< 64)
597 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
598 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
600 case TRACER_DISPLAY_BASE_2
:
601 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
603 case TRACER_DISPLAY_BASE_8
:
604 printf("0%" PRIo64
, v
.v_unsigned
);
606 case TRACER_DISPLAY_BASE_10
:
607 if (type_integer
->signedness
) {
609 if (type_integer
->len_bits
< 64) {
610 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
611 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
613 printf("%" PRId64
, v
.v_signed
);
615 printf("%" PRIu64
, v
.v_unsigned
);
618 case TRACER_DISPLAY_BASE_16
:
619 printf("0x%" PRIx64
, v
.v_unsigned
);
627 void tracer_print_type_float(const char *separator
,
628 const struct side_type_float
*type_float
,
629 const union side_float_value
*value
)
633 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
634 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
635 switch (type_float
->float_size_bits
) {
643 .f
= value
->side_float_binary16
,
647 float16
.u
= side_bswap_16(float16
.u
);
648 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
649 printf("%g", (double) float16
.f
);
652 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
663 .f
= value
->side_float_binary32
,
667 float32
.u
= side_bswap_32(float32
.u
);
668 printf("%g", (double) float32
.f
);
671 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
682 .f
= value
->side_float_binary64
,
686 float64
.u
= side_bswap_64(float64
.u
);
687 printf("%g", (double) float64
.f
);
690 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
701 .f
= value
->side_float_binary128
,
705 side_bswap_128p(float128
.arr
);
706 printf("%Lg", (long double) float128
.f
);
709 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
714 fprintf(stderr
, "ERROR: Unknown float size\n");
720 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
722 enum side_type_label type
;
724 switch (type_desc
->type
) {
725 case SIDE_TYPE_ARRAY
:
726 switch (item
->type
) {
727 case SIDE_TYPE_ARRAY_U8
:
728 case SIDE_TYPE_ARRAY_U16
:
729 case SIDE_TYPE_ARRAY_U32
:
730 case SIDE_TYPE_ARRAY_U64
:
731 case SIDE_TYPE_ARRAY_S8
:
732 case SIDE_TYPE_ARRAY_S16
:
733 case SIDE_TYPE_ARRAY_S32
:
734 case SIDE_TYPE_ARRAY_S64
:
735 case SIDE_TYPE_ARRAY_POINTER32
:
736 case SIDE_TYPE_ARRAY_POINTER64
:
737 case SIDE_TYPE_ARRAY_BYTE
:
738 case SIDE_TYPE_ARRAY
:
741 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
748 switch (item
->type
) {
749 case SIDE_TYPE_VLA_U8
:
750 case SIDE_TYPE_VLA_U16
:
751 case SIDE_TYPE_VLA_U32
:
752 case SIDE_TYPE_VLA_U64
:
753 case SIDE_TYPE_VLA_S8
:
754 case SIDE_TYPE_VLA_S16
:
755 case SIDE_TYPE_VLA_S32
:
756 case SIDE_TYPE_VLA_S64
:
757 case SIDE_TYPE_VLA_BYTE
:
758 case SIDE_TYPE_VLA_POINTER32
:
759 case SIDE_TYPE_VLA_POINTER64
:
763 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
770 switch (item
->type
) {
781 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
787 case SIDE_TYPE_ENUM_BITMAP
:
788 switch (item
->type
) {
794 case SIDE_TYPE_ARRAY
:
798 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
804 case SIDE_TYPE_DYNAMIC
:
805 switch (item
->type
) {
806 case SIDE_TYPE_DYNAMIC_NULL
:
807 case SIDE_TYPE_DYNAMIC_BOOL
:
808 case SIDE_TYPE_DYNAMIC_U8
:
809 case SIDE_TYPE_DYNAMIC_U16
:
810 case SIDE_TYPE_DYNAMIC_U32
:
811 case SIDE_TYPE_DYNAMIC_U64
:
812 case SIDE_TYPE_DYNAMIC_S8
:
813 case SIDE_TYPE_DYNAMIC_S16
:
814 case SIDE_TYPE_DYNAMIC_S32
:
815 case SIDE_TYPE_DYNAMIC_S64
:
816 case SIDE_TYPE_DYNAMIC_BYTE
:
817 case SIDE_TYPE_DYNAMIC_POINTER32
:
818 case SIDE_TYPE_DYNAMIC_POINTER64
:
819 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
820 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
821 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
822 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
823 case SIDE_TYPE_DYNAMIC_STRING
:
824 case SIDE_TYPE_DYNAMIC_STRUCT
:
825 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
826 case SIDE_TYPE_DYNAMIC_VLA
:
827 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
830 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
837 if (type_desc
->type
!= item
->type
) {
838 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
844 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
845 type
= (enum side_type_label
) type_desc
->type
;
847 type
= (enum side_type_label
) item
->type
;
852 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
853 printf("<NULL TYPE>");
857 tracer_print_type_header(":", type_desc
->u
.side_bool
.attr
, type_desc
->u
.side_bool
.nr_attr
);
858 printf("%s", item
->u
.side_static
.bool_value
? "true" : "false");
869 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
870 TRACER_DISPLAY_BASE_10
);
873 case SIDE_TYPE_POINTER32
:
874 case SIDE_TYPE_POINTER64
:
875 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
876 TRACER_DISPLAY_BASE_16
);
880 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
881 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
885 print_enum(type_desc
, item
);
888 case SIDE_TYPE_ENUM_BITMAP
:
889 print_enum_bitmap(type_desc
, item
);
892 case SIDE_TYPE_FLOAT_BINARY16
:
893 case SIDE_TYPE_FLOAT_BINARY32
:
894 case SIDE_TYPE_FLOAT_BINARY64
:
895 case SIDE_TYPE_FLOAT_BINARY128
:
896 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
899 case SIDE_TYPE_STRING
:
900 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
901 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
903 case SIDE_TYPE_STRUCT
:
904 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
906 case SIDE_TYPE_SG_STRUCT
:
907 (void) tracer_print_sg_struct(&type_desc
->u
.side_sg
, &item
->u
.side_static
.side_struct_sg_ptr
);
909 case SIDE_TYPE_SG_ARRAY
:
910 (void) tracer_print_sg_array(&type_desc
->u
.side_sg
, &item
->u
.side_static
.side_array_sg_ptr
);
912 case SIDE_TYPE_SG_UNSIGNED_INT
:
913 case SIDE_TYPE_SG_SIGNED_INT
:
914 (void) tracer_print_sg_integer_type(&type_desc
->u
.side_sg
, item
->u
.side_static
.side_integer_sg_ptr
);
916 case SIDE_TYPE_SG_FLOAT
:
917 (void) tracer_print_sg_float_type(&type_desc
->u
.side_sg
, item
->u
.side_static
.side_float_sg_ptr
);
919 case SIDE_TYPE_ARRAY
:
920 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
923 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
925 case SIDE_TYPE_VLA_VISITOR
:
926 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
928 case SIDE_TYPE_ARRAY_U8
:
929 case SIDE_TYPE_ARRAY_U16
:
930 case SIDE_TYPE_ARRAY_U32
:
931 case SIDE_TYPE_ARRAY_U64
:
932 case SIDE_TYPE_ARRAY_S8
:
933 case SIDE_TYPE_ARRAY_S16
:
934 case SIDE_TYPE_ARRAY_S32
:
935 case SIDE_TYPE_ARRAY_S64
:
936 case SIDE_TYPE_ARRAY_BYTE
:
937 case SIDE_TYPE_ARRAY_POINTER32
:
938 case SIDE_TYPE_ARRAY_POINTER64
:
939 tracer_print_array_fixint(type_desc
, item
);
941 case SIDE_TYPE_VLA_U8
:
942 case SIDE_TYPE_VLA_U16
:
943 case SIDE_TYPE_VLA_U32
:
944 case SIDE_TYPE_VLA_U64
:
945 case SIDE_TYPE_VLA_S8
:
946 case SIDE_TYPE_VLA_S16
:
947 case SIDE_TYPE_VLA_S32
:
948 case SIDE_TYPE_VLA_S64
:
949 case SIDE_TYPE_VLA_BYTE
:
950 case SIDE_TYPE_VLA_POINTER32
:
951 case SIDE_TYPE_VLA_POINTER64
:
952 tracer_print_vla_fixint(type_desc
, item
);
956 case SIDE_TYPE_DYNAMIC_NULL
:
957 case SIDE_TYPE_DYNAMIC_BOOL
:
958 case SIDE_TYPE_DYNAMIC_U8
:
959 case SIDE_TYPE_DYNAMIC_U16
:
960 case SIDE_TYPE_DYNAMIC_U32
:
961 case SIDE_TYPE_DYNAMIC_U64
:
962 case SIDE_TYPE_DYNAMIC_S8
:
963 case SIDE_TYPE_DYNAMIC_S16
:
964 case SIDE_TYPE_DYNAMIC_S32
:
965 case SIDE_TYPE_DYNAMIC_S64
:
966 case SIDE_TYPE_DYNAMIC_BYTE
:
967 case SIDE_TYPE_DYNAMIC_POINTER32
:
968 case SIDE_TYPE_DYNAMIC_POINTER64
:
969 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
970 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
971 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
972 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
973 case SIDE_TYPE_DYNAMIC_STRING
:
974 case SIDE_TYPE_DYNAMIC_STRUCT
:
975 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
976 case SIDE_TYPE_DYNAMIC_VLA
:
977 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
978 tracer_print_dynamic(item
);
981 fprintf(stderr
, "<UNKNOWN TYPE>");
988 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
990 printf("%s: ", item_desc
->field_name
);
991 tracer_print_type(&item_desc
->side_type
, item
);
995 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
997 const struct side_arg
*sav
= side_arg_vec
->sav
;
998 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1000 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
1001 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
1004 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1005 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1006 printf("fields: { ");
1007 for (i
= 0; i
< side_sav_len
; i
++) {
1008 printf("%s", i
? ", " : "");
1009 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1015 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1017 const struct side_arg
*sav
= side_arg_vec
->sav
;
1018 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1020 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1021 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1024 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1025 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1026 printf("elements: ");
1028 for (i
= 0; i
< side_sav_len
; i
++) {
1029 printf("%s", i
? ", " : "");
1030 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1036 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1038 const struct side_arg
*sav
= side_arg_vec
->sav
;
1039 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1041 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1042 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1043 printf("elements: ");
1045 for (i
= 0; i
< side_sav_len
; i
++) {
1046 printf("%s", i
? ", " : "");
1047 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1053 const char *tracer_sg_access(const struct side_type_sg
*type_sg
, const char *ptr
)
1055 switch (type_sg
->access_mode
) {
1056 case SIDE_TYPE_SG_ACCESS_ADDRESS
:
1058 case SIDE_TYPE_SG_ACCESS_POINTER
:
1059 /* Dereference pointer */
1060 memcpy(&ptr
, ptr
, sizeof(ptr
));
1068 uint32_t tracer_sg_size(const struct side_type_sg
*type_sg
, uint32_t len
)
1070 switch (type_sg
->access_mode
) {
1071 case SIDE_TYPE_SG_ACCESS_ADDRESS
:
1073 case SIDE_TYPE_SG_ACCESS_POINTER
:
1074 return sizeof(void *);
1081 uint32_t tracer_print_sg_integer_type(const struct side_type_sg
*type_sg
, const void *_ptr
)
1083 const char *ptr
= (const char *) _ptr
;
1084 union side_integer_value value
;
1085 uint32_t integer_size_bytes
= type_sg
->u
.side_integer
.type
.integer_size_bits
>> 3;
1087 switch (type_sg
->u
.side_integer
.type
.integer_size_bits
) {
1096 ptr
= tracer_sg_access(type_sg
, ptr
+ type_sg
->offset
);
1097 memcpy(&value
, ptr
, integer_size_bytes
);
1098 tracer_print_type_integer(":", &type_sg
->u
.side_integer
.type
, &value
,
1099 type_sg
->u
.side_integer
.offset_bits
, TRACER_DISPLAY_BASE_10
);
1100 return tracer_sg_size(type_sg
, integer_size_bytes
);
1104 uint32_t tracer_print_sg_float_type(const struct side_type_sg
*type_sg
, const void *_ptr
)
1106 const char *ptr
= (const char *) _ptr
;
1107 union side_float_value value
;
1108 uint32_t float_size_bytes
= type_sg
->u
.side_float
.float_size_bits
>> 3;
1110 switch (type_sg
->u
.side_float
.float_size_bits
) {
1119 ptr
= tracer_sg_access(type_sg
, ptr
+ type_sg
->offset
);
1120 memcpy(&value
, ptr
, float_size_bytes
);
1121 tracer_print_type_float(":", &type_sg
->u
.side_float
, &value
);
1122 return tracer_sg_size(type_sg
, float_size_bytes
);
1126 uint32_t tracer_print_sg_type(const struct side_type
*type_desc
, const void *ptr
)
1131 switch (type_desc
->type
) {
1132 case SIDE_TYPE_SG_UNSIGNED_INT
:
1133 case SIDE_TYPE_SG_SIGNED_INT
:
1134 len
= tracer_print_sg_integer_type(&type_desc
->u
.side_sg
, ptr
);
1136 case SIDE_TYPE_SG_FLOAT
:
1137 len
= tracer_print_sg_float_type(&type_desc
->u
.side_sg
, ptr
);
1139 case SIDE_TYPE_SG_STRUCT
:
1140 len
= tracer_print_sg_struct(&type_desc
->u
.side_sg
, ptr
);
1142 case SIDE_TYPE_SG_ARRAY
:
1143 len
= tracer_print_sg_array(&type_desc
->u
.side_sg
, ptr
);
1146 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER TYPE>");
1154 void tracer_print_sg_field(const struct side_event_field
*field
, const void *ptr
)
1156 printf("%s: ", field
->field_name
);
1157 (void) tracer_print_sg_type(&field
->side_type
, ptr
);
1161 uint32_t tracer_print_sg_struct(const struct side_type_sg
*type_sg
, const void *_ptr
)
1163 const char *ptr
= (const char *) _ptr
;
1166 ptr
= tracer_sg_access(type_sg
, ptr
+ type_sg
->offset
);
1167 print_attributes("attr", ":", type_sg
->u
.side_struct
.type
->attr
, type_sg
->u
.side_struct
.type
->nr_attr
);
1168 printf("%s", type_sg
->u
.side_struct
.type
->nr_attr
? ", " : "");
1169 printf("fields: { ");
1170 for (i
= 0; i
< type_sg
->u
.side_struct
.type
->nr_fields
; i
++) {
1171 printf("%s", i
? ", " : "");
1172 tracer_print_sg_field(&type_sg
->u
.side_struct
.type
->fields
[i
], ptr
);
1175 return tracer_sg_size(type_sg
, type_sg
->u
.side_struct
.size
);
1179 uint32_t tracer_print_sg_array(const struct side_type_sg
*type_sg
, const void *_ptr
)
1181 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1184 ptr
= tracer_sg_access(type_sg
, ptr
+ type_sg
->offset
);
1186 print_attributes("attr", ":", type_sg
->u
.side_array
.attr
, type_sg
->u
.side_array
.nr_attr
);
1187 printf("%s", type_sg
->u
.side_array
.nr_attr
? ", " : "");
1188 printf("elements: ");
1190 for (i
= 0; i
< type_sg
->u
.side_array
.length
; i
++) {
1191 printf("%s", i
? ", " : "");
1192 ptr
+= tracer_print_sg_type(type_sg
->u
.side_array
.elem_type
, ptr
);
1195 return tracer_sg_size(type_sg
, ptr
- orig_ptr
);
1198 struct tracer_visitor_priv
{
1199 const struct side_type
*elem_type
;
1204 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1205 const struct side_arg
*elem
)
1207 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1209 printf("%s", tracer_priv
->i
++ ? ", " : "");
1210 tracer_print_type(tracer_priv
->elem_type
, elem
);
1211 return SIDE_VISITOR_STATUS_OK
;
1215 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1217 enum side_visitor_status status
;
1218 struct tracer_visitor_priv tracer_priv
= {
1219 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1222 const struct side_tracer_visitor_ctx tracer_ctx
= {
1223 .write_elem
= tracer_write_elem_cb
,
1224 .priv
= &tracer_priv
,
1227 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1228 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1229 printf("elements: ");
1231 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1233 case SIDE_VISITOR_STATUS_OK
:
1235 case SIDE_VISITOR_STATUS_ERROR
:
1236 fprintf(stderr
, "ERROR: Visitor error\n");
1242 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1244 const struct side_type
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1245 uint32_t i
, side_sav_len
= type_desc
->u
.side_array
.length
;
1246 void *p
= item
->u
.side_static
.side_array_fixint
;
1247 enum side_type_label side_type
;
1249 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1250 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1251 printf("elements: ");
1252 switch (item
->type
) {
1253 case SIDE_TYPE_ARRAY_U8
:
1254 if (elem_type
->type
!= SIDE_TYPE_U8
)
1257 case SIDE_TYPE_ARRAY_U16
:
1258 if (elem_type
->type
!= SIDE_TYPE_U16
)
1261 case SIDE_TYPE_ARRAY_U32
:
1262 if (elem_type
->type
!= SIDE_TYPE_U32
)
1265 case SIDE_TYPE_ARRAY_U64
:
1266 if (elem_type
->type
!= SIDE_TYPE_U64
)
1269 case SIDE_TYPE_ARRAY_S8
:
1270 if (elem_type
->type
!= SIDE_TYPE_S8
)
1273 case SIDE_TYPE_ARRAY_S16
:
1274 if (elem_type
->type
!= SIDE_TYPE_S16
)
1277 case SIDE_TYPE_ARRAY_S32
:
1278 if (elem_type
->type
!= SIDE_TYPE_S32
)
1281 case SIDE_TYPE_ARRAY_S64
:
1282 if (elem_type
->type
!= SIDE_TYPE_S64
)
1285 case SIDE_TYPE_ARRAY_BYTE
:
1286 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1289 case SIDE_TYPE_ARRAY_POINTER32
:
1290 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1292 case SIDE_TYPE_ARRAY_POINTER64
:
1293 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1299 side_type
= (enum side_type_label
) elem_type
->type
;
1302 for (i
= 0; i
< side_sav_len
; i
++) {
1303 struct side_arg sav_elem
= {
1307 switch (side_type
) {
1309 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1312 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1315 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1318 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1321 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1324 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1327 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1330 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1332 case SIDE_TYPE_BYTE
:
1333 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1335 case SIDE_TYPE_POINTER32
:
1336 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1338 case SIDE_TYPE_POINTER64
:
1339 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1343 fprintf(stderr
, "ERROR: Unexpected type\n");
1347 printf("%s", i
? ", " : "");
1348 tracer_print_type(elem_type
, &sav_elem
);
1354 fprintf(stderr
, "ERROR: type mismatch\n");
1358 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1360 const struct side_type
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1361 uint32_t i
, side_sav_len
= item
->u
.side_static
.side_vla_fixint
.length
;
1362 void *p
= item
->u
.side_static
.side_vla_fixint
.p
;
1363 enum side_type_label side_type
;
1365 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1366 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1367 printf("elements: ");
1368 switch (item
->type
) {
1369 case SIDE_TYPE_VLA_U8
:
1370 if (elem_type
->type
!= SIDE_TYPE_U8
)
1373 case SIDE_TYPE_VLA_U16
:
1374 if (elem_type
->type
!= SIDE_TYPE_U16
)
1377 case SIDE_TYPE_VLA_U32
:
1378 if (elem_type
->type
!= SIDE_TYPE_U32
)
1381 case SIDE_TYPE_VLA_U64
:
1382 if (elem_type
->type
!= SIDE_TYPE_U64
)
1385 case SIDE_TYPE_VLA_S8
:
1386 if (elem_type
->type
!= SIDE_TYPE_S8
)
1389 case SIDE_TYPE_VLA_S16
:
1390 if (elem_type
->type
!= SIDE_TYPE_S16
)
1393 case SIDE_TYPE_VLA_S32
:
1394 if (elem_type
->type
!= SIDE_TYPE_S32
)
1397 case SIDE_TYPE_VLA_S64
:
1398 if (elem_type
->type
!= SIDE_TYPE_S64
)
1401 case SIDE_TYPE_VLA_BYTE
:
1402 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1405 case SIDE_TYPE_VLA_POINTER32
:
1406 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1408 case SIDE_TYPE_VLA_POINTER64
:
1409 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1415 side_type
= (enum side_type_label
) elem_type
->type
;
1418 for (i
= 0; i
< side_sav_len
; i
++) {
1419 struct side_arg sav_elem
= {
1423 switch (side_type
) {
1425 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1428 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1431 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1434 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1437 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1440 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1443 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1446 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1448 case SIDE_TYPE_BYTE
:
1449 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1451 case SIDE_TYPE_POINTER32
:
1452 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1454 case SIDE_TYPE_POINTER64
:
1455 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1459 fprintf(stderr
, "ERROR: Unexpected type\n");
1463 printf("%s", i
? ", " : "");
1464 tracer_print_type(elem_type
, &sav_elem
);
1470 fprintf(stderr
, "ERROR: type mismatch\n");
1475 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1477 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1478 uint32_t i
, len
= dynamic_struct
->len
;
1480 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1481 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1482 printf("fields:: ");
1484 for (i
= 0; i
< len
; i
++) {
1485 printf("%s", i
? ", " : "");
1486 printf("%s:: ", fields
[i
].field_name
);
1487 tracer_print_dynamic(&fields
[i
].elem
);
1492 struct tracer_dynamic_struct_visitor_priv
{
1497 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1498 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1499 const struct side_arg_dynamic_field
*dynamic_field
)
1501 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1502 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1504 printf("%s", tracer_priv
->i
++ ? ", " : "");
1505 printf("%s:: ", dynamic_field
->field_name
);
1506 tracer_print_dynamic(&dynamic_field
->elem
);
1507 return SIDE_VISITOR_STATUS_OK
;
1511 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1513 enum side_visitor_status status
;
1514 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1517 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1518 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1519 .priv
= &tracer_priv
,
1521 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1523 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1524 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1525 printf("fields:: ");
1527 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1529 case SIDE_VISITOR_STATUS_OK
:
1531 case SIDE_VISITOR_STATUS_ERROR
:
1532 fprintf(stderr
, "ERROR: Visitor error\n");
1539 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1541 const struct side_arg
*sav
= vla
->sav
;
1542 uint32_t i
, side_sav_len
= vla
->len
;
1544 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1545 printf("%s", vla
->nr_attr
? ", " : "");
1546 printf("elements:: ");
1548 for (i
= 0; i
< side_sav_len
; i
++) {
1549 printf("%s", i
? ", " : "");
1550 tracer_print_dynamic(&sav
[i
]);
1555 struct tracer_dynamic_vla_visitor_priv
{
1560 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1561 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1562 const struct side_arg
*elem
)
1564 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1565 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1567 printf("%s", tracer_priv
->i
++ ? ", " : "");
1568 tracer_print_dynamic(elem
);
1569 return SIDE_VISITOR_STATUS_OK
;
1573 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1575 enum side_visitor_status status
;
1576 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1579 const struct side_tracer_visitor_ctx tracer_ctx
= {
1580 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1581 .priv
= &tracer_priv
,
1583 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1585 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1586 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1587 printf("elements:: ");
1589 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1591 case SIDE_VISITOR_STATUS_OK
:
1593 case SIDE_VISITOR_STATUS_ERROR
:
1594 fprintf(stderr
, "ERROR: Visitor error\n");
1601 void tracer_print_dynamic(const struct side_arg
*item
)
1604 switch (item
->type
) {
1605 case SIDE_TYPE_DYNAMIC_NULL
:
1606 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1607 printf("<NULL TYPE>");
1609 case SIDE_TYPE_DYNAMIC_BOOL
:
1610 tracer_print_type_header("::", item
->u
.side_dynamic
.side_bool
.type
.attr
, item
->u
.side_dynamic
.side_bool
.type
.nr_attr
);
1611 printf("%s", item
->u
.side_dynamic
.side_bool
.value
? "true" : "false");
1613 case SIDE_TYPE_DYNAMIC_U8
:
1614 case SIDE_TYPE_DYNAMIC_U16
:
1615 case SIDE_TYPE_DYNAMIC_U32
:
1616 case SIDE_TYPE_DYNAMIC_U64
:
1617 case SIDE_TYPE_DYNAMIC_S8
:
1618 case SIDE_TYPE_DYNAMIC_S16
:
1619 case SIDE_TYPE_DYNAMIC_S32
:
1620 case SIDE_TYPE_DYNAMIC_S64
:
1621 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1622 TRACER_DISPLAY_BASE_10
);
1624 case SIDE_TYPE_DYNAMIC_BYTE
:
1625 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1626 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1629 case SIDE_TYPE_DYNAMIC_POINTER32
:
1630 case SIDE_TYPE_DYNAMIC_POINTER64
:
1631 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1632 TRACER_DISPLAY_BASE_16
);
1635 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
1636 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
1637 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
1638 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
1639 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1640 &item
->u
.side_dynamic
.side_float
.value
);
1643 case SIDE_TYPE_DYNAMIC_STRING
:
1644 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1645 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1647 case SIDE_TYPE_DYNAMIC_STRUCT
:
1648 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1650 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1651 tracer_print_dynamic_struct_visitor(item
);
1653 case SIDE_TYPE_DYNAMIC_VLA
:
1654 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1656 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1657 tracer_print_dynamic_vla_visitor(item
);
1660 fprintf(stderr
, "<UNKNOWN TYPE>");
1667 void tracer_print_static_fields(const struct side_event_description
*desc
,
1668 const struct side_arg_vec
*side_arg_vec
,
1671 const struct side_arg
*sav
= side_arg_vec
->sav
;
1672 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1674 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1675 if (desc
->nr_fields
!= side_sav_len
) {
1676 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1679 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1680 printf("%s", side_sav_len
? ", fields: [ " : "");
1681 for (i
= 0; i
< side_sav_len
; i
++) {
1682 printf("%s", i
? ", " : "");
1683 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1691 void tracer_call(const struct side_event_description
*desc
,
1692 const struct side_arg_vec
*side_arg_vec
,
1693 void *priv
__attribute__((unused
)))
1695 uint32_t nr_fields
= 0;
1697 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1701 void tracer_call_variadic(const struct side_event_description
*desc
,
1702 const struct side_arg_vec
*side_arg_vec
,
1703 const struct side_arg_dynamic_struct
*var_struct
,
1704 void *priv
__attribute__((unused
)))
1706 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1708 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1710 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1711 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1714 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1715 printf("%s", var_struct_len
? ", fields:: [ " : "");
1716 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1717 printf("%s", i
? ", " : "");
1718 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1719 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1726 void tracer_event_notification(enum side_tracer_notification notif
,
1727 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1732 printf("----------------------------------------------------------\n");
1733 printf("Tracer notified of events %s\n",
1734 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1735 for (i
= 0; i
< nr_events
; i
++) {
1736 struct side_event_description
*event
= events
[i
];
1738 /* Skip NULL pointers */
1741 printf("provider: %s, event: %s\n",
1742 event
->provider_name
, event
->event_name
);
1743 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1744 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1745 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1749 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1754 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1755 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1759 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1765 printf("----------------------------------------------------------\n");
1768 static __attribute__((constructor
))
1769 void tracer_init(void);
1771 void tracer_init(void)
1773 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1778 static __attribute__((destructor
))
1779 void tracer_exit(void);
1781 void tracer_exit(void)
1783 side_tracer_event_notification_unregister(tracer_handle
);