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_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
41 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
43 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
45 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
);
47 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
);
49 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
50 const void *_length_ptr
);
52 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
55 int64_t get_attr_integer_value(const struct side_attr
*attr
)
59 switch (attr
->value
.type
) {
60 case SIDE_ATTR_TYPE_U8
:
61 val
= attr
->value
.u
.integer_value
.side_u8
;
63 case SIDE_ATTR_TYPE_U16
:
64 val
= attr
->value
.u
.integer_value
.side_u16
;
66 case SIDE_ATTR_TYPE_U32
:
67 val
= attr
->value
.u
.integer_value
.side_u32
;
69 case SIDE_ATTR_TYPE_U64
:
70 val
= attr
->value
.u
.integer_value
.side_u64
;
72 case SIDE_ATTR_TYPE_S8
:
73 val
= attr
->value
.u
.integer_value
.side_s8
;
75 case SIDE_ATTR_TYPE_S16
:
76 val
= attr
->value
.u
.integer_value
.side_s16
;
78 case SIDE_ATTR_TYPE_S32
:
79 val
= attr
->value
.u
.integer_value
.side_s32
;
81 case SIDE_ATTR_TYPE_S64
:
82 val
= attr
->value
.u
.integer_value
.side_s64
;
85 fprintf(stderr
, "Unexpected attribute type\n");
92 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
93 enum tracer_display_base default_base
)
97 for (i
= 0; i
< nr_attr
; i
++) {
98 const struct side_attr
*attr
= &_attr
[i
];
100 if (!strcmp(attr
->key
, "std.integer.base")) {
101 int64_t val
= get_attr_integer_value(attr
);
105 return TRACER_DISPLAY_BASE_2
;
107 return TRACER_DISPLAY_BASE_8
;
109 return TRACER_DISPLAY_BASE_10
;
111 return TRACER_DISPLAY_BASE_16
;
113 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
118 return default_base
; /* Default */
122 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
124 switch (type_desc
->type
) {
135 case SIDE_TYPE_POINTER32
:
136 case SIDE_TYPE_POINTER64
:
137 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
142 case SIDE_TYPE_FLOAT_BINARY16
:
143 case SIDE_TYPE_FLOAT_BINARY32
:
144 case SIDE_TYPE_FLOAT_BINARY64
:
145 case SIDE_TYPE_FLOAT_BINARY128
:
146 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
152 fprintf(stderr
, "Unexpected type\n");
158 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
160 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
161 switch (attr
->value
.type
) {
162 case SIDE_ATTR_TYPE_BOOL
:
163 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
165 case SIDE_ATTR_TYPE_U8
:
166 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
168 case SIDE_ATTR_TYPE_U16
:
169 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
171 case SIDE_ATTR_TYPE_U32
:
172 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
174 case SIDE_ATTR_TYPE_U64
:
175 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
177 case SIDE_ATTR_TYPE_S8
:
178 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
180 case SIDE_ATTR_TYPE_S16
:
181 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
183 case SIDE_ATTR_TYPE_S32
:
184 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
186 case SIDE_ATTR_TYPE_S64
:
187 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
189 case SIDE_ATTR_TYPE_POINTER32
:
190 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
192 case SIDE_ATTR_TYPE_POINTER64
:
193 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
195 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
197 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
200 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
203 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
205 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
208 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
211 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
213 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
216 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
219 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
221 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
224 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
227 case SIDE_ATTR_TYPE_STRING
:
228 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
231 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
238 void print_attributes(const char *prefix_str
, const char *separator
,
239 const struct side_attr
*attr
, uint32_t nr_attr
)
245 printf("%s%s [ ", prefix_str
, separator
);
246 for (i
= 0; i
< nr_attr
; i
++) {
247 printf("%s", i
? ", " : "");
248 tracer_print_attr_type(separator
, &attr
[i
]);
254 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
256 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
257 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
258 uint32_t i
, print_count
= 0;
261 if (elem_type
->type
!= item
->type
) {
262 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
265 switch (item
->type
) {
267 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
273 v
= item
->u
.side_static
.integer_value
.side_u16
;
274 if (type_to_host_reverse_bo(elem_type
))
275 v
= side_bswap_16(v
);
283 v
= item
->u
.side_static
.integer_value
.side_u32
;
284 if (type_to_host_reverse_bo(elem_type
))
285 v
= side_bswap_32(v
);
293 v
= item
->u
.side_static
.integer_value
.side_u64
;
294 if (type_to_host_reverse_bo(elem_type
))
295 v
= side_bswap_64(v
);
300 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
306 v
= item
->u
.side_static
.integer_value
.side_s16
;
307 if (type_to_host_reverse_bo(elem_type
))
308 v
= side_bswap_16(v
);
316 v
= item
->u
.side_static
.integer_value
.side_s32
;
317 if (type_to_host_reverse_bo(elem_type
))
318 v
= side_bswap_32(v
);
326 v
= item
->u
.side_static
.integer_value
.side_s64
;
327 if (type_to_host_reverse_bo(elem_type
))
328 v
= side_bswap_64(v
);
333 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
336 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
337 printf("%s", mappings
->nr_attr
? ", " : "");
338 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
339 printf(", labels: [ ");
340 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
341 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
343 if (mapping
->range_end
< mapping
->range_begin
) {
344 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
345 mapping
->range_begin
, mapping
->range_end
);
348 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
349 printf("%s", print_count
++ ? ", " : "");
350 printf("\"%s\"", mapping
->label
);
354 printf("<NO LABEL>");
359 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
363 switch (elem_type
->type
) {
364 case SIDE_TYPE_U8
: /* Fall-through */
378 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
385 void print_enum_bitmap(const struct side_type
*type_desc
,
386 const struct side_arg
*item
)
388 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
389 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
390 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
391 bool reverse_byte_order
= false;
392 const struct side_arg
*array_item
;
394 switch (elem_type
->type
) {
395 case SIDE_TYPE_U8
: /* Fall-through */
396 case SIDE_TYPE_BYTE
: /* Fall-through */
397 case SIDE_TYPE_U16
: /* Fall-through */
398 case SIDE_TYPE_U32
: /* Fall-through */
400 stride_bit
= enum_elem_type_to_stride(elem_type
);
401 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
405 case SIDE_TYPE_ARRAY
:
406 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
407 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
408 array_item
= item
->u
.side_static
.side_array
->sav
;
409 nr_items
= type_desc
->u
.side_array
.length
;
412 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
413 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
414 array_item
= item
->u
.side_static
.side_vla
->sav
;
415 nr_items
= item
->u
.side_static
.side_vla
->len
;
418 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
422 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
423 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
424 printf("labels: [ ");
425 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
426 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
430 if (mapping
->range_end
< mapping
->range_begin
) {
431 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
432 mapping
->range_begin
, mapping
->range_end
);
435 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
436 if (bit
> (nr_items
* stride_bit
) - 1)
438 switch (stride_bit
) {
441 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
442 if (v
& (1ULL << (bit
% 8))) {
450 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
451 if (reverse_byte_order
)
452 v
= side_bswap_16(v
);
453 if (v
& (1ULL << (bit
% 16))) {
461 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
462 if (reverse_byte_order
)
463 v
= side_bswap_32(v
);
464 if (v
& (1ULL << (bit
% 32))) {
472 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
473 if (reverse_byte_order
)
474 v
= side_bswap_64(v
);
475 if (v
& (1ULL << (bit
% 64))) {
487 printf("%s", print_count
++ ? ", " : "");
488 printf("\"%s\"", mapping
->label
);
492 printf("<NO LABEL>");
497 void print_integer_binary(uint64_t v
, int bits
)
503 for (i
= 0; i
< bits
; i
++) {
504 printf("%c", v
& (1ULL << 63) ? '1' : '0');
510 void tracer_print_type_header(const char *separator
,
511 const struct side_attr
*attr
, uint32_t nr_attr
)
513 print_attributes("attr", separator
, attr
, nr_attr
);
514 printf("%s", nr_attr
? ", " : "");
515 printf("value%s ", separator
);
519 void tracer_print_type_integer(const char *separator
,
520 const struct side_type_integer
*type_integer
,
521 const union side_integer_value
*value
,
522 uint16_t offset_bits
,
523 enum tracer_display_base default_base
)
525 enum tracer_display_base base
;
532 if (!type_integer
->len_bits
||
533 type_integer
->len_bits
+ offset_bits
> type_integer
->integer_size_bits
)
535 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
536 base
= get_attr_display_base(type_integer
->attr
,
537 type_integer
->nr_attr
,
539 switch (type_integer
->integer_size_bits
) {
541 if (type_integer
->signedness
)
542 v
.v_signed
= value
->side_s8
;
544 v
.v_unsigned
= value
->side_u8
;
547 if (type_integer
->signedness
) {
550 side_s16
= value
->side_s16
;
552 side_s16
= side_bswap_16(side_s16
);
553 v
.v_signed
= side_s16
;
557 side_u16
= value
->side_u16
;
559 side_u16
= side_bswap_16(side_u16
);
560 v
.v_unsigned
= side_u16
;
564 if (type_integer
->signedness
) {
567 side_s32
= value
->side_s32
;
569 side_s32
= side_bswap_32(side_s32
);
570 v
.v_signed
= side_s32
;
574 side_u32
= value
->side_u32
;
576 side_u32
= side_bswap_32(side_u32
);
577 v
.v_unsigned
= side_u32
;
581 if (type_integer
->signedness
) {
584 side_s64
= value
->side_s64
;
586 side_s64
= side_bswap_64(side_s64
);
587 v
.v_signed
= side_s64
;
591 side_u64
= value
->side_u64
;
593 side_u64
= side_bswap_64(side_u64
);
594 v
.v_unsigned
= side_u64
;
600 v
.v_unsigned
>>= offset_bits
;
601 if (type_integer
->len_bits
< 64)
602 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
603 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
605 case TRACER_DISPLAY_BASE_2
:
606 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
608 case TRACER_DISPLAY_BASE_8
:
609 printf("0%" PRIo64
, v
.v_unsigned
);
611 case TRACER_DISPLAY_BASE_10
:
612 if (type_integer
->signedness
) {
614 if (type_integer
->len_bits
< 64) {
615 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
616 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
618 printf("%" PRId64
, v
.v_signed
);
620 printf("%" PRIu64
, v
.v_unsigned
);
623 case TRACER_DISPLAY_BASE_16
:
624 printf("0x%" PRIx64
, v
.v_unsigned
);
632 void tracer_print_type_float(const char *separator
,
633 const struct side_type_float
*type_float
,
634 const union side_float_value
*value
)
638 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
639 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
640 switch (type_float
->float_size_bits
) {
648 .f
= value
->side_float_binary16
,
652 float16
.u
= side_bswap_16(float16
.u
);
653 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
654 printf("%g", (double) float16
.f
);
657 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
668 .f
= value
->side_float_binary32
,
672 float32
.u
= side_bswap_32(float32
.u
);
673 printf("%g", (double) float32
.f
);
676 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
687 .f
= value
->side_float_binary64
,
691 float64
.u
= side_bswap_64(float64
.u
);
692 printf("%g", (double) float64
.f
);
695 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
706 .f
= value
->side_float_binary128
,
710 side_bswap_128p(float128
.arr
);
711 printf("%Lg", (long double) float128
.f
);
714 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
719 fprintf(stderr
, "ERROR: Unknown float size\n");
725 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
727 enum side_type_label type
;
729 switch (type_desc
->type
) {
730 case SIDE_TYPE_ARRAY
:
731 switch (item
->type
) {
732 case SIDE_TYPE_ARRAY_U8
:
733 case SIDE_TYPE_ARRAY_U16
:
734 case SIDE_TYPE_ARRAY_U32
:
735 case SIDE_TYPE_ARRAY_U64
:
736 case SIDE_TYPE_ARRAY_S8
:
737 case SIDE_TYPE_ARRAY_S16
:
738 case SIDE_TYPE_ARRAY_S32
:
739 case SIDE_TYPE_ARRAY_S64
:
740 case SIDE_TYPE_ARRAY_POINTER32
:
741 case SIDE_TYPE_ARRAY_POINTER64
:
742 case SIDE_TYPE_ARRAY_BYTE
:
743 case SIDE_TYPE_ARRAY
:
746 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
753 switch (item
->type
) {
754 case SIDE_TYPE_VLA_U8
:
755 case SIDE_TYPE_VLA_U16
:
756 case SIDE_TYPE_VLA_U32
:
757 case SIDE_TYPE_VLA_U64
:
758 case SIDE_TYPE_VLA_S8
:
759 case SIDE_TYPE_VLA_S16
:
760 case SIDE_TYPE_VLA_S32
:
761 case SIDE_TYPE_VLA_S64
:
762 case SIDE_TYPE_VLA_BYTE
:
763 case SIDE_TYPE_VLA_POINTER32
:
764 case SIDE_TYPE_VLA_POINTER64
:
768 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
775 switch (item
->type
) {
786 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
792 case SIDE_TYPE_ENUM_BITMAP
:
793 switch (item
->type
) {
799 case SIDE_TYPE_ARRAY
:
803 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
809 case SIDE_TYPE_DYNAMIC
:
810 switch (item
->type
) {
811 case SIDE_TYPE_DYNAMIC_NULL
:
812 case SIDE_TYPE_DYNAMIC_BOOL
:
813 case SIDE_TYPE_DYNAMIC_U8
:
814 case SIDE_TYPE_DYNAMIC_U16
:
815 case SIDE_TYPE_DYNAMIC_U32
:
816 case SIDE_TYPE_DYNAMIC_U64
:
817 case SIDE_TYPE_DYNAMIC_S8
:
818 case SIDE_TYPE_DYNAMIC_S16
:
819 case SIDE_TYPE_DYNAMIC_S32
:
820 case SIDE_TYPE_DYNAMIC_S64
:
821 case SIDE_TYPE_DYNAMIC_BYTE
:
822 case SIDE_TYPE_DYNAMIC_POINTER32
:
823 case SIDE_TYPE_DYNAMIC_POINTER64
:
824 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
825 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
826 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
827 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
828 case SIDE_TYPE_DYNAMIC_STRING
:
829 case SIDE_TYPE_DYNAMIC_STRUCT
:
830 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
831 case SIDE_TYPE_DYNAMIC_VLA
:
832 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
835 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
842 if (type_desc
->type
!= item
->type
) {
843 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
849 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
850 type
= (enum side_type_label
) type_desc
->type
;
852 type
= (enum side_type_label
) item
->type
;
857 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
858 printf("<NULL TYPE>");
862 tracer_print_type_header(":", type_desc
->u
.side_bool
.attr
, type_desc
->u
.side_bool
.nr_attr
);
863 printf("%s", item
->u
.side_static
.bool_value
? "true" : "false");
874 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
875 TRACER_DISPLAY_BASE_10
);
878 case SIDE_TYPE_POINTER32
:
879 case SIDE_TYPE_POINTER64
:
880 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
881 TRACER_DISPLAY_BASE_16
);
885 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
886 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
890 print_enum(type_desc
, item
);
893 case SIDE_TYPE_ENUM_BITMAP
:
894 print_enum_bitmap(type_desc
, item
);
897 case SIDE_TYPE_FLOAT_BINARY16
:
898 case SIDE_TYPE_FLOAT_BINARY32
:
899 case SIDE_TYPE_FLOAT_BINARY64
:
900 case SIDE_TYPE_FLOAT_BINARY128
:
901 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
904 case SIDE_TYPE_STRING
:
905 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
906 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
908 case SIDE_TYPE_STRUCT
:
909 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
911 case SIDE_TYPE_GATHER_STRUCT
:
912 (void) tracer_print_gather_struct(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_struct_gather_ptr
);
914 case SIDE_TYPE_GATHER_ARRAY
:
915 (void) tracer_print_gather_array(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_array_gather_ptr
);
917 case SIDE_TYPE_GATHER_VLA
:
918 (void) tracer_print_gather_vla(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_vla_gather
.ptr
,
919 item
->u
.side_static
.side_vla_gather
.length_ptr
);
921 case SIDE_TYPE_GATHER_BYTE
:
922 (void) tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_byte_gather_ptr
);
924 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
925 case SIDE_TYPE_GATHER_SIGNED_INT
:
926 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
);
928 case SIDE_TYPE_GATHER_FLOAT
:
929 (void) tracer_print_gather_float_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_float_gather_ptr
);
931 case SIDE_TYPE_ARRAY
:
932 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
935 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
937 case SIDE_TYPE_VLA_VISITOR
:
938 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
940 case SIDE_TYPE_ARRAY_U8
:
941 case SIDE_TYPE_ARRAY_U16
:
942 case SIDE_TYPE_ARRAY_U32
:
943 case SIDE_TYPE_ARRAY_U64
:
944 case SIDE_TYPE_ARRAY_S8
:
945 case SIDE_TYPE_ARRAY_S16
:
946 case SIDE_TYPE_ARRAY_S32
:
947 case SIDE_TYPE_ARRAY_S64
:
948 case SIDE_TYPE_ARRAY_BYTE
:
949 case SIDE_TYPE_ARRAY_POINTER32
:
950 case SIDE_TYPE_ARRAY_POINTER64
:
951 tracer_print_array_fixint(type_desc
, item
);
953 case SIDE_TYPE_VLA_U8
:
954 case SIDE_TYPE_VLA_U16
:
955 case SIDE_TYPE_VLA_U32
:
956 case SIDE_TYPE_VLA_U64
:
957 case SIDE_TYPE_VLA_S8
:
958 case SIDE_TYPE_VLA_S16
:
959 case SIDE_TYPE_VLA_S32
:
960 case SIDE_TYPE_VLA_S64
:
961 case SIDE_TYPE_VLA_BYTE
:
962 case SIDE_TYPE_VLA_POINTER32
:
963 case SIDE_TYPE_VLA_POINTER64
:
964 tracer_print_vla_fixint(type_desc
, item
);
968 case SIDE_TYPE_DYNAMIC_NULL
:
969 case SIDE_TYPE_DYNAMIC_BOOL
:
970 case SIDE_TYPE_DYNAMIC_U8
:
971 case SIDE_TYPE_DYNAMIC_U16
:
972 case SIDE_TYPE_DYNAMIC_U32
:
973 case SIDE_TYPE_DYNAMIC_U64
:
974 case SIDE_TYPE_DYNAMIC_S8
:
975 case SIDE_TYPE_DYNAMIC_S16
:
976 case SIDE_TYPE_DYNAMIC_S32
:
977 case SIDE_TYPE_DYNAMIC_S64
:
978 case SIDE_TYPE_DYNAMIC_BYTE
:
979 case SIDE_TYPE_DYNAMIC_POINTER32
:
980 case SIDE_TYPE_DYNAMIC_POINTER64
:
981 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
982 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
983 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
984 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
985 case SIDE_TYPE_DYNAMIC_STRING
:
986 case SIDE_TYPE_DYNAMIC_STRUCT
:
987 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
988 case SIDE_TYPE_DYNAMIC_VLA
:
989 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
990 tracer_print_dynamic(item
);
993 fprintf(stderr
, "<UNKNOWN TYPE>");
1000 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
1002 printf("%s: ", item_desc
->field_name
);
1003 tracer_print_type(&item_desc
->side_type
, item
);
1007 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1009 const struct side_arg
*sav
= side_arg_vec
->sav
;
1010 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1012 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
1013 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
1016 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1017 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1018 printf("fields: { ");
1019 for (i
= 0; i
< side_sav_len
; i
++) {
1020 printf("%s", i
? ", " : "");
1021 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1027 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1029 const struct side_arg
*sav
= side_arg_vec
->sav
;
1030 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1032 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1033 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1036 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1037 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1038 printf("elements: ");
1040 for (i
= 0; i
< side_sav_len
; i
++) {
1041 printf("%s", i
? ", " : "");
1042 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1048 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1050 const struct side_arg
*sav
= side_arg_vec
->sav
;
1051 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1053 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1054 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1055 printf("elements: ");
1057 for (i
= 0; i
< side_sav_len
; i
++) {
1058 printf("%s", i
? ", " : "");
1059 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1065 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode
, const char *ptr
)
1067 switch (access_mode
) {
1068 case SIDE_TYPE_GATHER_ACCESS_ADDRESS
:
1070 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1071 /* Dereference pointer */
1072 memcpy(&ptr
, ptr
, sizeof(ptr
));
1080 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode
, uint32_t len
)
1082 switch (access_mode
) {
1083 case SIDE_TYPE_GATHER_ACCESS_ADDRESS
:
1085 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1086 return sizeof(void *);
1093 uint64_t tracer_load_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1095 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_integer
.access_mode
;
1096 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size_bits
>> 3;
1097 const char *ptr
= (const char *) _ptr
;
1098 union side_integer_value value
;
1100 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1101 memcpy(&value
, ptr
, integer_size_bytes
);
1102 switch (type_gather
->u
.side_integer
.type
.integer_size_bits
) {
1104 return (uint64_t) value
.side_u8
;
1106 return (uint64_t) value
.side_u16
;
1108 return (uint64_t) value
.side_u32
;
1110 return (uint64_t) value
.side_u64
;
1117 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1119 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_byte
.access_mode
;
1120 const char *ptr
= (const char *) _ptr
;
1123 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_byte
.offset
);
1124 memcpy(&value
, ptr
, 1);
1125 tracer_print_type_header(":", type_gather
->u
.side_byte
.type
.attr
,
1126 type_gather
->u
.side_byte
.type
.nr_attr
);
1127 printf("0x%" PRIx8
, value
);
1128 return tracer_gather_size(access_mode
, 1);
1132 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1134 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_integer
.access_mode
;
1135 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size_bits
>> 3;
1136 const char *ptr
= (const char *) _ptr
;
1137 union side_integer_value value
;
1139 switch (type_gather
->u
.side_integer
.type
.integer_size_bits
) {
1148 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1149 memcpy(&value
, ptr
, integer_size_bytes
);
1150 tracer_print_type_integer(":", &type_gather
->u
.side_integer
.type
, &value
,
1151 type_gather
->u
.side_integer
.offset_bits
, TRACER_DISPLAY_BASE_10
);
1152 return tracer_gather_size(access_mode
, integer_size_bytes
);
1156 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1158 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_float
.access_mode
;
1159 uint32_t float_size_bytes
= type_gather
->u
.side_float
.type
.float_size_bits
>> 3;
1160 const char *ptr
= (const char *) _ptr
;
1161 union side_float_value value
;
1163 switch (type_gather
->u
.side_float
.type
.float_size_bits
) {
1172 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_float
.offset
);
1173 memcpy(&value
, ptr
, float_size_bytes
);
1174 tracer_print_type_float(":", &type_gather
->u
.side_float
.type
, &value
);
1175 return tracer_gather_size(access_mode
, float_size_bytes
);
1179 uint32_t tracer_print_gather_type(const struct side_type
*type_desc
, const void *ptr
)
1184 switch (type_desc
->type
) {
1185 case SIDE_TYPE_GATHER_BYTE
:
1186 len
= tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, ptr
);
1188 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
1189 case SIDE_TYPE_GATHER_SIGNED_INT
:
1190 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
);
1192 case SIDE_TYPE_GATHER_FLOAT
:
1193 len
= tracer_print_gather_float_type(&type_desc
->u
.side_gather
, ptr
);
1195 case SIDE_TYPE_GATHER_STRUCT
:
1196 len
= tracer_print_gather_struct(&type_desc
->u
.side_gather
, ptr
);
1198 case SIDE_TYPE_GATHER_ARRAY
:
1199 len
= tracer_print_gather_array(&type_desc
->u
.side_gather
, ptr
);
1201 case SIDE_TYPE_GATHER_VLA
:
1202 len
= tracer_print_gather_vla(&type_desc
->u
.side_gather
, ptr
, ptr
);
1205 fprintf(stderr
, "<UNKNOWN GATHER TYPE>");
1213 void tracer_print_gather_field(const struct side_event_field
*field
, const void *ptr
)
1215 printf("%s: ", field
->field_name
);
1216 (void) tracer_print_gather_type(&field
->side_type
, ptr
);
1220 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
)
1222 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_struct
.access_mode
;
1223 const char *ptr
= (const char *) _ptr
;
1226 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_struct
.offset
);
1227 print_attributes("attr", ":", type_gather
->u
.side_struct
.type
->attr
, type_gather
->u
.side_struct
.type
->nr_attr
);
1228 printf("%s", type_gather
->u
.side_struct
.type
->nr_attr
? ", " : "");
1229 printf("fields: { ");
1230 for (i
= 0; i
< type_gather
->u
.side_struct
.type
->nr_fields
; i
++) {
1231 printf("%s", i
? ", " : "");
1232 tracer_print_gather_field(&type_gather
->u
.side_struct
.type
->fields
[i
], ptr
);
1235 return tracer_gather_size(access_mode
, type_gather
->u
.side_struct
.size
);
1239 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
)
1241 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_array
.access_mode
;
1242 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1245 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_array
.offset
);
1247 print_attributes("attr", ":", type_gather
->u
.side_array
.type
.attr
, type_gather
->u
.side_array
.type
.nr_attr
);
1248 printf("%s", type_gather
->u
.side_array
.type
.nr_attr
? ", " : "");
1249 printf("elements: ");
1251 for (i
= 0; i
< type_gather
->u
.side_array
.type
.length
; i
++) {
1252 switch (type_gather
->u
.side_array
.type
.elem_type
->type
) {
1253 case SIDE_TYPE_GATHER_VLA
:
1254 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1259 printf("%s", i
? ", " : "");
1260 ptr
+= tracer_print_gather_type(type_gather
->u
.side_array
.type
.elem_type
, ptr
);
1263 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1267 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
1268 const void *_length_ptr
)
1270 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_vla
.access_mode
;
1271 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1272 const char *length_ptr
= (const char *) _length_ptr
;
1276 switch (type_gather
->u
.side_vla
.length_type
->type
) {
1277 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
1278 case SIDE_TYPE_GATHER_SIGNED_INT
:
1281 fprintf(stderr
, "<gather VLA expects integer gather length type>\n");
1284 length
= (uint32_t) tracer_load_gather_integer_type(&type_gather
->u
.side_vla
.length_type
->u
.side_gather
, length_ptr
);
1285 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_vla
.offset
);
1287 print_attributes("attr", ":", type_gather
->u
.side_vla
.type
.attr
, type_gather
->u
.side_vla
.type
.nr_attr
);
1288 printf("%s", type_gather
->u
.side_vla
.type
.nr_attr
? ", " : "");
1289 printf("elements: ");
1291 for (i
= 0; i
< length
; i
++) {
1292 switch (type_gather
->u
.side_vla
.type
.elem_type
->type
) {
1293 case SIDE_TYPE_GATHER_VLA
:
1294 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1299 printf("%s", i
? ", " : "");
1300 ptr
+= tracer_print_gather_type(type_gather
->u
.side_vla
.type
.elem_type
, ptr
);
1303 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1306 struct tracer_visitor_priv
{
1307 const struct side_type
*elem_type
;
1312 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1313 const struct side_arg
*elem
)
1315 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1317 printf("%s", tracer_priv
->i
++ ? ", " : "");
1318 tracer_print_type(tracer_priv
->elem_type
, elem
);
1319 return SIDE_VISITOR_STATUS_OK
;
1323 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1325 enum side_visitor_status status
;
1326 struct tracer_visitor_priv tracer_priv
= {
1327 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1330 const struct side_tracer_visitor_ctx tracer_ctx
= {
1331 .write_elem
= tracer_write_elem_cb
,
1332 .priv
= &tracer_priv
,
1335 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1336 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1337 printf("elements: ");
1339 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1341 case SIDE_VISITOR_STATUS_OK
:
1343 case SIDE_VISITOR_STATUS_ERROR
:
1344 fprintf(stderr
, "ERROR: Visitor error\n");
1350 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1352 const struct side_type
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1353 uint32_t i
, side_sav_len
= type_desc
->u
.side_array
.length
;
1354 void *p
= item
->u
.side_static
.side_array_fixint
;
1355 enum side_type_label side_type
;
1357 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1358 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1359 printf("elements: ");
1360 switch (item
->type
) {
1361 case SIDE_TYPE_ARRAY_U8
:
1362 if (elem_type
->type
!= SIDE_TYPE_U8
)
1365 case SIDE_TYPE_ARRAY_U16
:
1366 if (elem_type
->type
!= SIDE_TYPE_U16
)
1369 case SIDE_TYPE_ARRAY_U32
:
1370 if (elem_type
->type
!= SIDE_TYPE_U32
)
1373 case SIDE_TYPE_ARRAY_U64
:
1374 if (elem_type
->type
!= SIDE_TYPE_U64
)
1377 case SIDE_TYPE_ARRAY_S8
:
1378 if (elem_type
->type
!= SIDE_TYPE_S8
)
1381 case SIDE_TYPE_ARRAY_S16
:
1382 if (elem_type
->type
!= SIDE_TYPE_S16
)
1385 case SIDE_TYPE_ARRAY_S32
:
1386 if (elem_type
->type
!= SIDE_TYPE_S32
)
1389 case SIDE_TYPE_ARRAY_S64
:
1390 if (elem_type
->type
!= SIDE_TYPE_S64
)
1393 case SIDE_TYPE_ARRAY_BYTE
:
1394 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1397 case SIDE_TYPE_ARRAY_POINTER32
:
1398 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1400 case SIDE_TYPE_ARRAY_POINTER64
:
1401 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1407 side_type
= (enum side_type_label
) elem_type
->type
;
1410 for (i
= 0; i
< side_sav_len
; i
++) {
1411 struct side_arg sav_elem
= {
1415 switch (side_type
) {
1417 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1420 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1423 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1426 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1429 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1432 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1435 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1438 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1440 case SIDE_TYPE_BYTE
:
1441 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1443 case SIDE_TYPE_POINTER32
:
1444 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1446 case SIDE_TYPE_POINTER64
:
1447 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1451 fprintf(stderr
, "ERROR: Unexpected type\n");
1455 printf("%s", i
? ", " : "");
1456 tracer_print_type(elem_type
, &sav_elem
);
1462 fprintf(stderr
, "ERROR: type mismatch\n");
1466 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1468 const struct side_type
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1469 uint32_t i
, side_sav_len
= item
->u
.side_static
.side_vla_fixint
.length
;
1470 void *p
= item
->u
.side_static
.side_vla_fixint
.p
;
1471 enum side_type_label side_type
;
1473 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1474 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1475 printf("elements: ");
1476 switch (item
->type
) {
1477 case SIDE_TYPE_VLA_U8
:
1478 if (elem_type
->type
!= SIDE_TYPE_U8
)
1481 case SIDE_TYPE_VLA_U16
:
1482 if (elem_type
->type
!= SIDE_TYPE_U16
)
1485 case SIDE_TYPE_VLA_U32
:
1486 if (elem_type
->type
!= SIDE_TYPE_U32
)
1489 case SIDE_TYPE_VLA_U64
:
1490 if (elem_type
->type
!= SIDE_TYPE_U64
)
1493 case SIDE_TYPE_VLA_S8
:
1494 if (elem_type
->type
!= SIDE_TYPE_S8
)
1497 case SIDE_TYPE_VLA_S16
:
1498 if (elem_type
->type
!= SIDE_TYPE_S16
)
1501 case SIDE_TYPE_VLA_S32
:
1502 if (elem_type
->type
!= SIDE_TYPE_S32
)
1505 case SIDE_TYPE_VLA_S64
:
1506 if (elem_type
->type
!= SIDE_TYPE_S64
)
1509 case SIDE_TYPE_VLA_BYTE
:
1510 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1513 case SIDE_TYPE_VLA_POINTER32
:
1514 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1516 case SIDE_TYPE_VLA_POINTER64
:
1517 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1523 side_type
= (enum side_type_label
) elem_type
->type
;
1526 for (i
= 0; i
< side_sav_len
; i
++) {
1527 struct side_arg sav_elem
= {
1531 switch (side_type
) {
1533 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1536 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1539 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1542 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1545 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1548 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1551 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1554 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1556 case SIDE_TYPE_BYTE
:
1557 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1559 case SIDE_TYPE_POINTER32
:
1560 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1562 case SIDE_TYPE_POINTER64
:
1563 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1567 fprintf(stderr
, "ERROR: Unexpected type\n");
1571 printf("%s", i
? ", " : "");
1572 tracer_print_type(elem_type
, &sav_elem
);
1578 fprintf(stderr
, "ERROR: type mismatch\n");
1583 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1585 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1586 uint32_t i
, len
= dynamic_struct
->len
;
1588 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1589 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1590 printf("fields:: ");
1592 for (i
= 0; i
< len
; i
++) {
1593 printf("%s", i
? ", " : "");
1594 printf("%s:: ", fields
[i
].field_name
);
1595 tracer_print_dynamic(&fields
[i
].elem
);
1600 struct tracer_dynamic_struct_visitor_priv
{
1605 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1606 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1607 const struct side_arg_dynamic_field
*dynamic_field
)
1609 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1610 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1612 printf("%s", tracer_priv
->i
++ ? ", " : "");
1613 printf("%s:: ", dynamic_field
->field_name
);
1614 tracer_print_dynamic(&dynamic_field
->elem
);
1615 return SIDE_VISITOR_STATUS_OK
;
1619 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1621 enum side_visitor_status status
;
1622 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1625 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1626 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1627 .priv
= &tracer_priv
,
1629 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1631 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1632 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1633 printf("fields:: ");
1635 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1637 case SIDE_VISITOR_STATUS_OK
:
1639 case SIDE_VISITOR_STATUS_ERROR
:
1640 fprintf(stderr
, "ERROR: Visitor error\n");
1647 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1649 const struct side_arg
*sav
= vla
->sav
;
1650 uint32_t i
, side_sav_len
= vla
->len
;
1652 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1653 printf("%s", vla
->nr_attr
? ", " : "");
1654 printf("elements:: ");
1656 for (i
= 0; i
< side_sav_len
; i
++) {
1657 printf("%s", i
? ", " : "");
1658 tracer_print_dynamic(&sav
[i
]);
1663 struct tracer_dynamic_vla_visitor_priv
{
1668 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1669 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1670 const struct side_arg
*elem
)
1672 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1673 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1675 printf("%s", tracer_priv
->i
++ ? ", " : "");
1676 tracer_print_dynamic(elem
);
1677 return SIDE_VISITOR_STATUS_OK
;
1681 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1683 enum side_visitor_status status
;
1684 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1687 const struct side_tracer_visitor_ctx tracer_ctx
= {
1688 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1689 .priv
= &tracer_priv
,
1691 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1693 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1694 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1695 printf("elements:: ");
1697 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1699 case SIDE_VISITOR_STATUS_OK
:
1701 case SIDE_VISITOR_STATUS_ERROR
:
1702 fprintf(stderr
, "ERROR: Visitor error\n");
1709 void tracer_print_dynamic(const struct side_arg
*item
)
1712 switch (item
->type
) {
1713 case SIDE_TYPE_DYNAMIC_NULL
:
1714 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1715 printf("<NULL TYPE>");
1717 case SIDE_TYPE_DYNAMIC_BOOL
:
1718 tracer_print_type_header("::", item
->u
.side_dynamic
.side_bool
.type
.attr
, item
->u
.side_dynamic
.side_bool
.type
.nr_attr
);
1719 printf("%s", item
->u
.side_dynamic
.side_bool
.value
? "true" : "false");
1721 case SIDE_TYPE_DYNAMIC_U8
:
1722 case SIDE_TYPE_DYNAMIC_U16
:
1723 case SIDE_TYPE_DYNAMIC_U32
:
1724 case SIDE_TYPE_DYNAMIC_U64
:
1725 case SIDE_TYPE_DYNAMIC_S8
:
1726 case SIDE_TYPE_DYNAMIC_S16
:
1727 case SIDE_TYPE_DYNAMIC_S32
:
1728 case SIDE_TYPE_DYNAMIC_S64
:
1729 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1730 TRACER_DISPLAY_BASE_10
);
1732 case SIDE_TYPE_DYNAMIC_BYTE
:
1733 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1734 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1737 case SIDE_TYPE_DYNAMIC_POINTER32
:
1738 case SIDE_TYPE_DYNAMIC_POINTER64
:
1739 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1740 TRACER_DISPLAY_BASE_16
);
1743 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
1744 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
1745 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
1746 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
1747 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1748 &item
->u
.side_dynamic
.side_float
.value
);
1751 case SIDE_TYPE_DYNAMIC_STRING
:
1752 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1753 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1755 case SIDE_TYPE_DYNAMIC_STRUCT
:
1756 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1758 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1759 tracer_print_dynamic_struct_visitor(item
);
1761 case SIDE_TYPE_DYNAMIC_VLA
:
1762 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1764 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1765 tracer_print_dynamic_vla_visitor(item
);
1768 fprintf(stderr
, "<UNKNOWN TYPE>");
1775 void tracer_print_static_fields(const struct side_event_description
*desc
,
1776 const struct side_arg_vec
*side_arg_vec
,
1779 const struct side_arg
*sav
= side_arg_vec
->sav
;
1780 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1782 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1783 if (desc
->nr_fields
!= side_sav_len
) {
1784 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1787 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1788 printf("%s", side_sav_len
? ", fields: [ " : "");
1789 for (i
= 0; i
< side_sav_len
; i
++) {
1790 printf("%s", i
? ", " : "");
1791 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1799 void tracer_call(const struct side_event_description
*desc
,
1800 const struct side_arg_vec
*side_arg_vec
,
1801 void *priv
__attribute__((unused
)))
1803 uint32_t nr_fields
= 0;
1805 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1809 void tracer_call_variadic(const struct side_event_description
*desc
,
1810 const struct side_arg_vec
*side_arg_vec
,
1811 const struct side_arg_dynamic_struct
*var_struct
,
1812 void *priv
__attribute__((unused
)))
1814 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1816 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1818 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1819 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1822 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1823 printf("%s", var_struct_len
? ", fields:: [ " : "");
1824 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1825 printf("%s", i
? ", " : "");
1826 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1827 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1834 void tracer_event_notification(enum side_tracer_notification notif
,
1835 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1840 printf("----------------------------------------------------------\n");
1841 printf("Tracer notified of events %s\n",
1842 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1843 for (i
= 0; i
< nr_events
; i
++) {
1844 struct side_event_description
*event
= events
[i
];
1846 /* Skip NULL pointers */
1849 printf("provider: %s, event: %s\n",
1850 event
->provider_name
, event
->event_name
);
1851 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1852 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1853 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1857 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1862 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1863 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1867 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1873 printf("----------------------------------------------------------\n");
1876 static __attribute__((constructor
))
1877 void tracer_init(void);
1879 void tracer_init(void)
1881 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1886 static __attribute__((destructor
))
1887 void tracer_exit(void);
1889 void tracer_exit(void)
1891 side_tracer_event_notification_unregister(tracer_handle
);