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 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
128 switch (type_desc
->type
) {
139 case SIDE_TYPE_POINTER
:
140 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
145 case SIDE_TYPE_FLOAT_BINARY16
:
146 case SIDE_TYPE_FLOAT_BINARY32
:
147 case SIDE_TYPE_FLOAT_BINARY64
:
148 case SIDE_TYPE_FLOAT_BINARY128
:
149 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
155 fprintf(stderr
, "Unexpected type\n");
161 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
163 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
164 switch (attr
->value
.type
) {
165 case SIDE_ATTR_TYPE_BOOL
:
166 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
168 case SIDE_ATTR_TYPE_U8
:
169 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
171 case SIDE_ATTR_TYPE_U16
:
172 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
174 case SIDE_ATTR_TYPE_U32
:
175 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
177 case SIDE_ATTR_TYPE_U64
:
178 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
180 case SIDE_ATTR_TYPE_S8
:
181 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
183 case SIDE_ATTR_TYPE_S16
:
184 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
186 case SIDE_ATTR_TYPE_S32
:
187 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
189 case SIDE_ATTR_TYPE_S64
:
190 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
192 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
194 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
197 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
200 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
202 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
205 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
208 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
210 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
213 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
216 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
218 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
221 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
224 case SIDE_ATTR_TYPE_STRING
:
225 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
228 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
235 void print_attributes(const char *prefix_str
, const char *separator
,
236 const struct side_attr
*attr
, uint32_t nr_attr
)
242 printf("%s%s [ ", prefix_str
, separator
);
243 for (i
= 0; i
< nr_attr
; i
++) {
244 printf("%s", i
? ", " : "");
245 tracer_print_attr_type(separator
, &attr
[i
]);
251 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
253 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
254 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
255 uint32_t i
, print_count
= 0;
258 if (elem_type
->type
!= item
->type
) {
259 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
262 switch (item
->type
) {
264 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
270 v
= item
->u
.side_static
.integer_value
.side_u16
;
271 if (type_to_host_reverse_bo(elem_type
))
272 v
= side_bswap_16(v
);
280 v
= item
->u
.side_static
.integer_value
.side_u32
;
281 if (type_to_host_reverse_bo(elem_type
))
282 v
= side_bswap_32(v
);
290 v
= item
->u
.side_static
.integer_value
.side_u64
;
291 if (type_to_host_reverse_bo(elem_type
))
292 v
= side_bswap_64(v
);
297 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
303 v
= item
->u
.side_static
.integer_value
.side_s16
;
304 if (type_to_host_reverse_bo(elem_type
))
305 v
= side_bswap_16(v
);
313 v
= item
->u
.side_static
.integer_value
.side_s32
;
314 if (type_to_host_reverse_bo(elem_type
))
315 v
= side_bswap_32(v
);
323 v
= item
->u
.side_static
.integer_value
.side_s64
;
324 if (type_to_host_reverse_bo(elem_type
))
325 v
= side_bswap_64(v
);
330 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
333 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
334 printf("%s", mappings
->nr_attr
? ", " : "");
335 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
336 printf(", labels: [ ");
337 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
338 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
340 if (mapping
->range_end
< mapping
->range_begin
) {
341 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
342 mapping
->range_begin
, mapping
->range_end
);
345 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
346 printf("%s", print_count
++ ? ", " : "");
347 printf("\"%s\"", mapping
->label
);
351 printf("<NO LABEL>");
356 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
360 switch (elem_type
->type
) {
361 case SIDE_TYPE_U8
: /* Fall-through */
375 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
382 void print_enum_bitmap(const struct side_type
*type_desc
,
383 const struct side_arg
*item
)
385 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
386 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
387 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
388 bool reverse_byte_order
= false;
389 const struct side_arg
*array_item
;
391 switch (elem_type
->type
) {
392 case SIDE_TYPE_U8
: /* Fall-through */
393 case SIDE_TYPE_BYTE
: /* Fall-through */
394 case SIDE_TYPE_U16
: /* Fall-through */
395 case SIDE_TYPE_U32
: /* Fall-through */
397 stride_bit
= enum_elem_type_to_stride(elem_type
);
398 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
402 case SIDE_TYPE_ARRAY
:
403 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
404 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
405 array_item
= item
->u
.side_static
.side_array
->sav
;
406 nr_items
= type_desc
->u
.side_array
.length
;
409 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
410 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
411 array_item
= item
->u
.side_static
.side_vla
->sav
;
412 nr_items
= item
->u
.side_static
.side_vla
->len
;
415 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
419 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
420 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
421 printf("labels: [ ");
422 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
423 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
427 if (mapping
->range_end
< mapping
->range_begin
) {
428 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
429 mapping
->range_begin
, mapping
->range_end
);
432 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
433 if (bit
> (nr_items
* stride_bit
) - 1)
435 switch (stride_bit
) {
438 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
439 if (v
& (1ULL << (bit
% 8))) {
447 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
448 if (reverse_byte_order
)
449 v
= side_bswap_16(v
);
450 if (v
& (1ULL << (bit
% 16))) {
458 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
459 if (reverse_byte_order
)
460 v
= side_bswap_32(v
);
461 if (v
& (1ULL << (bit
% 32))) {
469 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
470 if (reverse_byte_order
)
471 v
= side_bswap_64(v
);
472 if (v
& (1ULL << (bit
% 64))) {
484 printf("%s", print_count
++ ? ", " : "");
485 printf("\"%s\"", mapping
->label
);
489 printf("<NO LABEL>");
494 void print_integer_binary(uint64_t v
, int bits
)
500 for (i
= 0; i
< bits
; i
++) {
501 printf("%c", v
& (1ULL << 63) ? '1' : '0');
507 void tracer_print_type_header(const char *separator
,
508 const struct side_attr
*attr
, uint32_t nr_attr
)
510 print_attributes("attr", separator
, attr
, nr_attr
);
511 printf("%s", nr_attr
? ", " : "");
512 printf("value%s ", separator
);
516 void tracer_print_type_bool(const char *separator
,
517 const struct side_type_bool
*type_bool
,
518 const union side_bool_value
*value
,
519 uint16_t offset_bits
)
525 if (!type_bool
->len_bits
)
526 len_bits
= type_bool
->bool_size
* CHAR_BIT
;
528 len_bits
= type_bool
->len_bits
;
529 if (len_bits
+ offset_bits
> type_bool
->bool_size
* CHAR_BIT
)
531 reverse_bo
= type_bool
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
532 switch (type_bool
->bool_size
) {
534 v
= value
->side_bool8
;
540 side_u16
= value
->side_bool16
;
542 side_u16
= side_bswap_16(side_u16
);
550 side_u32
= value
->side_bool32
;
552 side_u32
= side_bswap_32(side_u32
);
560 side_u64
= value
->side_bool64
;
562 side_u64
= side_bswap_64(side_u64
);
571 v
&= (1ULL << len_bits
) - 1;
572 tracer_print_type_header(separator
, type_bool
->attr
, type_bool
->nr_attr
);
573 printf("%s", v
? "true" : "false");
577 union int64_value
tracer_load_integer_value(const struct side_type_integer
*type_integer
,
578 const union side_integer_value
*value
,
579 uint16_t offset_bits
, uint16_t *_len_bits
)
581 union int64_value v64
;
585 if (!type_integer
->len_bits
)
586 len_bits
= type_integer
->integer_size
* CHAR_BIT
;
588 len_bits
= type_integer
->len_bits
;
589 if (len_bits
+ offset_bits
> type_integer
->integer_size
* CHAR_BIT
)
591 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
592 switch (type_integer
->integer_size
) {
594 if (type_integer
->signedness
)
595 v64
.s
= value
->side_s8
;
597 v64
.u
= value
->side_u8
;
600 if (type_integer
->signedness
) {
603 side_s16
= value
->side_s16
;
605 side_s16
= side_bswap_16(side_s16
);
610 side_u16
= value
->side_u16
;
612 side_u16
= side_bswap_16(side_u16
);
617 if (type_integer
->signedness
) {
620 side_s32
= value
->side_s32
;
622 side_s32
= side_bswap_32(side_s32
);
627 side_u32
= value
->side_u32
;
629 side_u32
= side_bswap_32(side_u32
);
634 if (type_integer
->signedness
) {
637 side_s64
= value
->side_s64
;
639 side_s64
= side_bswap_64(side_s64
);
644 side_u64
= value
->side_u64
;
646 side_u64
= side_bswap_64(side_u64
);
653 v64
.u
>>= offset_bits
;
655 v64
.u
&= (1ULL << len_bits
) - 1;
657 *_len_bits
= len_bits
;
662 void tracer_print_type_integer(const char *separator
,
663 const struct side_type_integer
*type_integer
,
664 const union side_integer_value
*value
,
665 uint16_t offset_bits
,
666 enum tracer_display_base default_base
)
668 enum tracer_display_base base
;
669 union int64_value v64
;
672 v64
= tracer_load_integer_value(type_integer
, value
, offset_bits
, &len_bits
);
673 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
674 base
= get_attr_display_base(type_integer
->attr
, type_integer
->nr_attr
, default_base
);
676 case TRACER_DISPLAY_BASE_2
:
677 print_integer_binary(v64
.u
, len_bits
);
679 case TRACER_DISPLAY_BASE_8
:
680 printf("0%" PRIo64
, v64
.u
);
682 case TRACER_DISPLAY_BASE_10
:
683 if (type_integer
->signedness
) {
686 if (v64
.u
& (1ULL << (len_bits
- 1)))
687 v64
.u
|= ~((1ULL << len_bits
) - 1);
689 printf("%" PRId64
, v64
.s
);
691 printf("%" PRIu64
, v64
.u
);
694 case TRACER_DISPLAY_BASE_16
:
695 printf("0x%" PRIx64
, v64
.u
);
703 void tracer_print_type_float(const char *separator
,
704 const struct side_type_float
*type_float
,
705 const union side_float_value
*value
)
709 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
710 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
711 switch (type_float
->float_size
) {
719 .f
= value
->side_float_binary16
,
723 float16
.u
= side_bswap_16(float16
.u
);
724 printf("%g", (double) float16
.f
);
727 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
738 .f
= value
->side_float_binary32
,
742 float32
.u
= side_bswap_32(float32
.u
);
743 printf("%g", (double) float32
.f
);
746 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
757 .f
= value
->side_float_binary64
,
761 float64
.u
= side_bswap_64(float64
.u
);
762 printf("%g", (double) float64
.f
);
765 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
776 .f
= value
->side_float_binary128
,
780 side_bswap_128p(float128
.arr
);
781 printf("%Lg", (long double) float128
.f
);
784 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
789 fprintf(stderr
, "ERROR: Unknown float size\n");
795 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
797 enum side_type_label type
;
799 switch (type_desc
->type
) {
801 switch (item
->type
) {
812 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
818 case SIDE_TYPE_ENUM_BITMAP
:
819 switch (item
->type
) {
825 case SIDE_TYPE_ARRAY
:
829 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
835 case SIDE_TYPE_DYNAMIC
:
836 switch (item
->type
) {
837 case SIDE_TYPE_DYNAMIC_NULL
:
838 case SIDE_TYPE_DYNAMIC_BOOL
:
839 case SIDE_TYPE_DYNAMIC_INTEGER
:
840 case SIDE_TYPE_DYNAMIC_BYTE
:
841 case SIDE_TYPE_DYNAMIC_POINTER
:
842 case SIDE_TYPE_DYNAMIC_FLOAT
:
843 case SIDE_TYPE_DYNAMIC_STRING
:
844 case SIDE_TYPE_DYNAMIC_STRUCT
:
845 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
846 case SIDE_TYPE_DYNAMIC_VLA
:
847 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
850 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
857 if (type_desc
->type
!= item
->type
) {
858 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
864 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
865 type
= (enum side_type_label
) type_desc
->type
;
867 type
= (enum side_type_label
) item
->type
;
871 /* Stack-copy basic types */
873 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
874 printf("<NULL TYPE>");
878 tracer_print_type_bool(":", &type_desc
->u
.side_bool
, &item
->u
.side_static
.bool_value
, 0);
889 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
890 TRACER_DISPLAY_BASE_10
);
894 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
895 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
898 case SIDE_TYPE_POINTER
:
899 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
900 TRACER_DISPLAY_BASE_16
);
903 case SIDE_TYPE_FLOAT_BINARY16
:
904 case SIDE_TYPE_FLOAT_BINARY32
:
905 case SIDE_TYPE_FLOAT_BINARY64
:
906 case SIDE_TYPE_FLOAT_BINARY128
:
907 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
910 case SIDE_TYPE_STRING
:
911 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
912 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
915 /* Stack-copy compound types */
916 case SIDE_TYPE_STRUCT
:
917 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
919 case SIDE_TYPE_ARRAY
:
920 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
923 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
925 case SIDE_TYPE_VLA_VISITOR
:
926 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
929 /* Stack-copy enumeration types */
931 print_enum(type_desc
, item
);
933 case SIDE_TYPE_ENUM_BITMAP
:
934 print_enum_bitmap(type_desc
, item
);
937 /* Gather basic types */
938 case SIDE_TYPE_GATHER_BOOL
:
939 (void) tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_bool_gather_ptr
);
941 case SIDE_TYPE_GATHER_INTEGER
:
942 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
943 TRACER_DISPLAY_BASE_10
);
945 case SIDE_TYPE_GATHER_BYTE
:
946 (void) tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_byte_gather_ptr
);
948 case SIDE_TYPE_GATHER_POINTER
:
949 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
,
950 TRACER_DISPLAY_BASE_16
);
952 case SIDE_TYPE_GATHER_FLOAT
:
953 (void) tracer_print_gather_float_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_float_gather_ptr
);
956 /* Gather compound type */
957 case SIDE_TYPE_GATHER_STRUCT
:
958 (void) tracer_print_gather_struct(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_struct_gather_ptr
);
960 case SIDE_TYPE_GATHER_ARRAY
:
961 (void) tracer_print_gather_array(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_array_gather_ptr
);
963 case SIDE_TYPE_GATHER_VLA
:
964 (void) tracer_print_gather_vla(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_vla_gather
.ptr
,
965 item
->u
.side_static
.side_vla_gather
.length_ptr
);
968 /* Dynamic basic types */
969 case SIDE_TYPE_DYNAMIC_NULL
:
970 case SIDE_TYPE_DYNAMIC_BOOL
:
971 case SIDE_TYPE_DYNAMIC_INTEGER
:
972 case SIDE_TYPE_DYNAMIC_BYTE
:
973 case SIDE_TYPE_DYNAMIC_POINTER
:
974 case SIDE_TYPE_DYNAMIC_FLOAT
:
975 case SIDE_TYPE_DYNAMIC_STRING
:
977 /* Dynamic compound types */
978 case SIDE_TYPE_DYNAMIC_STRUCT
:
979 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
980 case SIDE_TYPE_DYNAMIC_VLA
:
981 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
982 tracer_print_dynamic(item
);
985 fprintf(stderr
, "<UNKNOWN TYPE>\n");
992 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
994 printf("%s: ", item_desc
->field_name
);
995 tracer_print_type(&item_desc
->side_type
, item
);
999 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1001 const struct side_arg
*sav
= side_arg_vec
->sav
;
1002 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1004 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
1005 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
1008 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1009 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1010 printf("fields: { ");
1011 for (i
= 0; i
< side_sav_len
; i
++) {
1012 printf("%s", i
? ", " : "");
1013 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1019 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1021 const struct side_arg
*sav
= side_arg_vec
->sav
;
1022 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1024 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1025 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1028 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1029 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1030 printf("elements: ");
1032 for (i
= 0; i
< side_sav_len
; i
++) {
1033 printf("%s", i
? ", " : "");
1034 tracer_print_type(type_desc
->u
.side_array
.elem_type
, &sav
[i
]);
1040 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1042 const struct side_arg
*sav
= side_arg_vec
->sav
;
1043 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1045 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1046 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1047 printf("elements: ");
1049 for (i
= 0; i
< side_sav_len
; i
++) {
1050 printf("%s", i
? ", " : "");
1051 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1057 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode
, const char *ptr
)
1059 switch (access_mode
) {
1060 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
1062 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1063 /* Dereference pointer */
1064 memcpy(&ptr
, ptr
, sizeof(ptr
));
1072 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode
, uint32_t len
)
1074 switch (access_mode
) {
1075 case SIDE_TYPE_GATHER_ACCESS_DIRECT
:
1077 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1078 return sizeof(void *);
1085 union int64_value
tracer_load_gather_integer_value(const struct side_type_gather
*type_gather
,
1086 const void *_ptr
, uint16_t offset_bits
)
1088 enum side_type_gather_access_mode access_mode
=
1089 (enum side_type_gather_access_mode
) type_gather
->u
.side_integer
.access_mode
;
1090 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1091 const char *ptr
= (const char *) _ptr
;
1092 union side_integer_value value
;
1094 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1095 memcpy(&value
, ptr
, integer_size_bytes
);
1096 return tracer_load_integer_value(&type_gather
->u
.side_integer
.type
, &value
, offset_bits
, NULL
);
1100 uint32_t tracer_print_gather_bool_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1102 enum side_type_gather_access_mode access_mode
=
1103 (enum side_type_gather_access_mode
) type_gather
->u
.side_bool
.access_mode
;
1104 uint32_t bool_size_bytes
= type_gather
->u
.side_bool
.type
.bool_size
;
1105 const char *ptr
= (const char *) _ptr
;
1106 union side_bool_value value
;
1108 switch (bool_size_bytes
) {
1117 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_bool
.offset
);
1118 memcpy(&value
, ptr
, bool_size_bytes
);
1119 tracer_print_type_bool(":", &type_gather
->u
.side_bool
.type
, &value
,
1120 type_gather
->u
.side_bool
.offset_bits
);
1121 return tracer_gather_size(access_mode
, bool_size_bytes
);
1125 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1127 enum side_type_gather_access_mode access_mode
=
1128 (enum side_type_gather_access_mode
) type_gather
->u
.side_byte
.access_mode
;
1129 const char *ptr
= (const char *) _ptr
;
1132 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_byte
.offset
);
1133 memcpy(&value
, ptr
, 1);
1134 tracer_print_type_header(":", type_gather
->u
.side_byte
.type
.attr
,
1135 type_gather
->u
.side_byte
.type
.nr_attr
);
1136 printf("0x%" PRIx8
, value
);
1137 return tracer_gather_size(access_mode
, 1);
1141 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
,
1142 enum tracer_display_base default_base
)
1144 enum side_type_gather_access_mode access_mode
=
1145 (enum side_type_gather_access_mode
) type_gather
->u
.side_integer
.access_mode
;
1146 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size
;
1147 const char *ptr
= (const char *) _ptr
;
1148 union side_integer_value value
;
1150 switch (integer_size_bytes
) {
1159 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1160 memcpy(&value
, ptr
, integer_size_bytes
);
1161 tracer_print_type_integer(":", &type_gather
->u
.side_integer
.type
, &value
,
1162 type_gather
->u
.side_integer
.offset_bits
, default_base
);
1163 return tracer_gather_size(access_mode
, integer_size_bytes
);
1167 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1169 enum side_type_gather_access_mode access_mode
=
1170 (enum side_type_gather_access_mode
) type_gather
->u
.side_float
.access_mode
;
1171 uint32_t float_size_bytes
= type_gather
->u
.side_float
.type
.float_size
;
1172 const char *ptr
= (const char *) _ptr
;
1173 union side_float_value value
;
1175 switch (float_size_bytes
) {
1184 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_float
.offset
);
1185 memcpy(&value
, ptr
, float_size_bytes
);
1186 tracer_print_type_float(":", &type_gather
->u
.side_float
.type
, &value
);
1187 return tracer_gather_size(access_mode
, float_size_bytes
);
1191 uint32_t tracer_print_gather_type(const struct side_type
*type_desc
, const void *ptr
)
1196 switch (type_desc
->type
) {
1197 /* Gather basic types */
1198 case SIDE_TYPE_GATHER_BOOL
:
1199 len
= tracer_print_gather_bool_type(&type_desc
->u
.side_gather
, ptr
);
1201 case SIDE_TYPE_GATHER_INTEGER
:
1202 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1203 TRACER_DISPLAY_BASE_10
);
1205 case SIDE_TYPE_GATHER_BYTE
:
1206 len
= tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, ptr
);
1208 case SIDE_TYPE_GATHER_POINTER
:
1209 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
,
1210 TRACER_DISPLAY_BASE_16
);
1212 case SIDE_TYPE_GATHER_FLOAT
:
1213 len
= tracer_print_gather_float_type(&type_desc
->u
.side_gather
, ptr
);
1216 /* Gather compound types */
1217 case SIDE_TYPE_GATHER_STRUCT
:
1218 len
= tracer_print_gather_struct(&type_desc
->u
.side_gather
, ptr
);
1220 case SIDE_TYPE_GATHER_ARRAY
:
1221 len
= tracer_print_gather_array(&type_desc
->u
.side_gather
, ptr
);
1223 case SIDE_TYPE_GATHER_VLA
:
1224 len
= tracer_print_gather_vla(&type_desc
->u
.side_gather
, ptr
, ptr
);
1227 fprintf(stderr
, "<UNKNOWN GATHER TYPE>");
1235 void tracer_print_gather_field(const struct side_event_field
*field
, const void *ptr
)
1237 printf("%s: ", field
->field_name
);
1238 (void) tracer_print_gather_type(&field
->side_type
, ptr
);
1242 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
)
1244 enum side_type_gather_access_mode access_mode
=
1245 (enum side_type_gather_access_mode
) type_gather
->u
.side_struct
.access_mode
;
1246 const char *ptr
= (const char *) _ptr
;
1249 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_struct
.offset
);
1250 print_attributes("attr", ":", type_gather
->u
.side_struct
.type
->attr
, type_gather
->u
.side_struct
.type
->nr_attr
);
1251 printf("%s", type_gather
->u
.side_struct
.type
->nr_attr
? ", " : "");
1252 printf("fields: { ");
1253 for (i
= 0; i
< type_gather
->u
.side_struct
.type
->nr_fields
; i
++) {
1254 printf("%s", i
? ", " : "");
1255 tracer_print_gather_field(&type_gather
->u
.side_struct
.type
->fields
[i
], ptr
);
1258 return tracer_gather_size(access_mode
, type_gather
->u
.side_struct
.size
);
1262 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
)
1264 enum side_type_gather_access_mode access_mode
=
1265 (enum side_type_gather_access_mode
) type_gather
->u
.side_array
.access_mode
;
1266 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1269 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_array
.offset
);
1271 print_attributes("attr", ":", type_gather
->u
.side_array
.type
.attr
, type_gather
->u
.side_array
.type
.nr_attr
);
1272 printf("%s", type_gather
->u
.side_array
.type
.nr_attr
? ", " : "");
1273 printf("elements: ");
1275 for (i
= 0; i
< type_gather
->u
.side_array
.type
.length
; i
++) {
1276 switch (type_gather
->u
.side_array
.type
.elem_type
->type
) {
1277 case SIDE_TYPE_GATHER_VLA
:
1278 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1283 printf("%s", i
? ", " : "");
1284 ptr
+= tracer_print_gather_type(type_gather
->u
.side_array
.type
.elem_type
, ptr
);
1287 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1291 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
,
1292 const void *_length_ptr
)
1294 enum side_type_gather_access_mode access_mode
=
1295 (enum side_type_gather_access_mode
) type_gather
->u
.side_vla
.access_mode
;
1296 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1297 const char *length_ptr
= (const char *) _length_ptr
;
1298 union int64_value v64
;
1302 switch (type_gather
->u
.side_vla
.length_type
->type
) {
1303 case SIDE_TYPE_GATHER_INTEGER
:
1306 fprintf(stderr
, "<gather VLA expects integer gather length type>\n");
1309 v64
= tracer_load_gather_integer_value(&type_gather
->u
.side_vla
.length_type
->u
.side_gather
,
1311 length
= (uint32_t) v64
.u
;
1312 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_vla
.offset
);
1314 print_attributes("attr", ":", type_gather
->u
.side_vla
.type
.attr
, type_gather
->u
.side_vla
.type
.nr_attr
);
1315 printf("%s", type_gather
->u
.side_vla
.type
.nr_attr
? ", " : "");
1316 printf("elements: ");
1318 for (i
= 0; i
< length
; i
++) {
1319 switch (type_gather
->u
.side_vla
.type
.elem_type
->type
) {
1320 case SIDE_TYPE_GATHER_VLA
:
1321 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1326 printf("%s", i
? ", " : "");
1327 ptr
+= tracer_print_gather_type(type_gather
->u
.side_vla
.type
.elem_type
, ptr
);
1330 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1333 struct tracer_visitor_priv
{
1334 const struct side_type
*elem_type
;
1339 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1340 const struct side_arg
*elem
)
1342 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1344 printf("%s", tracer_priv
->i
++ ? ", " : "");
1345 tracer_print_type(tracer_priv
->elem_type
, elem
);
1346 return SIDE_VISITOR_STATUS_OK
;
1350 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1352 enum side_visitor_status status
;
1353 struct tracer_visitor_priv tracer_priv
= {
1354 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1357 const struct side_tracer_visitor_ctx tracer_ctx
= {
1358 .write_elem
= tracer_write_elem_cb
,
1359 .priv
= &tracer_priv
,
1362 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1363 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1364 printf("elements: ");
1366 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1368 case SIDE_VISITOR_STATUS_OK
:
1370 case SIDE_VISITOR_STATUS_ERROR
:
1371 fprintf(stderr
, "ERROR: Visitor error\n");
1378 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1380 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1381 uint32_t i
, len
= dynamic_struct
->len
;
1383 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1384 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1385 printf("fields:: ");
1387 for (i
= 0; i
< len
; i
++) {
1388 printf("%s", i
? ", " : "");
1389 printf("%s:: ", fields
[i
].field_name
);
1390 tracer_print_dynamic(&fields
[i
].elem
);
1395 struct tracer_dynamic_struct_visitor_priv
{
1400 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1401 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1402 const struct side_arg_dynamic_field
*dynamic_field
)
1404 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1405 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1407 printf("%s", tracer_priv
->i
++ ? ", " : "");
1408 printf("%s:: ", dynamic_field
->field_name
);
1409 tracer_print_dynamic(&dynamic_field
->elem
);
1410 return SIDE_VISITOR_STATUS_OK
;
1414 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1416 enum side_visitor_status status
;
1417 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1420 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1421 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1422 .priv
= &tracer_priv
,
1424 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1426 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1427 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1428 printf("fields:: ");
1430 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1432 case SIDE_VISITOR_STATUS_OK
:
1434 case SIDE_VISITOR_STATUS_ERROR
:
1435 fprintf(stderr
, "ERROR: Visitor error\n");
1442 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1444 const struct side_arg
*sav
= vla
->sav
;
1445 uint32_t i
, side_sav_len
= vla
->len
;
1447 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1448 printf("%s", vla
->nr_attr
? ", " : "");
1449 printf("elements:: ");
1451 for (i
= 0; i
< side_sav_len
; i
++) {
1452 printf("%s", i
? ", " : "");
1453 tracer_print_dynamic(&sav
[i
]);
1458 struct tracer_dynamic_vla_visitor_priv
{
1463 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1464 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1465 const struct side_arg
*elem
)
1467 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1468 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1470 printf("%s", tracer_priv
->i
++ ? ", " : "");
1471 tracer_print_dynamic(elem
);
1472 return SIDE_VISITOR_STATUS_OK
;
1476 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1478 enum side_visitor_status status
;
1479 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1482 const struct side_tracer_visitor_ctx tracer_ctx
= {
1483 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1484 .priv
= &tracer_priv
,
1486 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1488 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1489 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1490 printf("elements:: ");
1492 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1494 case SIDE_VISITOR_STATUS_OK
:
1496 case SIDE_VISITOR_STATUS_ERROR
:
1497 fprintf(stderr
, "ERROR: Visitor error\n");
1504 void tracer_print_dynamic(const struct side_arg
*item
)
1507 switch (item
->type
) {
1508 /* Dynamic basic types */
1509 case SIDE_TYPE_DYNAMIC_NULL
:
1510 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1511 printf("<NULL TYPE>");
1513 case SIDE_TYPE_DYNAMIC_BOOL
:
1514 tracer_print_type_bool("::", &item
->u
.side_dynamic
.side_bool
.type
, &item
->u
.side_dynamic
.side_bool
.value
, 0);
1516 case SIDE_TYPE_DYNAMIC_INTEGER
:
1517 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1518 TRACER_DISPLAY_BASE_10
);
1520 case SIDE_TYPE_DYNAMIC_BYTE
:
1521 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1522 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1524 case SIDE_TYPE_DYNAMIC_POINTER
:
1525 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1526 TRACER_DISPLAY_BASE_16
);
1528 case SIDE_TYPE_DYNAMIC_FLOAT
:
1529 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1530 &item
->u
.side_dynamic
.side_float
.value
);
1532 case SIDE_TYPE_DYNAMIC_STRING
:
1533 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1534 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1537 /* Dynamic compound types */
1538 case SIDE_TYPE_DYNAMIC_STRUCT
:
1539 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1541 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1542 tracer_print_dynamic_struct_visitor(item
);
1544 case SIDE_TYPE_DYNAMIC_VLA
:
1545 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1547 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1548 tracer_print_dynamic_vla_visitor(item
);
1551 fprintf(stderr
, "<UNKNOWN TYPE>\n");
1558 void tracer_print_static_fields(const struct side_event_description
*desc
,
1559 const struct side_arg_vec
*side_arg_vec
,
1562 const struct side_arg
*sav
= side_arg_vec
->sav
;
1563 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1565 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1566 if (desc
->nr_fields
!= side_sav_len
) {
1567 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1570 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1571 printf("%s", side_sav_len
? ", fields: [ " : "");
1572 for (i
= 0; i
< side_sav_len
; i
++) {
1573 printf("%s", i
? ", " : "");
1574 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1582 void tracer_call(const struct side_event_description
*desc
,
1583 const struct side_arg_vec
*side_arg_vec
,
1584 void *priv
__attribute__((unused
)))
1586 uint32_t nr_fields
= 0;
1588 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1592 void tracer_call_variadic(const struct side_event_description
*desc
,
1593 const struct side_arg_vec
*side_arg_vec
,
1594 const struct side_arg_dynamic_struct
*var_struct
,
1595 void *priv
__attribute__((unused
)))
1597 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1599 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1601 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1602 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1605 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1606 printf("%s", var_struct_len
? ", fields:: [ " : "");
1607 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1608 printf("%s", i
? ", " : "");
1609 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1610 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1617 void tracer_event_notification(enum side_tracer_notification notif
,
1618 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1623 printf("----------------------------------------------------------\n");
1624 printf("Tracer notified of events %s\n",
1625 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1626 for (i
= 0; i
< nr_events
; i
++) {
1627 struct side_event_description
*event
= events
[i
];
1629 /* Skip NULL pointers */
1632 printf("provider: %s, event: %s\n",
1633 event
->provider_name
, event
->event_name
);
1634 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1635 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1636 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1640 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1645 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1646 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1650 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1656 printf("----------------------------------------------------------\n");
1659 static __attribute__((constructor
))
1660 void tracer_init(void);
1662 void tracer_init(void)
1664 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1669 static __attribute__((destructor
))
1670 void tracer_exit(void);
1672 void tracer_exit(void)
1674 side_tracer_event_notification_unregister(tracer_handle
);