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_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_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_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
.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_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_integer_type_header(const struct side_type_description
*type_desc
)
567 print_attributes("attr", ":", type_desc
->u
.side_integer
.attr
, type_desc
->u
.side_integer
.nr_attr
);
568 printf("%s", type_desc
->u
.side_integer
.nr_attr
? ", " : "");
573 void tracer_print_type_integer(enum side_type type
, const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
575 enum tracer_display_base base
;
581 if (!type_desc
->u
.side_integer
.len_bits
||
582 type_desc
->u
.side_integer
.len_bits
> type_desc
->u
.side_integer
.integer_size_bits
)
584 base
= get_attr_display_base(type_desc
->u
.side_integer
.attr
,
585 type_desc
->u
.side_integer
.nr_attr
);
588 v
.v_unsigned
= item
->u
.integer_value
.side_u8
;
594 side_u16
= item
->u
.integer_value
.side_u16
;
595 if (type_to_host_reverse_bo(type_desc
))
596 side_u16
= side_bswap_16(side_u16
);
597 v
.v_unsigned
= side_u16
;
604 side_u32
= item
->u
.integer_value
.side_u32
;
605 if (type_to_host_reverse_bo(type_desc
))
606 side_u32
= side_bswap_32(side_u32
);
607 v
.v_unsigned
= side_u32
;
614 side_u64
= item
->u
.integer_value
.side_u64
;
615 if (type_to_host_reverse_bo(type_desc
))
616 side_u64
= side_bswap_64(side_u64
);
617 v
.v_unsigned
= side_u64
;
621 v
.v_signed
= item
->u
.integer_value
.side_s8
;
627 side_s16
= item
->u
.integer_value
.side_s16
;
628 if (type_to_host_reverse_bo(type_desc
))
629 side_s16
= side_bswap_16(side_s16
);
630 v
.v_unsigned
= side_s16
;
637 side_s32
= item
->u
.integer_value
.side_s32
;
638 if (type_to_host_reverse_bo(type_desc
))
639 side_s32
= side_bswap_32(side_s32
);
640 v
.v_unsigned
= side_s32
;
647 side_s64
= item
->u
.integer_value
.side_s64
;
648 if (type_to_host_reverse_bo(type_desc
))
649 side_s64
= side_bswap_64(side_s64
);
650 v
.v_unsigned
= side_s64
;
656 if (type_desc
->u
.side_integer
.len_bits
< 64)
657 v
.v_unsigned
&= (1ULL << type_desc
->u
.side_integer
.len_bits
) - 1;
658 tracer_print_integer_type_header(type_desc
);
660 case TRACER_DISPLAY_BASE_2
:
661 print_integer_binary(v
.v_unsigned
, type_desc
->u
.side_integer
.len_bits
);
663 case TRACER_DISPLAY_BASE_8
:
664 printf("0%" PRIo64
, v
.v_unsigned
);
666 case TRACER_DISPLAY_BASE_10
:
667 if (type_desc
->u
.side_integer
.signedness
) {
669 if (type_desc
->u
.side_integer
.len_bits
< 64) {
670 if (v
.v_unsigned
& (1ULL << (type_desc
->u
.side_integer
.len_bits
- 1)))
671 v
.v_unsigned
|= ~((1ULL << type_desc
->u
.side_integer
.len_bits
) - 1);
673 printf("%" PRId64
, v
.v_signed
);
675 printf("%" PRIu64
, v
.v_unsigned
);
678 case TRACER_DISPLAY_BASE_16
:
679 printf("0x%" PRIx64
, v
.v_unsigned
);
687 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
691 switch (type_desc
->type
) {
692 case SIDE_TYPE_ARRAY
:
693 switch (item
->type
) {
694 case SIDE_TYPE_ARRAY_U8
:
695 case SIDE_TYPE_ARRAY_U16
:
696 case SIDE_TYPE_ARRAY_U32
:
697 case SIDE_TYPE_ARRAY_U64
:
698 case SIDE_TYPE_ARRAY_S8
:
699 case SIDE_TYPE_ARRAY_S16
:
700 case SIDE_TYPE_ARRAY_S32
:
701 case SIDE_TYPE_ARRAY_S64
:
702 case SIDE_TYPE_ARRAY_POINTER32
:
703 case SIDE_TYPE_ARRAY_POINTER64
:
704 case SIDE_TYPE_ARRAY_BYTE
:
705 case SIDE_TYPE_ARRAY
:
708 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
715 switch (item
->type
) {
716 case SIDE_TYPE_VLA_U8
:
717 case SIDE_TYPE_VLA_U16
:
718 case SIDE_TYPE_VLA_U32
:
719 case SIDE_TYPE_VLA_U64
:
720 case SIDE_TYPE_VLA_S8
:
721 case SIDE_TYPE_VLA_S16
:
722 case SIDE_TYPE_VLA_S32
:
723 case SIDE_TYPE_VLA_S64
:
724 case SIDE_TYPE_VLA_BYTE
:
725 case SIDE_TYPE_VLA_POINTER32
:
726 case SIDE_TYPE_VLA_POINTER64
:
730 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
737 switch (item
->type
) {
748 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
754 case SIDE_TYPE_ENUM_BITMAP
:
755 switch (item
->type
) {
761 case SIDE_TYPE_ARRAY
:
765 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
772 if (type_desc
->type
!= item
->type
) {
773 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
779 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
780 type
= type_desc
->type
;
787 tracer_print_basic_type_header(type_desc
);
788 printf("%s", item
->u
.side_bool
? "true" : "false");
799 tracer_print_type_integer(type
, type_desc
, item
);
802 case SIDE_TYPE_POINTER32
:
806 v
= item
->u
.integer_value
.side_u32
;
807 if (type_to_host_reverse_bo(type_desc
))
808 v
= side_bswap_32(v
);
809 tracer_print_integer_type_header(type_desc
);
810 printf("0x%" PRIx32
, v
);
813 case SIDE_TYPE_POINTER64
:
817 v
= item
->u
.integer_value
.side_u64
;
818 if (type_to_host_reverse_bo(type_desc
))
819 v
= side_bswap_64(v
);
820 tracer_print_integer_type_header(type_desc
);
821 printf("0x%" PRIx64
, v
);
825 tracer_print_basic_type_header(type_desc
);
826 printf("0x%" PRIx8
, item
->u
.side_byte
);
830 print_enum(type_desc
, item
);
833 case SIDE_TYPE_ENUM_BITMAP
:
834 print_enum_bitmap(type_desc
, item
);
837 case SIDE_TYPE_FLOAT_BINARY16
:
844 .f
= item
->u
.float_value
.side_float_binary16
,
847 if (type_to_host_reverse_bo(type_desc
))
848 float16
.u
= side_bswap_16(float16
.u
);
849 tracer_print_basic_type_header(type_desc
);
850 printf("%g", (double) float16
.f
);
853 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
857 case SIDE_TYPE_FLOAT_BINARY32
:
864 .f
= item
->u
.float_value
.side_float_binary32
,
867 if (type_to_host_reverse_bo(type_desc
))
868 float32
.u
= side_bswap_32(float32
.u
);
869 tracer_print_basic_type_header(type_desc
);
870 printf("%g", (double) float32
.f
);
873 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
877 case SIDE_TYPE_FLOAT_BINARY64
:
884 .f
= item
->u
.float_value
.side_float_binary64
,
887 if (type_to_host_reverse_bo(type_desc
))
888 float64
.u
= side_bswap_64(float64
.u
);
889 tracer_print_basic_type_header(type_desc
);
890 printf("%g", (double) float64
.f
);
893 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
897 case SIDE_TYPE_FLOAT_BINARY128
:
904 .f
= item
->u
.float_value
.side_float_binary128
,
907 if (type_to_host_reverse_bo(type_desc
))
908 side_bswap_128p(float128
.arr
);
909 tracer_print_basic_type_header(type_desc
);
910 printf("%Lg", (long double) float128
.f
);
913 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
917 case SIDE_TYPE_STRING
:
918 tracer_print_basic_type_header(type_desc
);
919 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.string
);
921 case SIDE_TYPE_STRUCT
:
922 tracer_print_struct(type_desc
, item
->u
.side_struct
);
924 case SIDE_TYPE_STRUCT_SG
:
925 tracer_print_struct_sg(type_desc
, item
->u
.side_struct_sg_ptr
);
927 case SIDE_TYPE_ARRAY
:
928 tracer_print_array(type_desc
, item
->u
.side_array
);
931 tracer_print_vla(type_desc
, item
->u
.side_vla
);
933 case SIDE_TYPE_VLA_VISITOR
:
934 tracer_print_vla_visitor(type_desc
, item
->u
.side_vla_app_visitor_ctx
);
936 case SIDE_TYPE_ARRAY_U8
:
937 case SIDE_TYPE_ARRAY_U16
:
938 case SIDE_TYPE_ARRAY_U32
:
939 case SIDE_TYPE_ARRAY_U64
:
940 case SIDE_TYPE_ARRAY_S8
:
941 case SIDE_TYPE_ARRAY_S16
:
942 case SIDE_TYPE_ARRAY_S32
:
943 case SIDE_TYPE_ARRAY_S64
:
944 case SIDE_TYPE_ARRAY_BYTE
:
945 case SIDE_TYPE_ARRAY_POINTER32
:
946 case SIDE_TYPE_ARRAY_POINTER64
:
947 tracer_print_array_fixint(type_desc
, item
);
949 case SIDE_TYPE_VLA_U8
:
950 case SIDE_TYPE_VLA_U16
:
951 case SIDE_TYPE_VLA_U32
:
952 case SIDE_TYPE_VLA_U64
:
953 case SIDE_TYPE_VLA_S8
:
954 case SIDE_TYPE_VLA_S16
:
955 case SIDE_TYPE_VLA_S32
:
956 case SIDE_TYPE_VLA_S64
:
957 case SIDE_TYPE_VLA_BYTE
:
958 case SIDE_TYPE_VLA_POINTER32
:
959 case SIDE_TYPE_VLA_POINTER64
:
960 tracer_print_vla_fixint(type_desc
, item
);
962 case SIDE_TYPE_DYNAMIC
:
963 tracer_print_basic_type_header(type_desc
);
964 tracer_print_dynamic(&item
->u
.dynamic
);
967 fprintf(stderr
, "<UNKNOWN TYPE>");
974 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg_vec
*item
)
976 printf("%s: ", item_desc
->field_name
);
977 tracer_print_type(&item_desc
->side_type
, item
);
981 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
983 const struct side_arg_vec
*sav
= sav_desc
->sav
;
984 uint32_t side_sav_len
= sav_desc
->len
;
987 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
988 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
991 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
992 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
993 printf("fields: { ");
994 for (i
= 0; i
< side_sav_len
; i
++) {
995 printf("%s", i
? ", " : "");
996 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1002 void tracer_print_sg_integer_type_header(const struct side_type_sg_description
*sg_type
)
1004 print_attributes("attr", ":", sg_type
->u
.side_basic
.attr
, sg_type
->u
.side_basic
.nr_attr
);
1005 printf("%s", sg_type
->u
.side_basic
.nr_attr
? ", " : "");
1010 void tracer_print_sg_type(const struct side_type_sg_description
*sg_type
, void *_ptr
)
1012 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
1013 const char *ptr
= (const char *) _ptr
;
1015 switch (sg_type
->type
) {
1016 case SIDE_TYPE_SG_UNSIGNED_INT
:
1017 case SIDE_TYPE_SG_SIGNED_INT
:
1018 base
= get_attr_display_base(sg_type
->u
.side_basic
.attr
,
1019 sg_type
->u
.side_basic
.nr_attr
);
1026 switch (sg_type
->type
) {
1027 case SIDE_TYPE_SG_UNSIGNED_INT
:
1029 tracer_print_sg_integer_type_header(sg_type
);
1030 switch (sg_type
->u
.side_basic
.integer_size_bits
) {
1035 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 8)
1037 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1038 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1039 if (sg_type
->u
.side_basic
.len_bits
< 8)
1040 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1042 case TRACER_DISPLAY_BASE_2
:
1043 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1045 case TRACER_DISPLAY_BASE_8
:
1046 printf("0%" PRIo8
, v
);
1048 case TRACER_DISPLAY_BASE_10
:
1049 printf("%" PRIu8
, v
);
1051 case TRACER_DISPLAY_BASE_16
:
1052 printf("0x%" PRIx8
, v
);
1063 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 16)
1065 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1066 if (sg_type_to_host_reverse_bo(sg_type
))
1067 v
= side_bswap_16(v
);
1068 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1069 if (sg_type
->u
.side_basic
.len_bits
< 16)
1070 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1072 case TRACER_DISPLAY_BASE_2
:
1073 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1075 case TRACER_DISPLAY_BASE_8
:
1076 printf("0%" PRIo16
, v
);
1078 case TRACER_DISPLAY_BASE_10
:
1079 printf("%" PRIu16
, v
);
1081 case TRACER_DISPLAY_BASE_16
:
1082 printf("0x%" PRIx16
, v
);
1093 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 32)
1095 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1096 if (sg_type_to_host_reverse_bo(sg_type
))
1097 v
= side_bswap_32(v
);
1098 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1099 if (sg_type
->u
.side_basic
.len_bits
< 32)
1100 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1102 case TRACER_DISPLAY_BASE_2
:
1103 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1105 case TRACER_DISPLAY_BASE_8
:
1106 printf("0%" PRIo32
, v
);
1108 case TRACER_DISPLAY_BASE_10
:
1109 printf("%" PRIu32
, v
);
1111 case TRACER_DISPLAY_BASE_16
:
1112 printf("0x%" PRIx32
, v
);
1123 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 64)
1125 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1126 if (sg_type_to_host_reverse_bo(sg_type
))
1127 v
= side_bswap_64(v
);
1128 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1129 if (sg_type
->u
.side_basic
.len_bits
< 64)
1130 v
&= (1ULL << sg_type
->u
.side_basic
.len_bits
) - 1;
1132 case TRACER_DISPLAY_BASE_2
:
1133 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1135 case TRACER_DISPLAY_BASE_8
:
1136 printf("0%" PRIo64
, v
);
1138 case TRACER_DISPLAY_BASE_10
:
1139 printf("%" PRIu64
, v
);
1141 case TRACER_DISPLAY_BASE_16
:
1142 printf("0x%" PRIx64
, v
);
1150 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1155 case SIDE_TYPE_SG_SIGNED_INT
:
1157 tracer_print_sg_integer_type_header(sg_type
);
1158 switch (sg_type
->u
.side_basic
.integer_size_bits
) {
1163 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 8)
1165 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1166 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1167 if (sg_type
->u
.side_basic
.len_bits
< 8)
1168 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1170 case TRACER_DISPLAY_BASE_2
:
1171 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1173 case TRACER_DISPLAY_BASE_8
:
1174 printf("0%" PRIo8
, v
);
1176 case TRACER_DISPLAY_BASE_10
:
1178 if (sg_type
->u
.side_basic
.len_bits
< 8) {
1179 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1180 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1182 printf("%" PRId8
, v
);
1184 case TRACER_DISPLAY_BASE_16
:
1185 printf("0x%" PRIx8
, v
);
1196 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 16)
1198 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1199 if (sg_type_to_host_reverse_bo(sg_type
))
1200 v
= side_bswap_16(v
);
1201 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1202 if (sg_type
->u
.side_basic
.len_bits
< 16)
1203 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1205 case TRACER_DISPLAY_BASE_2
:
1206 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1208 case TRACER_DISPLAY_BASE_8
:
1209 printf("0%" PRIo16
, v
);
1211 case TRACER_DISPLAY_BASE_10
:
1213 if (sg_type
->u
.side_basic
.len_bits
< 16) {
1214 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1215 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1217 printf("%" PRId16
, v
);
1219 case TRACER_DISPLAY_BASE_16
:
1220 printf("0x%" PRIx16
, v
);
1231 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 32)
1233 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1234 if (sg_type_to_host_reverse_bo(sg_type
))
1235 v
= side_bswap_32(v
);
1236 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1237 if (sg_type
->u
.side_basic
.len_bits
< 32)
1238 v
&= (1U << sg_type
->u
.side_basic
.len_bits
) - 1;
1240 case TRACER_DISPLAY_BASE_2
:
1241 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1243 case TRACER_DISPLAY_BASE_8
:
1244 printf("0%" PRIo32
, v
);
1246 case TRACER_DISPLAY_BASE_10
:
1248 if (sg_type
->u
.side_basic
.len_bits
< 32) {
1249 if (v
& (1U << (sg_type
->u
.side_basic
.len_bits
- 1)))
1250 v
|= ~((1U << sg_type
->u
.side_basic
.len_bits
) - 1);
1252 printf("%" PRId32
, v
);
1254 case TRACER_DISPLAY_BASE_16
:
1255 printf("0x%" PRIx32
, v
);
1266 if (!sg_type
->u
.side_basic
.len_bits
|| sg_type
->u
.side_basic
.len_bits
+ sg_type
->u
.side_basic
.offset_bits
> 64)
1268 memcpy(&v
, ptr
+ sg_type
->u
.side_basic
.integer_offset
, sizeof(v
));
1269 if (sg_type_to_host_reverse_bo(sg_type
))
1270 v
= side_bswap_64(v
);
1271 v
>>= sg_type
->u
.side_basic
.offset_bits
;
1272 if (sg_type
->u
.side_basic
.len_bits
< 64)
1273 v
&= (1ULL << sg_type
->u
.side_basic
.len_bits
) - 1;
1275 case TRACER_DISPLAY_BASE_2
:
1276 print_integer_binary(v
, sg_type
->u
.side_basic
.len_bits
);
1278 case TRACER_DISPLAY_BASE_8
:
1279 printf("0%" PRIo64
, v
);
1281 case TRACER_DISPLAY_BASE_10
:
1283 if (sg_type
->u
.side_basic
.len_bits
< 64) {
1284 if (v
& (1ULL << (sg_type
->u
.side_basic
.len_bits
- 1)))
1285 v
|= ~((1ULL << sg_type
->u
.side_basic
.len_bits
) - 1);
1287 printf("%" PRId64
, v
);
1289 case TRACER_DISPLAY_BASE_16
:
1290 printf("0x%" PRIx64
, v
);
1298 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1304 fprintf(stderr
, "<UNKNOWN SCATTER-GATHER TYPE>");
1311 void tracer_print_sg_field(const struct side_struct_field_sg
*field_sg
, void *ptr
)
1313 printf("%s: ", field_sg
->field_name
);
1314 tracer_print_sg_type(&field_sg
->side_type
, ptr
);
1318 void tracer_print_struct_sg(const struct side_type_description
*type_desc
, void *ptr
)
1320 const struct side_type_struct_sg
*struct_sg
= type_desc
->u
.side_struct_sg
;
1323 print_attributes("attr", ":", struct_sg
->attr
, struct_sg
->nr_attr
);
1324 printf("%s", struct_sg
->nr_attr
? ", " : "");
1325 printf("fields: { ");
1326 for (i
= 0; i
< struct_sg
->nr_fields
; i
++) {
1327 printf("%s", i
? ", " : "");
1328 tracer_print_sg_field(&struct_sg
->fields_sg
[i
], ptr
);
1334 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1336 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1337 uint32_t side_sav_len
= sav_desc
->len
;
1340 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1341 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1344 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1345 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1346 printf("elements: ");
1348 for (i
= 0; i
< side_sav_len
; i
++) {
1349 printf("%s", i
? ", " : "");
1350 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1356 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1358 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1359 uint32_t side_sav_len
= sav_desc
->len
;
1362 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1363 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1364 printf("elements: ");
1366 for (i
= 0; i
< side_sav_len
; i
++) {
1367 printf("%s", i
? ", " : "");
1368 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1373 struct tracer_visitor_priv
{
1374 const struct side_type_description
*elem_type
;
1379 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1380 const struct side_arg_vec
*elem
)
1382 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1384 printf("%s", tracer_priv
->i
++ ? ", " : "");
1385 tracer_print_type(tracer_priv
->elem_type
, elem
);
1386 return SIDE_VISITOR_STATUS_OK
;
1390 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
)
1392 enum side_visitor_status status
;
1393 struct tracer_visitor_priv tracer_priv
= {
1394 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1397 const struct side_tracer_visitor_ctx tracer_ctx
= {
1398 .write_elem
= tracer_write_elem_cb
,
1399 .priv
= &tracer_priv
,
1402 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1403 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1404 printf("elements: ");
1406 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1408 case SIDE_VISITOR_STATUS_OK
:
1410 case SIDE_VISITOR_STATUS_ERROR
:
1411 fprintf(stderr
, "ERROR: Visitor error\n");
1417 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1419 const struct side_type_description
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1420 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
1421 void *p
= item
->u
.side_array_fixint
;
1422 enum side_type side_type
;
1425 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1426 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1427 printf("elements: ");
1428 switch (item
->type
) {
1429 case SIDE_TYPE_ARRAY_U8
:
1430 if (elem_type
->type
!= SIDE_TYPE_U8
)
1433 case SIDE_TYPE_ARRAY_U16
:
1434 if (elem_type
->type
!= SIDE_TYPE_U16
)
1437 case SIDE_TYPE_ARRAY_U32
:
1438 if (elem_type
->type
!= SIDE_TYPE_U32
)
1441 case SIDE_TYPE_ARRAY_U64
:
1442 if (elem_type
->type
!= SIDE_TYPE_U64
)
1445 case SIDE_TYPE_ARRAY_S8
:
1446 if (elem_type
->type
!= SIDE_TYPE_S8
)
1449 case SIDE_TYPE_ARRAY_S16
:
1450 if (elem_type
->type
!= SIDE_TYPE_S16
)
1453 case SIDE_TYPE_ARRAY_S32
:
1454 if (elem_type
->type
!= SIDE_TYPE_S32
)
1457 case SIDE_TYPE_ARRAY_S64
:
1458 if (elem_type
->type
!= SIDE_TYPE_S64
)
1461 case SIDE_TYPE_ARRAY_BYTE
:
1462 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1465 case SIDE_TYPE_ARRAY_POINTER32
:
1466 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1468 case SIDE_TYPE_ARRAY_POINTER64
:
1469 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1475 side_type
= elem_type
->type
;
1478 for (i
= 0; i
< side_sav_len
; i
++) {
1479 struct side_arg_vec sav_elem
= {
1483 switch (side_type
) {
1485 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1488 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1491 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1494 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1497 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1500 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1503 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1506 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1508 case SIDE_TYPE_BYTE
:
1509 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1511 case SIDE_TYPE_POINTER32
:
1512 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1514 case SIDE_TYPE_POINTER64
:
1515 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1519 fprintf(stderr
, "ERROR: Unexpected type\n");
1523 printf("%s", i
? ", " : "");
1524 tracer_print_type(elem_type
, &sav_elem
);
1530 fprintf(stderr
, "ERROR: type mismatch\n");
1534 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1536 const struct side_type_description
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1537 uint32_t side_sav_len
= item
->u
.side_vla_fixint
.length
;
1538 void *p
= item
->u
.side_vla_fixint
.p
;
1539 enum side_type side_type
;
1542 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1543 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1544 printf("elements: ");
1545 switch (item
->type
) {
1546 case SIDE_TYPE_VLA_U8
:
1547 if (elem_type
->type
!= SIDE_TYPE_U8
)
1550 case SIDE_TYPE_VLA_U16
:
1551 if (elem_type
->type
!= SIDE_TYPE_U16
)
1554 case SIDE_TYPE_VLA_U32
:
1555 if (elem_type
->type
!= SIDE_TYPE_U32
)
1558 case SIDE_TYPE_VLA_U64
:
1559 if (elem_type
->type
!= SIDE_TYPE_U64
)
1562 case SIDE_TYPE_VLA_S8
:
1563 if (elem_type
->type
!= SIDE_TYPE_S8
)
1566 case SIDE_TYPE_VLA_S16
:
1567 if (elem_type
->type
!= SIDE_TYPE_S16
)
1570 case SIDE_TYPE_VLA_S32
:
1571 if (elem_type
->type
!= SIDE_TYPE_S32
)
1574 case SIDE_TYPE_VLA_S64
:
1575 if (elem_type
->type
!= SIDE_TYPE_S64
)
1578 case SIDE_TYPE_VLA_BYTE
:
1579 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1582 case SIDE_TYPE_VLA_POINTER32
:
1583 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1585 case SIDE_TYPE_VLA_POINTER64
:
1586 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1592 side_type
= elem_type
->type
;
1595 for (i
= 0; i
< side_sav_len
; i
++) {
1596 struct side_arg_vec sav_elem
= {
1600 switch (side_type
) {
1602 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1605 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1608 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1611 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1614 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1617 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1620 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1623 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1625 case SIDE_TYPE_BYTE
:
1626 sav_elem
.u
.side_byte
= ((const uint8_t *) p
)[i
];
1628 case SIDE_TYPE_POINTER32
:
1629 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1631 case SIDE_TYPE_POINTER64
:
1632 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1636 fprintf(stderr
, "ERROR: Unexpected type\n");
1640 printf("%s", i
? ", " : "");
1641 tracer_print_type(elem_type
, &sav_elem
);
1647 fprintf(stderr
, "ERROR: type mismatch\n");
1652 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
1654 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
1655 uint32_t len
= dynamic_struct
->len
;
1658 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1659 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1660 printf("fields:: ");
1662 for (i
= 0; i
< len
; i
++) {
1663 printf("%s", i
? ", " : "");
1664 printf("%s:: ", fields
[i
].field_name
);
1665 tracer_print_dynamic(&fields
[i
].elem
);
1670 struct tracer_dynamic_struct_visitor_priv
{
1675 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1676 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1677 const struct side_arg_dynamic_event_field
*dynamic_field
)
1679 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1681 printf("%s", tracer_priv
->i
++ ? ", " : "");
1682 printf("%s:: ", dynamic_field
->field_name
);
1683 tracer_print_dynamic(&dynamic_field
->elem
);
1684 return SIDE_VISITOR_STATUS_OK
;
1688 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec
*item
)
1690 enum side_visitor_status status
;
1691 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1694 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1695 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1696 .priv
= &tracer_priv
,
1698 void *app_ctx
= item
->u
.side_dynamic_struct_visitor
.app_ctx
;
1700 print_attributes("attr", "::", item
->u
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic_struct_visitor
.nr_attr
);
1701 printf("%s", item
->u
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1702 printf("fields:: ");
1704 status
= item
->u
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1706 case SIDE_VISITOR_STATUS_OK
:
1708 case SIDE_VISITOR_STATUS_ERROR
:
1709 fprintf(stderr
, "ERROR: Visitor error\n");
1716 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla
*vla
)
1718 const struct side_arg_dynamic_vec
*sav
= vla
->sav
;
1719 uint32_t side_sav_len
= vla
->len
;
1722 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1723 printf("%s", vla
->nr_attr
? ", " : "");
1724 printf("elements:: ");
1726 for (i
= 0; i
< side_sav_len
; i
++) {
1727 printf("%s", i
? ", " : "");
1728 tracer_print_dynamic(&sav
[i
]);
1733 struct tracer_dynamic_vla_visitor_priv
{
1738 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1739 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
1740 const struct side_arg_dynamic_vec
*elem
)
1742 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1744 printf("%s", tracer_priv
->i
++ ? ", " : "");
1745 tracer_print_dynamic(elem
);
1746 return SIDE_VISITOR_STATUS_OK
;
1750 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec
*item
)
1752 enum side_visitor_status status
;
1753 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1756 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
1757 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1758 .priv
= &tracer_priv
,
1760 void *app_ctx
= item
->u
.side_dynamic_vla_visitor
.app_ctx
;
1762 print_attributes("attr", "::", item
->u
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic_vla_visitor
.nr_attr
);
1763 printf("%s", item
->u
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1764 printf("elements:: ");
1766 status
= item
->u
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1768 case SIDE_VISITOR_STATUS_OK
:
1770 case SIDE_VISITOR_STATUS_ERROR
:
1771 fprintf(stderr
, "ERROR: Visitor error\n");
1778 void tracer_print_dynamic_basic_type_header(const struct side_arg_dynamic_vec
*item
)
1780 print_attributes("attr", "::", item
->u
.side_basic
.attr
, item
->u
.side_basic
.nr_attr
);
1781 printf("%s", item
->u
.side_basic
.nr_attr
? ", " : "");
1786 void tracer_print_dynamic_integer_type_header(const struct side_arg_dynamic_vec
*item
)
1788 print_attributes("attr", "::", item
->u
.side_integer
.type
.attr
, item
->u
.side_integer
.type
.nr_attr
);
1789 printf("%s", item
->u
.side_integer
.type
.nr_attr
? ", " : "");
1794 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*item
)
1796 enum tracer_display_base base
= TRACER_DISPLAY_BASE_10
;
1798 switch (item
->dynamic_type
) {
1799 case SIDE_DYNAMIC_TYPE_U8
:
1800 case SIDE_DYNAMIC_TYPE_U16
:
1801 case SIDE_DYNAMIC_TYPE_U32
:
1802 case SIDE_DYNAMIC_TYPE_U64
:
1803 case SIDE_DYNAMIC_TYPE_S8
:
1804 case SIDE_DYNAMIC_TYPE_S16
:
1805 case SIDE_DYNAMIC_TYPE_S32
:
1806 case SIDE_DYNAMIC_TYPE_S64
:
1807 base
= get_attr_display_base(item
->u
.side_integer
.type
.attr
,
1808 item
->u
.side_integer
.type
.nr_attr
);
1816 switch (item
->dynamic_type
) {
1817 case SIDE_DYNAMIC_TYPE_NULL
:
1818 tracer_print_dynamic_basic_type_header(item
);
1819 printf("<NULL TYPE>");
1821 case SIDE_DYNAMIC_TYPE_BOOL
:
1822 tracer_print_dynamic_basic_type_header(item
);
1823 printf("%s", item
->u
.side_basic
.u
.side_bool
? "true" : "false");
1825 case SIDE_DYNAMIC_TYPE_U8
:
1829 v
= item
->u
.side_integer
.value
.side_u8
;
1830 tracer_print_dynamic_integer_type_header(item
);
1832 case TRACER_DISPLAY_BASE_2
:
1833 print_integer_binary(v
, 8);
1835 case TRACER_DISPLAY_BASE_8
:
1836 printf("0%" PRIo8
, v
);
1838 case TRACER_DISPLAY_BASE_10
:
1839 printf("%" PRIu8
, v
);
1841 case TRACER_DISPLAY_BASE_16
:
1842 printf("0x%" PRIx8
, v
);
1849 case SIDE_DYNAMIC_TYPE_U16
:
1853 v
= item
->u
.side_integer
.value
.side_u16
;
1854 if (dynamic_type_to_host_reverse_bo(item
))
1855 v
= side_bswap_16(v
);
1856 tracer_print_dynamic_integer_type_header(item
);
1858 case TRACER_DISPLAY_BASE_2
:
1859 print_integer_binary(v
, 16);
1861 case TRACER_DISPLAY_BASE_8
:
1862 printf("0%" PRIo16
, v
);
1864 case TRACER_DISPLAY_BASE_10
:
1865 printf("%" PRIu16
, v
);
1867 case TRACER_DISPLAY_BASE_16
:
1868 printf("0x%" PRIx16
, v
);
1875 case SIDE_DYNAMIC_TYPE_U32
:
1879 v
= item
->u
.side_integer
.value
.side_u32
;
1880 if (dynamic_type_to_host_reverse_bo(item
))
1881 v
= side_bswap_32(v
);
1882 tracer_print_dynamic_integer_type_header(item
);
1884 case TRACER_DISPLAY_BASE_2
:
1885 print_integer_binary(v
, 32);
1887 case TRACER_DISPLAY_BASE_8
:
1888 printf("0%" PRIo32
, v
);
1890 case TRACER_DISPLAY_BASE_10
:
1891 printf("%" PRIu32
, v
);
1893 case TRACER_DISPLAY_BASE_16
:
1894 printf("0x%" PRIx32
, v
);
1901 case SIDE_DYNAMIC_TYPE_U64
:
1905 v
= item
->u
.side_integer
.value
.side_u64
;
1906 if (dynamic_type_to_host_reverse_bo(item
))
1907 v
= side_bswap_64(v
);
1908 tracer_print_dynamic_integer_type_header(item
);
1910 case TRACER_DISPLAY_BASE_2
:
1911 print_integer_binary(v
, 64);
1913 case TRACER_DISPLAY_BASE_8
:
1914 printf("0%" PRIo64
, v
);
1916 case TRACER_DISPLAY_BASE_10
:
1917 printf("%" PRIu64
, v
);
1919 case TRACER_DISPLAY_BASE_16
:
1920 printf("0x%" PRIx64
, v
);
1927 case SIDE_DYNAMIC_TYPE_S8
:
1931 v
= item
->u
.side_integer
.value
.side_s8
;
1932 tracer_print_dynamic_integer_type_header(item
);
1934 case TRACER_DISPLAY_BASE_2
:
1935 print_integer_binary(v
, 8);
1937 case TRACER_DISPLAY_BASE_8
:
1938 printf("0%" PRIo8
, v
);
1940 case TRACER_DISPLAY_BASE_10
:
1941 printf("%" PRId8
, v
);
1943 case TRACER_DISPLAY_BASE_16
:
1944 printf("0x%" PRIx8
, v
);
1951 case SIDE_DYNAMIC_TYPE_S16
:
1955 v
= item
->u
.side_integer
.value
.side_s16
;
1956 if (dynamic_type_to_host_reverse_bo(item
))
1957 v
= side_bswap_16(v
);
1958 tracer_print_dynamic_integer_type_header(item
);
1960 case TRACER_DISPLAY_BASE_2
:
1961 print_integer_binary(v
, 16);
1963 case TRACER_DISPLAY_BASE_8
:
1964 printf("0%" PRIo16
, v
);
1966 case TRACER_DISPLAY_BASE_10
:
1967 printf("%" PRId16
, v
);
1969 case TRACER_DISPLAY_BASE_16
:
1970 printf("0x%" PRIx16
, v
);
1977 case SIDE_DYNAMIC_TYPE_S32
:
1981 v
= item
->u
.side_integer
.value
.side_s32
;
1982 if (dynamic_type_to_host_reverse_bo(item
))
1983 v
= side_bswap_32(v
);
1984 tracer_print_dynamic_integer_type_header(item
);
1986 case TRACER_DISPLAY_BASE_2
:
1987 print_integer_binary(v
, 32);
1989 case TRACER_DISPLAY_BASE_8
:
1990 printf("0%" PRIo32
, v
);
1992 case TRACER_DISPLAY_BASE_10
:
1993 printf("%" PRId32
, v
);
1995 case TRACER_DISPLAY_BASE_16
:
1996 printf("0x%" PRIx32
, v
);
2003 case SIDE_DYNAMIC_TYPE_S64
:
2007 v
= item
->u
.side_integer
.value
.side_s64
;
2008 if (dynamic_type_to_host_reverse_bo(item
))
2009 v
= side_bswap_64(v
);
2010 tracer_print_dynamic_integer_type_header(item
);
2012 case TRACER_DISPLAY_BASE_2
:
2013 print_integer_binary(v
, 64);
2015 case TRACER_DISPLAY_BASE_8
:
2016 printf("0%" PRIo64
, v
);
2018 case TRACER_DISPLAY_BASE_10
:
2019 printf("%" PRId64
, v
);
2021 case TRACER_DISPLAY_BASE_16
:
2022 printf("0x%" PRIx64
, v
);
2029 case SIDE_DYNAMIC_TYPE_BYTE
:
2030 tracer_print_dynamic_basic_type_header(item
);
2031 printf("0x%" PRIx8
, item
->u
.side_basic
.u
.side_byte
);
2033 case SIDE_DYNAMIC_TYPE_POINTER32
:
2037 v
= item
->u
.side_integer
.value
.side_u32
;
2038 if (dynamic_type_to_host_reverse_bo(item
))
2039 v
= side_bswap_32(v
);
2040 tracer_print_dynamic_integer_type_header(item
);
2041 printf("0x%" PRIx32
, v
);
2045 case SIDE_DYNAMIC_TYPE_POINTER64
:
2049 v
= item
->u
.side_integer
.value
.side_u64
;
2050 if (dynamic_type_to_host_reverse_bo(item
))
2051 v
= side_bswap_64(v
);
2052 tracer_print_dynamic_integer_type_header(item
);
2053 printf("0x%" PRIx64
, v
);
2057 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
2064 .f
= item
->u
.side_basic
.u
.float_value
.side_float_binary16
,
2067 if (dynamic_type_to_host_reverse_bo(item
))
2068 float16
.u
= side_bswap_16(float16
.u
);
2069 tracer_print_dynamic_basic_type_header(item
);
2070 printf("%g", (double) float16
.f
);
2073 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
2077 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
2084 .f
= item
->u
.side_basic
.u
.float_value
.side_float_binary32
,
2087 if (dynamic_type_to_host_reverse_bo(item
))
2088 float32
.u
= side_bswap_32(float32
.u
);
2089 tracer_print_dynamic_basic_type_header(item
);
2090 printf("%g", (double) float32
.f
);
2093 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
2097 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
2104 .f
= item
->u
.side_basic
.u
.float_value
.side_float_binary64
,
2107 if (dynamic_type_to_host_reverse_bo(item
))
2108 float64
.u
= side_bswap_64(float64
.u
);
2109 tracer_print_dynamic_basic_type_header(item
);
2110 printf("%g", (double) float64
.f
);
2113 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
2117 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
2124 .f
= item
->u
.side_basic
.u
.float_value
.side_float_binary128
,
2127 if (dynamic_type_to_host_reverse_bo(item
))
2128 side_bswap_128p(float128
.arr
);
2129 tracer_print_dynamic_basic_type_header(item
);
2130 printf("%Lg", (long double) float128
.f
);
2133 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
2137 case SIDE_DYNAMIC_TYPE_STRING
:
2138 tracer_print_dynamic_basic_type_header(item
);
2139 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_basic
.u
.string
);
2141 case SIDE_DYNAMIC_TYPE_STRUCT
:
2142 tracer_print_dynamic_struct(item
->u
.side_dynamic_struct
);
2144 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
:
2145 tracer_print_dynamic_struct_visitor(item
);
2147 case SIDE_DYNAMIC_TYPE_VLA
:
2148 tracer_print_dynamic_vla(item
->u
.side_dynamic_vla
);
2150 case SIDE_DYNAMIC_TYPE_VLA_VISITOR
:
2151 tracer_print_dynamic_vla_visitor(item
);
2154 fprintf(stderr
, "<UNKNOWN TYPE>");
2161 void tracer_print_static_fields(const struct side_event_description
*desc
,
2162 const struct side_arg_vec_description
*sav_desc
,
2165 const struct side_arg_vec
*sav
= sav_desc
->sav
;
2166 uint32_t side_sav_len
= sav_desc
->len
;
2169 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
2170 if (desc
->nr_fields
!= side_sav_len
) {
2171 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
2174 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
2175 printf("%s", side_sav_len
? ", fields: [ " : "");
2176 for (i
= 0; i
< side_sav_len
; i
++) {
2177 printf("%s", i
? ", " : "");
2178 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
2186 void tracer_call(const struct side_event_description
*desc
,
2187 const struct side_arg_vec_description
*sav_desc
,
2188 void *priv
__attribute__((unused
)))
2192 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
2196 void tracer_call_variadic(const struct side_event_description
*desc
,
2197 const struct side_arg_vec_description
*sav_desc
,
2198 const struct side_arg_dynamic_event_struct
*var_struct
,
2199 void *priv
__attribute__((unused
)))
2201 uint32_t var_struct_len
= var_struct
->len
;
2202 int nr_fields
= 0, i
;
2204 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
2206 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
2207 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
2210 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
2211 printf("%s", var_struct_len
? ", fields:: [ " : "");
2212 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
2213 printf("%s", i
? ", " : "");
2214 printf("%s:: ", var_struct
->fields
[i
].field_name
);
2215 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
2222 void tracer_event_notification(enum side_tracer_notification notif
,
2223 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
2228 printf("----------------------------------------------------------\n");
2229 printf("Tracer notified of events %s\n",
2230 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
2231 for (i
= 0; i
< nr_events
; i
++) {
2232 struct side_event_description
*event
= events
[i
];
2234 /* Skip NULL pointers */
2237 printf("provider: %s, event: %s\n",
2238 event
->provider_name
, event
->event_name
);
2239 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
2240 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
2241 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
2245 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
2250 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
2251 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
2255 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
2261 printf("----------------------------------------------------------\n");
2264 static __attribute__((constructor
))
2265 void tracer_init(void);
2267 void tracer_init(void)
2269 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
2274 static __attribute__((destructor
))
2275 void tracer_exit(void);
2277 void tracer_exit(void)
2279 side_tracer_event_notification_unregister(tracer_handle
);