1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 #include <side/trace.h>
15 enum tracer_display_base
{
16 TRACER_DISPLAY_BASE_2
,
17 TRACER_DISPLAY_BASE_8
,
18 TRACER_DISPLAY_BASE_10
,
19 TRACER_DISPLAY_BASE_16
,
22 static struct side_tracer_handle
*tracer_handle
;
25 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
27 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
29 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
);
31 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
);
33 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
35 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
);
37 void tracer_print_dynamic(const struct side_arg
*dynamic_item
);
39 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
41 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
43 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
);
45 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
);
47 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
);
49 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
);
51 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
);
54 int64_t get_attr_integer_value(const struct side_attr
*attr
)
58 switch (attr
->value
.type
) {
59 case SIDE_ATTR_TYPE_U8
:
60 val
= attr
->value
.u
.integer_value
.side_u8
;
62 case SIDE_ATTR_TYPE_U16
:
63 val
= attr
->value
.u
.integer_value
.side_u16
;
65 case SIDE_ATTR_TYPE_U32
:
66 val
= attr
->value
.u
.integer_value
.side_u32
;
68 case SIDE_ATTR_TYPE_U64
:
69 val
= attr
->value
.u
.integer_value
.side_u64
;
71 case SIDE_ATTR_TYPE_S8
:
72 val
= attr
->value
.u
.integer_value
.side_s8
;
74 case SIDE_ATTR_TYPE_S16
:
75 val
= attr
->value
.u
.integer_value
.side_s16
;
77 case SIDE_ATTR_TYPE_S32
:
78 val
= attr
->value
.u
.integer_value
.side_s32
;
80 case SIDE_ATTR_TYPE_S64
:
81 val
= attr
->value
.u
.integer_value
.side_s64
;
84 fprintf(stderr
, "Unexpected attribute type\n");
91 enum tracer_display_base
get_attr_display_base(const struct side_attr
*_attr
, uint32_t nr_attr
,
92 enum tracer_display_base default_base
)
96 for (i
= 0; i
< nr_attr
; i
++) {
97 const struct side_attr
*attr
= &_attr
[i
];
99 if (!strcmp(attr
->key
, "std.integer.base")) {
100 int64_t val
= get_attr_integer_value(attr
);
104 return TRACER_DISPLAY_BASE_2
;
106 return TRACER_DISPLAY_BASE_8
;
108 return TRACER_DISPLAY_BASE_10
;
110 return TRACER_DISPLAY_BASE_16
;
112 fprintf(stderr
, "Unexpected integer display base: %" PRId64
"\n", val
);
117 return default_base
; /* Default */
121 bool type_to_host_reverse_bo(const struct side_type
*type_desc
)
123 switch (type_desc
->type
) {
134 case SIDE_TYPE_POINTER32
:
135 case SIDE_TYPE_POINTER64
:
136 if (type_desc
->u
.side_integer
.byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
)
141 case SIDE_TYPE_FLOAT_BINARY16
:
142 case SIDE_TYPE_FLOAT_BINARY32
:
143 case SIDE_TYPE_FLOAT_BINARY64
:
144 case SIDE_TYPE_FLOAT_BINARY128
:
145 if (type_desc
->u
.side_float
.byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
)
151 fprintf(stderr
, "Unexpected type\n");
157 void tracer_print_attr_type(const char *separator
, const struct side_attr
*attr
)
159 printf("{ key%s \"%s\", value%s ", separator
, attr
->key
, separator
);
160 switch (attr
->value
.type
) {
161 case SIDE_ATTR_TYPE_BOOL
:
162 printf("%s", attr
->value
.u
.bool_value
? "true" : "false");
164 case SIDE_ATTR_TYPE_U8
:
165 printf("%" PRIu8
, attr
->value
.u
.integer_value
.side_u8
);
167 case SIDE_ATTR_TYPE_U16
:
168 printf("%" PRIu16
, attr
->value
.u
.integer_value
.side_u16
);
170 case SIDE_ATTR_TYPE_U32
:
171 printf("%" PRIu32
, attr
->value
.u
.integer_value
.side_u32
);
173 case SIDE_ATTR_TYPE_U64
:
174 printf("%" PRIu64
, attr
->value
.u
.integer_value
.side_u64
);
176 case SIDE_ATTR_TYPE_S8
:
177 printf("%" PRId8
, attr
->value
.u
.integer_value
.side_s8
);
179 case SIDE_ATTR_TYPE_S16
:
180 printf("%" PRId16
, attr
->value
.u
.integer_value
.side_s16
);
182 case SIDE_ATTR_TYPE_S32
:
183 printf("%" PRId32
, attr
->value
.u
.integer_value
.side_s32
);
185 case SIDE_ATTR_TYPE_S64
:
186 printf("%" PRId64
, attr
->value
.u
.integer_value
.side_s64
);
188 case SIDE_ATTR_TYPE_POINTER32
:
189 printf("0x%" PRIx32
, attr
->value
.u
.integer_value
.side_u32
);
191 case SIDE_ATTR_TYPE_POINTER64
:
192 printf("0x%" PRIx64
, attr
->value
.u
.integer_value
.side_u64
);
194 case SIDE_ATTR_TYPE_FLOAT_BINARY16
:
196 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary16
);
199 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
202 case SIDE_ATTR_TYPE_FLOAT_BINARY32
:
204 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary32
);
207 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
210 case SIDE_ATTR_TYPE_FLOAT_BINARY64
:
212 printf("%g", (double) attr
->value
.u
.float_value
.side_float_binary64
);
215 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
218 case SIDE_ATTR_TYPE_FLOAT_BINARY128
:
220 printf("%Lg", (long double) attr
->value
.u
.float_value
.side_float_binary128
);
223 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
226 case SIDE_ATTR_TYPE_STRING
:
227 printf("\"%s\"", (const char *)(uintptr_t) attr
->value
.u
.string_value
);
230 fprintf(stderr
, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
237 void print_attributes(const char *prefix_str
, const char *separator
,
238 const struct side_attr
*attr
, uint32_t nr_attr
)
244 printf("%s%s [ ", prefix_str
, separator
);
245 for (i
= 0; i
< nr_attr
; i
++) {
246 printf("%s", i
? ", " : "");
247 tracer_print_attr_type(separator
, &attr
[i
]);
253 void print_enum(const struct side_type
*type_desc
, const struct side_arg
*item
)
255 const struct side_enum_mappings
*mappings
= type_desc
->u
.side_enum
.mappings
;
256 const struct side_type
*elem_type
= type_desc
->u
.side_enum
.elem_type
;
257 uint32_t i
, print_count
= 0;
260 if (elem_type
->type
!= item
->type
) {
261 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
264 switch (item
->type
) {
266 value
= (int64_t) item
->u
.side_static
.integer_value
.side_u8
;
272 v
= item
->u
.side_static
.integer_value
.side_u16
;
273 if (type_to_host_reverse_bo(elem_type
))
274 v
= side_bswap_16(v
);
282 v
= item
->u
.side_static
.integer_value
.side_u32
;
283 if (type_to_host_reverse_bo(elem_type
))
284 v
= side_bswap_32(v
);
292 v
= item
->u
.side_static
.integer_value
.side_u64
;
293 if (type_to_host_reverse_bo(elem_type
))
294 v
= side_bswap_64(v
);
299 value
= (int64_t) item
->u
.side_static
.integer_value
.side_s8
;
305 v
= item
->u
.side_static
.integer_value
.side_s16
;
306 if (type_to_host_reverse_bo(elem_type
))
307 v
= side_bswap_16(v
);
315 v
= item
->u
.side_static
.integer_value
.side_s32
;
316 if (type_to_host_reverse_bo(elem_type
))
317 v
= side_bswap_32(v
);
325 v
= item
->u
.side_static
.integer_value
.side_s64
;
326 if (type_to_host_reverse_bo(elem_type
))
327 v
= side_bswap_64(v
);
332 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
335 print_attributes("attr", ":", mappings
->attr
, mappings
->nr_attr
);
336 printf("%s", mappings
->nr_attr
? ", " : "");
337 tracer_print_type(type_desc
->u
.side_enum
.elem_type
, item
);
338 printf(", labels: [ ");
339 for (i
= 0; i
< mappings
->nr_mappings
; i
++) {
340 const struct side_enum_mapping
*mapping
= &mappings
->mappings
[i
];
342 if (mapping
->range_end
< mapping
->range_begin
) {
343 fprintf(stderr
, "ERROR: Unexpected enum range: %" PRIu64
"-%" PRIu64
"\n",
344 mapping
->range_begin
, mapping
->range_end
);
347 if (value
>= mapping
->range_begin
&& value
<= mapping
->range_end
) {
348 printf("%s", print_count
++ ? ", " : "");
349 printf("\"%s\"", mapping
->label
);
353 printf("<NO LABEL>");
358 uint32_t enum_elem_type_to_stride(const struct side_type
*elem_type
)
362 switch (elem_type
->type
) {
363 case SIDE_TYPE_U8
: /* Fall-through */
377 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
384 void print_enum_bitmap(const struct side_type
*type_desc
,
385 const struct side_arg
*item
)
387 const struct side_type
*elem_type
= type_desc
->u
.side_enum_bitmap
.elem_type
;
388 const struct side_enum_bitmap_mappings
*side_enum_mappings
= type_desc
->u
.side_enum_bitmap
.mappings
;
389 uint32_t i
, print_count
= 0, stride_bit
, nr_items
;
390 bool reverse_byte_order
= false;
391 const struct side_arg
*array_item
;
393 switch (elem_type
->type
) {
394 case SIDE_TYPE_U8
: /* Fall-through */
395 case SIDE_TYPE_BYTE
: /* Fall-through */
396 case SIDE_TYPE_U16
: /* Fall-through */
397 case SIDE_TYPE_U32
: /* Fall-through */
399 stride_bit
= enum_elem_type_to_stride(elem_type
);
400 reverse_byte_order
= type_to_host_reverse_bo(elem_type
);
404 case SIDE_TYPE_ARRAY
:
405 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_array
.elem_type
);
406 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_array
.elem_type
);
407 array_item
= item
->u
.side_static
.side_array
->sav
;
408 nr_items
= type_desc
->u
.side_array
.length
;
411 stride_bit
= enum_elem_type_to_stride(elem_type
->u
.side_vla
.elem_type
);
412 reverse_byte_order
= type_to_host_reverse_bo(elem_type
->u
.side_vla
.elem_type
);
413 array_item
= item
->u
.side_static
.side_vla
->sav
;
414 nr_items
= item
->u
.side_static
.side_vla
->len
;
417 fprintf(stderr
, "ERROR: Unexpected enum element type\n");
421 print_attributes("attr", ":", side_enum_mappings
->attr
, side_enum_mappings
->nr_attr
);
422 printf("%s", side_enum_mappings
->nr_attr
? ", " : "");
423 printf("labels: [ ");
424 for (i
= 0; i
< side_enum_mappings
->nr_mappings
; i
++) {
425 const struct side_enum_bitmap_mapping
*mapping
= &side_enum_mappings
->mappings
[i
];
429 if (mapping
->range_end
< mapping
->range_begin
) {
430 fprintf(stderr
, "ERROR: Unexpected enum bitmap range: %" PRIu64
"-%" PRIu64
"\n",
431 mapping
->range_begin
, mapping
->range_end
);
434 for (bit
= mapping
->range_begin
; bit
<= mapping
->range_end
; bit
++) {
435 if (bit
> (nr_items
* stride_bit
) - 1)
437 switch (stride_bit
) {
440 uint8_t v
= array_item
[bit
/ 8].u
.side_static
.integer_value
.side_u8
;
441 if (v
& (1ULL << (bit
% 8))) {
449 uint16_t v
= array_item
[bit
/ 16].u
.side_static
.integer_value
.side_u16
;
450 if (reverse_byte_order
)
451 v
= side_bswap_16(v
);
452 if (v
& (1ULL << (bit
% 16))) {
460 uint32_t v
= array_item
[bit
/ 32].u
.side_static
.integer_value
.side_u32
;
461 if (reverse_byte_order
)
462 v
= side_bswap_32(v
);
463 if (v
& (1ULL << (bit
% 32))) {
471 uint64_t v
= array_item
[bit
/ 64].u
.side_static
.integer_value
.side_u64
;
472 if (reverse_byte_order
)
473 v
= side_bswap_64(v
);
474 if (v
& (1ULL << (bit
% 64))) {
486 printf("%s", print_count
++ ? ", " : "");
487 printf("\"%s\"", mapping
->label
);
491 printf("<NO LABEL>");
496 void print_integer_binary(uint64_t v
, int bits
)
502 for (i
= 0; i
< bits
; i
++) {
503 printf("%c", v
& (1ULL << 63) ? '1' : '0');
509 void tracer_print_type_header(const char *separator
,
510 const struct side_attr
*attr
, uint32_t nr_attr
)
512 print_attributes("attr", separator
, attr
, nr_attr
);
513 printf("%s", nr_attr
? ", " : "");
514 printf("value%s ", separator
);
518 void tracer_print_type_integer(const char *separator
,
519 const struct side_type_integer
*type_integer
,
520 const union side_integer_value
*value
,
521 uint16_t offset_bits
,
522 enum tracer_display_base default_base
)
524 enum tracer_display_base base
;
531 if (!type_integer
->len_bits
||
532 type_integer
->len_bits
+ offset_bits
> type_integer
->integer_size_bits
)
534 reverse_bo
= type_integer
->byte_order
!= SIDE_TYPE_BYTE_ORDER_HOST
;
535 base
= get_attr_display_base(type_integer
->attr
,
536 type_integer
->nr_attr
,
538 switch (type_integer
->integer_size_bits
) {
540 if (type_integer
->signedness
)
541 v
.v_signed
= value
->side_s8
;
543 v
.v_unsigned
= value
->side_u8
;
546 if (type_integer
->signedness
) {
549 side_s16
= value
->side_s16
;
551 side_s16
= side_bswap_16(side_s16
);
552 v
.v_signed
= side_s16
;
556 side_u16
= value
->side_u16
;
558 side_u16
= side_bswap_16(side_u16
);
559 v
.v_unsigned
= side_u16
;
563 if (type_integer
->signedness
) {
566 side_s32
= value
->side_s32
;
568 side_s32
= side_bswap_32(side_s32
);
569 v
.v_signed
= side_s32
;
573 side_u32
= value
->side_u32
;
575 side_u32
= side_bswap_32(side_u32
);
576 v
.v_unsigned
= side_u32
;
580 if (type_integer
->signedness
) {
583 side_s64
= value
->side_s64
;
585 side_s64
= side_bswap_64(side_s64
);
586 v
.v_signed
= side_s64
;
590 side_u64
= value
->side_u64
;
592 side_u64
= side_bswap_64(side_u64
);
593 v
.v_unsigned
= side_u64
;
599 v
.v_unsigned
>>= offset_bits
;
600 if (type_integer
->len_bits
< 64)
601 v
.v_unsigned
&= (1ULL << type_integer
->len_bits
) - 1;
602 tracer_print_type_header(separator
, type_integer
->attr
, type_integer
->nr_attr
);
604 case TRACER_DISPLAY_BASE_2
:
605 print_integer_binary(v
.v_unsigned
, type_integer
->len_bits
);
607 case TRACER_DISPLAY_BASE_8
:
608 printf("0%" PRIo64
, v
.v_unsigned
);
610 case TRACER_DISPLAY_BASE_10
:
611 if (type_integer
->signedness
) {
613 if (type_integer
->len_bits
< 64) {
614 if (v
.v_unsigned
& (1ULL << (type_integer
->len_bits
- 1)))
615 v
.v_unsigned
|= ~((1ULL << type_integer
->len_bits
) - 1);
617 printf("%" PRId64
, v
.v_signed
);
619 printf("%" PRIu64
, v
.v_unsigned
);
622 case TRACER_DISPLAY_BASE_16
:
623 printf("0x%" PRIx64
, v
.v_unsigned
);
631 void tracer_print_type_float(const char *separator
,
632 const struct side_type_float
*type_float
,
633 const union side_float_value
*value
)
637 reverse_bo
= type_float
->byte_order
!= SIDE_TYPE_FLOAT_WORD_ORDER_HOST
;
638 tracer_print_type_header(separator
, type_float
->attr
, type_float
->nr_attr
);
639 switch (type_float
->float_size_bits
) {
647 .f
= value
->side_float_binary16
,
651 float16
.u
= side_bswap_16(float16
.u
);
652 tracer_print_type_header(":", type_desc
->u
.side_float
.attr
, type_desc
->u
.side_float
.nr_attr
);
653 printf("%g", (double) float16
.f
);
656 fprintf(stderr
, "ERROR: Unsupported binary16 float type\n");
667 .f
= value
->side_float_binary32
,
671 float32
.u
= side_bswap_32(float32
.u
);
672 printf("%g", (double) float32
.f
);
675 fprintf(stderr
, "ERROR: Unsupported binary32 float type\n");
686 .f
= value
->side_float_binary64
,
690 float64
.u
= side_bswap_64(float64
.u
);
691 printf("%g", (double) float64
.f
);
694 fprintf(stderr
, "ERROR: Unsupported binary64 float type\n");
705 .f
= value
->side_float_binary128
,
709 side_bswap_128p(float128
.arr
);
710 printf("%Lg", (long double) float128
.f
);
713 fprintf(stderr
, "ERROR: Unsupported binary128 float type\n");
718 fprintf(stderr
, "ERROR: Unknown float size\n");
724 void tracer_print_type(const struct side_type
*type_desc
, const struct side_arg
*item
)
726 enum side_type_label type
;
728 switch (type_desc
->type
) {
729 case SIDE_TYPE_ARRAY
:
730 switch (item
->type
) {
731 case SIDE_TYPE_ARRAY_U8
:
732 case SIDE_TYPE_ARRAY_U16
:
733 case SIDE_TYPE_ARRAY_U32
:
734 case SIDE_TYPE_ARRAY_U64
:
735 case SIDE_TYPE_ARRAY_S8
:
736 case SIDE_TYPE_ARRAY_S16
:
737 case SIDE_TYPE_ARRAY_S32
:
738 case SIDE_TYPE_ARRAY_S64
:
739 case SIDE_TYPE_ARRAY_POINTER32
:
740 case SIDE_TYPE_ARRAY_POINTER64
:
741 case SIDE_TYPE_ARRAY_BYTE
:
742 case SIDE_TYPE_ARRAY
:
745 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
752 switch (item
->type
) {
753 case SIDE_TYPE_VLA_U8
:
754 case SIDE_TYPE_VLA_U16
:
755 case SIDE_TYPE_VLA_U32
:
756 case SIDE_TYPE_VLA_U64
:
757 case SIDE_TYPE_VLA_S8
:
758 case SIDE_TYPE_VLA_S16
:
759 case SIDE_TYPE_VLA_S32
:
760 case SIDE_TYPE_VLA_S64
:
761 case SIDE_TYPE_VLA_BYTE
:
762 case SIDE_TYPE_VLA_POINTER32
:
763 case SIDE_TYPE_VLA_POINTER64
:
767 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
774 switch (item
->type
) {
785 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
791 case SIDE_TYPE_ENUM_BITMAP
:
792 switch (item
->type
) {
798 case SIDE_TYPE_ARRAY
:
802 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
808 case SIDE_TYPE_DYNAMIC
:
809 switch (item
->type
) {
810 case SIDE_TYPE_DYNAMIC_NULL
:
811 case SIDE_TYPE_DYNAMIC_BOOL
:
812 case SIDE_TYPE_DYNAMIC_U8
:
813 case SIDE_TYPE_DYNAMIC_U16
:
814 case SIDE_TYPE_DYNAMIC_U32
:
815 case SIDE_TYPE_DYNAMIC_U64
:
816 case SIDE_TYPE_DYNAMIC_S8
:
817 case SIDE_TYPE_DYNAMIC_S16
:
818 case SIDE_TYPE_DYNAMIC_S32
:
819 case SIDE_TYPE_DYNAMIC_S64
:
820 case SIDE_TYPE_DYNAMIC_BYTE
:
821 case SIDE_TYPE_DYNAMIC_POINTER32
:
822 case SIDE_TYPE_DYNAMIC_POINTER64
:
823 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
824 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
825 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
826 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
827 case SIDE_TYPE_DYNAMIC_STRING
:
828 case SIDE_TYPE_DYNAMIC_STRUCT
:
829 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
830 case SIDE_TYPE_DYNAMIC_VLA
:
831 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
834 fprintf(stderr
, "ERROR: Unexpected dynamic type\n");
841 if (type_desc
->type
!= item
->type
) {
842 fprintf(stderr
, "ERROR: type mismatch between description and arguments\n");
848 if (type_desc
->type
== SIDE_TYPE_ENUM
|| type_desc
->type
== SIDE_TYPE_ENUM_BITMAP
)
849 type
= (enum side_type_label
) type_desc
->type
;
851 type
= (enum side_type_label
) item
->type
;
856 tracer_print_type_header(":", type_desc
->u
.side_null
.attr
, type_desc
->u
.side_null
.nr_attr
);
857 printf("<NULL TYPE>");
861 tracer_print_type_header(":", type_desc
->u
.side_bool
.attr
, type_desc
->u
.side_bool
.nr_attr
);
862 printf("%s", item
->u
.side_static
.bool_value
? "true" : "false");
873 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
874 TRACER_DISPLAY_BASE_10
);
877 case SIDE_TYPE_POINTER32
:
878 case SIDE_TYPE_POINTER64
:
879 tracer_print_type_integer(":", &type_desc
->u
.side_integer
, &item
->u
.side_static
.integer_value
, 0,
880 TRACER_DISPLAY_BASE_16
);
884 tracer_print_type_header(":", type_desc
->u
.side_byte
.attr
, type_desc
->u
.side_byte
.nr_attr
);
885 printf("0x%" PRIx8
, item
->u
.side_static
.byte_value
);
889 print_enum(type_desc
, item
);
892 case SIDE_TYPE_ENUM_BITMAP
:
893 print_enum_bitmap(type_desc
, item
);
896 case SIDE_TYPE_FLOAT_BINARY16
:
897 case SIDE_TYPE_FLOAT_BINARY32
:
898 case SIDE_TYPE_FLOAT_BINARY64
:
899 case SIDE_TYPE_FLOAT_BINARY128
:
900 tracer_print_type_float(":", &type_desc
->u
.side_float
, &item
->u
.side_static
.float_value
);
903 case SIDE_TYPE_STRING
:
904 tracer_print_type_header(":", type_desc
->u
.side_string
.attr
, type_desc
->u
.side_string
.nr_attr
);
905 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_static
.string_value
);
907 case SIDE_TYPE_STRUCT
:
908 tracer_print_struct(type_desc
, item
->u
.side_static
.side_struct
);
910 case SIDE_TYPE_GATHER_STRUCT
:
911 (void) tracer_print_gather_struct(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_struct_gather_ptr
);
913 case SIDE_TYPE_GATHER_ARRAY
:
914 (void) tracer_print_gather_array(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_array_gather_ptr
);
916 case SIDE_TYPE_GATHER_BYTE
:
917 (void) tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_byte_gather_ptr
);
919 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
920 case SIDE_TYPE_GATHER_SIGNED_INT
:
921 (void) tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_integer_gather_ptr
);
923 case SIDE_TYPE_GATHER_FLOAT
:
924 (void) tracer_print_gather_float_type(&type_desc
->u
.side_gather
, item
->u
.side_static
.side_float_gather_ptr
);
926 case SIDE_TYPE_ARRAY
:
927 tracer_print_array(type_desc
, item
->u
.side_static
.side_array
);
930 tracer_print_vla(type_desc
, item
->u
.side_static
.side_vla
);
932 case SIDE_TYPE_VLA_VISITOR
:
933 tracer_print_vla_visitor(type_desc
, item
->u
.side_static
.side_vla_app_visitor_ctx
);
935 case SIDE_TYPE_ARRAY_U8
:
936 case SIDE_TYPE_ARRAY_U16
:
937 case SIDE_TYPE_ARRAY_U32
:
938 case SIDE_TYPE_ARRAY_U64
:
939 case SIDE_TYPE_ARRAY_S8
:
940 case SIDE_TYPE_ARRAY_S16
:
941 case SIDE_TYPE_ARRAY_S32
:
942 case SIDE_TYPE_ARRAY_S64
:
943 case SIDE_TYPE_ARRAY_BYTE
:
944 case SIDE_TYPE_ARRAY_POINTER32
:
945 case SIDE_TYPE_ARRAY_POINTER64
:
946 tracer_print_array_fixint(type_desc
, item
);
948 case SIDE_TYPE_VLA_U8
:
949 case SIDE_TYPE_VLA_U16
:
950 case SIDE_TYPE_VLA_U32
:
951 case SIDE_TYPE_VLA_U64
:
952 case SIDE_TYPE_VLA_S8
:
953 case SIDE_TYPE_VLA_S16
:
954 case SIDE_TYPE_VLA_S32
:
955 case SIDE_TYPE_VLA_S64
:
956 case SIDE_TYPE_VLA_BYTE
:
957 case SIDE_TYPE_VLA_POINTER32
:
958 case SIDE_TYPE_VLA_POINTER64
:
959 tracer_print_vla_fixint(type_desc
, item
);
963 case SIDE_TYPE_DYNAMIC_NULL
:
964 case SIDE_TYPE_DYNAMIC_BOOL
:
965 case SIDE_TYPE_DYNAMIC_U8
:
966 case SIDE_TYPE_DYNAMIC_U16
:
967 case SIDE_TYPE_DYNAMIC_U32
:
968 case SIDE_TYPE_DYNAMIC_U64
:
969 case SIDE_TYPE_DYNAMIC_S8
:
970 case SIDE_TYPE_DYNAMIC_S16
:
971 case SIDE_TYPE_DYNAMIC_S32
:
972 case SIDE_TYPE_DYNAMIC_S64
:
973 case SIDE_TYPE_DYNAMIC_BYTE
:
974 case SIDE_TYPE_DYNAMIC_POINTER32
:
975 case SIDE_TYPE_DYNAMIC_POINTER64
:
976 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
977 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
978 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
979 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
980 case SIDE_TYPE_DYNAMIC_STRING
:
981 case SIDE_TYPE_DYNAMIC_STRUCT
:
982 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
983 case SIDE_TYPE_DYNAMIC_VLA
:
984 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
985 tracer_print_dynamic(item
);
987 case SIDE_TYPE_GATHER_VLA
:
988 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
991 fprintf(stderr
, "<UNKNOWN TYPE>");
998 void tracer_print_field(const struct side_event_field
*item_desc
, const struct side_arg
*item
)
1000 printf("%s: ", item_desc
->field_name
);
1001 tracer_print_type(&item_desc
->side_type
, item
);
1005 void tracer_print_struct(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1007 const struct side_arg
*sav
= side_arg_vec
->sav
;
1008 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1010 if (type_desc
->u
.side_struct
->nr_fields
!= side_sav_len
) {
1011 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments of structure\n");
1014 print_attributes("attr", ":", type_desc
->u
.side_struct
->attr
, type_desc
->u
.side_struct
->nr_attr
);
1015 printf("%s", type_desc
->u
.side_struct
->nr_attr
? ", " : "");
1016 printf("fields: { ");
1017 for (i
= 0; i
< side_sav_len
; i
++) {
1018 printf("%s", i
? ", " : "");
1019 tracer_print_field(&type_desc
->u
.side_struct
->fields
[i
], &sav
[i
]);
1025 void tracer_print_array(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1027 const struct side_arg
*sav
= side_arg_vec
->sav
;
1028 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1030 if (type_desc
->u
.side_array
.length
!= side_sav_len
) {
1031 fprintf(stderr
, "ERROR: length mismatch between description and arguments of array\n");
1034 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1035 printf("%s", type_desc
->u
.side_array
.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_array
.elem_type
, &sav
[i
]);
1046 void tracer_print_vla(const struct side_type
*type_desc
, const struct side_arg_vec
*side_arg_vec
)
1048 const struct side_arg
*sav
= side_arg_vec
->sav
;
1049 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1051 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1052 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1053 printf("elements: ");
1055 for (i
= 0; i
< side_sav_len
; i
++) {
1056 printf("%s", i
? ", " : "");
1057 tracer_print_type(type_desc
->u
.side_vla
.elem_type
, &sav
[i
]);
1063 const char *tracer_gather_access(enum side_type_gather_access_mode access_mode
, const char *ptr
)
1065 switch (access_mode
) {
1066 case SIDE_TYPE_GATHER_ACCESS_ADDRESS
:
1068 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1069 /* Dereference pointer */
1070 memcpy(&ptr
, ptr
, sizeof(ptr
));
1078 uint32_t tracer_gather_size(enum side_type_gather_access_mode access_mode
, uint32_t len
)
1080 switch (access_mode
) {
1081 case SIDE_TYPE_GATHER_ACCESS_ADDRESS
:
1083 case SIDE_TYPE_GATHER_ACCESS_POINTER
:
1084 return sizeof(void *);
1091 uint64_t tracer_load_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1093 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_integer
.access_mode
;
1094 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size_bits
>> 3;
1095 const char *ptr
= (const char *) _ptr
;
1096 union side_integer_value value
;
1098 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1099 memcpy(&value
, ptr
, integer_size_bytes
);
1100 switch (type_gather
->u
.side_integer
.type
.integer_size_bits
) {
1102 return (uint64_t) value
.side_u8
;
1104 return (uint64_t) value
.side_u16
;
1106 return (uint64_t) value
.side_u32
;
1108 return (uint64_t) value
.side_u64
;
1115 uint32_t tracer_print_gather_byte_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1117 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_byte
.access_mode
;
1118 const char *ptr
= (const char *) _ptr
;
1121 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_byte
.offset
);
1122 memcpy(&value
, ptr
, 1);
1123 tracer_print_type_header(":", type_gather
->u
.side_byte
.type
.attr
,
1124 type_gather
->u
.side_byte
.type
.nr_attr
);
1125 printf("0x%" PRIx8
, value
);
1126 return tracer_gather_size(access_mode
, 1);
1130 uint32_t tracer_print_gather_integer_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1132 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_integer
.access_mode
;
1133 uint32_t integer_size_bytes
= type_gather
->u
.side_integer
.type
.integer_size_bits
>> 3;
1134 const char *ptr
= (const char *) _ptr
;
1135 union side_integer_value value
;
1137 switch (type_gather
->u
.side_integer
.type
.integer_size_bits
) {
1146 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_integer
.offset
);
1147 memcpy(&value
, ptr
, integer_size_bytes
);
1148 tracer_print_type_integer(":", &type_gather
->u
.side_integer
.type
, &value
,
1149 type_gather
->u
.side_integer
.offset_bits
, TRACER_DISPLAY_BASE_10
);
1150 return tracer_gather_size(access_mode
, integer_size_bytes
);
1154 uint32_t tracer_print_gather_float_type(const struct side_type_gather
*type_gather
, const void *_ptr
)
1156 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_float
.access_mode
;
1157 uint32_t float_size_bytes
= type_gather
->u
.side_float
.type
.float_size_bits
>> 3;
1158 const char *ptr
= (const char *) _ptr
;
1159 union side_float_value value
;
1161 switch (type_gather
->u
.side_float
.type
.float_size_bits
) {
1170 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_float
.offset
);
1171 memcpy(&value
, ptr
, float_size_bytes
);
1172 tracer_print_type_float(":", &type_gather
->u
.side_float
.type
, &value
);
1173 return tracer_gather_size(access_mode
, float_size_bytes
);
1177 uint32_t tracer_print_gather_type(const struct side_type
*type_desc
, const void *ptr
)
1182 switch (type_desc
->type
) {
1183 case SIDE_TYPE_GATHER_BYTE
:
1184 len
= tracer_print_gather_byte_type(&type_desc
->u
.side_gather
, ptr
);
1186 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
1187 case SIDE_TYPE_GATHER_SIGNED_INT
:
1188 len
= tracer_print_gather_integer_type(&type_desc
->u
.side_gather
, ptr
);
1190 case SIDE_TYPE_GATHER_FLOAT
:
1191 len
= tracer_print_gather_float_type(&type_desc
->u
.side_gather
, ptr
);
1193 case SIDE_TYPE_GATHER_STRUCT
:
1194 len
= tracer_print_gather_struct(&type_desc
->u
.side_gather
, ptr
);
1196 case SIDE_TYPE_GATHER_ARRAY
:
1197 len
= tracer_print_gather_array(&type_desc
->u
.side_gather
, ptr
);
1199 case SIDE_TYPE_GATHER_VLA
:
1200 len
= tracer_print_gather_vla(&type_desc
->u
.side_gather
, ptr
);
1203 fprintf(stderr
, "<UNKNOWN GATHER TYPE>");
1211 void tracer_print_gather_field(const struct side_event_field
*field
, const void *ptr
)
1213 printf("%s: ", field
->field_name
);
1214 (void) tracer_print_gather_type(&field
->side_type
, ptr
);
1218 uint32_t tracer_print_gather_struct(const struct side_type_gather
*type_gather
, const void *_ptr
)
1220 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_struct
.access_mode
;
1221 const char *ptr
= (const char *) _ptr
;
1224 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_struct
.offset
);
1225 print_attributes("attr", ":", type_gather
->u
.side_struct
.type
->attr
, type_gather
->u
.side_struct
.type
->nr_attr
);
1226 printf("%s", type_gather
->u
.side_struct
.type
->nr_attr
? ", " : "");
1227 printf("fields: { ");
1228 for (i
= 0; i
< type_gather
->u
.side_struct
.type
->nr_fields
; i
++) {
1229 printf("%s", i
? ", " : "");
1230 tracer_print_gather_field(&type_gather
->u
.side_struct
.type
->fields
[i
], ptr
);
1233 return tracer_gather_size(access_mode
, type_gather
->u
.side_struct
.size
);
1237 uint32_t tracer_print_gather_array(const struct side_type_gather
*type_gather
, const void *_ptr
)
1239 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_array
.access_mode
;
1240 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1243 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_array
.offset
);
1245 print_attributes("attr", ":", type_gather
->u
.side_array
.type
.attr
, type_gather
->u
.side_array
.type
.nr_attr
);
1246 printf("%s", type_gather
->u
.side_array
.type
.nr_attr
? ", " : "");
1247 printf("elements: ");
1249 for (i
= 0; i
< type_gather
->u
.side_array
.type
.length
; i
++) {
1250 switch (type_gather
->u
.side_array
.type
.elem_type
->type
) {
1251 case SIDE_TYPE_GATHER_VLA
:
1252 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1257 printf("%s", i
? ", " : "");
1258 ptr
+= tracer_print_gather_type(type_gather
->u
.side_array
.type
.elem_type
, ptr
);
1261 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1265 uint32_t tracer_print_gather_vla(const struct side_type_gather
*type_gather
, const void *_ptr
)
1267 enum side_type_gather_access_mode access_mode
= type_gather
->u
.side_vla
.access_mode
;
1268 const char *ptr
= (const char *) _ptr
, *orig_ptr
;
1272 switch (type_gather
->u
.side_vla
.length_type
->type
) {
1273 case SIDE_TYPE_GATHER_UNSIGNED_INT
:
1274 case SIDE_TYPE_GATHER_SIGNED_INT
:
1277 fprintf(stderr
, "<gather VLA expects integer gather length type>\n");
1280 length
= (uint32_t) tracer_load_gather_integer_type(&type_gather
->u
.side_vla
.length_type
->u
.side_gather
, ptr
);
1281 ptr
= tracer_gather_access(access_mode
, ptr
+ type_gather
->u
.side_vla
.offset
);
1283 print_attributes("attr", ":", type_gather
->u
.side_vla
.type
.attr
, type_gather
->u
.side_vla
.type
.nr_attr
);
1284 printf("%s", type_gather
->u
.side_vla
.type
.nr_attr
? ", " : "");
1285 printf("elements: ");
1287 for (i
= 0; i
< length
; i
++) {
1288 switch (type_gather
->u
.side_vla
.type
.elem_type
->type
) {
1289 case SIDE_TYPE_GATHER_VLA
:
1290 fprintf(stderr
, "<gather VLA only supported within gather structures>\n");
1295 printf("%s", i
? ", " : "");
1296 ptr
+= tracer_print_gather_type(type_gather
->u
.side_vla
.type
.elem_type
, ptr
);
1299 return tracer_gather_size(access_mode
, ptr
- orig_ptr
);
1302 struct tracer_visitor_priv
{
1303 const struct side_type
*elem_type
;
1308 enum side_visitor_status
tracer_write_elem_cb(const struct side_tracer_visitor_ctx
*tracer_ctx
,
1309 const struct side_arg
*elem
)
1311 struct tracer_visitor_priv
*tracer_priv
= (struct tracer_visitor_priv
*) tracer_ctx
->priv
;
1313 printf("%s", tracer_priv
->i
++ ? ", " : "");
1314 tracer_print_type(tracer_priv
->elem_type
, elem
);
1315 return SIDE_VISITOR_STATUS_OK
;
1319 void tracer_print_vla_visitor(const struct side_type
*type_desc
, void *app_ctx
)
1321 enum side_visitor_status status
;
1322 struct tracer_visitor_priv tracer_priv
= {
1323 .elem_type
= type_desc
->u
.side_vla_visitor
.elem_type
,
1326 const struct side_tracer_visitor_ctx tracer_ctx
= {
1327 .write_elem
= tracer_write_elem_cb
,
1328 .priv
= &tracer_priv
,
1331 print_attributes("attr", ":", type_desc
->u
.side_vla_visitor
.attr
, type_desc
->u
.side_vla_visitor
.nr_attr
);
1332 printf("%s", type_desc
->u
.side_vla_visitor
.nr_attr
? ", " : "");
1333 printf("elements: ");
1335 status
= type_desc
->u
.side_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1337 case SIDE_VISITOR_STATUS_OK
:
1339 case SIDE_VISITOR_STATUS_ERROR
:
1340 fprintf(stderr
, "ERROR: Visitor error\n");
1346 void tracer_print_array_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1348 const struct side_type
*elem_type
= type_desc
->u
.side_array
.elem_type
;
1349 uint32_t i
, side_sav_len
= type_desc
->u
.side_array
.length
;
1350 void *p
= item
->u
.side_static
.side_array_fixint
;
1351 enum side_type_label side_type
;
1353 print_attributes("attr", ":", type_desc
->u
.side_array
.attr
, type_desc
->u
.side_array
.nr_attr
);
1354 printf("%s", type_desc
->u
.side_array
.nr_attr
? ", " : "");
1355 printf("elements: ");
1356 switch (item
->type
) {
1357 case SIDE_TYPE_ARRAY_U8
:
1358 if (elem_type
->type
!= SIDE_TYPE_U8
)
1361 case SIDE_TYPE_ARRAY_U16
:
1362 if (elem_type
->type
!= SIDE_TYPE_U16
)
1365 case SIDE_TYPE_ARRAY_U32
:
1366 if (elem_type
->type
!= SIDE_TYPE_U32
)
1369 case SIDE_TYPE_ARRAY_U64
:
1370 if (elem_type
->type
!= SIDE_TYPE_U64
)
1373 case SIDE_TYPE_ARRAY_S8
:
1374 if (elem_type
->type
!= SIDE_TYPE_S8
)
1377 case SIDE_TYPE_ARRAY_S16
:
1378 if (elem_type
->type
!= SIDE_TYPE_S16
)
1381 case SIDE_TYPE_ARRAY_S32
:
1382 if (elem_type
->type
!= SIDE_TYPE_S32
)
1385 case SIDE_TYPE_ARRAY_S64
:
1386 if (elem_type
->type
!= SIDE_TYPE_S64
)
1389 case SIDE_TYPE_ARRAY_BYTE
:
1390 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1393 case SIDE_TYPE_ARRAY_POINTER32
:
1394 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1396 case SIDE_TYPE_ARRAY_POINTER64
:
1397 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1403 side_type
= (enum side_type_label
) elem_type
->type
;
1406 for (i
= 0; i
< side_sav_len
; i
++) {
1407 struct side_arg sav_elem
= {
1411 switch (side_type
) {
1413 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1416 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1419 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1422 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1425 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1428 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1431 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1434 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1436 case SIDE_TYPE_BYTE
:
1437 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1439 case SIDE_TYPE_POINTER32
:
1440 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1442 case SIDE_TYPE_POINTER64
:
1443 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1447 fprintf(stderr
, "ERROR: Unexpected type\n");
1451 printf("%s", i
? ", " : "");
1452 tracer_print_type(elem_type
, &sav_elem
);
1458 fprintf(stderr
, "ERROR: type mismatch\n");
1462 void tracer_print_vla_fixint(const struct side_type
*type_desc
, const struct side_arg
*item
)
1464 const struct side_type
*elem_type
= type_desc
->u
.side_vla
.elem_type
;
1465 uint32_t i
, side_sav_len
= item
->u
.side_static
.side_vla_fixint
.length
;
1466 void *p
= item
->u
.side_static
.side_vla_fixint
.p
;
1467 enum side_type_label side_type
;
1469 print_attributes("attr", ":", type_desc
->u
.side_vla
.attr
, type_desc
->u
.side_vla
.nr_attr
);
1470 printf("%s", type_desc
->u
.side_vla
.nr_attr
? ", " : "");
1471 printf("elements: ");
1472 switch (item
->type
) {
1473 case SIDE_TYPE_VLA_U8
:
1474 if (elem_type
->type
!= SIDE_TYPE_U8
)
1477 case SIDE_TYPE_VLA_U16
:
1478 if (elem_type
->type
!= SIDE_TYPE_U16
)
1481 case SIDE_TYPE_VLA_U32
:
1482 if (elem_type
->type
!= SIDE_TYPE_U32
)
1485 case SIDE_TYPE_VLA_U64
:
1486 if (elem_type
->type
!= SIDE_TYPE_U64
)
1489 case SIDE_TYPE_VLA_S8
:
1490 if (elem_type
->type
!= SIDE_TYPE_S8
)
1493 case SIDE_TYPE_VLA_S16
:
1494 if (elem_type
->type
!= SIDE_TYPE_S16
)
1497 case SIDE_TYPE_VLA_S32
:
1498 if (elem_type
->type
!= SIDE_TYPE_S32
)
1501 case SIDE_TYPE_VLA_S64
:
1502 if (elem_type
->type
!= SIDE_TYPE_S64
)
1505 case SIDE_TYPE_VLA_BYTE
:
1506 if (elem_type
->type
!= SIDE_TYPE_BYTE
)
1509 case SIDE_TYPE_VLA_POINTER32
:
1510 if (elem_type
->type
!= SIDE_TYPE_POINTER32
)
1512 case SIDE_TYPE_VLA_POINTER64
:
1513 if (elem_type
->type
!= SIDE_TYPE_POINTER64
)
1519 side_type
= (enum side_type_label
) elem_type
->type
;
1522 for (i
= 0; i
< side_sav_len
; i
++) {
1523 struct side_arg sav_elem
= {
1527 switch (side_type
) {
1529 sav_elem
.u
.side_static
.integer_value
.side_u8
= ((const uint8_t *) p
)[i
];
1532 sav_elem
.u
.side_static
.integer_value
.side_s8
= ((const int8_t *) p
)[i
];
1535 sav_elem
.u
.side_static
.integer_value
.side_u16
= ((const uint16_t *) p
)[i
];
1538 sav_elem
.u
.side_static
.integer_value
.side_s16
= ((const int16_t *) p
)[i
];
1541 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1544 sav_elem
.u
.side_static
.integer_value
.side_s32
= ((const int32_t *) p
)[i
];
1547 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1550 sav_elem
.u
.side_static
.integer_value
.side_s64
= ((const int64_t *) p
)[i
];
1552 case SIDE_TYPE_BYTE
:
1553 sav_elem
.u
.side_static
.byte_value
= ((const uint8_t *) p
)[i
];
1555 case SIDE_TYPE_POINTER32
:
1556 sav_elem
.u
.side_static
.integer_value
.side_u32
= ((const uint32_t *) p
)[i
];
1558 case SIDE_TYPE_POINTER64
:
1559 sav_elem
.u
.side_static
.integer_value
.side_u64
= ((const uint64_t *) p
)[i
];
1563 fprintf(stderr
, "ERROR: Unexpected type\n");
1567 printf("%s", i
? ", " : "");
1568 tracer_print_type(elem_type
, &sav_elem
);
1574 fprintf(stderr
, "ERROR: type mismatch\n");
1579 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct
*dynamic_struct
)
1581 const struct side_arg_dynamic_field
*fields
= dynamic_struct
->fields
;
1582 uint32_t i
, len
= dynamic_struct
->len
;
1584 print_attributes("attr", "::", dynamic_struct
->attr
, dynamic_struct
->nr_attr
);
1585 printf("%s", dynamic_struct
->nr_attr
? ", " : "");
1586 printf("fields:: ");
1588 for (i
= 0; i
< len
; i
++) {
1589 printf("%s", i
? ", " : "");
1590 printf("%s:: ", fields
[i
].field_name
);
1591 tracer_print_dynamic(&fields
[i
].elem
);
1596 struct tracer_dynamic_struct_visitor_priv
{
1601 enum side_visitor_status
tracer_dynamic_struct_write_elem_cb(
1602 const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
,
1603 const struct side_arg_dynamic_field
*dynamic_field
)
1605 struct tracer_dynamic_struct_visitor_priv
*tracer_priv
=
1606 (struct tracer_dynamic_struct_visitor_priv
*) tracer_ctx
->priv
;
1608 printf("%s", tracer_priv
->i
++ ? ", " : "");
1609 printf("%s:: ", dynamic_field
->field_name
);
1610 tracer_print_dynamic(&dynamic_field
->elem
);
1611 return SIDE_VISITOR_STATUS_OK
;
1615 void tracer_print_dynamic_struct_visitor(const struct side_arg
*item
)
1617 enum side_visitor_status status
;
1618 struct tracer_dynamic_struct_visitor_priv tracer_priv
= {
1621 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx
= {
1622 .write_field
= tracer_dynamic_struct_write_elem_cb
,
1623 .priv
= &tracer_priv
,
1625 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.app_ctx
;
1627 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
);
1628 printf("%s", item
->u
.side_dynamic
.side_dynamic_struct_visitor
.nr_attr
? ", " : "");
1629 printf("fields:: ");
1631 status
= item
->u
.side_dynamic
.side_dynamic_struct_visitor
.visitor(&tracer_ctx
, app_ctx
);
1633 case SIDE_VISITOR_STATUS_OK
:
1635 case SIDE_VISITOR_STATUS_ERROR
:
1636 fprintf(stderr
, "ERROR: Visitor error\n");
1643 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla
*vla
)
1645 const struct side_arg
*sav
= vla
->sav
;
1646 uint32_t i
, side_sav_len
= vla
->len
;
1648 print_attributes("attr", "::", vla
->attr
, vla
->nr_attr
);
1649 printf("%s", vla
->nr_attr
? ", " : "");
1650 printf("elements:: ");
1652 for (i
= 0; i
< side_sav_len
; i
++) {
1653 printf("%s", i
? ", " : "");
1654 tracer_print_dynamic(&sav
[i
]);
1659 struct tracer_dynamic_vla_visitor_priv
{
1664 enum side_visitor_status
tracer_dynamic_vla_write_elem_cb(
1665 const struct side_tracer_visitor_ctx
*tracer_ctx
,
1666 const struct side_arg
*elem
)
1668 struct tracer_dynamic_vla_visitor_priv
*tracer_priv
=
1669 (struct tracer_dynamic_vla_visitor_priv
*) tracer_ctx
->priv
;
1671 printf("%s", tracer_priv
->i
++ ? ", " : "");
1672 tracer_print_dynamic(elem
);
1673 return SIDE_VISITOR_STATUS_OK
;
1677 void tracer_print_dynamic_vla_visitor(const struct side_arg
*item
)
1679 enum side_visitor_status status
;
1680 struct tracer_dynamic_vla_visitor_priv tracer_priv
= {
1683 const struct side_tracer_visitor_ctx tracer_ctx
= {
1684 .write_elem
= tracer_dynamic_vla_write_elem_cb
,
1685 .priv
= &tracer_priv
,
1687 void *app_ctx
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.app_ctx
;
1689 print_attributes("attr", "::", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.attr
, item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
);
1690 printf("%s", item
->u
.side_dynamic
.side_dynamic_vla_visitor
.nr_attr
? ", " : "");
1691 printf("elements:: ");
1693 status
= item
->u
.side_dynamic
.side_dynamic_vla_visitor
.visitor(&tracer_ctx
, app_ctx
);
1695 case SIDE_VISITOR_STATUS_OK
:
1697 case SIDE_VISITOR_STATUS_ERROR
:
1698 fprintf(stderr
, "ERROR: Visitor error\n");
1705 void tracer_print_dynamic(const struct side_arg
*item
)
1708 switch (item
->type
) {
1709 case SIDE_TYPE_DYNAMIC_NULL
:
1710 tracer_print_type_header("::", item
->u
.side_dynamic
.side_null
.attr
, item
->u
.side_dynamic
.side_null
.nr_attr
);
1711 printf("<NULL TYPE>");
1713 case SIDE_TYPE_DYNAMIC_BOOL
:
1714 tracer_print_type_header("::", item
->u
.side_dynamic
.side_bool
.type
.attr
, item
->u
.side_dynamic
.side_bool
.type
.nr_attr
);
1715 printf("%s", item
->u
.side_dynamic
.side_bool
.value
? "true" : "false");
1717 case SIDE_TYPE_DYNAMIC_U8
:
1718 case SIDE_TYPE_DYNAMIC_U16
:
1719 case SIDE_TYPE_DYNAMIC_U32
:
1720 case SIDE_TYPE_DYNAMIC_U64
:
1721 case SIDE_TYPE_DYNAMIC_S8
:
1722 case SIDE_TYPE_DYNAMIC_S16
:
1723 case SIDE_TYPE_DYNAMIC_S32
:
1724 case SIDE_TYPE_DYNAMIC_S64
:
1725 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1726 TRACER_DISPLAY_BASE_10
);
1728 case SIDE_TYPE_DYNAMIC_BYTE
:
1729 tracer_print_type_header("::", item
->u
.side_dynamic
.side_byte
.type
.attr
, item
->u
.side_dynamic
.side_byte
.type
.nr_attr
);
1730 printf("0x%" PRIx8
, item
->u
.side_dynamic
.side_byte
.value
);
1733 case SIDE_TYPE_DYNAMIC_POINTER32
:
1734 case SIDE_TYPE_DYNAMIC_POINTER64
:
1735 tracer_print_type_integer("::", &item
->u
.side_dynamic
.side_integer
.type
, &item
->u
.side_dynamic
.side_integer
.value
, 0,
1736 TRACER_DISPLAY_BASE_16
);
1739 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16
:
1740 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32
:
1741 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64
:
1742 case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128
:
1743 tracer_print_type_float("::", &item
->u
.side_dynamic
.side_float
.type
,
1744 &item
->u
.side_dynamic
.side_float
.value
);
1747 case SIDE_TYPE_DYNAMIC_STRING
:
1748 tracer_print_type_header("::", item
->u
.side_dynamic
.side_string
.type
.attr
, item
->u
.side_dynamic
.side_string
.type
.nr_attr
);
1749 printf("\"%s\"", (const char *)(uintptr_t) item
->u
.side_dynamic
.side_string
.value
);
1751 case SIDE_TYPE_DYNAMIC_STRUCT
:
1752 tracer_print_dynamic_struct(item
->u
.side_dynamic
.side_dynamic_struct
);
1754 case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR
:
1755 tracer_print_dynamic_struct_visitor(item
);
1757 case SIDE_TYPE_DYNAMIC_VLA
:
1758 tracer_print_dynamic_vla(item
->u
.side_dynamic
.side_dynamic_vla
);
1760 case SIDE_TYPE_DYNAMIC_VLA_VISITOR
:
1761 tracer_print_dynamic_vla_visitor(item
);
1764 fprintf(stderr
, "<UNKNOWN TYPE>");
1771 void tracer_print_static_fields(const struct side_event_description
*desc
,
1772 const struct side_arg_vec
*side_arg_vec
,
1775 const struct side_arg
*sav
= side_arg_vec
->sav
;
1776 uint32_t i
, side_sav_len
= side_arg_vec
->len
;
1778 printf("provider: %s, event: %s", desc
->provider_name
, desc
->event_name
);
1779 if (desc
->nr_fields
!= side_sav_len
) {
1780 fprintf(stderr
, "ERROR: number of fields mismatch between description and arguments\n");
1783 print_attributes(", attr", ":", desc
->attr
, desc
->nr_attr
);
1784 printf("%s", side_sav_len
? ", fields: [ " : "");
1785 for (i
= 0; i
< side_sav_len
; i
++) {
1786 printf("%s", i
? ", " : "");
1787 tracer_print_field(&desc
->fields
[i
], &sav
[i
]);
1795 void tracer_call(const struct side_event_description
*desc
,
1796 const struct side_arg_vec
*side_arg_vec
,
1797 void *priv
__attribute__((unused
)))
1799 uint32_t nr_fields
= 0;
1801 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1805 void tracer_call_variadic(const struct side_event_description
*desc
,
1806 const struct side_arg_vec
*side_arg_vec
,
1807 const struct side_arg_dynamic_struct
*var_struct
,
1808 void *priv
__attribute__((unused
)))
1810 uint32_t nr_fields
= 0, i
, var_struct_len
= var_struct
->len
;
1812 tracer_print_static_fields(desc
, side_arg_vec
, &nr_fields
);
1814 if (side_unlikely(!(desc
->flags
& SIDE_EVENT_FLAG_VARIADIC
))) {
1815 fprintf(stderr
, "ERROR: unexpected non-variadic event description\n");
1818 print_attributes(", attr ", "::", var_struct
->attr
, var_struct
->nr_attr
);
1819 printf("%s", var_struct_len
? ", fields:: [ " : "");
1820 for (i
= 0; i
< var_struct_len
; i
++, nr_fields
++) {
1821 printf("%s", i
? ", " : "");
1822 printf("%s:: ", var_struct
->fields
[i
].field_name
);
1823 tracer_print_dynamic(&var_struct
->fields
[i
].elem
);
1830 void tracer_event_notification(enum side_tracer_notification notif
,
1831 struct side_event_description
**events
, uint32_t nr_events
, void *priv
)
1836 printf("----------------------------------------------------------\n");
1837 printf("Tracer notified of events %s\n",
1838 notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
? "inserted" : "removed");
1839 for (i
= 0; i
< nr_events
; i
++) {
1840 struct side_event_description
*event
= events
[i
];
1842 /* Skip NULL pointers */
1845 printf("provider: %s, event: %s\n",
1846 event
->provider_name
, event
->event_name
);
1847 if (notif
== SIDE_TRACER_NOTIFICATION_INSERT_EVENTS
) {
1848 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1849 ret
= side_tracer_callback_variadic_register(event
, tracer_call_variadic
, NULL
);
1853 ret
= side_tracer_callback_register(event
, tracer_call
, NULL
);
1858 if (event
->flags
& SIDE_EVENT_FLAG_VARIADIC
) {
1859 ret
= side_tracer_callback_variadic_unregister(event
, tracer_call_variadic
, NULL
);
1863 ret
= side_tracer_callback_unregister(event
, tracer_call
, NULL
);
1869 printf("----------------------------------------------------------\n");
1872 static __attribute__((constructor
))
1873 void tracer_init(void);
1875 void tracer_init(void)
1877 tracer_handle
= side_tracer_event_notification_register(tracer_event_notification
, NULL
);
1882 static __attribute__((destructor
))
1883 void tracer_exit(void);
1885 void tracer_exit(void)
1887 side_tracer_event_notification_unregister(tracer_handle
);