1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include <side/trace.h>
15 enum tracer_display_base
{
16 TRACER_DISPLAY_BASE_2
,
17 TRACER_DISPLAY_BASE_8
,
18 TRACER_DISPLAY_BASE_10
,
19 TRACER_DISPLAY_BASE_16
,
22 static struct side_tracer_handle
*tracer_handle
;
25 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
27 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
29 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
31 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
);
33 void tracer_print_dynamic(const struct side_arg
*dynamic_item
);
35 uint32_t tracer_print_gather_bool_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
37 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
39 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
,
40 enum tracer_display_base default_base
);
42 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
44 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
);
46 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
);
48 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
49 const void *_length_ptr
);
51 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
54 int64_t get_attr_integer_value(const struct side_attr
*attr
)
58 switch (attr
->value
.type
) {
59 case SIDE_ATTR_TYPE_U8
:
60 val
= attr
->value
.u
.integer_value
.side_u8
;
62 case SIDE_ATTR_TYPE_U16
:
63 val
= attr
->value
.u
.integer_value
.side_u16
;
65 case SIDE_ATTR_TYPE_U32
:
66 val
= attr
->value
.u
.integer_value
.side_u32
;
68 case SIDE_ATTR_TYPE_U64
:
69 val
= attr
->value
.u
.integer_value
.side_u64
;
71 case SIDE_ATTR_TYPE_S8
:
72 val
= attr
->value
.u
.integer_value
.side_s8
;
74 case SIDE_ATTR_TYPE_S16
:
75 val
= attr
->value
.u
.integer_value
.side_s16
;
77 case SIDE_ATTR_TYPE_S32
:
78 val
= attr
->value
.u
.integer_value
.side_s32
;
80 case SIDE_ATTR_TYPE_S64
:
81 val
= attr
->value
.u
.integer_value
.side_s64
;
84 fprintf(stderr
, "Unexpected attribute type\n");
91 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
92 enum tracer_display_base default_base
)
96 for (i
= 0; i
< nr_attr
; i
++) {
97 const struct side_attr
*attr
= &_attr
[i
];
99 if (!strcmp(attr
->key
, "std.integer.base")) {
100 int64_t val
= get_attr_integer_value(attr
);
104 return TRACER_DISPLAY_BASE_2
;
106 return TRACER_DISPLAY_BASE_8
;
108 return TRACER_DISPLAY_BASE_10
;
110 return TRACER_DISPLAY_BASE_16
;
112 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
117 return default_base
; /* Default */
121 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
123 switch (type_desc
->type
) {
134 case SIDE_TYPE_POINTER
:
135 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
140 case SIDE_TYPE_FLOAT_BINARY16
:
141 case SIDE_TYPE_FLOAT_BINARY32
:
142 case SIDE_TYPE_FLOAT_BINARY64
:
143 case SIDE_TYPE_FLOAT_BINARY128
:
144 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
150 fprintf(stderr
, "Unexpected type\n");
156 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
158 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
159 switch (attr
->value
.type
) {
160 case SIDE_ATTR_TYPE_BOOL
:
161 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
163 case SIDE_ATTR_TYPE_U8
:
164 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
166 case SIDE_ATTR_TYPE_U16
:
167 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
169 case SIDE_ATTR_TYPE_U32
:
170 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
172 case SIDE_ATTR_TYPE_U64
:
173 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
175 case SIDE_ATTR_TYPE_S8
:
176 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
178 case SIDE_ATTR_TYPE_S16
:
179 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
181 case SIDE_ATTR_TYPE_S32
:
182 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
184 case SIDE_ATTR_TYPE_S64
:
185 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
187 case SIDE_ATTR_TYPE_POINTER32
:
188 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
190 case SIDE_ATTR_TYPE_POINTER64
:
191 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
193 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
195 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
198 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
201 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
203 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
206 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
209 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
211 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
214 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
217 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
219 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
222 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
225 case SIDE_ATTR_TYPE_STRING
:
226 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
229 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
236 void print_attributes(const char *prefix_str
, const char *separator
,
237 const struct side_attr
*attr
, uint32_t nr_attr
)
243 printf("%s%s [ ", prefix_str
, separator
);
244 for (i
= 0; i
< nr_attr
; i
++) {
245 printf("%s", i
? ", " : "");
246 tracer_print_attr_type(separator
, &attr
[i
]);
252 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
254 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
255 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
256 uint32_t i
, print_count
= 0;
259 if (elem_type
->type
!= item
->type
) {
260 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
263 switch (item
->type
) {
265 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
271 v
= item
->u
.side_static
.integer_value
.side_u16
;
272 if (type_to_host_reverse_bo(elem_type
))
273 v
= side_bswap_16(v
);
281 v
= item
->u
.side_static
.integer_value
.side_u32
;
282 if (type_to_host_reverse_bo(elem_type
))
283 v
= side_bswap_32(v
);
291 v
= item
->u
.side_static
.integer_value
.side_u64
;
292 if (type_to_host_reverse_bo(elem_type
))
293 v
= side_bswap_64(v
);
298 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
304 v
= item
->u
.side_static
.integer_value
.side_s16
;
305 if (type_to_host_reverse_bo(elem_type
))
306 v
= side_bswap_16(v
);
314 v
= item
->u
.side_static
.integer_value
.side_s32
;
315 if (type_to_host_reverse_bo(elem_type
))
316 v
= side_bswap_32(v
);
324 v
= item
->u
.side_static
.integer_value
.side_s64
;
325 if (type_to_host_reverse_bo(elem_type
))
326 v
= side_bswap_64(v
);
331 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
334 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
335 printf("%s", mappings
->nr_attr
? ", " : "");
336 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
337 printf(", labels: [ ");
338 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
339 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
341 if (mapping
->range_end
< mapping
->range_begin
) {
342 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
343 mapping
->range_begin
, mapping
->range_end
);
346 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
347 printf("%s", print_count
++ ? ", " : "");
348 printf("\"%s\"", mapping
->label
);
352 printf("<NO LABEL>");
357 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
361 switch (elem_type
->type
) {
362 case SIDE_TYPE_U8
: /* Fall-through */
376 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
383 void print_enum_bitmap(const struct side_type
*type_desc
,
384 const struct side_arg
*item
)
386 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
387 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
388 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
389 bool reverse_byte_order
= false;
390 const struct side_arg
*array_item
;
392 switch (elem_type
->type
) {
393 case SIDE_TYPE_U8
: /* Fall-through */
394 case SIDE_TYPE_BYTE
: /* Fall-through */
395 case SIDE_TYPE_U16
: /* Fall-through */
396 case SIDE_TYPE_U32
: /* Fall-through */
398 stride_bit
= enum_elem_type_to_stride(elem_type
);
399 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
403 case SIDE_TYPE_ARRAY
:
404 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
405 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
406 array_item
= item
->u
.side_static
.side_array
->sav
;
407 nr_items
= type_desc
->u
.side_array
.length
;
410 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
411 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
412 array_item
= item
->u
.side_static
.side_vla
->sav
;
413 nr_items
= item
->u
.side_static
.side_vla
->len
;
416 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
420 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
421 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
422 printf("labels: [ ");
423 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
424 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
428 if (mapping
->range_end
< mapping
->range_begin
) {
429 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
430 mapping
->range_begin
, mapping
->range_end
);
433 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
434 if (bit
> (nr_items
* stride_bit
) - 1)
436 switch (stride_bit
) {
439 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
440 if (v
& (1ULL << (bit
% 8))) {
448 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
449 if (reverse_byte_order
)
450 v
= side_bswap_16(v
);
451 if (v
& (1ULL << (bit
% 16))) {
459 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
460 if (reverse_byte_order
)
461 v
= side_bswap_32(v
);
462 if (v
& (1ULL << (bit
% 32))) {
470 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
471 if (reverse_byte_order
)
472 v
= side_bswap_64(v
);
473 if (v
& (1ULL << (bit
% 64))) {
485 printf("%s", print_count
++ ? ", " : "");
486 printf("\"%s\"", mapping
->label
);
490 printf("<NO LABEL>");
495 void print_integer_binary(uint64_t v
, int bits
)
501 for (i
= 0; i
< bits
; i
++) {
502 printf("%c", v
& (1ULL << 63) ? '1' : '0');
508 void tracer_print_type_header(const char *separator
,
509 const struct side_attr
*attr
, uint32_t nr_attr
)
511 print_attributes("attr", separator
, attr
, nr_attr
);
512 printf("%s", nr_attr
? ", " : "");
513 printf("value%s ", separator
);
517 void tracer_print_type_bool(const char *separator
,
518 const struct side_type_bool
*type_bool
,
519 const union side_bool_value
*value
,
520 uint16_t offset_bits
)
526 if (!type_bool
->len_bits
)
527 len_bits
= type_bool
->bool_size
* CHAR_BIT
;
529 len_bits
= type_bool
->len_bits
;
530 if (len_bits
+ offset_bits
> type_bool
->bool_size
* CHAR_BIT
)
532 reverse_bo
= type_bool
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
533 switch (type_bool
->bool_size
) {
535 v
= value
->side_bool8
;
541 side_u16
= value
->side_bool16
;
543 side_u16
= side_bswap_16(side_u16
);
551 side_u32
= value
->side_bool32
;
553 side_u32
= side_bswap_32(side_u32
);
561 side_u64
= value
->side_bool64
;
563 side_u64
= side_bswap_64(side_u64
);
572 v
&= (1ULL << len_bits
) - 1;
573 tracer_print_type_header(separator
, type_bool
->attr
, type_bool
->nr_attr
);
574 printf("%s", v
? "true" : "false");
578 void tracer_print_type_integer(const char *separator
,
579 const struct side_type_integer
*type_integer
,
580 const union side_integer_value
*value
,
581 uint16_t offset_bits
,
582 enum tracer_display_base default_base
)
584 enum tracer_display_base base
;
592 if (!type_integer
->len_bits
)
593 len_bits
= type_integer
->integer_size
* CHAR_BIT
;
595 len_bits
= type_integer
->len_bits
;
596 if (len_bits
+ offset_bits
> type_integer
->integer_size
* CHAR_BIT
)
598 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
599 base
= get_attr_display_base(type_integer
->attr
,
600 type_integer
->nr_attr
,
602 switch (type_integer
->integer_size
) {
604 if (type_integer
->signedness
)
605 v
.v_signed
= value
->side_s8
;
607 v
.v_unsigned
= value
->side_u8
;
610 if (type_integer
->signedness
) {
613 side_s16
= value
->side_s16
;
615 side_s16
= side_bswap_16(side_s16
);
616 v
.v_signed
= side_s16
;
620 side_u16
= value
->side_u16
;
622 side_u16
= side_bswap_16(side_u16
);
623 v
.v_unsigned
= side_u16
;
627 if (type_integer
->signedness
) {
630 side_s32
= value
->side_s32
;
632 side_s32
= side_bswap_32(side_s32
);
633 v
.v_signed
= side_s32
;
637 side_u32
= value
->side_u32
;
639 side_u32
= side_bswap_32(side_u32
);
640 v
.v_unsigned
= side_u32
;
644 if (type_integer
->signedness
) {
647 side_s64
= value
->side_s64
;
649 side_s64
= side_bswap_64(side_s64
);
650 v
.v_signed
= side_s64
;
654 side_u64
= value
->side_u64
;
656 side_u64
= side_bswap_64(side_u64
);
657 v
.v_unsigned
= side_u64
;
663 v
.v_unsigned
>>= offset_bits
;
665 v
.v_unsigned
&= (1ULL << len_bits
) - 1;
666 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
668 case TRACER_DISPLAY_BASE_2
:
669 print_integer_binary(v
.v_unsigned
, len_bits
);
671 case TRACER_DISPLAY_BASE_8
:
672 printf("0%" PRIo64
, v
.v_unsigned
);
674 case TRACER_DISPLAY_BASE_10
:
675 if (type_integer
->signedness
) {
678 if (v
.v_unsigned
& (1ULL << (len_bits
- 1)))
679 v
.v_unsigned
|= ~((1ULL << len_bits
) - 1);
681 printf("%" PRId64
, v
.v_signed
);
683 printf("%" PRIu64
, v
.v_unsigned
);
686 case TRACER_DISPLAY_BASE_16
:
687 printf("0x%" PRIx64
, v
.v_unsigned
);
695 void tracer_print_type_float(const char *separator
,
696 const struct side_type_float
*type_float
,
697 const union side_float_value
*value
)
701 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
702 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
703 switch (type_float
->float_size
) {
711 .f
= value
->side_float_binary16
,
715 float16
.u
= side_bswap_16(float16
.u
);
716 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
717 printf("%g", (double) float16
.f
);
720 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
731 .f
= value
->side_float_binary32
,
735 float32
.u
= side_bswap_32(float32
.u
);
736 printf("%g", (double) float32
.f
);
739 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
750 .f
= value
->side_float_binary64
,
754 float64
.u
= side_bswap_64(float64
.u
);
755 printf("%g", (double) float64
.f
);
758 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
769 .f
= value
->side_float_binary128
,
773 side_bswap_128p(float128
.arr
);
774 printf("%Lg", (long double) float128
.f
);
777 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
782 fprintf(stderr
, "ERROR: Unknown float size\n");
788 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
790 enum side_type_label type
;
792 switch (type_desc
->type
) {
794 switch (item
->type
) {
805 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
811 case SIDE_TYPE_ENUM_BITMAP
:
812 switch (item
->type
) {
818 case SIDE_TYPE_ARRAY
:
822 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
828 case SIDE_TYPE_DYNAMIC
:
829 switch (item
->type
) {
830 case SIDE_TYPE_DYNAMIC_NULL
:
831 case SIDE_TYPE_DYNAMIC_BOOL
:
832 case SIDE_TYPE_DYNAMIC_U8
:
833 case SIDE_TYPE_DYNAMIC_U16
:
834 case SIDE_TYPE_DYNAMIC_U32
:
835 case SIDE_TYPE_DYNAMIC_U64
:
836 case SIDE_TYPE_DYNAMIC_S8
:
837 case SIDE_TYPE_DYNAMIC_S16
:
838 case SIDE_TYPE_DYNAMIC_S32
:
839 case SIDE_TYPE_DYNAMIC_S64
:
840 case SIDE_TYPE_DYNAMIC_BYTE
:
841 case SIDE_TYPE_DYNAMIC_POINTER
:
842 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
843 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
844 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
845 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
846 case SIDE_TYPE_DYNAMIC_STRING
:
847 case SIDE_TYPE_DYNAMIC_STRUCT
:
848 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
849 case SIDE_TYPE_DYNAMIC_VLA
:
850 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
853 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
860 if (type_desc
->type
!= item
->type
) {
861 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
867 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
868 type
= (enum side_type_label
) type_desc
->type
;
870 type
= (enum side_type_label
) item
->type
;
875 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
876 printf("<NULL TYPE>");
880 tracer_print_type_bool(":", &type_desc
->u
.side_bool
, &item
->u
.side_static
.bool_value
, 0);
891 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
892 TRACER_DISPLAY_BASE_10
);
895 case SIDE_TYPE_POINTER
:
896 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
897 TRACER_DISPLAY_BASE_16
);
901 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
902 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
906 print_enum(type_desc
, item
);
909 case SIDE_TYPE_ENUM_BITMAP
:
910 print_enum_bitmap(type_desc
, item
);
913 case SIDE_TYPE_FLOAT_BINARY16
:
914 case SIDE_TYPE_FLOAT_BINARY32
:
915 case SIDE_TYPE_FLOAT_BINARY64
:
916 case SIDE_TYPE_FLOAT_BINARY128
:
917 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
920 case SIDE_TYPE_STRING
:
921 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
922 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
924 case SIDE_TYPE_STRUCT
:
925 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
927 case SIDE_TYPE_GATHER_STRUCT
:
928 (void) tracer_print_gather_struct(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_struct_gather_ptr
);
930 case SIDE_TYPE_GATHER_ARRAY
:
931 (void) tracer_print_gather_array(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_array_gather_ptr
);
933 case SIDE_TYPE_GATHER_VLA
:
934 (void) tracer_print_gather_vla(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_vla_gather
.ptr
,
935 item
->u
.side_static
.side_vla_gather
.length_ptr
);
937 case SIDE_TYPE_GATHER_BOOL
:
938 (void) tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_bool_gather_ptr
);
940 case SIDE_TYPE_GATHER_BYTE
:
941 (void) tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_byte_gather_ptr
);
943 case SIDE_TYPE_GATHER_POINTER
:
944 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
945 TRACER_DISPLAY_BASE_16
);
947 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
948 case SIDE_TYPE_GATHER_SIGNED_INT
:
949 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
950 TRACER_DISPLAY_BASE_10
);
952 case SIDE_TYPE_GATHER_FLOAT
:
953 (void) tracer_print_gather_float_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_float_gather_ptr
);
955 case SIDE_TYPE_ARRAY
:
956 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
959 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
961 case SIDE_TYPE_VLA_VISITOR
:
962 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
966 case SIDE_TYPE_DYNAMIC_NULL
:
967 case SIDE_TYPE_DYNAMIC_BOOL
:
968 case SIDE_TYPE_DYNAMIC_U8
:
969 case SIDE_TYPE_DYNAMIC_U16
:
970 case SIDE_TYPE_DYNAMIC_U32
:
971 case SIDE_TYPE_DYNAMIC_U64
:
972 case SIDE_TYPE_DYNAMIC_S8
:
973 case SIDE_TYPE_DYNAMIC_S16
:
974 case SIDE_TYPE_DYNAMIC_S32
:
975 case SIDE_TYPE_DYNAMIC_S64
:
976 case SIDE_TYPE_DYNAMIC_BYTE
:
977 case SIDE_TYPE_DYNAMIC_POINTER
:
978 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
979 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
980 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
981 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
982 case SIDE_TYPE_DYNAMIC_STRING
:
983 case SIDE_TYPE_DYNAMIC_STRUCT
:
984 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
985 case SIDE_TYPE_DYNAMIC_VLA
:
986 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
987 tracer_print_dynamic(item
);
990 fprintf(stderr
, "<UNKNOWN TYPE>\n");
997 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
999 printf("%s: ", item_desc
->field_name
);
1000 tracer_print_type(&item_desc
->side_type
, item
);
1004 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1006 const struct side_arg
*sav
= side_arg_vec
->sav
;
1007 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1009 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
1010 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
1013 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1014 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1015 printf("fields: { ");
1016 for (i
= 0; i
< side_sav_len
; i
++) {
1017 printf("%s", i
? ", " : "");
1018 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1024 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1026 const struct side_arg
*sav
= side_arg_vec
->sav
;
1027 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1029 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1030 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1033 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1034 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1035 printf("elements: ");
1037 for (i
= 0; i
< side_sav_len
; i
++) {
1038 printf("%s", i
? ", " : "");
1039 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1045 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1047 const struct side_arg
*sav
= side_arg_vec
->sav
;
1048 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1050 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1051 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1052 printf("elements: ");
1054 for (i
= 0; i
< side_sav_len
; i
++) {
1055 printf("%s", i
? ", " : "");
1056 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1062 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode
, const char *ptr
)
1064 switch (access_mode
) {
1065 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
1067 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1068 /* Dereference pointer */
1069 memcpy(&ptr
, ptr
, sizeof(ptr
));
1077 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode
, uint32_t len
)
1079 switch (access_mode
) {
1080 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
1082 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1083 return sizeof(void *);
1090 uint64_t tracer_load_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1092 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_integer
.access_mode
;
1093 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1094 const char *ptr
= (const char *) _ptr
;
1095 union side_integer_value value
;
1097 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1098 memcpy(&value
, ptr
, integer_size_bytes
);
1099 switch (type_gather
->u
.side_integer
.type
.integer_size
) {
1101 return (uint64_t) value
.side_u8
;
1103 return (uint64_t) value
.side_u16
;
1105 return (uint64_t) value
.side_u32
;
1107 return (uint64_t) value
.side_u64
;
1114 uint32_t tracer_print_gather_bool_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1116 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_bool
.access_mode
;
1117 uint32_t bool_size_bytes
= type_gather
->u
.side_bool
.type
.bool_size
;
1118 const char *ptr
= (const char *) _ptr
;
1119 union side_bool_value value
;
1121 switch (bool_size_bytes
) {
1130 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_bool
.offset
);
1131 memcpy(&value
, ptr
, bool_size_bytes
);
1132 tracer_print_type_bool(":", &type_gather
->u
.side_bool
.type
, &value
,
1133 type_gather
->u
.side_bool
.offset_bits
);
1134 return tracer_gather_size(access_mode
, bool_size_bytes
);
1138 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1140 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_byte
.access_mode
;
1141 const char *ptr
= (const char *) _ptr
;
1144 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_byte
.offset
);
1145 memcpy(&value
, ptr
, 1);
1146 tracer_print_type_header(":", type_gather
->u
.side_byte
.type
.attr
,
1147 type_gather
->u
.side_byte
.type
.nr_attr
);
1148 printf("0x%" PRIx8
, value
);
1149 return tracer_gather_size(access_mode
, 1);
1153 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
,
1154 enum tracer_display_base default_base
)
1156 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_integer
.access_mode
;
1157 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1158 const char *ptr
= (const char *) _ptr
;
1159 union side_integer_value value
;
1161 switch (integer_size_bytes
) {
1170 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1171 memcpy(&value
, ptr
, integer_size_bytes
);
1172 tracer_print_type_integer(":", &type_gather
->u
.side_integer
.type
, &value
,
1173 type_gather
->u
.side_integer
.offset_bits
, default_base
);
1174 return tracer_gather_size(access_mode
, integer_size_bytes
);
1178 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1180 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_float
.access_mode
;
1181 uint32_t float_size_bytes
= type_gather
->u
.side_float
.type
.float_size
;
1182 const char *ptr
= (const char *) _ptr
;
1183 union side_float_value value
;
1185 switch (float_size_bytes
) {
1194 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_float
.offset
);
1195 memcpy(&value
, ptr
, float_size_bytes
);
1196 tracer_print_type_float(":", &type_gather
->u
.side_float
.type
, &value
);
1197 return tracer_gather_size(access_mode
, float_size_bytes
);
1201 uint32_t tracer_print_gather_type(const struct side_type
*type_desc
, const void *ptr
)
1206 switch (type_desc
->type
) {
1207 case SIDE_TYPE_GATHER_BOOL
:
1208 len
= tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, ptr
);
1210 case SIDE_TYPE_GATHER_BYTE
:
1211 len
= tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, ptr
);
1213 case SIDE_TYPE_GATHER_POINTER
:
1214 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1215 TRACER_DISPLAY_BASE_16
);
1217 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
1218 case SIDE_TYPE_GATHER_SIGNED_INT
:
1219 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1220 TRACER_DISPLAY_BASE_10
);
1222 case SIDE_TYPE_GATHER_FLOAT
:
1223 len
= tracer_print_gather_float_type(&type_desc
->u
.side_gather
, ptr
);
1225 case SIDE_TYPE_GATHER_STRUCT
:
1226 len
= tracer_print_gather_struct(&type_desc
->u
.side_gather
, ptr
);
1228 case SIDE_TYPE_GATHER_ARRAY
:
1229 len
= tracer_print_gather_array(&type_desc
->u
.side_gather
, ptr
);
1231 case SIDE_TYPE_GATHER_VLA
:
1232 len
= tracer_print_gather_vla(&type_desc
->u
.side_gather
, ptr
, ptr
);
1235 fprintf(stderr
, "<UNKNOWN GATHER TYPE>");
1243 void tracer_print_gather_field(const struct side_event_field
*field
, const void *ptr
)
1245 printf("%s: ", field
->field_name
);
1246 (void) tracer_print_gather_type(&field
->side_type
, ptr
);
1250 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
)
1252 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_struct
.access_mode
;
1253 const char *ptr
= (const char *) _ptr
;
1256 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_struct
.offset
);
1257 print_attributes("attr", ":", type_gather
->u
.side_struct
.type
->attr
, type_gather
->u
.side_struct
.type
->nr_attr
);
1258 printf("%s", type_gather
->u
.side_struct
.type
->nr_attr
? ", " : "");
1259 printf("fields: { ");
1260 for (i
= 0; i
< type_gather
->u
.side_struct
.type
->nr_fields
; i
++) {
1261 printf("%s", i
? ", " : "");
1262 tracer_print_gather_field(&type_gather
->u
.side_struct
.type
->fields
[i
], ptr
);
1265 return tracer_gather_size(access_mode
, type_gather
->u
.side_struct
.size
);
1269 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
)
1271 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_array
.access_mode
;
1272 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1275 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_array
.offset
);
1277 print_attributes("attr", ":", type_gather
->u
.side_array
.type
.attr
, type_gather
->u
.side_array
.type
.nr_attr
);
1278 printf("%s", type_gather
->u
.side_array
.type
.nr_attr
? ", " : "");
1279 printf("elements: ");
1281 for (i
= 0; i
< type_gather
->u
.side_array
.type
.length
; i
++) {
1282 switch (type_gather
->u
.side_array
.type
.elem_type
->type
) {
1283 case SIDE_TYPE_GATHER_VLA
:
1284 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1289 printf("%s", i
? ", " : "");
1290 ptr
+= tracer_print_gather_type(type_gather
->u
.side_array
.type
.elem_type
, ptr
);
1293 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1297 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
1298 const void *_length_ptr
)
1300 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_vla
.access_mode
;
1301 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1302 const char *length_ptr
= (const char *) _length_ptr
;
1306 switch (type_gather
->u
.side_vla
.length_type
->type
) {
1307 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
1308 case SIDE_TYPE_GATHER_SIGNED_INT
:
1311 fprintf(stderr
, "<gather VLA expects integer gather length type>\n");
1314 length
= (uint32_t) tracer_load_gather_integer_type(&type_gather
->u
.side_vla
.length_type
->u
.side_gather
, length_ptr
);
1315 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_vla
.offset
);
1317 print_attributes("attr", ":", type_gather
->u
.side_vla
.type
.attr
, type_gather
->u
.side_vla
.type
.nr_attr
);
1318 printf("%s", type_gather
->u
.side_vla
.type
.nr_attr
? ", " : "");
1319 printf("elements: ");
1321 for (i
= 0; i
< length
; i
++) {
1322 switch (type_gather
->u
.side_vla
.type
.elem_type
->type
) {
1323 case SIDE_TYPE_GATHER_VLA
:
1324 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1329 printf("%s", i
? ", " : "");
1330 ptr
+= tracer_print_gather_type(type_gather
->u
.side_vla
.type
.elem_type
, ptr
);
1333 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1336 struct tracer_visitor_priv
{
1337 const struct side_type
*elem_type
;
1342 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1343 const struct side_arg
*elem
)
1345 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1347 printf("%s", tracer_priv
->i
++ ? ", " : "");
1348 tracer_print_type(tracer_priv
->elem_type
, elem
);
1349 return SIDE_VISITOR_STATUS_OK
;
1353 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1355 enum side_visitor_status status
;
1356 struct tracer_visitor_priv tracer_priv
= {
1357 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1360 const struct side_tracer_visitor_ctx tracer_ctx
= {
1361 .write_elem
= tracer_write_elem_cb
,
1362 .priv
= &tracer_priv
,
1365 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1366 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1367 printf("elements: ");
1369 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1371 case SIDE_VISITOR_STATUS_OK
:
1373 case SIDE_VISITOR_STATUS_ERROR
:
1374 fprintf(stderr
, "ERROR: Visitor error\n");
1381 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1383 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1384 uint32_t i
, len
= dynamic_struct
->len
;
1386 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1387 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1388 printf("fields:: ");
1390 for (i
= 0; i
< len
; i
++) {
1391 printf("%s", i
? ", " : "");
1392 printf("%s:: ", fields
[i
].field_name
);
1393 tracer_print_dynamic(&fields
[i
].elem
);
1398 struct tracer_dynamic_struct_visitor_priv
{
1403 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1404 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1405 const struct side_arg_dynamic_field
*dynamic_field
)
1407 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1408 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1410 printf("%s", tracer_priv
->i
++ ? ", " : "");
1411 printf("%s:: ", dynamic_field
->field_name
);
1412 tracer_print_dynamic(&dynamic_field
->elem
);
1413 return SIDE_VISITOR_STATUS_OK
;
1417 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1419 enum side_visitor_status status
;
1420 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1423 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1424 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1425 .priv
= &tracer_priv
,
1427 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1429 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1430 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1431 printf("fields:: ");
1433 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1435 case SIDE_VISITOR_STATUS_OK
:
1437 case SIDE_VISITOR_STATUS_ERROR
:
1438 fprintf(stderr
, "ERROR: Visitor error\n");
1445 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1447 const struct side_arg
*sav
= vla
->sav
;
1448 uint32_t i
, side_sav_len
= vla
->len
;
1450 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1451 printf("%s", vla
->nr_attr
? ", " : "");
1452 printf("elements:: ");
1454 for (i
= 0; i
< side_sav_len
; i
++) {
1455 printf("%s", i
? ", " : "");
1456 tracer_print_dynamic(&sav
[i
]);
1461 struct tracer_dynamic_vla_visitor_priv
{
1466 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1467 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1468 const struct side_arg
*elem
)
1470 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1471 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1473 printf("%s", tracer_priv
->i
++ ? ", " : "");
1474 tracer_print_dynamic(elem
);
1475 return SIDE_VISITOR_STATUS_OK
;
1479 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1481 enum side_visitor_status status
;
1482 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1485 const struct side_tracer_visitor_ctx tracer_ctx
= {
1486 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1487 .priv
= &tracer_priv
,
1489 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1491 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1492 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1493 printf("elements:: ");
1495 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1497 case SIDE_VISITOR_STATUS_OK
:
1499 case SIDE_VISITOR_STATUS_ERROR
:
1500 fprintf(stderr
, "ERROR: Visitor error\n");
1507 void tracer_print_dynamic(const struct side_arg
*item
)
1510 switch (item
->type
) {
1511 case SIDE_TYPE_DYNAMIC_NULL
:
1512 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1513 printf("<NULL TYPE>");
1516 case SIDE_TYPE_DYNAMIC_BOOL
:
1517 tracer_print_type_bool("::", &item
->u
.side_dynamic
.side_bool
.type
, &item
->u
.side_dynamic
.side_bool
.value
, 0);
1520 case SIDE_TYPE_DYNAMIC_U8
:
1521 case SIDE_TYPE_DYNAMIC_U16
:
1522 case SIDE_TYPE_DYNAMIC_U32
:
1523 case SIDE_TYPE_DYNAMIC_U64
:
1524 case SIDE_TYPE_DYNAMIC_S8
:
1525 case SIDE_TYPE_DYNAMIC_S16
:
1526 case SIDE_TYPE_DYNAMIC_S32
:
1527 case SIDE_TYPE_DYNAMIC_S64
:
1528 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1529 TRACER_DISPLAY_BASE_10
);
1531 case SIDE_TYPE_DYNAMIC_BYTE
:
1532 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1533 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1536 case SIDE_TYPE_DYNAMIC_POINTER
:
1537 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1538 TRACER_DISPLAY_BASE_16
);
1541 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
1542 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
1543 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
1544 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
1545 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1546 &item
->u
.side_dynamic
.side_float
.value
);
1549 case SIDE_TYPE_DYNAMIC_STRING
:
1550 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1551 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1553 case SIDE_TYPE_DYNAMIC_STRUCT
:
1554 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1556 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1557 tracer_print_dynamic_struct_visitor(item
);
1559 case SIDE_TYPE_DYNAMIC_VLA
:
1560 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1562 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1563 tracer_print_dynamic_vla_visitor(item
);
1566 fprintf(stderr
, "<UNKNOWN TYPE>\n");
1573 void tracer_print_static_fields(const struct side_event_description
*desc
,
1574 const struct side_arg_vec
*side_arg_vec
,
1577 const struct side_arg
*sav
= side_arg_vec
->sav
;
1578 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1580 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1581 if (desc
->nr_fields
!= side_sav_len
) {
1582 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1585 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1586 printf("%s", side_sav_len
? ", fields: [ " : "");
1587 for (i
= 0; i
< side_sav_len
; i
++) {
1588 printf("%s", i
? ", " : "");
1589 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1597 void tracer_call(const struct side_event_description
*desc
,
1598 const struct side_arg_vec
*side_arg_vec
,
1599 void *priv
__attribute__((unused
)))
1601 uint32_t nr_fields
= 0;
1603 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1607 void tracer_call_variadic(const struct side_event_description
*desc
,
1608 const struct side_arg_vec
*side_arg_vec
,
1609 const struct side_arg_dynamic_struct
*var_struct
,
1610 void *priv
__attribute__((unused
)))
1612 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1614 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1616 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1617 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1620 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1621 printf("%s", var_struct_len
? ", fields:: [ " : "");
1622 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1623 printf("%s", i
? ", " : "");
1624 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1625 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1632 void tracer_event_notification(enum side_tracer_notification notif
,
1633 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1638 printf("----------------------------------------------------------\n");
1639 printf("Tracer notified of events %s\n",
1640 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1641 for (i
= 0; i
< nr_events
; i
++) {
1642 struct side_event_description
*event
= events
[i
];
1644 /* Skip NULL pointers */
1647 printf("provider: %s, event: %s\n",
1648 event
->provider_name
, event
->event_name
);
1649 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1650 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1651 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1655 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1660 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1661 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1665 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1671 printf("----------------------------------------------------------\n");
1674 static __attribute__((constructor
))
1675 void tracer_init(void);
1677 void tracer_init(void)
1679 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1684 static __attribute__((destructor
))
1685 void tracer_exit(void);
1687 void tracer_exit(void)
1689 side_tracer_event_notification_unregister(tracer_handle
);