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
,
82 enum tracer_display_base default_base
)
86 for (i
= 0; i
< nr_attr
; i
++) {
87 const struct side_attr
*attr
= &_attr
[i
];
89 if (!strcmp(attr
->key
, "std.integer.base")) {
90 int64_t val
= get_attr_integer_value(attr
);
94 return TRACER_DISPLAY_BASE_2
;
96 return TRACER_DISPLAY_BASE_8
;
98 return TRACER_DISPLAY_BASE_10
;
100 return TRACER_DISPLAY_BASE_16
;
102 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
107 return default_base
; /* Default */
111 bool type_to_host_reverse_bo(const struct side_type_description
*type_desc
)
113 switch (type_desc
->type
) {
124 case SIDE_TYPE_POINTER32
:
125 case SIDE_TYPE_POINTER64
:
126 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
131 case SIDE_TYPE_FLOAT_BINARY16
:
132 case SIDE_TYPE_FLOAT_BINARY32
:
133 case SIDE_TYPE_FLOAT_BINARY64
:
134 case SIDE_TYPE_FLOAT_BINARY128
:
135 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
141 fprintf(stderr
, "Unexpected type\n");
147 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
149 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
150 switch (attr
->value
.type
) {
151 case SIDE_ATTR_TYPE_BOOL
:
152 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
154 case SIDE_ATTR_TYPE_U8
:
155 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
157 case SIDE_ATTR_TYPE_U16
:
158 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
160 case SIDE_ATTR_TYPE_U32
:
161 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
163 case SIDE_ATTR_TYPE_U64
:
164 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
166 case SIDE_ATTR_TYPE_S8
:
167 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
169 case SIDE_ATTR_TYPE_S16
:
170 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
172 case SIDE_ATTR_TYPE_S32
:
173 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
175 case SIDE_ATTR_TYPE_S64
:
176 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
178 case SIDE_ATTR_TYPE_POINTER32
:
179 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
181 case SIDE_ATTR_TYPE_POINTER64
:
182 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
184 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
186 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
189 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
192 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
194 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
197 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
200 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
202 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
205 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
208 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
210 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
213 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
216 case SIDE_ATTR_TYPE_STRING
:
217 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
220 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
227 void print_attributes(const char *prefix_str
, const char *separator
,
228 const struct side_attr
*attr
, uint32_t nr_attr
)
234 printf("%s%s [ ", prefix_str
, separator
);
235 for (i
= 0; i
< nr_attr
; i
++) {
236 printf("%s", i
? ", " : "");
237 tracer_print_attr_type(separator
, &attr
[i
]);
243 void print_enum(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
245 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
246 const struct side_type_description
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
247 int i
, print_count
= 0;
250 if (elem_type
->type
!= item
->type
) {
251 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
254 switch (item
->type
) {
256 value
= (int64_t) item
->u
.integer_value
.side_u8
;
262 v
= item
->u
.integer_value
.side_u16
;
263 if (type_to_host_reverse_bo(elem_type
))
264 v
= side_bswap_16(v
);
272 v
= item
->u
.integer_value
.side_u32
;
273 if (type_to_host_reverse_bo(elem_type
))
274 v
= side_bswap_32(v
);
282 v
= item
->u
.integer_value
.side_u64
;
283 if (type_to_host_reverse_bo(elem_type
))
284 v
= side_bswap_64(v
);
289 value
= (int64_t) item
->u
.integer_value
.side_s8
;
295 v
= item
->u
.integer_value
.side_s16
;
296 if (type_to_host_reverse_bo(elem_type
))
297 v
= side_bswap_16(v
);
305 v
= item
->u
.integer_value
.side_s32
;
306 if (type_to_host_reverse_bo(elem_type
))
307 v
= side_bswap_32(v
);
315 v
= item
->u
.integer_value
.side_s64
;
316 if (type_to_host_reverse_bo(elem_type
))
317 v
= side_bswap_64(v
);
322 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
325 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
326 printf("%s", mappings
->nr_attr
? ", " : "");
327 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
328 printf(", labels: [ ");
329 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
330 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
332 if (mapping
->range_end
< mapping
->range_begin
) {
333 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
334 mapping
->range_begin
, mapping
->range_end
);
337 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
338 printf("%s", print_count
++ ? ", " : "");
339 printf("\"%s\"", mapping
->label
);
343 printf("<NO LABEL>");
348 uint32_t enum_elem_type_to_stride(const struct side_type_description
*elem_type
)
352 switch (elem_type
->type
) {
353 case SIDE_TYPE_U8
: /* Fall-through */
367 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
374 void print_enum_bitmap(const struct side_type_description
*type_desc
,
375 const struct side_arg_vec
*item
)
377 const struct side_type_description
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
378 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
379 int i
, print_count
= 0;
380 uint32_t stride_bit
, nr_items
;
381 bool reverse_byte_order
= false;
382 const struct side_arg_vec
*array_item
;
384 switch (elem_type
->type
) {
385 case SIDE_TYPE_U8
: /* Fall-through */
386 case SIDE_TYPE_BYTE
: /* Fall-through */
387 case SIDE_TYPE_U16
: /* Fall-through */
388 case SIDE_TYPE_U32
: /* Fall-through */
390 stride_bit
= enum_elem_type_to_stride(elem_type
);
391 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
395 case SIDE_TYPE_ARRAY
:
396 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
397 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
398 array_item
= item
->u
.side_array
->sav
;
399 nr_items
= type_desc
->u
.side_array
.length
;
402 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
403 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
404 array_item
= item
->u
.side_vla
->sav
;
405 nr_items
= item
->u
.side_vla
->len
;
408 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
412 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
413 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
414 printf("labels: [ ");
415 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
416 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
420 if (mapping
->range_end
< mapping
->range_begin
) {
421 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
422 mapping
->range_begin
, mapping
->range_end
);
425 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
426 if (bit
> (nr_items
* stride_bit
) - 1)
428 switch (stride_bit
) {
431 uint8_t v
= array_item
[bit
/ 8].u
.integer_value
.side_u8
;
432 if (v
& (1ULL << (bit
% 8))) {
440 uint16_t v
= array_item
[bit
/ 16].u
.integer_value
.side_u16
;
441 if (reverse_byte_order
)
442 v
= side_bswap_16(v
);
443 if (v
& (1ULL << (bit
% 16))) {
451 uint32_t v
= array_item
[bit
/ 32].u
.integer_value
.side_u32
;
452 if (reverse_byte_order
)
453 v
= side_bswap_32(v
);
454 if (v
& (1ULL << (bit
% 32))) {
462 uint64_t v
= array_item
[bit
/ 64].u
.integer_value
.side_u64
;
463 if (reverse_byte_order
)
464 v
= side_bswap_64(v
);
465 if (v
& (1ULL << (bit
% 64))) {
477 printf("%s", print_count
++ ? ", " : "");
478 printf("\"%s\"", mapping
->label
);
482 printf("<NO LABEL>");
487 void print_integer_binary(uint64_t v
, int bits
)
493 for (i
= 0; i
< bits
; i
++) {
494 printf("%c", v
& (1ULL << 63) ? '1' : '0');
500 void tracer_print_type_header(const char *separator
,
501 const struct side_attr
*attr
, uint32_t nr_attr
)
503 print_attributes("attr", separator
, attr
, nr_attr
);
504 printf("%s", nr_attr
? ", " : "");
505 printf("value%s ", separator
);
509 void tracer_print_type_integer(const char *separator
,
510 const struct side_type_integer
*type_integer
,
511 const union side_integer_value
*value
,
512 uint16_t offset_bits
,
513 enum tracer_display_base default_base
)
515 enum tracer_display_base base
;
522 if (!type_integer
->len_bits
||
523 type_integer
->len_bits
+ offset_bits
> type_integer
->integer_size_bits
)
525 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
526 base
= get_attr_display_base(type_integer
->attr
,
527 type_integer
->nr_attr
,
529 switch (type_integer
->integer_size_bits
) {
531 if (type_integer
->signedness
)
532 v
.v_signed
= value
->side_s8
;
534 v
.v_unsigned
= value
->side_u8
;
537 if (type_integer
->signedness
) {
540 side_s16
= value
->side_s16
;
542 side_s16
= side_bswap_16(side_s16
);
543 v
.v_signed
= side_s16
;
547 side_u16
= value
->side_u16
;
549 side_u16
= side_bswap_16(side_u16
);
550 v
.v_unsigned
= side_u16
;
554 if (type_integer
->signedness
) {
557 side_s32
= value
->side_s32
;
559 side_s32
= side_bswap_32(side_s32
);
560 v
.v_signed
= side_s32
;
564 side_u32
= value
->side_u32
;
566 side_u32
= side_bswap_32(side_u32
);
567 v
.v_unsigned
= side_u32
;
571 if (type_integer
->signedness
) {
574 side_s64
= value
->side_s64
;
576 side_s64
= side_bswap_64(side_s64
);
577 v
.v_signed
= side_s64
;
581 side_u64
= value
->side_u64
;
583 side_u64
= side_bswap_64(side_u64
);
584 v
.v_unsigned
= side_u64
;
590 v
.v_unsigned
>>= offset_bits
;
591 if (type_integer
->len_bits
< 64)
592 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
593 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
595 case TRACER_DISPLAY_BASE_2
:
596 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
598 case TRACER_DISPLAY_BASE_8
:
599 printf("0%" PRIo64
, v
.v_unsigned
);
601 case TRACER_DISPLAY_BASE_10
:
602 if (type_integer
->signedness
) {
604 if (type_integer
->len_bits
< 64) {
605 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
606 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
608 printf("%" PRId64
, v
.v_signed
);
610 printf("%" PRIu64
, v
.v_unsigned
);
613 case TRACER_DISPLAY_BASE_16
:
614 printf("0x%" PRIx64
, v
.v_unsigned
);
622 void tracer_print_type_float(const char *separator
,
623 const struct side_type_float
*type_float
,
624 const union side_float_value
*value
)
628 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
629 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
630 switch (type_float
->float_size_bits
) {
638 .f
= value
->side_float_binary16
,
642 float16
.u
= side_bswap_16(float16
.u
);
643 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
644 printf("%g", (double) float16
.f
);
647 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
658 .f
= value
->side_float_binary32
,
662 float32
.u
= side_bswap_32(float32
.u
);
663 printf("%g", (double) float32
.f
);
666 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
677 .f
= value
->side_float_binary64
,
681 float64
.u
= side_bswap_64(float64
.u
);
682 printf("%g", (double) float64
.f
);
685 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
696 .f
= value
->side_float_binary128
,
700 side_bswap_128p(float128
.arr
);
701 printf("%Lg", (long double) float128
.f
);
704 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
709 fprintf(stderr
, "ERROR: Unknown float size\n");
715 void tracer_print_type(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
719 switch (type_desc
->type
) {
720 case SIDE_TYPE_ARRAY
:
721 switch (item
->type
) {
722 case SIDE_TYPE_ARRAY_U8
:
723 case SIDE_TYPE_ARRAY_U16
:
724 case SIDE_TYPE_ARRAY_U32
:
725 case SIDE_TYPE_ARRAY_U64
:
726 case SIDE_TYPE_ARRAY_S8
:
727 case SIDE_TYPE_ARRAY_S16
:
728 case SIDE_TYPE_ARRAY_S32
:
729 case SIDE_TYPE_ARRAY_S64
:
730 case SIDE_TYPE_ARRAY_POINTER32
:
731 case SIDE_TYPE_ARRAY_POINTER64
:
732 case SIDE_TYPE_ARRAY_BYTE
:
733 case SIDE_TYPE_ARRAY
:
736 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
743 switch (item
->type
) {
744 case SIDE_TYPE_VLA_U8
:
745 case SIDE_TYPE_VLA_U16
:
746 case SIDE_TYPE_VLA_U32
:
747 case SIDE_TYPE_VLA_U64
:
748 case SIDE_TYPE_VLA_S8
:
749 case SIDE_TYPE_VLA_S16
:
750 case SIDE_TYPE_VLA_S32
:
751 case SIDE_TYPE_VLA_S64
:
752 case SIDE_TYPE_VLA_BYTE
:
753 case SIDE_TYPE_VLA_POINTER32
:
754 case SIDE_TYPE_VLA_POINTER64
:
758 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
765 switch (item
->type
) {
776 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
782 case SIDE_TYPE_ENUM_BITMAP
:
783 switch (item
->type
) {
789 case SIDE_TYPE_ARRAY
:
793 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
800 if (type_desc
->type
!= item
->type
) {
801 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
807 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
808 type
= type_desc
->type
;
815 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
816 printf("<NULL TYPE>");
820 tracer_print_type_header(":", type_desc
->u
.side_bool
.attr
, type_desc
->u
.side_bool
.nr_attr
);
821 printf("%s", item
->u
.bool_value
? "true" : "false");
832 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.integer_value
, 0,
833 TRACER_DISPLAY_BASE_10
);
836 case SIDE_TYPE_POINTER32
:
837 case SIDE_TYPE_POINTER64
:
838 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.integer_value
, 0,
839 TRACER_DISPLAY_BASE_16
);
843 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
844 printf("0x%" PRIx8
, item
->u
.byte_value
);
848 print_enum(type_desc
, item
);
851 case SIDE_TYPE_ENUM_BITMAP
:
852 print_enum_bitmap(type_desc
, item
);
855 case SIDE_TYPE_FLOAT_BINARY16
:
856 case SIDE_TYPE_FLOAT_BINARY32
:
857 case SIDE_TYPE_FLOAT_BINARY64
:
858 case SIDE_TYPE_FLOAT_BINARY128
:
859 tracer_print_type_float(":", &type_desc
->u
.side_float
,
860 &item
->u
.float_value
);
863 case SIDE_TYPE_STRING
:
864 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
865 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.string_value
);
867 case SIDE_TYPE_STRUCT
:
868 tracer_print_struct(type_desc
, item
->u
.side_struct
);
870 case SIDE_TYPE_STRUCT_SG
:
871 tracer_print_struct_sg(type_desc
, item
->u
.side_struct_sg_ptr
);
873 case SIDE_TYPE_ARRAY
:
874 tracer_print_array(type_desc
, item
->u
.side_array
);
877 tracer_print_vla(type_desc
, item
->u
.side_vla
);
879 case SIDE_TYPE_VLA_VISITOR
:
880 tracer_print_vla_visitor(type_desc
, item
->u
.side_vla_app_visitor_ctx
);
882 case SIDE_TYPE_ARRAY_U8
:
883 case SIDE_TYPE_ARRAY_U16
:
884 case SIDE_TYPE_ARRAY_U32
:
885 case SIDE_TYPE_ARRAY_U64
:
886 case SIDE_TYPE_ARRAY_S8
:
887 case SIDE_TYPE_ARRAY_S16
:
888 case SIDE_TYPE_ARRAY_S32
:
889 case SIDE_TYPE_ARRAY_S64
:
890 case SIDE_TYPE_ARRAY_BYTE
:
891 case SIDE_TYPE_ARRAY_POINTER32
:
892 case SIDE_TYPE_ARRAY_POINTER64
:
893 tracer_print_array_fixint(type_desc
, item
);
895 case SIDE_TYPE_VLA_U8
:
896 case SIDE_TYPE_VLA_U16
:
897 case SIDE_TYPE_VLA_U32
:
898 case SIDE_TYPE_VLA_U64
:
899 case SIDE_TYPE_VLA_S8
:
900 case SIDE_TYPE_VLA_S16
:
901 case SIDE_TYPE_VLA_S32
:
902 case SIDE_TYPE_VLA_S64
:
903 case SIDE_TYPE_VLA_BYTE
:
904 case SIDE_TYPE_VLA_POINTER32
:
905 case SIDE_TYPE_VLA_POINTER64
:
906 tracer_print_vla_fixint(type_desc
, item
);
908 case SIDE_TYPE_DYNAMIC
:
909 tracer_print_type_header(":", type_desc
->u
.side_dynamic
.attr
, type_desc
->u
.side_dynamic
.nr_attr
);
910 tracer_print_dynamic(&item
->u
.dynamic_value
);
913 fprintf(stderr
, "<UNKNOWN TYPE>");
920 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg_vec
*item
)
922 printf("%s: ", item_desc
->field_name
);
923 tracer_print_type(&item_desc
->side_type
, item
);
927 void tracer_print_struct(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
929 const struct side_arg_vec
*sav
= sav_desc
->sav
;
930 uint32_t side_sav_len
= sav_desc
->len
;
933 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
934 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
937 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
938 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
939 printf("fields: { ");
940 for (i
= 0; i
< side_sav_len
; i
++) {
941 printf("%s", i
? ", " : "");
942 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
948 void tracer_print_sg_type(const struct side_type_sg_description
*sg_type
, void *_ptr
)
950 const char *ptr
= (const char *) _ptr
;
951 union side_integer_value value
;
954 switch (sg_type
->type
) {
955 case SIDE_TYPE_SG_NULL
:
956 tracer_print_type_header(":", sg_type
->u
.side_null
.attr
, sg_type
->u
.side_null
.nr_attr
);
957 printf("<NULL TYPE>");
960 case SIDE_TYPE_SG_UNSIGNED_INT
:
961 case SIDE_TYPE_SG_SIGNED_INT
:
962 switch (sg_type
->u
.side_integer
.type
.integer_size_bits
) {
971 memcpy(&value
, ptr
+ sg_type
->offset
, sg_type
->u
.side_integer
.type
.integer_size_bits
>> 3);
972 tracer_print_type_integer(":", &sg_type
->u
.side_integer
.type
, &value
,
973 sg_type
->u
.side_integer
.offset_bits
, TRACER_DISPLAY_BASE_10
);
976 fprintf(stderr
, "<UNKNOWN TYPE>");
983 void tracer_print_sg_field(const struct side_struct_field_sg
*field_sg
, void *ptr
)
985 printf("%s: ", field_sg
->field_name
);
986 tracer_print_sg_type(&field_sg
->side_type
, ptr
);
990 void tracer_print_struct_sg(const struct side_type_description
*type_desc
, void *ptr
)
992 const struct side_type_struct_sg
*struct_sg
= type_desc
->u
.side_struct_sg
;
995 print_attributes("attr", ":", struct_sg
->attr
, struct_sg
->nr_attr
);
996 printf("%s", struct_sg
->nr_attr
? ", " : "");
997 printf("fields: { ");
998 for (i
= 0; i
< struct_sg
->nr_fields
; i
++) {
999 printf("%s", i
? ", " : "");
1000 tracer_print_sg_field(&struct_sg
->fields_sg
[i
], ptr
);
1006 void tracer_print_array(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1008 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1009 uint32_t side_sav_len
= sav_desc
->len
;
1012 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1013 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1016 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1017 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1018 printf("elements: ");
1020 for (i
= 0; i
< side_sav_len
; i
++) {
1021 printf("%s", i
? ", " : "");
1022 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1028 void tracer_print_vla(const struct side_type_description
*type_desc
, const struct side_arg_vec_description
*sav_desc
)
1030 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1031 uint32_t side_sav_len
= sav_desc
->len
;
1034 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1035 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1036 printf("elements: ");
1038 for (i
= 0; i
< side_sav_len
; i
++) {
1039 printf("%s", i
? ", " : "");
1040 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1045 struct tracer_visitor_priv
{
1046 const struct side_type_description
*elem_type
;
1051 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1052 const struct side_arg_vec
*elem
)
1054 struct tracer_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1056 printf("%s", tracer_priv
->i
++ ? ", " : "");
1057 tracer_print_type(tracer_priv
->elem_type
, elem
);
1058 return SIDE_VISITOR_STATUS_OK
;
1062 void tracer_print_vla_visitor(const struct side_type_description
*type_desc
, void *app_ctx
)
1064 enum side_visitor_status status
;
1065 struct tracer_visitor_priv tracer_priv
= {
1066 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1069 const struct side_tracer_visitor_ctx tracer_ctx
= {
1070 .write_elem
= tracer_write_elem_cb
,
1071 .priv
= &tracer_priv
,
1074 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1075 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1076 printf("elements: ");
1078 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1080 case SIDE_VISITOR_STATUS_OK
:
1082 case SIDE_VISITOR_STATUS_ERROR
:
1083 fprintf(stderr
, "ERROR: Visitor error\n");
1089 void tracer_print_array_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1091 const struct side_type_description
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1092 uint32_t side_sav_len
= type_desc
->u
.side_array
.length
;
1093 void *p
= item
->u
.side_array_fixint
;
1094 enum side_type side_type
;
1097 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1098 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1099 printf("elements: ");
1100 switch (item
->type
) {
1101 case SIDE_TYPE_ARRAY_U8
:
1102 if (elem_type
->type
!= SIDE_TYPE_U8
)
1105 case SIDE_TYPE_ARRAY_U16
:
1106 if (elem_type
->type
!= SIDE_TYPE_U16
)
1109 case SIDE_TYPE_ARRAY_U32
:
1110 if (elem_type
->type
!= SIDE_TYPE_U32
)
1113 case SIDE_TYPE_ARRAY_U64
:
1114 if (elem_type
->type
!= SIDE_TYPE_U64
)
1117 case SIDE_TYPE_ARRAY_S8
:
1118 if (elem_type
->type
!= SIDE_TYPE_S8
)
1121 case SIDE_TYPE_ARRAY_S16
:
1122 if (elem_type
->type
!= SIDE_TYPE_S16
)
1125 case SIDE_TYPE_ARRAY_S32
:
1126 if (elem_type
->type
!= SIDE_TYPE_S32
)
1129 case SIDE_TYPE_ARRAY_S64
:
1130 if (elem_type
->type
!= SIDE_TYPE_S64
)
1133 case SIDE_TYPE_ARRAY_BYTE
:
1134 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1137 case SIDE_TYPE_ARRAY_POINTER32
:
1138 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1140 case SIDE_TYPE_ARRAY_POINTER64
:
1141 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1147 side_type
= elem_type
->type
;
1150 for (i
= 0; i
< side_sav_len
; i
++) {
1151 struct side_arg_vec sav_elem
= {
1155 switch (side_type
) {
1157 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1160 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1163 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1166 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1169 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1172 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1175 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1178 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1180 case SIDE_TYPE_BYTE
:
1181 sav_elem
.u
.byte_value
= ((const uint8_t *) p
)[i
];
1183 case SIDE_TYPE_POINTER32
:
1184 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1186 case SIDE_TYPE_POINTER64
:
1187 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1191 fprintf(stderr
, "ERROR: Unexpected type\n");
1195 printf("%s", i
? ", " : "");
1196 tracer_print_type(elem_type
, &sav_elem
);
1202 fprintf(stderr
, "ERROR: type mismatch\n");
1206 void tracer_print_vla_fixint(const struct side_type_description
*type_desc
, const struct side_arg_vec
*item
)
1208 const struct side_type_description
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1209 uint32_t side_sav_len
= item
->u
.side_vla_fixint
.length
;
1210 void *p
= item
->u
.side_vla_fixint
.p
;
1211 enum side_type side_type
;
1214 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1215 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1216 printf("elements: ");
1217 switch (item
->type
) {
1218 case SIDE_TYPE_VLA_U8
:
1219 if (elem_type
->type
!= SIDE_TYPE_U8
)
1222 case SIDE_TYPE_VLA_U16
:
1223 if (elem_type
->type
!= SIDE_TYPE_U16
)
1226 case SIDE_TYPE_VLA_U32
:
1227 if (elem_type
->type
!= SIDE_TYPE_U32
)
1230 case SIDE_TYPE_VLA_U64
:
1231 if (elem_type
->type
!= SIDE_TYPE_U64
)
1234 case SIDE_TYPE_VLA_S8
:
1235 if (elem_type
->type
!= SIDE_TYPE_S8
)
1238 case SIDE_TYPE_VLA_S16
:
1239 if (elem_type
->type
!= SIDE_TYPE_S16
)
1242 case SIDE_TYPE_VLA_S32
:
1243 if (elem_type
->type
!= SIDE_TYPE_S32
)
1246 case SIDE_TYPE_VLA_S64
:
1247 if (elem_type
->type
!= SIDE_TYPE_S64
)
1250 case SIDE_TYPE_VLA_BYTE
:
1251 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1254 case SIDE_TYPE_VLA_POINTER32
:
1255 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1257 case SIDE_TYPE_VLA_POINTER64
:
1258 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1264 side_type
= elem_type
->type
;
1267 for (i
= 0; i
< side_sav_len
; i
++) {
1268 struct side_arg_vec sav_elem
= {
1272 switch (side_type
) {
1274 sav_elem
.u
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1277 sav_elem
.u
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1280 sav_elem
.u
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1283 sav_elem
.u
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1286 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1289 sav_elem
.u
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1292 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1295 sav_elem
.u
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1297 case SIDE_TYPE_BYTE
:
1298 sav_elem
.u
.byte_value
= ((const uint8_t *) p
)[i
];
1300 case SIDE_TYPE_POINTER32
:
1301 sav_elem
.u
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1303 case SIDE_TYPE_POINTER64
:
1304 sav_elem
.u
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1308 fprintf(stderr
, "ERROR: Unexpected type\n");
1312 printf("%s", i
? ", " : "");
1313 tracer_print_type(elem_type
, &sav_elem
);
1319 fprintf(stderr
, "ERROR: type mismatch\n");
1324 void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct
*dynamic_struct
)
1326 const struct side_arg_dynamic_event_field
*fields
= dynamic_struct
->fields
;
1327 uint32_t len
= dynamic_struct
->len
;
1330 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1331 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1332 printf("fields:: ");
1334 for (i
= 0; i
< len
; i
++) {
1335 printf("%s", i
? ", " : "");
1336 printf("%s:: ", fields
[i
].field_name
);
1337 tracer_print_dynamic(&fields
[i
].elem
);
1342 struct tracer_dynamic_struct_visitor_priv
{
1347 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1348 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1349 const struct side_arg_dynamic_event_field
*dynamic_field
)
1351 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1353 printf("%s", tracer_priv
->i
++ ? ", " : "");
1354 printf("%s:: ", dynamic_field
->field_name
);
1355 tracer_print_dynamic(&dynamic_field
->elem
);
1356 return SIDE_VISITOR_STATUS_OK
;
1360 void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec
*item
)
1362 enum side_visitor_status status
;
1363 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1366 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1367 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1368 .priv
= &tracer_priv
,
1370 void *app_ctx
= item
->u
.side_dynamic_struct_visitor
.app_ctx
;
1372 print_attributes("attr", "::", item
->u
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic_struct_visitor
.nr_attr
);
1373 printf("%s", item
->u
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1374 printf("fields:: ");
1376 status
= item
->u
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1378 case SIDE_VISITOR_STATUS_OK
:
1380 case SIDE_VISITOR_STATUS_ERROR
:
1381 fprintf(stderr
, "ERROR: Visitor error\n");
1388 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla
*vla
)
1390 const struct side_arg_dynamic_vec
*sav
= vla
->sav
;
1391 uint32_t side_sav_len
= vla
->len
;
1394 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1395 printf("%s", vla
->nr_attr
? ", " : "");
1396 printf("elements:: ");
1398 for (i
= 0; i
< side_sav_len
; i
++) {
1399 printf("%s", i
? ", " : "");
1400 tracer_print_dynamic(&sav
[i
]);
1405 struct tracer_dynamic_vla_visitor_priv
{
1410 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1411 const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
,
1412 const struct side_arg_dynamic_vec
*elem
)
1414 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
= tracer_ctx
->priv
;
1416 printf("%s", tracer_priv
->i
++ ? ", " : "");
1417 tracer_print_dynamic(elem
);
1418 return SIDE_VISITOR_STATUS_OK
;
1422 void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec
*item
)
1424 enum side_visitor_status status
;
1425 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1428 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx
= {
1429 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1430 .priv
= &tracer_priv
,
1432 void *app_ctx
= item
->u
.side_dynamic_vla_visitor
.app_ctx
;
1434 print_attributes("attr", "::", item
->u
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic_vla_visitor
.nr_attr
);
1435 printf("%s", item
->u
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1436 printf("elements:: ");
1438 status
= item
->u
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1440 case SIDE_VISITOR_STATUS_OK
:
1442 case SIDE_VISITOR_STATUS_ERROR
:
1443 fprintf(stderr
, "ERROR: Visitor error\n");
1450 void tracer_print_dynamic(const struct side_arg_dynamic_vec
*item
)
1453 switch (item
->dynamic_type
) {
1454 case SIDE_DYNAMIC_TYPE_NULL
:
1455 tracer_print_type_header("::", item
->u
.side_null
.attr
, item
->u
.side_null
.nr_attr
);
1456 printf("<NULL TYPE>");
1458 case SIDE_DYNAMIC_TYPE_BOOL
:
1459 tracer_print_type_header("::", item
->u
.side_bool
.type
.attr
, item
->u
.side_bool
.type
.nr_attr
);
1460 printf("%s", item
->u
.side_bool
.value
? "true" : "false");
1462 case SIDE_DYNAMIC_TYPE_U8
:
1463 case SIDE_DYNAMIC_TYPE_U16
:
1464 case SIDE_DYNAMIC_TYPE_U32
:
1465 case SIDE_DYNAMIC_TYPE_U64
:
1466 case SIDE_DYNAMIC_TYPE_S8
:
1467 case SIDE_DYNAMIC_TYPE_S16
:
1468 case SIDE_DYNAMIC_TYPE_S32
:
1469 case SIDE_DYNAMIC_TYPE_S64
:
1470 tracer_print_type_integer("::", &item
->u
.side_integer
.type
, &item
->u
.side_integer
.value
, 0,
1471 TRACER_DISPLAY_BASE_10
);
1473 case SIDE_DYNAMIC_TYPE_BYTE
:
1474 tracer_print_type_header("::", item
->u
.side_byte
.type
.attr
, item
->u
.side_byte
.type
.nr_attr
);
1475 printf("0x%" PRIx8
, item
->u
.side_byte
.value
);
1478 case SIDE_DYNAMIC_TYPE_POINTER32
:
1479 case SIDE_DYNAMIC_TYPE_POINTER64
:
1480 tracer_print_type_integer("::", &item
->u
.side_integer
.type
, &item
->u
.side_integer
.value
, 0,
1481 TRACER_DISPLAY_BASE_16
);
1484 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16
:
1485 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32
:
1486 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64
:
1487 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128
:
1488 tracer_print_type_float("::", &item
->u
.side_float
.type
,
1489 &item
->u
.side_float
.value
);
1492 case SIDE_DYNAMIC_TYPE_STRING
:
1493 tracer_print_type_header("::", item
->u
.side_string
.type
.attr
, item
->u
.side_string
.type
.nr_attr
);
1494 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_string
.value
);
1496 case SIDE_DYNAMIC_TYPE_STRUCT
:
1497 tracer_print_dynamic_struct(item
->u
.side_dynamic_struct
);
1499 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR
:
1500 tracer_print_dynamic_struct_visitor(item
);
1502 case SIDE_DYNAMIC_TYPE_VLA
:
1503 tracer_print_dynamic_vla(item
->u
.side_dynamic_vla
);
1505 case SIDE_DYNAMIC_TYPE_VLA_VISITOR
:
1506 tracer_print_dynamic_vla_visitor(item
);
1509 fprintf(stderr
, "<UNKNOWN TYPE>");
1516 void tracer_print_static_fields(const struct side_event_description
*desc
,
1517 const struct side_arg_vec_description
*sav_desc
,
1520 const struct side_arg_vec
*sav
= sav_desc
->sav
;
1521 uint32_t side_sav_len
= sav_desc
->len
;
1524 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1525 if (desc
->nr_fields
!= side_sav_len
) {
1526 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1529 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1530 printf("%s", side_sav_len
? ", fields: [ " : "");
1531 for (i
= 0; i
< side_sav_len
; i
++) {
1532 printf("%s", i
? ", " : "");
1533 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1541 void tracer_call(const struct side_event_description
*desc
,
1542 const struct side_arg_vec_description
*sav_desc
,
1543 void *priv
__attribute__((unused
)))
1547 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
1551 void tracer_call_variadic(const struct side_event_description
*desc
,
1552 const struct side_arg_vec_description
*sav_desc
,
1553 const struct side_arg_dynamic_event_struct
*var_struct
,
1554 void *priv
__attribute__((unused
)))
1556 uint32_t var_struct_len
= var_struct
->len
;
1557 int nr_fields
= 0, i
;
1559 tracer_print_static_fields(desc
, sav_desc
, &nr_fields
);
1561 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1562 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1565 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1566 printf("%s", var_struct_len
? ", fields:: [ " : "");
1567 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1568 printf("%s", i
? ", " : "");
1569 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1570 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1577 void tracer_event_notification(enum side_tracer_notification notif
,
1578 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1583 printf("----------------------------------------------------------\n");
1584 printf("Tracer notified of events %s\n",
1585 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1586 for (i
= 0; i
< nr_events
; i
++) {
1587 struct side_event_description
*event
= events
[i
];
1589 /* Skip NULL pointers */
1592 printf("provider: %s, event: %s\n",
1593 event
->provider_name
, event
->event_name
);
1594 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1595 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1596 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1600 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1605 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1606 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1610 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1616 printf("----------------------------------------------------------\n");
1619 static __attribute__((constructor
))
1620 void tracer_init(void);
1622 void tracer_init(void)
1624 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1629 static __attribute__((destructor
))
1630 void tracer_exit(void);
1632 void tracer_exit(void)
1634 side_tracer_event_notification_unregister(tracer_handle
);