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_FLOAT_BINARY16
:
189 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
192 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
195 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
197 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
200 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
203 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
205 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
208 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
211 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
213 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
216 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
219 case SIDE_ATTR_TYPE_STRING
:
220 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
223 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
230 void print_attributes(const char *prefix_str
, const char *separator
,
231 const struct side_attr
*attr
, uint32_t nr_attr
)
237 printf("%s%s [ ", prefix_str
, separator
);
238 for (i
= 0; i
< nr_attr
; i
++) {
239 printf("%s", i
? ", " : "");
240 tracer_print_attr_type(separator
, &attr
[i
]);
246 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
248 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
249 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
250 uint32_t i
, print_count
= 0;
253 if (elem_type
->type
!= item
->type
) {
254 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
257 switch (item
->type
) {
259 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
265 v
= item
->u
.side_static
.integer_value
.side_u16
;
266 if (type_to_host_reverse_bo(elem_type
))
267 v
= side_bswap_16(v
);
275 v
= item
->u
.side_static
.integer_value
.side_u32
;
276 if (type_to_host_reverse_bo(elem_type
))
277 v
= side_bswap_32(v
);
285 v
= item
->u
.side_static
.integer_value
.side_u64
;
286 if (type_to_host_reverse_bo(elem_type
))
287 v
= side_bswap_64(v
);
292 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
298 v
= item
->u
.side_static
.integer_value
.side_s16
;
299 if (type_to_host_reverse_bo(elem_type
))
300 v
= side_bswap_16(v
);
308 v
= item
->u
.side_static
.integer_value
.side_s32
;
309 if (type_to_host_reverse_bo(elem_type
))
310 v
= side_bswap_32(v
);
318 v
= item
->u
.side_static
.integer_value
.side_s64
;
319 if (type_to_host_reverse_bo(elem_type
))
320 v
= side_bswap_64(v
);
325 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
328 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
329 printf("%s", mappings
->nr_attr
? ", " : "");
330 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
331 printf(", labels: [ ");
332 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
333 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
335 if (mapping
->range_end
< mapping
->range_begin
) {
336 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
337 mapping
->range_begin
, mapping
->range_end
);
340 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
341 printf("%s", print_count
++ ? ", " : "");
342 printf("\"%s\"", mapping
->label
);
346 printf("<NO LABEL>");
351 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
355 switch (elem_type
->type
) {
356 case SIDE_TYPE_U8
: /* Fall-through */
370 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
377 void print_enum_bitmap(const struct side_type
*type_desc
,
378 const struct side_arg
*item
)
380 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
381 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
382 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
383 bool reverse_byte_order
= false;
384 const struct side_arg
*array_item
;
386 switch (elem_type
->type
) {
387 case SIDE_TYPE_U8
: /* Fall-through */
388 case SIDE_TYPE_BYTE
: /* Fall-through */
389 case SIDE_TYPE_U16
: /* Fall-through */
390 case SIDE_TYPE_U32
: /* Fall-through */
392 stride_bit
= enum_elem_type_to_stride(elem_type
);
393 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
397 case SIDE_TYPE_ARRAY
:
398 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
399 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
400 array_item
= item
->u
.side_static
.side_array
->sav
;
401 nr_items
= type_desc
->u
.side_array
.length
;
404 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
405 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
406 array_item
= item
->u
.side_static
.side_vla
->sav
;
407 nr_items
= item
->u
.side_static
.side_vla
->len
;
410 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
414 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
415 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
416 printf("labels: [ ");
417 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
418 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
422 if (mapping
->range_end
< mapping
->range_begin
) {
423 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
424 mapping
->range_begin
, mapping
->range_end
);
427 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
428 if (bit
> (nr_items
* stride_bit
) - 1)
430 switch (stride_bit
) {
433 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
434 if (v
& (1ULL << (bit
% 8))) {
442 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
443 if (reverse_byte_order
)
444 v
= side_bswap_16(v
);
445 if (v
& (1ULL << (bit
% 16))) {
453 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
454 if (reverse_byte_order
)
455 v
= side_bswap_32(v
);
456 if (v
& (1ULL << (bit
% 32))) {
464 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
465 if (reverse_byte_order
)
466 v
= side_bswap_64(v
);
467 if (v
& (1ULL << (bit
% 64))) {
479 printf("%s", print_count
++ ? ", " : "");
480 printf("\"%s\"", mapping
->label
);
484 printf("<NO LABEL>");
489 void print_integer_binary(uint64_t v
, int bits
)
495 for (i
= 0; i
< bits
; i
++) {
496 printf("%c", v
& (1ULL << 63) ? '1' : '0');
502 void tracer_print_type_header(const char *separator
,
503 const struct side_attr
*attr
, uint32_t nr_attr
)
505 print_attributes("attr", separator
, attr
, nr_attr
);
506 printf("%s", nr_attr
? ", " : "");
507 printf("value%s ", separator
);
511 void tracer_print_type_bool(const char *separator
,
512 const struct side_type_bool
*type_bool
,
513 const union side_bool_value
*value
,
514 uint16_t offset_bits
)
520 if (!type_bool
->len_bits
)
521 len_bits
= type_bool
->bool_size
* CHAR_BIT
;
523 len_bits
= type_bool
->len_bits
;
524 if (len_bits
+ offset_bits
> type_bool
->bool_size
* CHAR_BIT
)
526 reverse_bo
= type_bool
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
527 switch (type_bool
->bool_size
) {
529 v
= value
->side_bool8
;
535 side_u16
= value
->side_bool16
;
537 side_u16
= side_bswap_16(side_u16
);
545 side_u32
= value
->side_bool32
;
547 side_u32
= side_bswap_32(side_u32
);
555 side_u64
= value
->side_bool64
;
557 side_u64
= side_bswap_64(side_u64
);
566 v
&= (1ULL << len_bits
) - 1;
567 tracer_print_type_header(separator
, type_bool
->attr
, type_bool
->nr_attr
);
568 printf("%s", v
? "true" : "false");
572 void tracer_print_type_integer(const char *separator
,
573 const struct side_type_integer
*type_integer
,
574 const union side_integer_value
*value
,
575 uint16_t offset_bits
,
576 enum tracer_display_base default_base
)
578 enum tracer_display_base base
;
586 if (!type_integer
->len_bits
)
587 len_bits
= type_integer
->integer_size
* CHAR_BIT
;
589 len_bits
= type_integer
->len_bits
;
590 if (len_bits
+ offset_bits
> type_integer
->integer_size
* CHAR_BIT
)
592 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
593 switch (type_integer
->integer_size
) {
595 if (type_integer
->signedness
)
596 v
.v_signed
= value
->side_s8
;
598 v
.v_unsigned
= value
->side_u8
;
601 if (type_integer
->signedness
) {
604 side_s16
= value
->side_s16
;
606 side_s16
= side_bswap_16(side_s16
);
607 v
.v_signed
= side_s16
;
611 side_u16
= value
->side_u16
;
613 side_u16
= side_bswap_16(side_u16
);
614 v
.v_unsigned
= side_u16
;
618 if (type_integer
->signedness
) {
621 side_s32
= value
->side_s32
;
623 side_s32
= side_bswap_32(side_s32
);
624 v
.v_signed
= side_s32
;
628 side_u32
= value
->side_u32
;
630 side_u32
= side_bswap_32(side_u32
);
631 v
.v_unsigned
= side_u32
;
635 if (type_integer
->signedness
) {
638 side_s64
= value
->side_s64
;
640 side_s64
= side_bswap_64(side_s64
);
641 v
.v_signed
= side_s64
;
645 side_u64
= value
->side_u64
;
647 side_u64
= side_bswap_64(side_u64
);
648 v
.v_unsigned
= side_u64
;
654 v
.v_unsigned
>>= offset_bits
;
656 v
.v_unsigned
&= (1ULL << len_bits
) - 1;
657 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
658 base
= get_attr_display_base(type_integer
->attr
,
659 type_integer
->nr_attr
,
662 case TRACER_DISPLAY_BASE_2
:
663 print_integer_binary(v
.v_unsigned
, len_bits
);
665 case TRACER_DISPLAY_BASE_8
:
666 printf("0%" PRIo64
, v
.v_unsigned
);
668 case TRACER_DISPLAY_BASE_10
:
669 if (type_integer
->signedness
) {
672 if (v
.v_unsigned
& (1ULL << (len_bits
- 1)))
673 v
.v_unsigned
|= ~((1ULL << len_bits
) - 1);
675 printf("%" PRId64
, v
.v_signed
);
677 printf("%" PRIu64
, v
.v_unsigned
);
680 case TRACER_DISPLAY_BASE_16
:
681 printf("0x%" PRIx64
, v
.v_unsigned
);
689 void tracer_print_type_float(const char *separator
,
690 const struct side_type_float
*type_float
,
691 const union side_float_value
*value
)
695 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
696 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
697 switch (type_float
->float_size
) {
705 .f
= value
->side_float_binary16
,
709 float16
.u
= side_bswap_16(float16
.u
);
710 printf("%g", (double) float16
.f
);
713 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
724 .f
= value
->side_float_binary32
,
728 float32
.u
= side_bswap_32(float32
.u
);
729 printf("%g", (double) float32
.f
);
732 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
743 .f
= value
->side_float_binary64
,
747 float64
.u
= side_bswap_64(float64
.u
);
748 printf("%g", (double) float64
.f
);
751 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
762 .f
= value
->side_float_binary128
,
766 side_bswap_128p(float128
.arr
);
767 printf("%Lg", (long double) float128
.f
);
770 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
775 fprintf(stderr
, "ERROR: Unknown float size\n");
781 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
783 enum side_type_label type
;
785 switch (type_desc
->type
) {
787 switch (item
->type
) {
798 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
804 case SIDE_TYPE_ENUM_BITMAP
:
805 switch (item
->type
) {
811 case SIDE_TYPE_ARRAY
:
815 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
821 case SIDE_TYPE_DYNAMIC
:
822 switch (item
->type
) {
823 case SIDE_TYPE_DYNAMIC_NULL
:
824 case SIDE_TYPE_DYNAMIC_BOOL
:
825 case SIDE_TYPE_DYNAMIC_INTEGER
:
826 case SIDE_TYPE_DYNAMIC_BYTE
:
827 case SIDE_TYPE_DYNAMIC_POINTER
:
828 case SIDE_TYPE_DYNAMIC_FLOAT
:
829 case SIDE_TYPE_DYNAMIC_STRING
:
830 case SIDE_TYPE_DYNAMIC_STRUCT
:
831 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
832 case SIDE_TYPE_DYNAMIC_VLA
:
833 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
836 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
843 if (type_desc
->type
!= item
->type
) {
844 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
850 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
851 type
= (enum side_type_label
) type_desc
->type
;
853 type
= (enum side_type_label
) item
->type
;
857 /* Stack-copy basic types */
859 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
860 printf("<NULL TYPE>");
864 tracer_print_type_bool(":", &type_desc
->u
.side_bool
, &item
->u
.side_static
.bool_value
, 0);
875 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
876 TRACER_DISPLAY_BASE_10
);
880 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
881 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
884 case SIDE_TYPE_POINTER
:
885 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
886 TRACER_DISPLAY_BASE_16
);
889 case SIDE_TYPE_FLOAT_BINARY16
:
890 case SIDE_TYPE_FLOAT_BINARY32
:
891 case SIDE_TYPE_FLOAT_BINARY64
:
892 case SIDE_TYPE_FLOAT_BINARY128
:
893 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
896 case SIDE_TYPE_STRING
:
897 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
898 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
901 /* Stack-copy compound types */
902 case SIDE_TYPE_STRUCT
:
903 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
905 case SIDE_TYPE_ARRAY
:
906 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
909 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
911 case SIDE_TYPE_VLA_VISITOR
:
912 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
915 /* Stack-copy enumeration types */
917 print_enum(type_desc
, item
);
919 case SIDE_TYPE_ENUM_BITMAP
:
920 print_enum_bitmap(type_desc
, item
);
923 /* Gather basic types */
924 case SIDE_TYPE_GATHER_BOOL
:
925 (void) tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_bool_gather_ptr
);
927 case SIDE_TYPE_GATHER_INTEGER
:
928 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
929 TRACER_DISPLAY_BASE_10
);
931 case SIDE_TYPE_GATHER_BYTE
:
932 (void) tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_byte_gather_ptr
);
934 case SIDE_TYPE_GATHER_POINTER
:
935 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
936 TRACER_DISPLAY_BASE_16
);
938 case SIDE_TYPE_GATHER_FLOAT
:
939 (void) tracer_print_gather_float_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_float_gather_ptr
);
942 /* Gather compound type */
943 case SIDE_TYPE_GATHER_STRUCT
:
944 (void) tracer_print_gather_struct(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_struct_gather_ptr
);
946 case SIDE_TYPE_GATHER_ARRAY
:
947 (void) tracer_print_gather_array(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_array_gather_ptr
);
949 case SIDE_TYPE_GATHER_VLA
:
950 (void) tracer_print_gather_vla(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_vla_gather
.ptr
,
951 item
->u
.side_static
.side_vla_gather
.length_ptr
);
954 /* Dynamic basic types */
955 case SIDE_TYPE_DYNAMIC_NULL
:
956 case SIDE_TYPE_DYNAMIC_BOOL
:
957 case SIDE_TYPE_DYNAMIC_INTEGER
:
958 case SIDE_TYPE_DYNAMIC_BYTE
:
959 case SIDE_TYPE_DYNAMIC_POINTER
:
960 case SIDE_TYPE_DYNAMIC_FLOAT
:
961 case SIDE_TYPE_DYNAMIC_STRING
:
963 /* Dynamic compound types */
964 case SIDE_TYPE_DYNAMIC_STRUCT
:
965 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
966 case SIDE_TYPE_DYNAMIC_VLA
:
967 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
968 tracer_print_dynamic(item
);
971 fprintf(stderr
, "<UNKNOWN TYPE>\n");
978 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
980 printf("%s: ", item_desc
->field_name
);
981 tracer_print_type(&item_desc
->side_type
, item
);
985 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
987 const struct side_arg
*sav
= side_arg_vec
->sav
;
988 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
990 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
991 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
994 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
995 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
996 printf("fields: { ");
997 for (i
= 0; i
< side_sav_len
; i
++) {
998 printf("%s", i
? ", " : "");
999 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1005 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1007 const struct side_arg
*sav
= side_arg_vec
->sav
;
1008 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1010 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1011 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1014 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1015 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1016 printf("elements: ");
1018 for (i
= 0; i
< side_sav_len
; i
++) {
1019 printf("%s", i
? ", " : "");
1020 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1026 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1028 const struct side_arg
*sav
= side_arg_vec
->sav
;
1029 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1031 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1032 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1033 printf("elements: ");
1035 for (i
= 0; i
< side_sav_len
; i
++) {
1036 printf("%s", i
? ", " : "");
1037 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1043 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode
, const char *ptr
)
1045 switch (access_mode
) {
1046 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
1048 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1049 /* Dereference pointer */
1050 memcpy(&ptr
, ptr
, sizeof(ptr
));
1058 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode
, uint32_t len
)
1060 switch (access_mode
) {
1061 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
1063 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1064 return sizeof(void *);
1071 uint64_t tracer_load_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1073 enum side_type_gather_access_mode access_mode
=
1074 (enum side_type_gather_access_mode
) type_gather
->u
.side_integer
.access_mode
;
1075 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1076 const char *ptr
= (const char *) _ptr
;
1077 union side_integer_value value
;
1079 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1080 memcpy(&value
, ptr
, integer_size_bytes
);
1081 switch (type_gather
->u
.side_integer
.type
.integer_size
) {
1083 return (uint64_t) value
.side_u8
;
1085 return (uint64_t) value
.side_u16
;
1087 return (uint64_t) value
.side_u32
;
1089 return (uint64_t) value
.side_u64
;
1096 uint32_t tracer_print_gather_bool_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1098 enum side_type_gather_access_mode access_mode
=
1099 (enum side_type_gather_access_mode
) type_gather
->u
.side_bool
.access_mode
;
1100 uint32_t bool_size_bytes
= type_gather
->u
.side_bool
.type
.bool_size
;
1101 const char *ptr
= (const char *) _ptr
;
1102 union side_bool_value value
;
1104 switch (bool_size_bytes
) {
1113 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_bool
.offset
);
1114 memcpy(&value
, ptr
, bool_size_bytes
);
1115 tracer_print_type_bool(":", &type_gather
->u
.side_bool
.type
, &value
,
1116 type_gather
->u
.side_bool
.offset_bits
);
1117 return tracer_gather_size(access_mode
, bool_size_bytes
);
1121 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1123 enum side_type_gather_access_mode access_mode
=
1124 (enum side_type_gather_access_mode
) type_gather
->u
.side_byte
.access_mode
;
1125 const char *ptr
= (const char *) _ptr
;
1128 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_byte
.offset
);
1129 memcpy(&value
, ptr
, 1);
1130 tracer_print_type_header(":", type_gather
->u
.side_byte
.type
.attr
,
1131 type_gather
->u
.side_byte
.type
.nr_attr
);
1132 printf("0x%" PRIx8
, value
);
1133 return tracer_gather_size(access_mode
, 1);
1137 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
,
1138 enum tracer_display_base default_base
)
1140 enum side_type_gather_access_mode access_mode
=
1141 (enum side_type_gather_access_mode
) type_gather
->u
.side_integer
.access_mode
;
1142 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1143 const char *ptr
= (const char *) _ptr
;
1144 union side_integer_value value
;
1146 switch (integer_size_bytes
) {
1155 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1156 memcpy(&value
, ptr
, integer_size_bytes
);
1157 tracer_print_type_integer(":", &type_gather
->u
.side_integer
.type
, &value
,
1158 type_gather
->u
.side_integer
.offset_bits
, default_base
);
1159 return tracer_gather_size(access_mode
, integer_size_bytes
);
1163 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1165 enum side_type_gather_access_mode access_mode
=
1166 (enum side_type_gather_access_mode
) type_gather
->u
.side_float
.access_mode
;
1167 uint32_t float_size_bytes
= type_gather
->u
.side_float
.type
.float_size
;
1168 const char *ptr
= (const char *) _ptr
;
1169 union side_float_value value
;
1171 switch (float_size_bytes
) {
1180 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_float
.offset
);
1181 memcpy(&value
, ptr
, float_size_bytes
);
1182 tracer_print_type_float(":", &type_gather
->u
.side_float
.type
, &value
);
1183 return tracer_gather_size(access_mode
, float_size_bytes
);
1187 uint32_t tracer_print_gather_type(const struct side_type
*type_desc
, const void *ptr
)
1192 switch (type_desc
->type
) {
1193 /* Gather basic types */
1194 case SIDE_TYPE_GATHER_BOOL
:
1195 len
= tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, ptr
);
1197 case SIDE_TYPE_GATHER_INTEGER
:
1198 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1199 TRACER_DISPLAY_BASE_10
);
1201 case SIDE_TYPE_GATHER_BYTE
:
1202 len
= tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, ptr
);
1204 case SIDE_TYPE_GATHER_POINTER
:
1205 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1206 TRACER_DISPLAY_BASE_16
);
1208 case SIDE_TYPE_GATHER_FLOAT
:
1209 len
= tracer_print_gather_float_type(&type_desc
->u
.side_gather
, ptr
);
1212 /* Gather compound types */
1213 case SIDE_TYPE_GATHER_STRUCT
:
1214 len
= tracer_print_gather_struct(&type_desc
->u
.side_gather
, ptr
);
1216 case SIDE_TYPE_GATHER_ARRAY
:
1217 len
= tracer_print_gather_array(&type_desc
->u
.side_gather
, ptr
);
1219 case SIDE_TYPE_GATHER_VLA
:
1220 len
= tracer_print_gather_vla(&type_desc
->u
.side_gather
, ptr
, ptr
);
1223 fprintf(stderr
, "<UNKNOWN GATHER TYPE>");
1231 void tracer_print_gather_field(const struct side_event_field
*field
, const void *ptr
)
1233 printf("%s: ", field
->field_name
);
1234 (void) tracer_print_gather_type(&field
->side_type
, ptr
);
1238 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
)
1240 enum side_type_gather_access_mode access_mode
=
1241 (enum side_type_gather_access_mode
) type_gather
->u
.side_struct
.access_mode
;
1242 const char *ptr
= (const char *) _ptr
;
1245 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_struct
.offset
);
1246 print_attributes("attr", ":", type_gather
->u
.side_struct
.type
->attr
, type_gather
->u
.side_struct
.type
->nr_attr
);
1247 printf("%s", type_gather
->u
.side_struct
.type
->nr_attr
? ", " : "");
1248 printf("fields: { ");
1249 for (i
= 0; i
< type_gather
->u
.side_struct
.type
->nr_fields
; i
++) {
1250 printf("%s", i
? ", " : "");
1251 tracer_print_gather_field(&type_gather
->u
.side_struct
.type
->fields
[i
], ptr
);
1254 return tracer_gather_size(access_mode
, type_gather
->u
.side_struct
.size
);
1258 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
)
1260 enum side_type_gather_access_mode access_mode
=
1261 (enum side_type_gather_access_mode
) type_gather
->u
.side_array
.access_mode
;
1262 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1265 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_array
.offset
);
1267 print_attributes("attr", ":", type_gather
->u
.side_array
.type
.attr
, type_gather
->u
.side_array
.type
.nr_attr
);
1268 printf("%s", type_gather
->u
.side_array
.type
.nr_attr
? ", " : "");
1269 printf("elements: ");
1271 for (i
= 0; i
< type_gather
->u
.side_array
.type
.length
; i
++) {
1272 switch (type_gather
->u
.side_array
.type
.elem_type
->type
) {
1273 case SIDE_TYPE_GATHER_VLA
:
1274 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1279 printf("%s", i
? ", " : "");
1280 ptr
+= tracer_print_gather_type(type_gather
->u
.side_array
.type
.elem_type
, ptr
);
1283 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1287 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
1288 const void *_length_ptr
)
1290 enum side_type_gather_access_mode access_mode
=
1291 (enum side_type_gather_access_mode
) type_gather
->u
.side_vla
.access_mode
;
1292 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1293 const char *length_ptr
= (const char *) _length_ptr
;
1297 switch (type_gather
->u
.side_vla
.length_type
->type
) {
1298 case SIDE_TYPE_GATHER_INTEGER
:
1301 fprintf(stderr
, "<gather VLA expects integer gather length type>\n");
1304 length
= (uint32_t) tracer_load_gather_integer_type(&type_gather
->u
.side_vla
.length_type
->u
.side_gather
, length_ptr
);
1305 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_vla
.offset
);
1307 print_attributes("attr", ":", type_gather
->u
.side_vla
.type
.attr
, type_gather
->u
.side_vla
.type
.nr_attr
);
1308 printf("%s", type_gather
->u
.side_vla
.type
.nr_attr
? ", " : "");
1309 printf("elements: ");
1311 for (i
= 0; i
< length
; i
++) {
1312 switch (type_gather
->u
.side_vla
.type
.elem_type
->type
) {
1313 case SIDE_TYPE_GATHER_VLA
:
1314 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1319 printf("%s", i
? ", " : "");
1320 ptr
+= tracer_print_gather_type(type_gather
->u
.side_vla
.type
.elem_type
, ptr
);
1323 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1326 struct tracer_visitor_priv
{
1327 const struct side_type
*elem_type
;
1332 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1333 const struct side_arg
*elem
)
1335 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1337 printf("%s", tracer_priv
->i
++ ? ", " : "");
1338 tracer_print_type(tracer_priv
->elem_type
, elem
);
1339 return SIDE_VISITOR_STATUS_OK
;
1343 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1345 enum side_visitor_status status
;
1346 struct tracer_visitor_priv tracer_priv
= {
1347 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1350 const struct side_tracer_visitor_ctx tracer_ctx
= {
1351 .write_elem
= tracer_write_elem_cb
,
1352 .priv
= &tracer_priv
,
1355 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1356 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1357 printf("elements: ");
1359 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1361 case SIDE_VISITOR_STATUS_OK
:
1363 case SIDE_VISITOR_STATUS_ERROR
:
1364 fprintf(stderr
, "ERROR: Visitor error\n");
1371 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1373 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1374 uint32_t i
, len
= dynamic_struct
->len
;
1376 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1377 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1378 printf("fields:: ");
1380 for (i
= 0; i
< len
; i
++) {
1381 printf("%s", i
? ", " : "");
1382 printf("%s:: ", fields
[i
].field_name
);
1383 tracer_print_dynamic(&fields
[i
].elem
);
1388 struct tracer_dynamic_struct_visitor_priv
{
1393 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1394 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1395 const struct side_arg_dynamic_field
*dynamic_field
)
1397 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1398 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1400 printf("%s", tracer_priv
->i
++ ? ", " : "");
1401 printf("%s:: ", dynamic_field
->field_name
);
1402 tracer_print_dynamic(&dynamic_field
->elem
);
1403 return SIDE_VISITOR_STATUS_OK
;
1407 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1409 enum side_visitor_status status
;
1410 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1413 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1414 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1415 .priv
= &tracer_priv
,
1417 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1419 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1420 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1421 printf("fields:: ");
1423 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1425 case SIDE_VISITOR_STATUS_OK
:
1427 case SIDE_VISITOR_STATUS_ERROR
:
1428 fprintf(stderr
, "ERROR: Visitor error\n");
1435 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1437 const struct side_arg
*sav
= vla
->sav
;
1438 uint32_t i
, side_sav_len
= vla
->len
;
1440 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1441 printf("%s", vla
->nr_attr
? ", " : "");
1442 printf("elements:: ");
1444 for (i
= 0; i
< side_sav_len
; i
++) {
1445 printf("%s", i
? ", " : "");
1446 tracer_print_dynamic(&sav
[i
]);
1451 struct tracer_dynamic_vla_visitor_priv
{
1456 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1457 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1458 const struct side_arg
*elem
)
1460 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1461 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1463 printf("%s", tracer_priv
->i
++ ? ", " : "");
1464 tracer_print_dynamic(elem
);
1465 return SIDE_VISITOR_STATUS_OK
;
1469 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1471 enum side_visitor_status status
;
1472 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1475 const struct side_tracer_visitor_ctx tracer_ctx
= {
1476 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1477 .priv
= &tracer_priv
,
1479 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1481 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1482 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1483 printf("elements:: ");
1485 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1487 case SIDE_VISITOR_STATUS_OK
:
1489 case SIDE_VISITOR_STATUS_ERROR
:
1490 fprintf(stderr
, "ERROR: Visitor error\n");
1497 void tracer_print_dynamic(const struct side_arg
*item
)
1500 switch (item
->type
) {
1501 /* Dynamic basic types */
1502 case SIDE_TYPE_DYNAMIC_NULL
:
1503 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1504 printf("<NULL TYPE>");
1506 case SIDE_TYPE_DYNAMIC_BOOL
:
1507 tracer_print_type_bool("::", &item
->u
.side_dynamic
.side_bool
.type
, &item
->u
.side_dynamic
.side_bool
.value
, 0);
1509 case SIDE_TYPE_DYNAMIC_INTEGER
:
1510 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1511 TRACER_DISPLAY_BASE_10
);
1513 case SIDE_TYPE_DYNAMIC_BYTE
:
1514 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1515 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1517 case SIDE_TYPE_DYNAMIC_POINTER
:
1518 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1519 TRACER_DISPLAY_BASE_16
);
1521 case SIDE_TYPE_DYNAMIC_FLOAT
:
1522 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1523 &item
->u
.side_dynamic
.side_float
.value
);
1525 case SIDE_TYPE_DYNAMIC_STRING
:
1526 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1527 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1530 /* Dynamic compound types */
1531 case SIDE_TYPE_DYNAMIC_STRUCT
:
1532 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1534 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1535 tracer_print_dynamic_struct_visitor(item
);
1537 case SIDE_TYPE_DYNAMIC_VLA
:
1538 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1540 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1541 tracer_print_dynamic_vla_visitor(item
);
1544 fprintf(stderr
, "<UNKNOWN TYPE>\n");
1551 void tracer_print_static_fields(const struct side_event_description
*desc
,
1552 const struct side_arg_vec
*side_arg_vec
,
1555 const struct side_arg
*sav
= side_arg_vec
->sav
;
1556 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1558 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1559 if (desc
->nr_fields
!= side_sav_len
) {
1560 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1563 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1564 printf("%s", side_sav_len
? ", fields: [ " : "");
1565 for (i
= 0; i
< side_sav_len
; i
++) {
1566 printf("%s", i
? ", " : "");
1567 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1575 void tracer_call(const struct side_event_description
*desc
,
1576 const struct side_arg_vec
*side_arg_vec
,
1577 void *priv
__attribute__((unused
)))
1579 uint32_t nr_fields
= 0;
1581 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1585 void tracer_call_variadic(const struct side_event_description
*desc
,
1586 const struct side_arg_vec
*side_arg_vec
,
1587 const struct side_arg_dynamic_struct
*var_struct
,
1588 void *priv
__attribute__((unused
)))
1590 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1592 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1594 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1595 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1598 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1599 printf("%s", var_struct_len
? ", fields:: [ " : "");
1600 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1601 printf("%s", i
? ", " : "");
1602 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1603 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1610 void tracer_event_notification(enum side_tracer_notification notif
,
1611 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1616 printf("----------------------------------------------------------\n");
1617 printf("Tracer notified of events %s\n",
1618 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1619 for (i
= 0; i
< nr_events
; i
++) {
1620 struct side_event_description
*event
= events
[i
];
1622 /* Skip NULL pointers */
1625 printf("provider: %s, event: %s\n",
1626 event
->provider_name
, event
->event_name
);
1627 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1628 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1629 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1633 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1638 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1639 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1643 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1649 printf("----------------------------------------------------------\n");
1652 static __attribute__((constructor
))
1653 void tracer_init(void);
1655 void tracer_init(void)
1657 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1662 static __attribute__((destructor
))
1663 void tracer_exit(void);
1665 void tracer_exit(void)
1667 side_tracer_event_notification_unregister(tracer_handle
);