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_basic
.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_basic
.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_basic
.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_basic
.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
.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
.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
.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
.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_basic_type_header(const struct side_type_description
*type_desc
)
559 print_attributes("attr", ":", type_desc
->u
.side_basic
.attr
, type_desc
->u
.side_basic
.nr_attr
);
560 printf("%s", type_desc
->u
.side_basic
.nr_attr
? ", " : "");
565 void tracer_print_type_integer(enum side_type type
, const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
567 enum tracer_display_base base
;
573 if (!type_desc
->u
.side_integer
.len_bits
||
574 type_desc
->u
.side_integer
.len_bits
> type_desc
->u
.side_integer
.integer_size_bits
)
576 base
= get_attr_display_base(type_desc
->u
.side_integer
.attr
,
577 type_desc
->u
.side_integer
.nr_attr
);
580 v
.v_unsigned
= item
->u
.integer_value
.side_u8
;
586 side_u16
= item
->u
.integer_value
.side_u16
;
587 if (type_to_host_reverse_bo(type_desc
))
588 side_u16
= side_bswap_16(side_u16
);
589 v
.v_unsigned
= side_u16
;
596 side_u32
= item
->u
.integer_value
.side_u32
;
597 if (type_to_host_reverse_bo(type_desc
))
598 side_u32
= side_bswap_32(side_u32
);
599 v
.v_unsigned
= side_u32
;
606 side_u64
= item
->u
.integer_value
.side_u64
;
607 if (type_to_host_reverse_bo(type_desc
))
608 side_u64
= side_bswap_64(side_u64
);
609 v
.v_unsigned
= side_u64
;
613 v
.v_signed
= item
->u
.integer_value
.side_s8
;
619 side_s16
= item
->u
.integer_value
.side_s16
;
620 if (type_to_host_reverse_bo(type_desc
))
621 side_s16
= side_bswap_16(side_s16
);
622 v
.v_unsigned
= side_s16
;
629 side_s32
= item
->u
.integer_value
.side_s32
;
630 if (type_to_host_reverse_bo(type_desc
))
631 side_s32
= side_bswap_32(side_s32
);
632 v
.v_unsigned
= side_s32
;
639 side_s64
= item
->u
.integer_value
.side_s64
;
640 if (type_to_host_reverse_bo(type_desc
))
641 side_s64
= side_bswap_64(side_s64
);
642 v
.v_unsigned
= side_s64
;
648 if (type_desc
->u
.side_integer
.len_bits
< 64)
649 v
.v_unsigned
&= (1ULL << type_desc
->u
.side_integer
.len_bits
) - 1;
650 tracer_print_basic_type_header(type_desc
);
652 case TRACER_DISPLAY_BASE_2
:
653 print_integer_binary(v
.v_unsigned
, type_desc
->u
.side_integer
.len_bits
);
655 case TRACER_DISPLAY_BASE_8
:
656 printf("0%" PRIo64
, v
.v_unsigned
);
658 case TRACER_DISPLAY_BASE_10
:
659 if (type_desc
->u
.side_integer
.signedness
) {
661 if (type_desc
->u
.side_integer
.len_bits
< 64) {
662 if (v
.v_unsigned
& (1ULL << (type_desc
->u
.side_integer
.len_bits
- 1)))
663 v
.v_unsigned
|= ~((1ULL << type_desc
->u
.side_integer
.len_bits
) - 1);
665 printf("%" PRId64
, v
.v_signed
);
667 printf("%" PRIu64
, v
.v_unsigned
);
670 case TRACER_DISPLAY_BASE_16
:
671 printf("0x%" PRIx64
, v
.v_unsigned
);
679 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
683 switch (type_desc
->type
) {
684 case SIDE_TYPE_ARRAY
:
685 switch (item
->type
) {
686 case SIDE_TYPE_ARRAY_U8
:
687 case SIDE_TYPE_ARRAY_U16
:
688 case SIDE_TYPE_ARRAY_U32
:
689 case SIDE_TYPE_ARRAY_U64
:
690 case SIDE_TYPE_ARRAY_S8
:
691 case SIDE_TYPE_ARRAY_S16
:
692 case SIDE_TYPE_ARRAY_S32
:
693 case SIDE_TYPE_ARRAY_S64
:
694 case SIDE_TYPE_ARRAY_POINTER32
:
695 case SIDE_TYPE_ARRAY_POINTER64
:
696 case SIDE_TYPE_ARRAY_BYTE
:
697 case SIDE_TYPE_ARRAY
:
700 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
707 switch (item
->type
) {
708 case SIDE_TYPE_VLA_U8
:
709 case SIDE_TYPE_VLA_U16
:
710 case SIDE_TYPE_VLA_U32
:
711 case SIDE_TYPE_VLA_U64
:
712 case SIDE_TYPE_VLA_S8
:
713 case SIDE_TYPE_VLA_S16
:
714 case SIDE_TYPE_VLA_S32
:
715 case SIDE_TYPE_VLA_S64
:
716 case SIDE_TYPE_VLA_BYTE
:
717 case SIDE_TYPE_VLA_POINTER32
:
718 case SIDE_TYPE_VLA_POINTER64
:
722 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
729 switch (item
->type
) {
740 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
746 case SIDE_TYPE_ENUM_BITMAP
:
747 switch (item
->type
) {
753 case SIDE_TYPE_ARRAY
:
757 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
764 if (type_desc
->type
!= item
->type
) {
765 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
771 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
772 type
= type_desc
->type
;
779 tracer_print_basic_type_header(type_desc
);
780 printf("%s", item
->u
.side_bool
? "true" : "false");
791 tracer_print_type_integer(type
, type_desc
, item
);
794 case SIDE_TYPE_POINTER32
:
798 v
= item
->u
.integer_value
.side_u32
;
799 if (type_to_host_reverse_bo(type_desc
))
800 v
= side_bswap_32(v
);
801 tracer_print_basic_type_header(type_desc
);
802 printf("0x%" PRIx32
, v
);
805 case SIDE_TYPE_POINTER64
:
809 v
= item
->u
.integer_value
.side_u64
;
810 if (type_to_host_reverse_bo(type_desc
))
811 v
= side_bswap_64(v
);
812 tracer_print_basic_type_header(type_desc
);
813 printf("0x%" PRIx64
, v
);
817 tracer_print_basic_type_header(type_desc
);
818 printf("0x%" PRIx8
, item
->u
.side_byte
);
822 print_enum(type_desc
, item
);
825 case SIDE_TYPE_ENUM_BITMAP
:
826 print_enum_bitmap(type_desc
, item
);
829 case SIDE_TYPE_FLOAT_BINARY16
:
836 .f
= item
->u
.side_float_binary16
,
839 if (type_to_host_reverse_bo(type_desc
))
840 float16
.u
= side_bswap_16(float16
.u
);
841 tracer_print_basic_type_header(type_desc
);
842 printf("%g", (double) float16
.f
);
845 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
849 case SIDE_TYPE_FLOAT_BINARY32
:
856 .f
= item
->u
.side_float_binary32
,
859 if (type_to_host_reverse_bo(type_desc
))
860 float32
.u
= side_bswap_32(float32
.u
);
861 tracer_print_basic_type_header(type_desc
);
862 printf("%g", (double) float32
.f
);
865 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
869 case SIDE_TYPE_FLOAT_BINARY64
:
876 .f
= item
->u
.side_float_binary64
,
879 if (type_to_host_reverse_bo(type_desc
))
880 float64
.u
= side_bswap_64(float64
.u
);
881 tracer_print_basic_type_header(type_desc
);
882 printf("%g", (double) float64
.f
);
885 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
889 case SIDE_TYPE_FLOAT_BINARY128
:
896 .f
= item
->u
.side_float_binary128
,
899 if (type_to_host_reverse_bo(type_desc
))
900 side_bswap_128p(float128
.arr
);
901 tracer_print_basic_type_header(type_desc
);
902 printf("%Lg", (long double) float128
.f
);
905 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
909 case SIDE_TYPE_STRING
:
910 tracer_print_basic_type_header(type_desc
);
911 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.string
);
913 case SIDE_TYPE_STRUCT
:
914 tracer_print_struct(type_desc
, item
->u
.side_struct
);
916 case SIDE_TYPE_STRUCT_SG
:
917 tracer_print_struct_sg(type_desc
, item
->u
.side_struct_sg_ptr
);
919 case SIDE_TYPE_ARRAY
:
920 tracer_print_array(type_desc
, item
->u
.side_array
);
923 tracer_print_vla(type_desc
, item
->u
.side_vla
);
925 case SIDE_TYPE_VLA_VISITOR
:
926 tracer_print_vla_visitor(type_desc
, item
->u
.side_vla_app_visitor_ctx
);
928 case SIDE_TYPE_ARRAY_U8
:
929 case SIDE_TYPE_ARRAY_U16
:
930 case SIDE_TYPE_ARRAY_U32
:
931 case SIDE_TYPE_ARRAY_U64
:
932 case SIDE_TYPE_ARRAY_S8
:
933 case SIDE_TYPE_ARRAY_S16
:
934 case SIDE_TYPE_ARRAY_S32
:
935 case SIDE_TYPE_ARRAY_S64
:
936 case SIDE_TYPE_ARRAY_BYTE
:
937 case SIDE_TYPE_ARRAY_POINTER32
:
938 case SIDE_TYPE_ARRAY_POINTER64
:
939 tracer_print_array_fixint(type_desc
, item
);
941 case SIDE_TYPE_VLA_U8
:
942 case SIDE_TYPE_VLA_U16
:
943 case SIDE_TYPE_VLA_U32
:
944 case SIDE_TYPE_VLA_U64
:
945 case SIDE_TYPE_VLA_S8
:
946 case SIDE_TYPE_VLA_S16
:
947 case SIDE_TYPE_VLA_S32
:
948 case SIDE_TYPE_VLA_S64
:
949 case SIDE_TYPE_VLA_BYTE
:
950 case SIDE_TYPE_VLA_POINTER32
:
951 case SIDE_TYPE_VLA_POINTER64
:
952 tracer_print_vla_fixint(type_desc
, item
);
954 case SIDE_TYPE_DYNAMIC
:
955 tracer_print_basic_type_header(type_desc
);
956 tracer_print_dynamic(&item
->u
.dynamic
);
959 fprintf(stderr
, "<UNKNOWN TYPE>");
966 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg_vec
*item
)
968 printf("%s: ", item_desc
->field_name
);
969 tracer_print_type(&item_desc
->side_type
, item
);
973 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
975 const struct side_arg_vec
*sav
= sav_desc
->sav
;
976 uint32_t side_sav_len
= sav_desc
->len
;
979 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
980 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
983 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
984 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
985 printf("fields: { ");
986 for (i
= 0; i
< side_sav_len
; i
++) {
987 printf("%s", i
? ", " : "");
988 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
994 void tracer_print_sg_integer_type_header(const struct side_type_sg_description
*sg_type
)
996 print_attributes("attr", ":", sg_type
->u
.side_basic
.attr
, sg_type
->u
.side_basic
.nr_attr
);
997 printf("%s", sg_type
->u
.side_basic
.nr_attr
? ", " : "");
1002 void tracer_print_sg_type(const struct side_type_sg_description
*sg_type
, void *_ptr
)
1004 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
1005 const char *ptr
= (const char *) _ptr
;
1007 switch (sg_type
->type
) {
1008 case SIDE_TYPE_SG_UNSIGNED_INT
:
1009 case SIDE_TYPE_SG_SIGNED_INT
:
1010 base
= get_attr_display_base(sg_type
->u
.side_basic
.attr
,
1011 sg_type
->u
.side_basic
.nr_attr
);
1018 switch (sg_type
->type
) {
1019 case SIDE_TYPE_SG_UNSIGNED_INT
:
1021 tracer_print_sg_integer_type_header(sg_type
);
1022 switch (sg_type
->u
.side_basic
.integer_size_bits
) {
1027 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 8)
1029 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1030 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1031 if (sg_type
->u
.side_basic
.len_bits
< 8)
1032 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1034 case TRACER_DISPLAY_BASE_2
:
1035 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1037 case TRACER_DISPLAY_BASE_8
:
1038 printf("0%" PRIo8
, v
);
1040 case TRACER_DISPLAY_BASE_10
:
1041 printf("%" PRIu8
, v
);
1043 case TRACER_DISPLAY_BASE_16
:
1044 printf("0x%" PRIx8
, v
);
1055 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 16)
1057 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1058 if (sg_type_to_host_reverse_bo(sg_type
))
1059 v
= side_bswap_16(v
);
1060 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1061 if (sg_type
->u
.side_basic
.len_bits
< 16)
1062 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1064 case TRACER_DISPLAY_BASE_2
:
1065 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1067 case TRACER_DISPLAY_BASE_8
:
1068 printf("0%" PRIo16
, v
);
1070 case TRACER_DISPLAY_BASE_10
:
1071 printf("%" PRIu16
, v
);
1073 case TRACER_DISPLAY_BASE_16
:
1074 printf("0x%" PRIx16
, v
);
1085 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 32)
1087 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1088 if (sg_type_to_host_reverse_bo(sg_type
))
1089 v
= side_bswap_32(v
);
1090 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1091 if (sg_type
->u
.side_basic
.len_bits
< 32)
1092 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1094 case TRACER_DISPLAY_BASE_2
:
1095 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1097 case TRACER_DISPLAY_BASE_8
:
1098 printf("0%" PRIo32
, v
);
1100 case TRACER_DISPLAY_BASE_10
:
1101 printf("%" PRIu32
, v
);
1103 case TRACER_DISPLAY_BASE_16
:
1104 printf("0x%" PRIx32
, v
);
1115 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 64)
1117 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1118 if (sg_type_to_host_reverse_bo(sg_type
))
1119 v
= side_bswap_64(v
);
1120 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1121 if (sg_type
->u
.side_basic
.len_bits
< 64)
1122 v
&= (1ULL << sg_type
->u
.side_basic
.len_bits
) - 1;
1124 case TRACER_DISPLAY_BASE_2
:
1125 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1127 case TRACER_DISPLAY_BASE_8
:
1128 printf("0%" PRIo64
, v
);
1130 case TRACER_DISPLAY_BASE_10
:
1131 printf("%" PRIu64
, v
);
1133 case TRACER_DISPLAY_BASE_16
:
1134 printf("0x%" PRIx64
, v
);
1142 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1147 case SIDE_TYPE_SG_SIGNED_INT
:
1149 tracer_print_sg_integer_type_header(sg_type
);
1150 switch (sg_type
->u
.side_basic
.integer_size_bits
) {
1155 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 8)
1157 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1158 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1159 if (sg_type
->u
.side_basic
.len_bits
< 8)
1160 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1162 case TRACER_DISPLAY_BASE_2
:
1163 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1165 case TRACER_DISPLAY_BASE_8
:
1166 printf("0%" PRIo8
, v
);
1168 case TRACER_DISPLAY_BASE_10
:
1170 if (sg_type
->u
.side_basic
.len_bits
< 8) {
1171 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1172 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1174 printf("%" PRId8
, v
);
1176 case TRACER_DISPLAY_BASE_16
:
1177 printf("0x%" PRIx8
, v
);
1188 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 16)
1190 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1191 if (sg_type_to_host_reverse_bo(sg_type
))
1192 v
= side_bswap_16(v
);
1193 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1194 if (sg_type
->u
.side_basic
.len_bits
< 16)
1195 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1197 case TRACER_DISPLAY_BASE_2
:
1198 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1200 case TRACER_DISPLAY_BASE_8
:
1201 printf("0%" PRIo16
, v
);
1203 case TRACER_DISPLAY_BASE_10
:
1205 if (sg_type
->u
.side_basic
.len_bits
< 16) {
1206 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1207 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1209 printf("%" PRId16
, v
);
1211 case TRACER_DISPLAY_BASE_16
:
1212 printf("0x%" PRIx16
, v
);
1223 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 32)
1225 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1226 if (sg_type_to_host_reverse_bo(sg_type
))
1227 v
= side_bswap_32(v
);
1228 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1229 if (sg_type
->u
.side_basic
.len_bits
< 32)
1230 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1232 case TRACER_DISPLAY_BASE_2
:
1233 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1235 case TRACER_DISPLAY_BASE_8
:
1236 printf("0%" PRIo32
, v
);
1238 case TRACER_DISPLAY_BASE_10
:
1240 if (sg_type
->u
.side_basic
.len_bits
< 32) {
1241 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1242 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1244 printf("%" PRId32
, v
);
1246 case TRACER_DISPLAY_BASE_16
:
1247 printf("0x%" PRIx32
, v
);
1258 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 64)
1260 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1261 if (sg_type_to_host_reverse_bo(sg_type
))
1262 v
= side_bswap_64(v
);
1263 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1264 if (sg_type
->u
.side_basic
.len_bits
< 64)
1265 v
&= (1ULL << sg_type
->u
.side_basic
.len_bits
) - 1;
1267 case TRACER_DISPLAY_BASE_2
:
1268 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1270 case TRACER_DISPLAY_BASE_8
:
1271 printf("0%" PRIo64
, v
);
1273 case TRACER_DISPLAY_BASE_10
:
1275 if (sg_type
->u
.side_basic
.len_bits
< 64) {
1276 if (v
& (1ULL << (sg_type
->u
.side_basic
.len_bits
- 1)))
1277 v
|= ~((1ULL << sg_type
->u
.side_basic
.len_bits
) - 1);
1279 printf("%" PRId64
, v
);
1281 case TRACER_DISPLAY_BASE_16
:
1282 printf("0x%" PRIx64
, v
);
1290 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1296 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER TYPE>");
1303 void tracer_print_sg_field(const struct side_struct_field_sg
*field_sg
, void *ptr
)
1305 printf("%s: ", field_sg
->field_name
);
1306 tracer_print_sg_type(&field_sg
->side_type
, ptr
);
1310 void tracer_print_struct_sg(const struct side_type_description
*type_desc
, void *ptr
)
1312 const struct side_type_struct_sg
*struct_sg
= type_desc
->u
.side_struct_sg
;
1315 print_attributes("attr", ":", struct_sg
->attr
, struct_sg
->nr_attr
);
1316 printf("%s", struct_sg
->nr_attr
? ", " : "");
1317 printf("fields: { ");
1318 for (i
= 0; i
< struct_sg
->nr_fields
; i
++) {
1319 printf("%s", i
? ", " : "");
1320 tracer_print_sg_field(&struct_sg
->fields_sg
[i
], ptr
);
1326 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1328 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1329 uint32_t side_sav_len
= sav_desc
->len
;
1332 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1333 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1336 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1337 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1338 printf("elements: ");
1340 for (i
= 0; i
< side_sav_len
; i
++) {
1341 printf("%s", i
? ", " : "");
1342 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1348 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1350 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1351 uint32_t side_sav_len
= sav_desc
->len
;
1354 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1355 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1356 printf("elements: ");
1358 for (i
= 0; i
< side_sav_len
; i
++) {
1359 printf("%s", i
? ", " : "");
1360 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1365 struct tracer_visitor_priv
{
1366 const struct side_type_description
*elem_type
;
1371 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1372 const struct side_arg_vec
*elem
)
1374 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1376 printf("%s", tracer_priv
->i
++ ? ", " : "");
1377 tracer_print_type(tracer_priv
->elem_type
, elem
);
1378 return SIDE_VISITOR_STATUS_OK
;
1382 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
)
1384 enum side_visitor_status status
;
1385 struct tracer_visitor_priv tracer_priv
= {
1386 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1389 const struct side_tracer_visitor_ctx tracer_ctx
= {
1390 .write_elem
= tracer_write_elem_cb
,
1391 .priv
= &tracer_priv
,
1394 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1395 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1396 printf("elements: ");
1398 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1400 case SIDE_VISITOR_STATUS_OK
:
1402 case SIDE_VISITOR_STATUS_ERROR
:
1403 fprintf(stderr
, "ERROR: Visitor error\n");
1409 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1411 const struct side_type_description
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1412 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
1413 void *p
= item
->u
.side_array_fixint
;
1414 enum side_type side_type
;
1417 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1418 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1419 printf("elements: ");
1420 switch (item
->type
) {
1421 case SIDE_TYPE_ARRAY_U8
:
1422 if (elem_type
->type
!= SIDE_TYPE_U8
)
1425 case SIDE_TYPE_ARRAY_U16
:
1426 if (elem_type
->type
!= SIDE_TYPE_U16
)
1429 case SIDE_TYPE_ARRAY_U32
:
1430 if (elem_type
->type
!= SIDE_TYPE_U32
)
1433 case SIDE_TYPE_ARRAY_U64
:
1434 if (elem_type
->type
!= SIDE_TYPE_U64
)
1437 case SIDE_TYPE_ARRAY_S8
:
1438 if (elem_type
->type
!= SIDE_TYPE_S8
)
1441 case SIDE_TYPE_ARRAY_S16
:
1442 if (elem_type
->type
!= SIDE_TYPE_S16
)
1445 case SIDE_TYPE_ARRAY_S32
:
1446 if (elem_type
->type
!= SIDE_TYPE_S32
)
1449 case SIDE_TYPE_ARRAY_S64
:
1450 if (elem_type
->type
!= SIDE_TYPE_S64
)
1453 case SIDE_TYPE_ARRAY_BYTE
:
1454 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1457 case SIDE_TYPE_ARRAY_POINTER32
:
1458 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1460 case SIDE_TYPE_ARRAY_POINTER64
:
1461 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1467 side_type
= elem_type
->type
;
1470 for (i
= 0; i
< side_sav_len
; i
++) {
1471 struct side_arg_vec sav_elem
= {
1475 switch (side_type
) {
1477 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1480 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1483 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1486 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1489 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1492 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1495 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1498 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1500 case SIDE_TYPE_BYTE
:
1501 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1503 case SIDE_TYPE_POINTER32
:
1504 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1506 case SIDE_TYPE_POINTER64
:
1507 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1511 fprintf(stderr
, "ERROR: Unexpected type\n");
1515 printf("%s", i
? ", " : "");
1516 tracer_print_type(elem_type
, &sav_elem
);
1522 fprintf(stderr
, "ERROR: type mismatch\n");
1526 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1528 const struct side_type_description
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1529 uint32_t side_sav_len
= item
->u
.side_vla_fixint
.length
;
1530 void *p
= item
->u
.side_vla_fixint
.p
;
1531 enum side_type side_type
;
1534 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1535 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1536 printf("elements: ");
1537 switch (item
->type
) {
1538 case SIDE_TYPE_VLA_U8
:
1539 if (elem_type
->type
!= SIDE_TYPE_U8
)
1542 case SIDE_TYPE_VLA_U16
:
1543 if (elem_type
->type
!= SIDE_TYPE_U16
)
1546 case SIDE_TYPE_VLA_U32
:
1547 if (elem_type
->type
!= SIDE_TYPE_U32
)
1550 case SIDE_TYPE_VLA_U64
:
1551 if (elem_type
->type
!= SIDE_TYPE_U64
)
1554 case SIDE_TYPE_VLA_S8
:
1555 if (elem_type
->type
!= SIDE_TYPE_S8
)
1558 case SIDE_TYPE_VLA_S16
:
1559 if (elem_type
->type
!= SIDE_TYPE_S16
)
1562 case SIDE_TYPE_VLA_S32
:
1563 if (elem_type
->type
!= SIDE_TYPE_S32
)
1566 case SIDE_TYPE_VLA_S64
:
1567 if (elem_type
->type
!= SIDE_TYPE_S64
)
1570 case SIDE_TYPE_VLA_BYTE
:
1571 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1574 case SIDE_TYPE_VLA_POINTER32
:
1575 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1577 case SIDE_TYPE_VLA_POINTER64
:
1578 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1584 side_type
= elem_type
->type
;
1587 for (i
= 0; i
< side_sav_len
; i
++) {
1588 struct side_arg_vec sav_elem
= {
1592 switch (side_type
) {
1594 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1597 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1600 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1603 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1606 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1609 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1612 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1615 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1617 case SIDE_TYPE_BYTE
:
1618 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1620 case SIDE_TYPE_POINTER32
:
1621 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1623 case SIDE_TYPE_POINTER64
:
1624 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1628 fprintf(stderr
, "ERROR: Unexpected type\n");
1632 printf("%s", i
? ", " : "");
1633 tracer_print_type(elem_type
, &sav_elem
);
1639 fprintf(stderr
, "ERROR: type mismatch\n");
1644 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
1646 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
1647 uint32_t len
= dynamic_struct
->len
;
1650 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1651 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1652 printf("fields:: ");
1654 for (i
= 0; i
< len
; i
++) {
1655 printf("%s", i
? ", " : "");
1656 printf("%s:: ", fields
[i
].field_name
);
1657 tracer_print_dynamic(&fields
[i
].elem
);
1662 struct tracer_dynamic_struct_visitor_priv
{
1667 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1668 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1669 const struct side_arg_dynamic_event_field
*dynamic_field
)
1671 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1673 printf("%s", tracer_priv
->i
++ ? ", " : "");
1674 printf("%s:: ", dynamic_field
->field_name
);
1675 tracer_print_dynamic(&dynamic_field
->elem
);
1676 return SIDE_VISITOR_STATUS_OK
;
1680 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec
*item
)
1682 enum side_visitor_status status
;
1683 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1686 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1687 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1688 .priv
= &tracer_priv
,
1690 void *app_ctx
= item
->u
.side_dynamic_struct_visitor
.app_ctx
;
1692 print_attributes("attr", "::", item
->u
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic_struct_visitor
.nr_attr
);
1693 printf("%s", item
->u
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1694 printf("fields:: ");
1696 status
= item
->u
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1698 case SIDE_VISITOR_STATUS_OK
:
1700 case SIDE_VISITOR_STATUS_ERROR
:
1701 fprintf(stderr
, "ERROR: Visitor error\n");
1708 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla
*vla
)
1710 const struct side_arg_dynamic_vec
*sav
= vla
->sav
;
1711 uint32_t side_sav_len
= vla
->len
;
1714 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1715 printf("%s", vla
->nr_attr
? ", " : "");
1716 printf("elements:: ");
1718 for (i
= 0; i
< side_sav_len
; i
++) {
1719 printf("%s", i
? ", " : "");
1720 tracer_print_dynamic(&sav
[i
]);
1725 struct tracer_dynamic_vla_visitor_priv
{
1730 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1731 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
1732 const struct side_arg_dynamic_vec
*elem
)
1734 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1736 printf("%s", tracer_priv
->i
++ ? ", " : "");
1737 tracer_print_dynamic(elem
);
1738 return SIDE_VISITOR_STATUS_OK
;
1742 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec
*item
)
1744 enum side_visitor_status status
;
1745 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1748 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
1749 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1750 .priv
= &tracer_priv
,
1752 void *app_ctx
= item
->u
.side_dynamic_vla_visitor
.app_ctx
;
1754 print_attributes("attr", "::", item
->u
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic_vla_visitor
.nr_attr
);
1755 printf("%s", item
->u
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1756 printf("elements:: ");
1758 status
= item
->u
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1760 case SIDE_VISITOR_STATUS_OK
:
1762 case SIDE_VISITOR_STATUS_ERROR
:
1763 fprintf(stderr
, "ERROR: Visitor error\n");
1770 void tracer_print_dynamic_basic_type_header(const struct side_arg_dynamic_vec
*item
)
1772 print_attributes("attr", "::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1773 printf("%s", item
->u
.side_basic
.nr_attr
? ", " : "");
1778 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*item
)
1780 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
1782 switch (item
->dynamic_type
) {
1783 case SIDE_DYNAMIC_TYPE_U8
:
1784 case SIDE_DYNAMIC_TYPE_U16
:
1785 case SIDE_DYNAMIC_TYPE_U32
:
1786 case SIDE_DYNAMIC_TYPE_U64
:
1787 case SIDE_DYNAMIC_TYPE_S8
:
1788 case SIDE_DYNAMIC_TYPE_S16
:
1789 case SIDE_DYNAMIC_TYPE_S32
:
1790 case SIDE_DYNAMIC_TYPE_S64
:
1791 base
= get_attr_display_base(item
->u
.side_basic
.attr
,
1792 item
->u
.side_basic
.nr_attr
);
1800 switch (item
->dynamic_type
) {
1801 case SIDE_DYNAMIC_TYPE_NULL
:
1802 tracer_print_dynamic_basic_type_header(item
);
1803 printf("<NULL TYPE>");
1805 case SIDE_DYNAMIC_TYPE_BOOL
:
1806 tracer_print_dynamic_basic_type_header(item
);
1807 printf("%s", item
->u
.side_basic
.u
.side_bool
? "true" : "false");
1809 case SIDE_DYNAMIC_TYPE_U8
:
1813 v
= item
->u
.side_basic
.u
.integer_value
.side_u8
;
1814 tracer_print_dynamic_basic_type_header(item
);
1816 case TRACER_DISPLAY_BASE_2
:
1817 print_integer_binary(v
, 8);
1819 case TRACER_DISPLAY_BASE_8
:
1820 printf("0%" PRIo8
, v
);
1822 case TRACER_DISPLAY_BASE_10
:
1823 printf("%" PRIu8
, v
);
1825 case TRACER_DISPLAY_BASE_16
:
1826 printf("0x%" PRIx8
, v
);
1833 case SIDE_DYNAMIC_TYPE_U16
:
1837 v
= item
->u
.side_basic
.u
.integer_value
.side_u16
;
1838 if (dynamic_type_to_host_reverse_bo(item
))
1839 v
= side_bswap_16(v
);
1840 tracer_print_dynamic_basic_type_header(item
);
1842 case TRACER_DISPLAY_BASE_2
:
1843 print_integer_binary(v
, 16);
1845 case TRACER_DISPLAY_BASE_8
:
1846 printf("0%" PRIo16
, v
);
1848 case TRACER_DISPLAY_BASE_10
:
1849 printf("%" PRIu16
, v
);
1851 case TRACER_DISPLAY_BASE_16
:
1852 printf("0x%" PRIx16
, v
);
1859 case SIDE_DYNAMIC_TYPE_U32
:
1863 v
= item
->u
.side_basic
.u
.integer_value
.side_u32
;
1864 if (dynamic_type_to_host_reverse_bo(item
))
1865 v
= side_bswap_32(v
);
1866 tracer_print_dynamic_basic_type_header(item
);
1868 case TRACER_DISPLAY_BASE_2
:
1869 print_integer_binary(v
, 32);
1871 case TRACER_DISPLAY_BASE_8
:
1872 printf("0%" PRIo32
, v
);
1874 case TRACER_DISPLAY_BASE_10
:
1875 printf("%" PRIu32
, v
);
1877 case TRACER_DISPLAY_BASE_16
:
1878 printf("0x%" PRIx32
, v
);
1885 case SIDE_DYNAMIC_TYPE_U64
:
1889 v
= item
->u
.side_basic
.u
.integer_value
.side_u64
;
1890 if (dynamic_type_to_host_reverse_bo(item
))
1891 v
= side_bswap_64(v
);
1892 tracer_print_dynamic_basic_type_header(item
);
1894 case TRACER_DISPLAY_BASE_2
:
1895 print_integer_binary(v
, 64);
1897 case TRACER_DISPLAY_BASE_8
:
1898 printf("0%" PRIo64
, v
);
1900 case TRACER_DISPLAY_BASE_10
:
1901 printf("%" PRIu64
, v
);
1903 case TRACER_DISPLAY_BASE_16
:
1904 printf("0x%" PRIx64
, v
);
1911 case SIDE_DYNAMIC_TYPE_S8
:
1915 v
= item
->u
.side_basic
.u
.integer_value
.side_s8
;
1916 tracer_print_dynamic_basic_type_header(item
);
1918 case TRACER_DISPLAY_BASE_2
:
1919 print_integer_binary(v
, 8);
1921 case TRACER_DISPLAY_BASE_8
:
1922 printf("0%" PRIo8
, v
);
1924 case TRACER_DISPLAY_BASE_10
:
1925 printf("%" PRId8
, v
);
1927 case TRACER_DISPLAY_BASE_16
:
1928 printf("0x%" PRIx8
, v
);
1935 case SIDE_DYNAMIC_TYPE_S16
:
1939 v
= item
->u
.side_basic
.u
.integer_value
.side_u16
;
1940 if (dynamic_type_to_host_reverse_bo(item
))
1941 v
= side_bswap_16(v
);
1942 tracer_print_dynamic_basic_type_header(item
);
1944 case TRACER_DISPLAY_BASE_2
:
1945 print_integer_binary(v
, 16);
1947 case TRACER_DISPLAY_BASE_8
:
1948 printf("0%" PRIo16
, v
);
1950 case TRACER_DISPLAY_BASE_10
:
1951 printf("%" PRId16
, v
);
1953 case TRACER_DISPLAY_BASE_16
:
1954 printf("0x%" PRIx16
, v
);
1961 case SIDE_DYNAMIC_TYPE_S32
:
1965 v
= item
->u
.side_basic
.u
.integer_value
.side_u32
;
1966 if (dynamic_type_to_host_reverse_bo(item
))
1967 v
= side_bswap_32(v
);
1968 tracer_print_dynamic_basic_type_header(item
);
1970 case TRACER_DISPLAY_BASE_2
:
1971 print_integer_binary(v
, 32);
1973 case TRACER_DISPLAY_BASE_8
:
1974 printf("0%" PRIo32
, v
);
1976 case TRACER_DISPLAY_BASE_10
:
1977 printf("%" PRId32
, v
);
1979 case TRACER_DISPLAY_BASE_16
:
1980 printf("0x%" PRIx32
, v
);
1987 case SIDE_DYNAMIC_TYPE_S64
:
1991 v
= item
->u
.side_basic
.u
.integer_value
.side_u64
;
1992 if (dynamic_type_to_host_reverse_bo(item
))
1993 v
= side_bswap_64(v
);
1994 tracer_print_dynamic_basic_type_header(item
);
1996 case TRACER_DISPLAY_BASE_2
:
1997 print_integer_binary(v
, 64);
1999 case TRACER_DISPLAY_BASE_8
:
2000 printf("0%" PRIo64
, v
);
2002 case TRACER_DISPLAY_BASE_10
:
2003 printf("%" PRId64
, v
);
2005 case TRACER_DISPLAY_BASE_16
:
2006 printf("0x%" PRIx64
, v
);
2013 case SIDE_DYNAMIC_TYPE_BYTE
:
2014 tracer_print_dynamic_basic_type_header(item
);
2015 printf("0x%" PRIx8
, item
->u
.side_basic
.u
.side_byte
);
2017 case SIDE_DYNAMIC_TYPE_POINTER32
:
2021 v
= item
->u
.side_basic
.u
.integer_value
.side_u32
;
2022 if (dynamic_type_to_host_reverse_bo(item
))
2023 v
= side_bswap_32(v
);
2024 tracer_print_dynamic_basic_type_header(item
);
2025 printf("0x%" PRIx32
, v
);
2029 case SIDE_DYNAMIC_TYPE_POINTER64
:
2033 v
= item
->u
.side_basic
.u
.integer_value
.side_u64
;
2034 if (dynamic_type_to_host_reverse_bo(item
))
2035 v
= side_bswap_64(v
);
2036 tracer_print_dynamic_basic_type_header(item
);
2037 printf("0x%" PRIx64
, v
);
2041 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
2048 .f
= item
->u
.side_basic
.u
.side_float_binary16
,
2051 if (dynamic_type_to_host_reverse_bo(item
))
2052 float16
.u
= side_bswap_16(float16
.u
);
2053 tracer_print_dynamic_basic_type_header(item
);
2054 printf("%g", (double) float16
.f
);
2057 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
2061 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
2068 .f
= item
->u
.side_basic
.u
.side_float_binary32
,
2071 if (dynamic_type_to_host_reverse_bo(item
))
2072 float32
.u
= side_bswap_32(float32
.u
);
2073 tracer_print_dynamic_basic_type_header(item
);
2074 printf("%g", (double) float32
.f
);
2077 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
2081 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
2088 .f
= item
->u
.side_basic
.u
.side_float_binary64
,
2091 if (dynamic_type_to_host_reverse_bo(item
))
2092 float64
.u
= side_bswap_64(float64
.u
);
2093 tracer_print_dynamic_basic_type_header(item
);
2094 printf("%g", (double) float64
.f
);
2097 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
2101 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
2108 .f
= item
->u
.side_basic
.u
.side_float_binary128
,
2111 if (dynamic_type_to_host_reverse_bo(item
))
2112 side_bswap_128p(float128
.arr
);
2113 tracer_print_dynamic_basic_type_header(item
);
2114 printf("%Lg", (long double) float128
.f
);
2117 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
2121 case SIDE_DYNAMIC_TYPE_STRING
:
2122 tracer_print_dynamic_basic_type_header(item
);
2123 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_basic
.u
.string
);
2125 case SIDE_DYNAMIC_TYPE_STRUCT
:
2126 tracer_print_dynamic_struct(item
->u
.side_dynamic_struct
);
2128 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
:
2129 tracer_print_dynamic_struct_visitor(item
);
2131 case SIDE_DYNAMIC_TYPE_VLA
:
2132 tracer_print_dynamic_vla(item
->u
.side_dynamic_vla
);
2134 case SIDE_DYNAMIC_TYPE_VLA_VISITOR
:
2135 tracer_print_dynamic_vla_visitor(item
);
2138 fprintf(stderr
, "<UNKNOWN TYPE>");
2145 void tracer_print_static_fields(const struct side_event_description
*desc
,
2146 const struct side_arg_vec_description
*sav_desc
,
2149 const struct side_arg_vec
*sav
= sav_desc
->sav
;
2150 uint32_t side_sav_len
= sav_desc
->len
;
2153 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
2154 if (desc
->nr_fields
!= side_sav_len
) {
2155 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
2158 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
2159 printf("%s", side_sav_len
? ", fields: [ " : "");
2160 for (i
= 0; i
< side_sav_len
; i
++) {
2161 printf("%s", i
? ", " : "");
2162 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
2170 void tracer_call(const struct side_event_description
*desc
,
2171 const struct side_arg_vec_description
*sav_desc
,
2172 void *priv
__attribute__((unused
)))
2176 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
2180 void tracer_call_variadic(const struct side_event_description
*desc
,
2181 const struct side_arg_vec_description
*sav_desc
,
2182 const struct side_arg_dynamic_event_struct
*var_struct
,
2183 void *priv
__attribute__((unused
)))
2185 uint32_t var_struct_len
= var_struct
->len
;
2186 int nr_fields
= 0, i
;
2188 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
2190 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
2191 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
2194 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
2195 printf("%s", var_struct_len
? ", fields:: [ " : "");
2196 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
2197 printf("%s", i
? ", " : "");
2198 printf("%s:: ", var_struct
->fields
[i
].field_name
);
2199 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
2206 void tracer_event_notification(enum side_tracer_notification notif
,
2207 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
2212 printf("----------------------------------------------------------\n");
2213 printf("Tracer notified of events %s\n",
2214 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
2215 for (i
= 0; i
< nr_events
; i
++) {
2216 struct side_event_description
*event
= events
[i
];
2218 /* Skip NULL pointers */
2221 printf("provider: %s, event: %s\n",
2222 event
->provider_name
, event
->event_name
);
2223 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
2224 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
2225 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
2229 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
2234 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
2235 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
2239 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
2245 printf("----------------------------------------------------------\n");
2248 static __attribute__((constructor
))
2249 void tracer_init(void);
2251 void tracer_init(void)
2253 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
2258 static __attribute__((destructor
))
2259 void tracer_exit(void);
2261 void tracer_exit(void)
2263 side_tracer_event_notification_unregister(tracer_handle
);