1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include <side/trace.h>
15 enum tracer_display_base
{
16 TRACER_DISPLAY_BASE_2
,
17 TRACER_DISPLAY_BASE_8
,
18 TRACER_DISPLAY_BASE_10
,
19 TRACER_DISPLAY_BASE_16
,
22 static struct side_tracer_handle
*tracer_handle
;
25 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
27 void tracer_print_struct_sg(const struct side_type_description
*type_desc
, void *ptr
);
29 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
31 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
);
33 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
);
35 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
37 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
39 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*dynamic_item
);
41 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
);
44 int64_t get_attr_integer_value(const struct side_attr
*attr
)
48 switch (attr
->value
.type
) {
49 case SIDE_ATTR_TYPE_U8
:
50 val
= attr
->value
.u
.integer_value
.side_u8
;
52 case SIDE_ATTR_TYPE_U16
:
53 val
= attr
->value
.u
.integer_value
.side_u16
;
55 case SIDE_ATTR_TYPE_U32
:
56 val
= attr
->value
.u
.integer_value
.side_u32
;
58 case SIDE_ATTR_TYPE_U64
:
59 val
= attr
->value
.u
.integer_value
.side_u64
;
61 case SIDE_ATTR_TYPE_S8
:
62 val
= attr
->value
.u
.integer_value
.side_s8
;
64 case SIDE_ATTR_TYPE_S16
:
65 val
= attr
->value
.u
.integer_value
.side_s16
;
67 case SIDE_ATTR_TYPE_S32
:
68 val
= attr
->value
.u
.integer_value
.side_s32
;
70 case SIDE_ATTR_TYPE_S64
:
71 val
= attr
->value
.u
.integer_value
.side_s64
;
74 fprintf(stderr
, "Unexpected attribute type\n");
81 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
)
85 for (i
= 0; i
< nr_attr
; i
++) {
86 const struct side_attr
*attr
= &_attr
[i
];
88 if (!strcmp(attr
->key
, "std.integer.base")) {
89 int64_t val
= get_attr_integer_value(attr
);
93 return TRACER_DISPLAY_BASE_2
;
95 return TRACER_DISPLAY_BASE_8
;
97 return TRACER_DISPLAY_BASE_10
;
99 return TRACER_DISPLAY_BASE_16
;
101 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
106 return TRACER_DISPLAY_BASE_10
; /* Default */
110 bool type_to_host_reverse_bo(const struct side_type_description
*type_desc
)
112 switch (type_desc
->type
) {
123 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
128 case SIDE_TYPE_POINTER32
:
129 case SIDE_TYPE_POINTER64
:
130 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
135 case SIDE_TYPE_FLOAT_BINARY16
:
136 case SIDE_TYPE_FLOAT_BINARY32
:
137 case SIDE_TYPE_FLOAT_BINARY64
:
138 case SIDE_TYPE_FLOAT_BINARY128
:
139 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
145 fprintf(stderr
, "Unexpected type\n");
151 bool sg_type_to_host_reverse_bo(const struct side_type_sg_description
*sg_type
)
153 switch (sg_type
->type
) {
154 case SIDE_TYPE_SG_UNSIGNED_INT
:
155 case SIDE_TYPE_SG_SIGNED_INT
:
156 if (sg_type
->u
.side_basic
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
162 fprintf(stderr
, "Unexpected type\n");
168 bool dynamic_type_to_host_reverse_bo(const struct side_arg_dynamic_vec
*item
)
170 switch (item
->dynamic_type
) {
171 case SIDE_DYNAMIC_TYPE_U8
:
172 case SIDE_DYNAMIC_TYPE_S8
:
173 case SIDE_DYNAMIC_TYPE_BYTE
:
175 case SIDE_DYNAMIC_TYPE_U16
:
176 case SIDE_DYNAMIC_TYPE_U32
:
177 case SIDE_DYNAMIC_TYPE_U64
:
178 case SIDE_DYNAMIC_TYPE_S16
:
179 case SIDE_DYNAMIC_TYPE_S32
:
180 case SIDE_DYNAMIC_TYPE_S64
:
181 case SIDE_DYNAMIC_TYPE_POINTER32
:
182 case SIDE_DYNAMIC_TYPE_POINTER64
:
183 if (item
->u
.side_integer
.type
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
188 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
189 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
190 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
191 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
192 if (item
->u
.side_float
.type
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
198 fprintf(stderr
, "Unexpected type\n");
204 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
206 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
207 switch (attr
->value
.type
) {
208 case SIDE_ATTR_TYPE_BOOL
:
209 printf("%s", attr
->value
.u
.side_bool
? "true" : "false");
211 case SIDE_ATTR_TYPE_U8
:
212 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
214 case SIDE_ATTR_TYPE_U16
:
215 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
217 case SIDE_ATTR_TYPE_U32
:
218 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
220 case SIDE_ATTR_TYPE_U64
:
221 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
223 case SIDE_ATTR_TYPE_S8
:
224 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
226 case SIDE_ATTR_TYPE_S16
:
227 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
229 case SIDE_ATTR_TYPE_S32
:
230 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
232 case SIDE_ATTR_TYPE_S64
:
233 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
235 case SIDE_ATTR_TYPE_POINTER32
:
236 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
238 case SIDE_ATTR_TYPE_POINTER64
:
239 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
241 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
243 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
246 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
249 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
251 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
254 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
257 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
259 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
262 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
265 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
267 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
270 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
273 case SIDE_ATTR_TYPE_STRING
:
274 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string
);
277 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
284 void print_attributes(const char *prefix_str
, const char *separator
,
285 const struct side_attr
*attr
, uint32_t nr_attr
)
291 printf("%s%s [ ", prefix_str
, separator
);
292 for (i
= 0; i
< nr_attr
; i
++) {
293 printf("%s", i
? ", " : "");
294 tracer_print_attr_type(separator
, &attr
[i
]);
300 void print_enum(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
302 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
303 const struct side_type_description
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
304 int i
, print_count
= 0;
307 if (elem_type
->type
!= item
->type
) {
308 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
311 switch (item
->type
) {
313 value
= (int64_t) item
->u
.integer_value
.side_u8
;
319 v
= item
->u
.integer_value
.side_u16
;
320 if (type_to_host_reverse_bo(elem_type
))
321 v
= side_bswap_16(v
);
329 v
= item
->u
.integer_value
.side_u32
;
330 if (type_to_host_reverse_bo(elem_type
))
331 v
= side_bswap_32(v
);
339 v
= item
->u
.integer_value
.side_u64
;
340 if (type_to_host_reverse_bo(elem_type
))
341 v
= side_bswap_64(v
);
346 value
= (int64_t) item
->u
.integer_value
.side_s8
;
352 v
= item
->u
.integer_value
.side_s16
;
353 if (type_to_host_reverse_bo(elem_type
))
354 v
= side_bswap_16(v
);
362 v
= item
->u
.integer_value
.side_s32
;
363 if (type_to_host_reverse_bo(elem_type
))
364 v
= side_bswap_32(v
);
372 v
= item
->u
.integer_value
.side_s64
;
373 if (type_to_host_reverse_bo(elem_type
))
374 v
= side_bswap_64(v
);
379 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
382 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
383 printf("%s", mappings
->nr_attr
? ", " : "");
384 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
385 printf(", labels: [ ");
386 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
387 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
389 if (mapping
->range_end
< mapping
->range_begin
) {
390 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
391 mapping
->range_begin
, mapping
->range_end
);
394 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
395 printf("%s", print_count
++ ? ", " : "");
396 printf("\"%s\"", mapping
->label
);
400 printf("<NO LABEL>");
405 uint32_t enum_elem_type_to_stride(const struct side_type_description
*elem_type
)
409 switch (elem_type
->type
) {
410 case SIDE_TYPE_U8
: /* Fall-through */
424 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
431 void print_enum_bitmap(const struct side_type_description
*type_desc
,
432 const struct side_arg_vec
*item
)
434 const struct side_type_description
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
435 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
436 int i
, print_count
= 0;
437 uint32_t stride_bit
, nr_items
;
438 bool reverse_byte_order
= false;
439 const struct side_arg_vec
*array_item
;
441 switch (elem_type
->type
) {
442 case SIDE_TYPE_U8
: /* Fall-through */
443 case SIDE_TYPE_BYTE
: /* Fall-through */
444 case SIDE_TYPE_U16
: /* Fall-through */
445 case SIDE_TYPE_U32
: /* Fall-through */
447 stride_bit
= enum_elem_type_to_stride(elem_type
);
448 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
452 case SIDE_TYPE_ARRAY
:
453 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
454 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
455 array_item
= item
->u
.side_array
->sav
;
456 nr_items
= type_desc
->u
.side_array
.length
;
459 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
460 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
461 array_item
= item
->u
.side_vla
->sav
;
462 nr_items
= item
->u
.side_vla
->len
;
465 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
469 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
470 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
471 printf("labels: [ ");
472 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
473 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
477 if (mapping
->range_end
< mapping
->range_begin
) {
478 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
479 mapping
->range_begin
, mapping
->range_end
);
482 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
483 if (bit
> (nr_items
* stride_bit
) - 1)
485 switch (stride_bit
) {
488 uint8_t v
= array_item
[bit
/ 8].u
.integer_value
.side_u8
;
489 if (v
& (1ULL << (bit
% 8))) {
497 uint16_t v
= array_item
[bit
/ 16].u
.integer_value
.side_u16
;
498 if (reverse_byte_order
)
499 v
= side_bswap_16(v
);
500 if (v
& (1ULL << (bit
% 16))) {
508 uint32_t v
= array_item
[bit
/ 32].u
.integer_value
.side_u32
;
509 if (reverse_byte_order
)
510 v
= side_bswap_32(v
);
511 if (v
& (1ULL << (bit
% 32))) {
519 uint64_t v
= array_item
[bit
/ 64].u
.integer_value
.side_u64
;
520 if (reverse_byte_order
)
521 v
= side_bswap_64(v
);
522 if (v
& (1ULL << (bit
% 64))) {
534 printf("%s", print_count
++ ? ", " : "");
535 printf("\"%s\"", mapping
->label
);
539 printf("<NO LABEL>");
544 void print_integer_binary(uint64_t v
, int bits
)
550 for (i
= 0; i
< bits
; i
++) {
551 printf("%c", v
& (1ULL << 63) ? '1' : '0');
557 void tracer_print_type_header(const char *separator
,
558 const struct side_attr
*attr
, uint32_t nr_attr
)
560 print_attributes("attr", separator
, attr
, nr_attr
);
561 printf("%s", nr_attr
? ", " : "");
562 printf("value%s ", separator
);
566 void tracer_print_type_integer(const char *separator
,
567 const struct side_type_integer
*type_integer
,
568 const union side_integer_value
*value
)
570 enum tracer_display_base base
;
577 if (!type_integer
->len_bits
||
578 type_integer
->len_bits
> type_integer
->integer_size_bits
)
580 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
581 base
= get_attr_display_base(type_integer
->attr
,
582 type_integer
->nr_attr
);
583 switch (type_integer
->integer_size_bits
) {
585 if (type_integer
->signedness
)
586 v
.v_signed
= value
->side_s8
;
588 v
.v_unsigned
= value
->side_u8
;
591 if (type_integer
->signedness
) {
594 side_s16
= value
->side_s16
;
596 side_s16
= side_bswap_16(side_s16
);
597 v
.v_signed
= side_s16
;
601 side_u16
= value
->side_u16
;
603 side_u16
= side_bswap_16(side_u16
);
604 v
.v_unsigned
= side_u16
;
608 if (type_integer
->signedness
) {
611 side_s32
= value
->side_s32
;
613 side_s32
= side_bswap_32(side_s32
);
614 v
.v_signed
= side_s32
;
618 side_u32
= value
->side_u32
;
620 side_u32
= side_bswap_32(side_u32
);
621 v
.v_unsigned
= side_u32
;
625 if (type_integer
->signedness
) {
628 side_s64
= value
->side_s64
;
630 side_s64
= side_bswap_64(side_s64
);
631 v
.v_signed
= side_s64
;
635 side_u64
= value
->side_u64
;
637 side_u64
= side_bswap_64(side_u64
);
638 v
.v_unsigned
= side_u64
;
644 if (type_integer
->len_bits
< 64)
645 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
646 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
648 case TRACER_DISPLAY_BASE_2
:
649 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
651 case TRACER_DISPLAY_BASE_8
:
652 printf("0%" PRIo64
, v
.v_unsigned
);
654 case TRACER_DISPLAY_BASE_10
:
655 if (type_integer
->signedness
) {
657 if (type_integer
->len_bits
< 64) {
658 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
659 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
661 printf("%" PRId64
, v
.v_signed
);
663 printf("%" PRIu64
, v
.v_unsigned
);
666 case TRACER_DISPLAY_BASE_16
:
667 printf("0x%" PRIx64
, v
.v_unsigned
);
675 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
679 switch (type_desc
->type
) {
680 case SIDE_TYPE_ARRAY
:
681 switch (item
->type
) {
682 case SIDE_TYPE_ARRAY_U8
:
683 case SIDE_TYPE_ARRAY_U16
:
684 case SIDE_TYPE_ARRAY_U32
:
685 case SIDE_TYPE_ARRAY_U64
:
686 case SIDE_TYPE_ARRAY_S8
:
687 case SIDE_TYPE_ARRAY_S16
:
688 case SIDE_TYPE_ARRAY_S32
:
689 case SIDE_TYPE_ARRAY_S64
:
690 case SIDE_TYPE_ARRAY_POINTER32
:
691 case SIDE_TYPE_ARRAY_POINTER64
:
692 case SIDE_TYPE_ARRAY_BYTE
:
693 case SIDE_TYPE_ARRAY
:
696 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
703 switch (item
->type
) {
704 case SIDE_TYPE_VLA_U8
:
705 case SIDE_TYPE_VLA_U16
:
706 case SIDE_TYPE_VLA_U32
:
707 case SIDE_TYPE_VLA_U64
:
708 case SIDE_TYPE_VLA_S8
:
709 case SIDE_TYPE_VLA_S16
:
710 case SIDE_TYPE_VLA_S32
:
711 case SIDE_TYPE_VLA_S64
:
712 case SIDE_TYPE_VLA_BYTE
:
713 case SIDE_TYPE_VLA_POINTER32
:
714 case SIDE_TYPE_VLA_POINTER64
:
718 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
725 switch (item
->type
) {
736 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
742 case SIDE_TYPE_ENUM_BITMAP
:
743 switch (item
->type
) {
749 case SIDE_TYPE_ARRAY
:
753 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
760 if (type_desc
->type
!= item
->type
) {
761 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
767 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
768 type
= type_desc
->type
;
775 tracer_print_type_header(":", type_desc
->u
.side_basic
.attr
, type_desc
->u
.side_basic
.nr_attr
);
776 printf("%s", item
->u
.side_bool
? "true" : "false");
787 tracer_print_type_integer(":", &type_desc
->u
.side_integer
,
788 &item
->u
.integer_value
);
791 case SIDE_TYPE_POINTER32
:
795 v
= item
->u
.integer_value
.side_u32
;
796 if (type_to_host_reverse_bo(type_desc
))
797 v
= side_bswap_32(v
);
798 tracer_print_type_header(":", type_desc
->u
.side_integer
.attr
, type_desc
->u
.side_integer
.nr_attr
);
799 printf("0x%" PRIx32
, v
);
802 case SIDE_TYPE_POINTER64
:
806 v
= item
->u
.integer_value
.side_u64
;
807 if (type_to_host_reverse_bo(type_desc
))
808 v
= side_bswap_64(v
);
809 tracer_print_type_header(":", type_desc
->u
.side_integer
.attr
, type_desc
->u
.side_integer
.nr_attr
);
810 printf("0x%" PRIx64
, v
);
814 tracer_print_type_header(":", type_desc
->u
.side_basic
.attr
, type_desc
->u
.side_basic
.nr_attr
);
815 printf("0x%" PRIx8
, item
->u
.side_byte
);
819 print_enum(type_desc
, item
);
822 case SIDE_TYPE_ENUM_BITMAP
:
823 print_enum_bitmap(type_desc
, item
);
826 case SIDE_TYPE_FLOAT_BINARY16
:
833 .f
= item
->u
.float_value
.side_float_binary16
,
836 if (type_to_host_reverse_bo(type_desc
))
837 float16
.u
= side_bswap_16(float16
.u
);
838 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
839 printf("%g", (double) float16
.f
);
842 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
846 case SIDE_TYPE_FLOAT_BINARY32
:
853 .f
= item
->u
.float_value
.side_float_binary32
,
856 if (type_to_host_reverse_bo(type_desc
))
857 float32
.u
= side_bswap_32(float32
.u
);
858 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
859 printf("%g", (double) float32
.f
);
862 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
866 case SIDE_TYPE_FLOAT_BINARY64
:
873 .f
= item
->u
.float_value
.side_float_binary64
,
876 if (type_to_host_reverse_bo(type_desc
))
877 float64
.u
= side_bswap_64(float64
.u
);
878 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
879 printf("%g", (double) float64
.f
);
882 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
886 case SIDE_TYPE_FLOAT_BINARY128
:
893 .f
= item
->u
.float_value
.side_float_binary128
,
896 if (type_to_host_reverse_bo(type_desc
))
897 side_bswap_128p(float128
.arr
);
898 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
899 printf("%Lg", (long double) float128
.f
);
902 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
906 case SIDE_TYPE_STRING
:
907 tracer_print_type_header(":", type_desc
->u
.side_basic
.attr
, type_desc
->u
.side_basic
.nr_attr
);
908 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.string
);
910 case SIDE_TYPE_STRUCT
:
911 tracer_print_struct(type_desc
, item
->u
.side_struct
);
913 case SIDE_TYPE_STRUCT_SG
:
914 tracer_print_struct_sg(type_desc
, item
->u
.side_struct_sg_ptr
);
916 case SIDE_TYPE_ARRAY
:
917 tracer_print_array(type_desc
, item
->u
.side_array
);
920 tracer_print_vla(type_desc
, item
->u
.side_vla
);
922 case SIDE_TYPE_VLA_VISITOR
:
923 tracer_print_vla_visitor(type_desc
, item
->u
.side_vla_app_visitor_ctx
);
925 case SIDE_TYPE_ARRAY_U8
:
926 case SIDE_TYPE_ARRAY_U16
:
927 case SIDE_TYPE_ARRAY_U32
:
928 case SIDE_TYPE_ARRAY_U64
:
929 case SIDE_TYPE_ARRAY_S8
:
930 case SIDE_TYPE_ARRAY_S16
:
931 case SIDE_TYPE_ARRAY_S32
:
932 case SIDE_TYPE_ARRAY_S64
:
933 case SIDE_TYPE_ARRAY_BYTE
:
934 case SIDE_TYPE_ARRAY_POINTER32
:
935 case SIDE_TYPE_ARRAY_POINTER64
:
936 tracer_print_array_fixint(type_desc
, item
);
938 case SIDE_TYPE_VLA_U8
:
939 case SIDE_TYPE_VLA_U16
:
940 case SIDE_TYPE_VLA_U32
:
941 case SIDE_TYPE_VLA_U64
:
942 case SIDE_TYPE_VLA_S8
:
943 case SIDE_TYPE_VLA_S16
:
944 case SIDE_TYPE_VLA_S32
:
945 case SIDE_TYPE_VLA_S64
:
946 case SIDE_TYPE_VLA_BYTE
:
947 case SIDE_TYPE_VLA_POINTER32
:
948 case SIDE_TYPE_VLA_POINTER64
:
949 tracer_print_vla_fixint(type_desc
, item
);
951 case SIDE_TYPE_DYNAMIC
:
952 tracer_print_type_header(":", type_desc
->u
.side_basic
.attr
, type_desc
->u
.side_basic
.nr_attr
);
953 tracer_print_dynamic(&item
->u
.dynamic
);
956 fprintf(stderr
, "<UNKNOWN TYPE>");
963 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg_vec
*item
)
965 printf("%s: ", item_desc
->field_name
);
966 tracer_print_type(&item_desc
->side_type
, item
);
970 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
972 const struct side_arg_vec
*sav
= sav_desc
->sav
;
973 uint32_t side_sav_len
= sav_desc
->len
;
976 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
977 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
980 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
981 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
982 printf("fields: { ");
983 for (i
= 0; i
< side_sav_len
; i
++) {
984 printf("%s", i
? ", " : "");
985 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
991 void tracer_print_sg_integer_type_header(const struct side_type_sg_description
*sg_type
)
993 print_attributes("attr", ":", sg_type
->u
.side_basic
.attr
, sg_type
->u
.side_basic
.nr_attr
);
994 printf("%s", sg_type
->u
.side_basic
.nr_attr
? ", " : "");
999 void tracer_print_sg_type(const struct side_type_sg_description
*sg_type
, void *_ptr
)
1001 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
1002 const char *ptr
= (const char *) _ptr
;
1004 switch (sg_type
->type
) {
1005 case SIDE_TYPE_SG_UNSIGNED_INT
:
1006 case SIDE_TYPE_SG_SIGNED_INT
:
1007 base
= get_attr_display_base(sg_type
->u
.side_basic
.attr
,
1008 sg_type
->u
.side_basic
.nr_attr
);
1015 switch (sg_type
->type
) {
1016 case SIDE_TYPE_SG_UNSIGNED_INT
:
1018 tracer_print_sg_integer_type_header(sg_type
);
1019 switch (sg_type
->u
.side_basic
.integer_size_bits
) {
1024 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 8)
1026 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1027 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1028 if (sg_type
->u
.side_basic
.len_bits
< 8)
1029 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1031 case TRACER_DISPLAY_BASE_2
:
1032 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1034 case TRACER_DISPLAY_BASE_8
:
1035 printf("0%" PRIo8
, v
);
1037 case TRACER_DISPLAY_BASE_10
:
1038 printf("%" PRIu8
, v
);
1040 case TRACER_DISPLAY_BASE_16
:
1041 printf("0x%" PRIx8
, v
);
1052 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 16)
1054 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1055 if (sg_type_to_host_reverse_bo(sg_type
))
1056 v
= side_bswap_16(v
);
1057 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1058 if (sg_type
->u
.side_basic
.len_bits
< 16)
1059 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1061 case TRACER_DISPLAY_BASE_2
:
1062 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1064 case TRACER_DISPLAY_BASE_8
:
1065 printf("0%" PRIo16
, v
);
1067 case TRACER_DISPLAY_BASE_10
:
1068 printf("%" PRIu16
, v
);
1070 case TRACER_DISPLAY_BASE_16
:
1071 printf("0x%" PRIx16
, v
);
1082 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 32)
1084 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1085 if (sg_type_to_host_reverse_bo(sg_type
))
1086 v
= side_bswap_32(v
);
1087 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1088 if (sg_type
->u
.side_basic
.len_bits
< 32)
1089 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1091 case TRACER_DISPLAY_BASE_2
:
1092 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1094 case TRACER_DISPLAY_BASE_8
:
1095 printf("0%" PRIo32
, v
);
1097 case TRACER_DISPLAY_BASE_10
:
1098 printf("%" PRIu32
, v
);
1100 case TRACER_DISPLAY_BASE_16
:
1101 printf("0x%" PRIx32
, v
);
1112 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 64)
1114 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1115 if (sg_type_to_host_reverse_bo(sg_type
))
1116 v
= side_bswap_64(v
);
1117 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1118 if (sg_type
->u
.side_basic
.len_bits
< 64)
1119 v
&= (1ULL << sg_type
->u
.side_basic
.len_bits
) - 1;
1121 case TRACER_DISPLAY_BASE_2
:
1122 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1124 case TRACER_DISPLAY_BASE_8
:
1125 printf("0%" PRIo64
, v
);
1127 case TRACER_DISPLAY_BASE_10
:
1128 printf("%" PRIu64
, v
);
1130 case TRACER_DISPLAY_BASE_16
:
1131 printf("0x%" PRIx64
, v
);
1139 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1144 case SIDE_TYPE_SG_SIGNED_INT
:
1146 tracer_print_sg_integer_type_header(sg_type
);
1147 switch (sg_type
->u
.side_basic
.integer_size_bits
) {
1152 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 8)
1154 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1155 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1156 if (sg_type
->u
.side_basic
.len_bits
< 8)
1157 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1159 case TRACER_DISPLAY_BASE_2
:
1160 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1162 case TRACER_DISPLAY_BASE_8
:
1163 printf("0%" PRIo8
, v
);
1165 case TRACER_DISPLAY_BASE_10
:
1167 if (sg_type
->u
.side_basic
.len_bits
< 8) {
1168 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1169 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1171 printf("%" PRId8
, v
);
1173 case TRACER_DISPLAY_BASE_16
:
1174 printf("0x%" PRIx8
, v
);
1185 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 16)
1187 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1188 if (sg_type_to_host_reverse_bo(sg_type
))
1189 v
= side_bswap_16(v
);
1190 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1191 if (sg_type
->u
.side_basic
.len_bits
< 16)
1192 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1194 case TRACER_DISPLAY_BASE_2
:
1195 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1197 case TRACER_DISPLAY_BASE_8
:
1198 printf("0%" PRIo16
, v
);
1200 case TRACER_DISPLAY_BASE_10
:
1202 if (sg_type
->u
.side_basic
.len_bits
< 16) {
1203 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1204 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1206 printf("%" PRId16
, v
);
1208 case TRACER_DISPLAY_BASE_16
:
1209 printf("0x%" PRIx16
, v
);
1220 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 32)
1222 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1223 if (sg_type_to_host_reverse_bo(sg_type
))
1224 v
= side_bswap_32(v
);
1225 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1226 if (sg_type
->u
.side_basic
.len_bits
< 32)
1227 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1229 case TRACER_DISPLAY_BASE_2
:
1230 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1232 case TRACER_DISPLAY_BASE_8
:
1233 printf("0%" PRIo32
, v
);
1235 case TRACER_DISPLAY_BASE_10
:
1237 if (sg_type
->u
.side_basic
.len_bits
< 32) {
1238 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1239 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1241 printf("%" PRId32
, v
);
1243 case TRACER_DISPLAY_BASE_16
:
1244 printf("0x%" PRIx32
, v
);
1255 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 64)
1257 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1258 if (sg_type_to_host_reverse_bo(sg_type
))
1259 v
= side_bswap_64(v
);
1260 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1261 if (sg_type
->u
.side_basic
.len_bits
< 64)
1262 v
&= (1ULL << sg_type
->u
.side_basic
.len_bits
) - 1;
1264 case TRACER_DISPLAY_BASE_2
:
1265 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1267 case TRACER_DISPLAY_BASE_8
:
1268 printf("0%" PRIo64
, v
);
1270 case TRACER_DISPLAY_BASE_10
:
1272 if (sg_type
->u
.side_basic
.len_bits
< 64) {
1273 if (v
& (1ULL << (sg_type
->u
.side_basic
.len_bits
- 1)))
1274 v
|= ~((1ULL << sg_type
->u
.side_basic
.len_bits
) - 1);
1276 printf("%" PRId64
, v
);
1278 case TRACER_DISPLAY_BASE_16
:
1279 printf("0x%" PRIx64
, v
);
1287 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1293 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER TYPE>");
1300 void tracer_print_sg_field(const struct side_struct_field_sg
*field_sg
, void *ptr
)
1302 printf("%s: ", field_sg
->field_name
);
1303 tracer_print_sg_type(&field_sg
->side_type
, ptr
);
1307 void tracer_print_struct_sg(const struct side_type_description
*type_desc
, void *ptr
)
1309 const struct side_type_struct_sg
*struct_sg
= type_desc
->u
.side_struct_sg
;
1312 print_attributes("attr", ":", struct_sg
->attr
, struct_sg
->nr_attr
);
1313 printf("%s", struct_sg
->nr_attr
? ", " : "");
1314 printf("fields: { ");
1315 for (i
= 0; i
< struct_sg
->nr_fields
; i
++) {
1316 printf("%s", i
? ", " : "");
1317 tracer_print_sg_field(&struct_sg
->fields_sg
[i
], ptr
);
1323 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1325 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1326 uint32_t side_sav_len
= sav_desc
->len
;
1329 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1330 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1333 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1334 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1335 printf("elements: ");
1337 for (i
= 0; i
< side_sav_len
; i
++) {
1338 printf("%s", i
? ", " : "");
1339 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1345 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1347 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1348 uint32_t side_sav_len
= sav_desc
->len
;
1351 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1352 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1353 printf("elements: ");
1355 for (i
= 0; i
< side_sav_len
; i
++) {
1356 printf("%s", i
? ", " : "");
1357 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1362 struct tracer_visitor_priv
{
1363 const struct side_type_description
*elem_type
;
1368 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1369 const struct side_arg_vec
*elem
)
1371 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1373 printf("%s", tracer_priv
->i
++ ? ", " : "");
1374 tracer_print_type(tracer_priv
->elem_type
, elem
);
1375 return SIDE_VISITOR_STATUS_OK
;
1379 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
)
1381 enum side_visitor_status status
;
1382 struct tracer_visitor_priv tracer_priv
= {
1383 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1386 const struct side_tracer_visitor_ctx tracer_ctx
= {
1387 .write_elem
= tracer_write_elem_cb
,
1388 .priv
= &tracer_priv
,
1391 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1392 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1393 printf("elements: ");
1395 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1397 case SIDE_VISITOR_STATUS_OK
:
1399 case SIDE_VISITOR_STATUS_ERROR
:
1400 fprintf(stderr
, "ERROR: Visitor error\n");
1406 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1408 const struct side_type_description
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1409 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
1410 void *p
= item
->u
.side_array_fixint
;
1411 enum side_type side_type
;
1414 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1415 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1416 printf("elements: ");
1417 switch (item
->type
) {
1418 case SIDE_TYPE_ARRAY_U8
:
1419 if (elem_type
->type
!= SIDE_TYPE_U8
)
1422 case SIDE_TYPE_ARRAY_U16
:
1423 if (elem_type
->type
!= SIDE_TYPE_U16
)
1426 case SIDE_TYPE_ARRAY_U32
:
1427 if (elem_type
->type
!= SIDE_TYPE_U32
)
1430 case SIDE_TYPE_ARRAY_U64
:
1431 if (elem_type
->type
!= SIDE_TYPE_U64
)
1434 case SIDE_TYPE_ARRAY_S8
:
1435 if (elem_type
->type
!= SIDE_TYPE_S8
)
1438 case SIDE_TYPE_ARRAY_S16
:
1439 if (elem_type
->type
!= SIDE_TYPE_S16
)
1442 case SIDE_TYPE_ARRAY_S32
:
1443 if (elem_type
->type
!= SIDE_TYPE_S32
)
1446 case SIDE_TYPE_ARRAY_S64
:
1447 if (elem_type
->type
!= SIDE_TYPE_S64
)
1450 case SIDE_TYPE_ARRAY_BYTE
:
1451 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1454 case SIDE_TYPE_ARRAY_POINTER32
:
1455 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1457 case SIDE_TYPE_ARRAY_POINTER64
:
1458 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1464 side_type
= elem_type
->type
;
1467 for (i
= 0; i
< side_sav_len
; i
++) {
1468 struct side_arg_vec sav_elem
= {
1472 switch (side_type
) {
1474 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1477 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1480 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1483 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1486 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1489 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1492 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1495 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1497 case SIDE_TYPE_BYTE
:
1498 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1500 case SIDE_TYPE_POINTER32
:
1501 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1503 case SIDE_TYPE_POINTER64
:
1504 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1508 fprintf(stderr
, "ERROR: Unexpected type\n");
1512 printf("%s", i
? ", " : "");
1513 tracer_print_type(elem_type
, &sav_elem
);
1519 fprintf(stderr
, "ERROR: type mismatch\n");
1523 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1525 const struct side_type_description
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1526 uint32_t side_sav_len
= item
->u
.side_vla_fixint
.length
;
1527 void *p
= item
->u
.side_vla_fixint
.p
;
1528 enum side_type side_type
;
1531 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1532 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1533 printf("elements: ");
1534 switch (item
->type
) {
1535 case SIDE_TYPE_VLA_U8
:
1536 if (elem_type
->type
!= SIDE_TYPE_U8
)
1539 case SIDE_TYPE_VLA_U16
:
1540 if (elem_type
->type
!= SIDE_TYPE_U16
)
1543 case SIDE_TYPE_VLA_U32
:
1544 if (elem_type
->type
!= SIDE_TYPE_U32
)
1547 case SIDE_TYPE_VLA_U64
:
1548 if (elem_type
->type
!= SIDE_TYPE_U64
)
1551 case SIDE_TYPE_VLA_S8
:
1552 if (elem_type
->type
!= SIDE_TYPE_S8
)
1555 case SIDE_TYPE_VLA_S16
:
1556 if (elem_type
->type
!= SIDE_TYPE_S16
)
1559 case SIDE_TYPE_VLA_S32
:
1560 if (elem_type
->type
!= SIDE_TYPE_S32
)
1563 case SIDE_TYPE_VLA_S64
:
1564 if (elem_type
->type
!= SIDE_TYPE_S64
)
1567 case SIDE_TYPE_VLA_BYTE
:
1568 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1571 case SIDE_TYPE_VLA_POINTER32
:
1572 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1574 case SIDE_TYPE_VLA_POINTER64
:
1575 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1581 side_type
= elem_type
->type
;
1584 for (i
= 0; i
< side_sav_len
; i
++) {
1585 struct side_arg_vec sav_elem
= {
1589 switch (side_type
) {
1591 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1594 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1597 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1600 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1603 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1606 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1609 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1612 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1614 case SIDE_TYPE_BYTE
:
1615 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1617 case SIDE_TYPE_POINTER32
:
1618 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1620 case SIDE_TYPE_POINTER64
:
1621 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1625 fprintf(stderr
, "ERROR: Unexpected type\n");
1629 printf("%s", i
? ", " : "");
1630 tracer_print_type(elem_type
, &sav_elem
);
1636 fprintf(stderr
, "ERROR: type mismatch\n");
1641 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
1643 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
1644 uint32_t len
= dynamic_struct
->len
;
1647 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1648 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1649 printf("fields:: ");
1651 for (i
= 0; i
< len
; i
++) {
1652 printf("%s", i
? ", " : "");
1653 printf("%s:: ", fields
[i
].field_name
);
1654 tracer_print_dynamic(&fields
[i
].elem
);
1659 struct tracer_dynamic_struct_visitor_priv
{
1664 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1665 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1666 const struct side_arg_dynamic_event_field
*dynamic_field
)
1668 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1670 printf("%s", tracer_priv
->i
++ ? ", " : "");
1671 printf("%s:: ", dynamic_field
->field_name
);
1672 tracer_print_dynamic(&dynamic_field
->elem
);
1673 return SIDE_VISITOR_STATUS_OK
;
1677 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec
*item
)
1679 enum side_visitor_status status
;
1680 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1683 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1684 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1685 .priv
= &tracer_priv
,
1687 void *app_ctx
= item
->u
.side_dynamic_struct_visitor
.app_ctx
;
1689 print_attributes("attr", "::", item
->u
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic_struct_visitor
.nr_attr
);
1690 printf("%s", item
->u
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1691 printf("fields:: ");
1693 status
= item
->u
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1695 case SIDE_VISITOR_STATUS_OK
:
1697 case SIDE_VISITOR_STATUS_ERROR
:
1698 fprintf(stderr
, "ERROR: Visitor error\n");
1705 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla
*vla
)
1707 const struct side_arg_dynamic_vec
*sav
= vla
->sav
;
1708 uint32_t side_sav_len
= vla
->len
;
1711 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1712 printf("%s", vla
->nr_attr
? ", " : "");
1713 printf("elements:: ");
1715 for (i
= 0; i
< side_sav_len
; i
++) {
1716 printf("%s", i
? ", " : "");
1717 tracer_print_dynamic(&sav
[i
]);
1722 struct tracer_dynamic_vla_visitor_priv
{
1727 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1728 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
1729 const struct side_arg_dynamic_vec
*elem
)
1731 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1733 printf("%s", tracer_priv
->i
++ ? ", " : "");
1734 tracer_print_dynamic(elem
);
1735 return SIDE_VISITOR_STATUS_OK
;
1739 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec
*item
)
1741 enum side_visitor_status status
;
1742 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1745 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
1746 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1747 .priv
= &tracer_priv
,
1749 void *app_ctx
= item
->u
.side_dynamic_vla_visitor
.app_ctx
;
1751 print_attributes("attr", "::", item
->u
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic_vla_visitor
.nr_attr
);
1752 printf("%s", item
->u
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1753 printf("elements:: ");
1755 status
= item
->u
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1757 case SIDE_VISITOR_STATUS_OK
:
1759 case SIDE_VISITOR_STATUS_ERROR
:
1760 fprintf(stderr
, "ERROR: Visitor error\n");
1767 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*item
)
1770 switch (item
->dynamic_type
) {
1771 case SIDE_DYNAMIC_TYPE_NULL
:
1772 tracer_print_type_header("::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1773 printf("<NULL TYPE>");
1775 case SIDE_DYNAMIC_TYPE_BOOL
:
1776 tracer_print_type_header("::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1777 printf("%s", item
->u
.side_basic
.u
.side_bool
? "true" : "false");
1779 case SIDE_DYNAMIC_TYPE_U8
:
1780 case SIDE_DYNAMIC_TYPE_U16
:
1781 case SIDE_DYNAMIC_TYPE_U32
:
1782 case SIDE_DYNAMIC_TYPE_U64
:
1783 case SIDE_DYNAMIC_TYPE_S8
:
1784 case SIDE_DYNAMIC_TYPE_S16
:
1785 case SIDE_DYNAMIC_TYPE_S32
:
1786 case SIDE_DYNAMIC_TYPE_S64
:
1787 tracer_print_type_integer("::", &item
->u
.side_integer
.type
,
1788 &item
->u
.side_integer
.value
);
1790 case SIDE_DYNAMIC_TYPE_BYTE
:
1791 tracer_print_type_header("::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1792 printf("0x%" PRIx8
, item
->u
.side_basic
.u
.side_byte
);
1794 case SIDE_DYNAMIC_TYPE_POINTER32
:
1798 v
= item
->u
.side_integer
.value
.side_u32
;
1799 if (dynamic_type_to_host_reverse_bo(item
))
1800 v
= side_bswap_32(v
);
1801 tracer_print_type_header("::", item
->u
.side_integer
.type
.attr
, item
->u
.side_integer
.type
.nr_attr
);
1802 printf("0x%" PRIx32
, v
);
1806 case SIDE_DYNAMIC_TYPE_POINTER64
:
1810 v
= item
->u
.side_integer
.value
.side_u64
;
1811 if (dynamic_type_to_host_reverse_bo(item
))
1812 v
= side_bswap_64(v
);
1813 tracer_print_type_header("::", item
->u
.side_integer
.type
.attr
, item
->u
.side_integer
.type
.nr_attr
);
1814 printf("0x%" PRIx64
, v
);
1818 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
1825 .f
= item
->u
.side_float
.value
.side_float_binary16
,
1828 if (dynamic_type_to_host_reverse_bo(item
))
1829 float16
.u
= side_bswap_16(float16
.u
);
1830 tracer_print_type_header("::", item
->u
.side_float
.type
.attr
, item
->u
.side_float
.type
.nr_attr
);
1831 printf("%g", (double) float16
.f
);
1834 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
1838 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
1845 .f
= item
->u
.side_float
.value
.side_float_binary32
,
1848 if (dynamic_type_to_host_reverse_bo(item
))
1849 float32
.u
= side_bswap_32(float32
.u
);
1850 tracer_print_type_header("::", item
->u
.side_float
.type
.attr
, item
->u
.side_float
.type
.nr_attr
);
1851 printf("%g", (double) float32
.f
);
1854 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
1858 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
1865 .f
= item
->u
.side_float
.value
.side_float_binary64
,
1868 if (dynamic_type_to_host_reverse_bo(item
))
1869 float64
.u
= side_bswap_64(float64
.u
);
1870 tracer_print_type_header("::", item
->u
.side_float
.type
.attr
, item
->u
.side_float
.type
.nr_attr
);
1871 printf("%g", (double) float64
.f
);
1874 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
1878 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
1885 .f
= item
->u
.side_float
.value
.side_float_binary128
,
1888 if (dynamic_type_to_host_reverse_bo(item
))
1889 side_bswap_128p(float128
.arr
);
1890 tracer_print_type_header("::", item
->u
.side_float
.type
.attr
, item
->u
.side_float
.type
.nr_attr
);
1891 printf("%Lg", (long double) float128
.f
);
1894 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
1898 case SIDE_DYNAMIC_TYPE_STRING
:
1899 tracer_print_type_header("::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1900 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_basic
.u
.string
);
1902 case SIDE_DYNAMIC_TYPE_STRUCT
:
1903 tracer_print_dynamic_struct(item
->u
.side_dynamic_struct
);
1905 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
:
1906 tracer_print_dynamic_struct_visitor(item
);
1908 case SIDE_DYNAMIC_TYPE_VLA
:
1909 tracer_print_dynamic_vla(item
->u
.side_dynamic_vla
);
1911 case SIDE_DYNAMIC_TYPE_VLA_VISITOR
:
1912 tracer_print_dynamic_vla_visitor(item
);
1915 fprintf(stderr
, "<UNKNOWN TYPE>");
1922 void tracer_print_static_fields(const struct side_event_description
*desc
,
1923 const struct side_arg_vec_description
*sav_desc
,
1926 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1927 uint32_t side_sav_len
= sav_desc
->len
;
1930 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1931 if (desc
->nr_fields
!= side_sav_len
) {
1932 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1935 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1936 printf("%s", side_sav_len
? ", fields: [ " : "");
1937 for (i
= 0; i
< side_sav_len
; i
++) {
1938 printf("%s", i
? ", " : "");
1939 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1947 void tracer_call(const struct side_event_description
*desc
,
1948 const struct side_arg_vec_description
*sav_desc
,
1949 void *priv
__attribute__((unused
)))
1953 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
1957 void tracer_call_variadic(const struct side_event_description
*desc
,
1958 const struct side_arg_vec_description
*sav_desc
,
1959 const struct side_arg_dynamic_event_struct
*var_struct
,
1960 void *priv
__attribute__((unused
)))
1962 uint32_t var_struct_len
= var_struct
->len
;
1963 int nr_fields
= 0, i
;
1965 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
1967 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1968 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1971 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1972 printf("%s", var_struct_len
? ", fields:: [ " : "");
1973 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1974 printf("%s", i
? ", " : "");
1975 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1976 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1983 void tracer_event_notification(enum side_tracer_notification notif
,
1984 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1989 printf("----------------------------------------------------------\n");
1990 printf("Tracer notified of events %s\n",
1991 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1992 for (i
= 0; i
< nr_events
; i
++) {
1993 struct side_event_description
*event
= events
[i
];
1995 /* Skip NULL pointers */
1998 printf("provider: %s, event: %s\n",
1999 event
->provider_name
, event
->event_name
);
2000 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
2001 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
2002 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
2006 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
2011 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
2012 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
2016 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
2022 printf("----------------------------------------------------------\n");
2025 static __attribute__((constructor
))
2026 void tracer_init(void);
2028 void tracer_init(void)
2030 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
2035 static __attribute__((destructor
))
2036 void tracer_exit(void);
2038 void tracer_exit(void)
2040 side_tracer_event_notification_unregister(tracer_handle
);