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
,
27 static struct side_tracer_handle
*tracer_handle
;
30 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
32 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
34 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
36 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
);
38 void tracer_print_dynamic(const struct side_arg
*dynamic_item
);
40 uint32_t tracer_print_gather_bool_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
42 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
44 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
,
45 enum tracer_display_base default_base
);
47 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
49 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
);
51 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
);
53 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
54 const void *_length_ptr
);
56 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
59 int64_t get_attr_integer_value(const struct side_attr
*attr
)
63 switch (attr
->value
.type
) {
64 case SIDE_ATTR_TYPE_U8
:
65 val
= attr
->value
.u
.integer_value
.side_u8
;
67 case SIDE_ATTR_TYPE_U16
:
68 val
= attr
->value
.u
.integer_value
.side_u16
;
70 case SIDE_ATTR_TYPE_U32
:
71 val
= attr
->value
.u
.integer_value
.side_u32
;
73 case SIDE_ATTR_TYPE_U64
:
74 val
= attr
->value
.u
.integer_value
.side_u64
;
76 case SIDE_ATTR_TYPE_S8
:
77 val
= attr
->value
.u
.integer_value
.side_s8
;
79 case SIDE_ATTR_TYPE_S16
:
80 val
= attr
->value
.u
.integer_value
.side_s16
;
82 case SIDE_ATTR_TYPE_S32
:
83 val
= attr
->value
.u
.integer_value
.side_s32
;
85 case SIDE_ATTR_TYPE_S64
:
86 val
= attr
->value
.u
.integer_value
.side_s64
;
89 fprintf(stderr
, "Unexpected attribute type\n");
96 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
97 enum tracer_display_base default_base
)
101 for (i
= 0; i
< nr_attr
; i
++) {
102 const struct side_attr
*attr
= &_attr
[i
];
104 if (!strcmp(attr
->key
, "std.integer.base")) {
105 int64_t val
= get_attr_integer_value(attr
);
109 return TRACER_DISPLAY_BASE_2
;
111 return TRACER_DISPLAY_BASE_8
;
113 return TRACER_DISPLAY_BASE_10
;
115 return TRACER_DISPLAY_BASE_16
;
117 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
122 return default_base
; /* Default */
126 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
128 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
129 switch (attr
->value
.type
) {
130 case SIDE_ATTR_TYPE_BOOL
:
131 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
133 case SIDE_ATTR_TYPE_U8
:
134 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
136 case SIDE_ATTR_TYPE_U16
:
137 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
139 case SIDE_ATTR_TYPE_U32
:
140 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
142 case SIDE_ATTR_TYPE_U64
:
143 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
145 case SIDE_ATTR_TYPE_S8
:
146 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
148 case SIDE_ATTR_TYPE_S16
:
149 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
151 case SIDE_ATTR_TYPE_S32
:
152 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
154 case SIDE_ATTR_TYPE_S64
:
155 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
157 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
159 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
162 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
165 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
167 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
170 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
173 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
175 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
178 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
181 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
183 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
186 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
189 case SIDE_ATTR_TYPE_STRING
:
190 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
193 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
200 void print_attributes(const char *prefix_str
, const char *separator
,
201 const struct side_attr
*attr
, uint32_t nr_attr
)
207 printf("%s%s [ ", prefix_str
, separator
);
208 for (i
= 0; i
< nr_attr
; i
++) {
209 printf("%s", i
? ", " : "");
210 tracer_print_attr_type(separator
, &attr
[i
]);
216 union int64_value
tracer_load_integer_value(const struct side_type_integer
*type_integer
,
217 const union side_integer_value
*value
,
218 uint16_t offset_bits
, uint16_t *_len_bits
)
220 union int64_value v64
;
224 if (!type_integer
->len_bits
)
225 len_bits
= type_integer
->integer_size
* CHAR_BIT
;
227 len_bits
= type_integer
->len_bits
;
228 if (len_bits
+ offset_bits
> type_integer
->integer_size
* CHAR_BIT
)
230 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
231 switch (type_integer
->integer_size
) {
233 if (type_integer
->signedness
)
234 v64
.s
= value
->side_s8
;
236 v64
.u
= value
->side_u8
;
239 if (type_integer
->signedness
) {
242 side_s16
= value
->side_s16
;
244 side_s16
= side_bswap_16(side_s16
);
249 side_u16
= value
->side_u16
;
251 side_u16
= side_bswap_16(side_u16
);
256 if (type_integer
->signedness
) {
259 side_s32
= value
->side_s32
;
261 side_s32
= side_bswap_32(side_s32
);
266 side_u32
= value
->side_u32
;
268 side_u32
= side_bswap_32(side_u32
);
273 if (type_integer
->signedness
) {
276 side_s64
= value
->side_s64
;
278 side_s64
= side_bswap_64(side_s64
);
283 side_u64
= value
->side_u64
;
285 side_u64
= side_bswap_64(side_u64
);
292 v64
.u
>>= offset_bits
;
294 v64
.u
&= (1ULL << len_bits
) - 1;
295 if (type_integer
->signedness
) {
297 if (v64
.u
& (1ULL << (len_bits
- 1)))
298 v64
.u
|= ~((1ULL << len_bits
) - 1);
302 *_len_bits
= len_bits
;
307 void print_enum_labels(const struct side_type
*type_desc
, union int64_value v64
)
309 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
310 uint32_t i
, print_count
= 0;
312 printf(", labels: [ ");
313 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
314 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
316 if (mapping
->range_end
< mapping
->range_begin
) {
317 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
318 mapping
->range_begin
, mapping
->range_end
);
321 if (v64
.s
>= mapping
->range_begin
&& v64
.s
<= mapping
->range_end
) {
322 printf("%s", print_count
++ ? ", " : "");
323 printf("\"%s\"", mapping
->label
);
327 printf("<NO LABEL>");
332 void tracer_print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
334 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
335 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
336 union int64_value v64
;
338 if (elem_type
->type
!= item
->type
) {
339 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
342 v64
= tracer_load_integer_value(&elem_type
->u
.side_integer
,
343 &item
->u
.side_static
.integer_value
, 0, NULL
);
344 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
345 printf("%s", mappings
->nr_attr
? ", " : "");
346 tracer_print_type(elem_type
, item
);
347 print_enum_labels(type_desc
, v64
);
351 uint32_t 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 tracer_print_enum_bitmap(const struct side_type
*type_desc
,
378 const struct side_arg
*item
)
380 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
381 const struct side_type
*enum_elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
, *elem_type
;
382 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
383 const struct side_arg
*array_item
;
385 switch (enum_elem_type
->type
) {
386 case SIDE_TYPE_U8
: /* Fall-through */
387 case SIDE_TYPE_BYTE
: /* Fall-through */
388 case SIDE_TYPE_U16
: /* Fall-through */
389 case SIDE_TYPE_U32
: /* Fall-through */
391 elem_type
= enum_elem_type
;
395 case SIDE_TYPE_ARRAY
:
396 elem_type
= enum_elem_type
->u
.side_array
.elem_type
;
397 array_item
= item
->u
.side_static
.side_array
->sav
;
398 nr_items
= type_desc
->u
.side_array
.length
;
401 elem_type
= enum_elem_type
->u
.side_vla
.elem_type
;
402 array_item
= item
->u
.side_static
.side_vla
->sav
;
403 nr_items
= item
->u
.side_static
.side_vla
->len
;
406 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
409 stride_bit
= elem_type_to_stride(elem_type
);
411 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
412 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
413 printf("labels: [ ");
414 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
415 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
419 if (mapping
->range_end
< mapping
->range_begin
) {
420 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
421 mapping
->range_begin
, mapping
->range_end
);
424 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
425 if (bit
> (nr_items
* stride_bit
) - 1)
427 if (elem_type
->type
== SIDE_TYPE_BYTE
) {
428 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.byte_value
;
429 if (v
& (1ULL << (bit
% 8))) {
434 union int64_value v64
;
436 v64
= tracer_load_integer_value(&elem_type
->u
.side_integer
,
437 &array_item
[bit
/ stride_bit
].u
.side_static
.integer_value
,
439 if (v64
.u
& (1ULL << (bit
% stride_bit
))) {
447 printf("%s", print_count
++ ? ", " : "");
448 printf("\"%s\"", mapping
->label
);
452 printf("<NO LABEL>");
457 void print_integer_binary(uint64_t v
, int bits
)
463 for (i
= 0; i
< bits
; i
++) {
464 printf("%c", v
& (1ULL << 63) ? '1' : '0');
470 void tracer_print_type_header(const char *separator
,
471 const struct side_attr
*attr
, uint32_t nr_attr
)
473 print_attributes("attr", separator
, attr
, nr_attr
);
474 printf("%s", nr_attr
? ", " : "");
475 printf("value%s ", separator
);
479 void tracer_print_type_bool(const char *separator
,
480 const struct side_type_bool
*type_bool
,
481 const union side_bool_value
*value
,
482 uint16_t offset_bits
)
488 if (!type_bool
->len_bits
)
489 len_bits
= type_bool
->bool_size
* CHAR_BIT
;
491 len_bits
= type_bool
->len_bits
;
492 if (len_bits
+ offset_bits
> type_bool
->bool_size
* CHAR_BIT
)
494 reverse_bo
= type_bool
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
495 switch (type_bool
->bool_size
) {
497 v
= value
->side_bool8
;
503 side_u16
= value
->side_bool16
;
505 side_u16
= side_bswap_16(side_u16
);
513 side_u32
= value
->side_bool32
;
515 side_u32
= side_bswap_32(side_u32
);
523 side_u64
= value
->side_bool64
;
525 side_u64
= side_bswap_64(side_u64
);
534 v
&= (1ULL << len_bits
) - 1;
535 tracer_print_type_header(separator
, type_bool
->attr
, type_bool
->nr_attr
);
536 printf("%s", v
? "true" : "false");
540 void tracer_print_type_integer(const char *separator
,
541 const struct side_type_integer
*type_integer
,
542 const union side_integer_value
*value
,
543 uint16_t offset_bits
,
544 enum tracer_display_base default_base
)
546 enum tracer_display_base base
;
547 union int64_value v64
;
550 v64
= tracer_load_integer_value(type_integer
, value
, offset_bits
, &len_bits
);
551 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
552 base
= get_attr_display_base(type_integer
->attr
, type_integer
->nr_attr
, default_base
);
554 case TRACER_DISPLAY_BASE_2
:
555 print_integer_binary(v64
.u
, len_bits
);
557 case TRACER_DISPLAY_BASE_8
:
558 /* Clear sign bits beyond len_bits */
560 v64
.u
&= (1ULL << len_bits
) - 1;
561 printf("0%" PRIo64
, v64
.u
);
563 case TRACER_DISPLAY_BASE_10
:
564 if (type_integer
->signedness
)
565 printf("%" PRId64
, v64
.s
);
567 printf("%" PRIu64
, v64
.u
);
569 case TRACER_DISPLAY_BASE_16
:
570 /* Clear sign bits beyond len_bits */
572 v64
.u
&= (1ULL << len_bits
) - 1;
573 printf("0x%" PRIx64
, v64
.u
);
581 void tracer_print_type_float(const char *separator
,
582 const struct side_type_float
*type_float
,
583 const union side_float_value
*value
)
587 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
588 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
589 switch (type_float
->float_size
) {
597 .f
= value
->side_float_binary16
,
601 float16
.u
= side_bswap_16(float16
.u
);
602 printf("%g", (double) float16
.f
);
605 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
616 .f
= value
->side_float_binary32
,
620 float32
.u
= side_bswap_32(float32
.u
);
621 printf("%g", (double) float32
.f
);
624 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
635 .f
= value
->side_float_binary64
,
639 float64
.u
= side_bswap_64(float64
.u
);
640 printf("%g", (double) float64
.f
);
643 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
654 .f
= value
->side_float_binary128
,
658 side_bswap_128p(float128
.arr
);
659 printf("%Lg", (long double) float128
.f
);
662 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
667 fprintf(stderr
, "ERROR: Unknown float size\n");
673 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
675 enum side_type_label type
;
677 switch (type_desc
->type
) {
679 switch (item
->type
) {
690 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
696 case SIDE_TYPE_ENUM_BITMAP
:
697 switch (item
->type
) {
703 case SIDE_TYPE_ARRAY
:
707 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
713 case SIDE_TYPE_DYNAMIC
:
714 switch (item
->type
) {
715 case SIDE_TYPE_DYNAMIC_NULL
:
716 case SIDE_TYPE_DYNAMIC_BOOL
:
717 case SIDE_TYPE_DYNAMIC_INTEGER
:
718 case SIDE_TYPE_DYNAMIC_BYTE
:
719 case SIDE_TYPE_DYNAMIC_POINTER
:
720 case SIDE_TYPE_DYNAMIC_FLOAT
:
721 case SIDE_TYPE_DYNAMIC_STRING
:
722 case SIDE_TYPE_DYNAMIC_STRUCT
:
723 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
724 case SIDE_TYPE_DYNAMIC_VLA
:
725 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
728 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
735 if (type_desc
->type
!= item
->type
) {
736 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
742 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
743 type
= (enum side_type_label
) type_desc
->type
;
745 type
= (enum side_type_label
) item
->type
;
749 /* Stack-copy basic types */
751 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
752 printf("<NULL TYPE>");
756 tracer_print_type_bool(":", &type_desc
->u
.side_bool
, &item
->u
.side_static
.bool_value
, 0);
767 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
768 TRACER_DISPLAY_BASE_10
);
772 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
773 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
776 case SIDE_TYPE_POINTER
:
777 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
778 TRACER_DISPLAY_BASE_16
);
781 case SIDE_TYPE_FLOAT_BINARY16
:
782 case SIDE_TYPE_FLOAT_BINARY32
:
783 case SIDE_TYPE_FLOAT_BINARY64
:
784 case SIDE_TYPE_FLOAT_BINARY128
:
785 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
788 case SIDE_TYPE_STRING
:
789 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
790 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
793 /* Stack-copy compound types */
794 case SIDE_TYPE_STRUCT
:
795 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
797 case SIDE_TYPE_ARRAY
:
798 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
801 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
803 case SIDE_TYPE_VLA_VISITOR
:
804 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
807 /* Stack-copy enumeration types */
809 tracer_print_enum(type_desc
, item
);
811 case SIDE_TYPE_ENUM_BITMAP
:
812 tracer_print_enum_bitmap(type_desc
, item
);
815 /* Gather basic types */
816 case SIDE_TYPE_GATHER_BOOL
:
817 (void) tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_bool_gather_ptr
);
819 case SIDE_TYPE_GATHER_INTEGER
:
820 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
821 TRACER_DISPLAY_BASE_10
);
823 case SIDE_TYPE_GATHER_BYTE
:
824 (void) tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_byte_gather_ptr
);
826 case SIDE_TYPE_GATHER_POINTER
:
827 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
828 TRACER_DISPLAY_BASE_16
);
830 case SIDE_TYPE_GATHER_FLOAT
:
831 (void) tracer_print_gather_float_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_float_gather_ptr
);
834 /* Gather compound type */
835 case SIDE_TYPE_GATHER_STRUCT
:
836 (void) tracer_print_gather_struct(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_struct_gather_ptr
);
838 case SIDE_TYPE_GATHER_ARRAY
:
839 (void) tracer_print_gather_array(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_array_gather_ptr
);
841 case SIDE_TYPE_GATHER_VLA
:
842 (void) tracer_print_gather_vla(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_vla_gather
.ptr
,
843 item
->u
.side_static
.side_vla_gather
.length_ptr
);
846 /* Dynamic basic types */
847 case SIDE_TYPE_DYNAMIC_NULL
:
848 case SIDE_TYPE_DYNAMIC_BOOL
:
849 case SIDE_TYPE_DYNAMIC_INTEGER
:
850 case SIDE_TYPE_DYNAMIC_BYTE
:
851 case SIDE_TYPE_DYNAMIC_POINTER
:
852 case SIDE_TYPE_DYNAMIC_FLOAT
:
853 case SIDE_TYPE_DYNAMIC_STRING
:
855 /* Dynamic compound types */
856 case SIDE_TYPE_DYNAMIC_STRUCT
:
857 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
858 case SIDE_TYPE_DYNAMIC_VLA
:
859 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
860 tracer_print_dynamic(item
);
863 fprintf(stderr
, "<UNKNOWN TYPE>\n");
870 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
872 printf("%s: ", item_desc
->field_name
);
873 tracer_print_type(&item_desc
->side_type
, item
);
877 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
879 const struct side_arg
*sav
= side_arg_vec
->sav
;
880 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
882 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
883 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
886 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
887 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
888 printf("fields: { ");
889 for (i
= 0; i
< side_sav_len
; i
++) {
890 printf("%s", i
? ", " : "");
891 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
897 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
899 const struct side_arg
*sav
= side_arg_vec
->sav
;
900 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
902 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
903 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
906 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
907 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
908 printf("elements: ");
910 for (i
= 0; i
< side_sav_len
; i
++) {
911 printf("%s", i
? ", " : "");
912 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
918 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
920 const struct side_arg
*sav
= side_arg_vec
->sav
;
921 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
923 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
924 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
925 printf("elements: ");
927 for (i
= 0; i
< side_sav_len
; i
++) {
928 printf("%s", i
? ", " : "");
929 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
935 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode
, const char *ptr
)
937 switch (access_mode
) {
938 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
940 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
941 /* Dereference pointer */
942 memcpy(&ptr
, ptr
, sizeof(ptr
));
950 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode
, uint32_t len
)
952 switch (access_mode
) {
953 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
955 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
956 return sizeof(void *);
963 union int64_value
tracer_load_gather_integer_value(const struct side_type_gather
*type_gather
,
964 const void *_ptr
, uint16_t offset_bits
)
966 enum side_type_gather_access_mode access_mode
=
967 (enum side_type_gather_access_mode
) type_gather
->u
.side_integer
.access_mode
;
968 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
969 const char *ptr
= (const char *) _ptr
;
970 union side_integer_value value
;
972 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
973 memcpy(&value
, ptr
, integer_size_bytes
);
974 return tracer_load_integer_value(&type_gather
->u
.side_integer
.type
, &value
, offset_bits
, NULL
);
978 uint32_t tracer_print_gather_bool_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
980 enum side_type_gather_access_mode access_mode
=
981 (enum side_type_gather_access_mode
) type_gather
->u
.side_bool
.access_mode
;
982 uint32_t bool_size_bytes
= type_gather
->u
.side_bool
.type
.bool_size
;
983 const char *ptr
= (const char *) _ptr
;
984 union side_bool_value value
;
986 switch (bool_size_bytes
) {
995 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_bool
.offset
);
996 memcpy(&value
, ptr
, bool_size_bytes
);
997 tracer_print_type_bool(":", &type_gather
->u
.side_bool
.type
, &value
,
998 type_gather
->u
.side_bool
.offset_bits
);
999 return tracer_gather_size(access_mode
, bool_size_bytes
);
1003 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1005 enum side_type_gather_access_mode access_mode
=
1006 (enum side_type_gather_access_mode
) type_gather
->u
.side_byte
.access_mode
;
1007 const char *ptr
= (const char *) _ptr
;
1010 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_byte
.offset
);
1011 memcpy(&value
, ptr
, 1);
1012 tracer_print_type_header(":", type_gather
->u
.side_byte
.type
.attr
,
1013 type_gather
->u
.side_byte
.type
.nr_attr
);
1014 printf("0x%" PRIx8
, value
);
1015 return tracer_gather_size(access_mode
, 1);
1019 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
,
1020 enum tracer_display_base default_base
)
1022 enum side_type_gather_access_mode access_mode
=
1023 (enum side_type_gather_access_mode
) type_gather
->u
.side_integer
.access_mode
;
1024 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1025 const char *ptr
= (const char *) _ptr
;
1026 union side_integer_value value
;
1028 switch (integer_size_bytes
) {
1037 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1038 memcpy(&value
, ptr
, integer_size_bytes
);
1039 tracer_print_type_integer(":", &type_gather
->u
.side_integer
.type
, &value
,
1040 type_gather
->u
.side_integer
.offset_bits
, default_base
);
1041 return tracer_gather_size(access_mode
, integer_size_bytes
);
1045 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1047 enum side_type_gather_access_mode access_mode
=
1048 (enum side_type_gather_access_mode
) type_gather
->u
.side_float
.access_mode
;
1049 uint32_t float_size_bytes
= type_gather
->u
.side_float
.type
.float_size
;
1050 const char *ptr
= (const char *) _ptr
;
1051 union side_float_value value
;
1053 switch (float_size_bytes
) {
1062 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_float
.offset
);
1063 memcpy(&value
, ptr
, float_size_bytes
);
1064 tracer_print_type_float(":", &type_gather
->u
.side_float
.type
, &value
);
1065 return tracer_gather_size(access_mode
, float_size_bytes
);
1069 uint32_t tracer_print_gather_type(const struct side_type
*type_desc
, const void *ptr
)
1074 switch (type_desc
->type
) {
1075 /* Gather basic types */
1076 case SIDE_TYPE_GATHER_BOOL
:
1077 len
= tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, ptr
);
1079 case SIDE_TYPE_GATHER_INTEGER
:
1080 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1081 TRACER_DISPLAY_BASE_10
);
1083 case SIDE_TYPE_GATHER_BYTE
:
1084 len
= tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, ptr
);
1086 case SIDE_TYPE_GATHER_POINTER
:
1087 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1088 TRACER_DISPLAY_BASE_16
);
1090 case SIDE_TYPE_GATHER_FLOAT
:
1091 len
= tracer_print_gather_float_type(&type_desc
->u
.side_gather
, ptr
);
1094 /* Gather compound types */
1095 case SIDE_TYPE_GATHER_STRUCT
:
1096 len
= tracer_print_gather_struct(&type_desc
->u
.side_gather
, ptr
);
1098 case SIDE_TYPE_GATHER_ARRAY
:
1099 len
= tracer_print_gather_array(&type_desc
->u
.side_gather
, ptr
);
1101 case SIDE_TYPE_GATHER_VLA
:
1102 len
= tracer_print_gather_vla(&type_desc
->u
.side_gather
, ptr
, ptr
);
1105 fprintf(stderr
, "<UNKNOWN GATHER TYPE>");
1113 void tracer_print_gather_field(const struct side_event_field
*field
, const void *ptr
)
1115 printf("%s: ", field
->field_name
);
1116 (void) tracer_print_gather_type(&field
->side_type
, ptr
);
1120 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
)
1122 enum side_type_gather_access_mode access_mode
=
1123 (enum side_type_gather_access_mode
) type_gather
->u
.side_struct
.access_mode
;
1124 const char *ptr
= (const char *) _ptr
;
1127 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_struct
.offset
);
1128 print_attributes("attr", ":", type_gather
->u
.side_struct
.type
->attr
, type_gather
->u
.side_struct
.type
->nr_attr
);
1129 printf("%s", type_gather
->u
.side_struct
.type
->nr_attr
? ", " : "");
1130 printf("fields: { ");
1131 for (i
= 0; i
< type_gather
->u
.side_struct
.type
->nr_fields
; i
++) {
1132 printf("%s", i
? ", " : "");
1133 tracer_print_gather_field(&type_gather
->u
.side_struct
.type
->fields
[i
], ptr
);
1136 return tracer_gather_size(access_mode
, type_gather
->u
.side_struct
.size
);
1140 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
)
1142 enum side_type_gather_access_mode access_mode
=
1143 (enum side_type_gather_access_mode
) type_gather
->u
.side_array
.access_mode
;
1144 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1147 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_array
.offset
);
1149 print_attributes("attr", ":", type_gather
->u
.side_array
.type
.attr
, type_gather
->u
.side_array
.type
.nr_attr
);
1150 printf("%s", type_gather
->u
.side_array
.type
.nr_attr
? ", " : "");
1151 printf("elements: ");
1153 for (i
= 0; i
< type_gather
->u
.side_array
.type
.length
; i
++) {
1154 switch (type_gather
->u
.side_array
.type
.elem_type
->type
) {
1155 case SIDE_TYPE_GATHER_VLA
:
1156 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1161 printf("%s", i
? ", " : "");
1162 ptr
+= tracer_print_gather_type(type_gather
->u
.side_array
.type
.elem_type
, ptr
);
1165 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1169 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
1170 const void *_length_ptr
)
1172 enum side_type_gather_access_mode access_mode
=
1173 (enum side_type_gather_access_mode
) type_gather
->u
.side_vla
.access_mode
;
1174 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1175 const char *length_ptr
= (const char *) _length_ptr
;
1176 union int64_value v64
;
1180 switch (type_gather
->u
.side_vla
.length_type
->type
) {
1181 case SIDE_TYPE_GATHER_INTEGER
:
1184 fprintf(stderr
, "<gather VLA expects integer gather length type>\n");
1187 v64
= tracer_load_gather_integer_value(&type_gather
->u
.side_vla
.length_type
->u
.side_gather
,
1189 length
= (uint32_t) v64
.u
;
1190 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_vla
.offset
);
1192 print_attributes("attr", ":", type_gather
->u
.side_vla
.type
.attr
, type_gather
->u
.side_vla
.type
.nr_attr
);
1193 printf("%s", type_gather
->u
.side_vla
.type
.nr_attr
? ", " : "");
1194 printf("elements: ");
1196 for (i
= 0; i
< length
; i
++) {
1197 switch (type_gather
->u
.side_vla
.type
.elem_type
->type
) {
1198 case SIDE_TYPE_GATHER_VLA
:
1199 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1204 printf("%s", i
? ", " : "");
1205 ptr
+= tracer_print_gather_type(type_gather
->u
.side_vla
.type
.elem_type
, ptr
);
1208 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1211 struct tracer_visitor_priv
{
1212 const struct side_type
*elem_type
;
1217 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1218 const struct side_arg
*elem
)
1220 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1222 printf("%s", tracer_priv
->i
++ ? ", " : "");
1223 tracer_print_type(tracer_priv
->elem_type
, elem
);
1224 return SIDE_VISITOR_STATUS_OK
;
1228 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1230 enum side_visitor_status status
;
1231 struct tracer_visitor_priv tracer_priv
= {
1232 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1235 const struct side_tracer_visitor_ctx tracer_ctx
= {
1236 .write_elem
= tracer_write_elem_cb
,
1237 .priv
= &tracer_priv
,
1240 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1241 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1242 printf("elements: ");
1244 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1246 case SIDE_VISITOR_STATUS_OK
:
1248 case SIDE_VISITOR_STATUS_ERROR
:
1249 fprintf(stderr
, "ERROR: Visitor error\n");
1256 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1258 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1259 uint32_t i
, len
= dynamic_struct
->len
;
1261 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1262 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1263 printf("fields:: ");
1265 for (i
= 0; i
< len
; i
++) {
1266 printf("%s", i
? ", " : "");
1267 printf("%s:: ", fields
[i
].field_name
);
1268 tracer_print_dynamic(&fields
[i
].elem
);
1273 struct tracer_dynamic_struct_visitor_priv
{
1278 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1279 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1280 const struct side_arg_dynamic_field
*dynamic_field
)
1282 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1283 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1285 printf("%s", tracer_priv
->i
++ ? ", " : "");
1286 printf("%s:: ", dynamic_field
->field_name
);
1287 tracer_print_dynamic(&dynamic_field
->elem
);
1288 return SIDE_VISITOR_STATUS_OK
;
1292 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1294 enum side_visitor_status status
;
1295 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1298 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1299 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1300 .priv
= &tracer_priv
,
1302 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1304 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1305 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1306 printf("fields:: ");
1308 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1310 case SIDE_VISITOR_STATUS_OK
:
1312 case SIDE_VISITOR_STATUS_ERROR
:
1313 fprintf(stderr
, "ERROR: Visitor error\n");
1320 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1322 const struct side_arg
*sav
= vla
->sav
;
1323 uint32_t i
, side_sav_len
= vla
->len
;
1325 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1326 printf("%s", vla
->nr_attr
? ", " : "");
1327 printf("elements:: ");
1329 for (i
= 0; i
< side_sav_len
; i
++) {
1330 printf("%s", i
? ", " : "");
1331 tracer_print_dynamic(&sav
[i
]);
1336 struct tracer_dynamic_vla_visitor_priv
{
1341 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1342 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1343 const struct side_arg
*elem
)
1345 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1346 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1348 printf("%s", tracer_priv
->i
++ ? ", " : "");
1349 tracer_print_dynamic(elem
);
1350 return SIDE_VISITOR_STATUS_OK
;
1354 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1356 enum side_visitor_status status
;
1357 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1360 const struct side_tracer_visitor_ctx tracer_ctx
= {
1361 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1362 .priv
= &tracer_priv
,
1364 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1366 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1367 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1368 printf("elements:: ");
1370 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1372 case SIDE_VISITOR_STATUS_OK
:
1374 case SIDE_VISITOR_STATUS_ERROR
:
1375 fprintf(stderr
, "ERROR: Visitor error\n");
1382 void tracer_print_dynamic(const struct side_arg
*item
)
1385 switch (item
->type
) {
1386 /* Dynamic basic types */
1387 case SIDE_TYPE_DYNAMIC_NULL
:
1388 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1389 printf("<NULL TYPE>");
1391 case SIDE_TYPE_DYNAMIC_BOOL
:
1392 tracer_print_type_bool("::", &item
->u
.side_dynamic
.side_bool
.type
, &item
->u
.side_dynamic
.side_bool
.value
, 0);
1394 case SIDE_TYPE_DYNAMIC_INTEGER
:
1395 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1396 TRACER_DISPLAY_BASE_10
);
1398 case SIDE_TYPE_DYNAMIC_BYTE
:
1399 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1400 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1402 case SIDE_TYPE_DYNAMIC_POINTER
:
1403 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1404 TRACER_DISPLAY_BASE_16
);
1406 case SIDE_TYPE_DYNAMIC_FLOAT
:
1407 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1408 &item
->u
.side_dynamic
.side_float
.value
);
1410 case SIDE_TYPE_DYNAMIC_STRING
:
1411 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1412 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1415 /* Dynamic compound types */
1416 case SIDE_TYPE_DYNAMIC_STRUCT
:
1417 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1419 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1420 tracer_print_dynamic_struct_visitor(item
);
1422 case SIDE_TYPE_DYNAMIC_VLA
:
1423 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1425 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1426 tracer_print_dynamic_vla_visitor(item
);
1429 fprintf(stderr
, "<UNKNOWN TYPE>\n");
1436 void tracer_print_static_fields(const struct side_event_description
*desc
,
1437 const struct side_arg_vec
*side_arg_vec
,
1440 const struct side_arg
*sav
= side_arg_vec
->sav
;
1441 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1443 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1444 if (desc
->nr_fields
!= side_sav_len
) {
1445 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1448 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1449 printf("%s", side_sav_len
? ", fields: [ " : "");
1450 for (i
= 0; i
< side_sav_len
; i
++) {
1451 printf("%s", i
? ", " : "");
1452 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1460 void tracer_call(const struct side_event_description
*desc
,
1461 const struct side_arg_vec
*side_arg_vec
,
1462 void *priv
__attribute__((unused
)))
1464 uint32_t nr_fields
= 0;
1466 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1470 void tracer_call_variadic(const struct side_event_description
*desc
,
1471 const struct side_arg_vec
*side_arg_vec
,
1472 const struct side_arg_dynamic_struct
*var_struct
,
1473 void *priv
__attribute__((unused
)))
1475 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1477 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1479 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1480 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1483 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1484 printf("%s", var_struct_len
? ", fields:: [ " : "");
1485 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1486 printf("%s", i
? ", " : "");
1487 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1488 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1495 void tracer_event_notification(enum side_tracer_notification notif
,
1496 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1501 printf("----------------------------------------------------------\n");
1502 printf("Tracer notified of events %s\n",
1503 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1504 for (i
= 0; i
< nr_events
; i
++) {
1505 struct side_event_description
*event
= events
[i
];
1507 /* Skip NULL pointers */
1510 printf("provider: %s, event: %s\n",
1511 event
->provider_name
, event
->event_name
);
1512 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1513 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1514 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1518 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1523 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1524 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1528 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1534 printf("----------------------------------------------------------\n");
1537 static __attribute__((constructor
))
1538 void tracer_init(void);
1540 void tracer_init(void)
1542 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1547 static __attribute__((destructor
))
1548 void tracer_exit(void);
1550 void tracer_exit(void)
1552 side_tracer_event_notification_unregister(tracer_handle
);