Remove byte order from basic type
[libside.git] / src / tracer.c
CommitLineData
f611d0c3
MD
1// SPDX-License-Identifier: MIT
2/*
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 */
5
6#include <stdint.h>
7#include <inttypes.h>
8#include <stdlib.h>
9#include <stdio.h>
ea32e5fc 10#include <stdbool.h>
1d9c515c 11#include <string.h>
f611d0c3
MD
12
13#include <side/trace.h>
14
1d9c515c
MD
15enum tracer_display_base {
16 TRACER_DISPLAY_BASE_2,
17 TRACER_DISPLAY_BASE_8,
18 TRACER_DISPLAY_BASE_10,
19 TRACER_DISPLAY_BASE_16,
20};
21
1e8aec23
MD
22static struct side_tracer_handle *tracer_handle;
23
f611d0c3
MD
24static
25void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
26static
7a1cb105
MD
27void tracer_print_struct_sg(const struct side_type_description *type_desc, void *ptr);
28static
f611d0c3
MD
29void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
30static
31void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc);
32static
352a4b77 33void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx);
ba845af5
MD
34static
35void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item);
1533629f
MD
36static
37void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item);
a2e2357e
MD
38static
39void tracer_print_dynamic(const struct side_arg_dynamic_vec *dynamic_item);
d8be25de
MD
40static
41void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item);
f611d0c3 42
1d9c515c
MD
43static
44int64_t get_attr_integer_value(const struct side_attr *attr)
45{
46 int64_t val;
47
48 switch (attr->value.type) {
49 case SIDE_ATTR_TYPE_U8:
43d85239 50 val = attr->value.u.integer_value.side_u8;
1d9c515c
MD
51 break;
52 case SIDE_ATTR_TYPE_U16:
43d85239 53 val = attr->value.u.integer_value.side_u16;
1d9c515c
MD
54 break;
55 case SIDE_ATTR_TYPE_U32:
43d85239 56 val = attr->value.u.integer_value.side_u32;
1d9c515c
MD
57 break;
58 case SIDE_ATTR_TYPE_U64:
43d85239 59 val = attr->value.u.integer_value.side_u64;
1d9c515c
MD
60 break;
61 case SIDE_ATTR_TYPE_S8:
43d85239 62 val = attr->value.u.integer_value.side_s8;
1d9c515c
MD
63 break;
64 case SIDE_ATTR_TYPE_S16:
43d85239 65 val = attr->value.u.integer_value.side_s16;
1d9c515c
MD
66 break;
67 case SIDE_ATTR_TYPE_S32:
43d85239 68 val = attr->value.u.integer_value.side_s32;
1d9c515c
MD
69 break;
70 case SIDE_ATTR_TYPE_S64:
43d85239 71 val = attr->value.u.integer_value.side_s64;
1d9c515c
MD
72 break;
73 default:
74 fprintf(stderr, "Unexpected attribute type\n");
75 abort();
76 }
77 return val;
78}
79
80static
81enum tracer_display_base get_attr_display_base(const struct side_attr *_attr, uint32_t nr_attr)
82{
83 uint32_t i;
84
85 for (i = 0; i < nr_attr; i++) {
86 const struct side_attr *attr = &_attr[i];
87
88 if (!strcmp(attr->key, "std.integer.base")) {
89 int64_t val = get_attr_integer_value(attr);
90
91 switch (val) {
92 case 2:
93 return TRACER_DISPLAY_BASE_2;
94 case 8:
95 return TRACER_DISPLAY_BASE_8;
96 case 10:
97 return TRACER_DISPLAY_BASE_10;
98 case 16:
99 return TRACER_DISPLAY_BASE_16;
100 default:
101 fprintf(stderr, "Unexpected integer display base: %" PRId64 "\n", val);
102 abort();
103 }
104 }
105 }
106 return TRACER_DISPLAY_BASE_10; /* Default */
107}
108
8bdd5c12
MD
109static
110bool type_to_host_reverse_bo(const struct side_type_description *type_desc)
111{
112 switch (type_desc->type) {
113 case SIDE_TYPE_U8:
114 case SIDE_TYPE_S8:
115 case SIDE_TYPE_BYTE:
116 return false;
117 case SIDE_TYPE_U16:
118 case SIDE_TYPE_U32:
119 case SIDE_TYPE_U64:
120 case SIDE_TYPE_S16:
121 case SIDE_TYPE_S32:
122 case SIDE_TYPE_S64:
56c21987
MD
123 if (type_desc->u.side_integer.byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
124 return true;
125 else
126 return false;
127 break;
dd6e76cb
MD
128 case SIDE_TYPE_POINTER32:
129 case SIDE_TYPE_POINTER64:
ac81c466 130 if (type_desc->u.side_integer.byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
8bdd5c12
MD
131 return true;
132 else
133 return false;
134 break;
135 case SIDE_TYPE_FLOAT_BINARY16:
136 case SIDE_TYPE_FLOAT_BINARY32:
137 case SIDE_TYPE_FLOAT_BINARY64:
138 case SIDE_TYPE_FLOAT_BINARY128:
aac52685 139 if (type_desc->u.side_float.byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST)
8bdd5c12
MD
140 return true;
141 else
142 return false;
143 break;
144 default:
145 fprintf(stderr, "Unexpected type\n");
146 abort();
147 }
148}
149
150static
151bool dynamic_type_to_host_reverse_bo(const struct side_arg_dynamic_vec *item)
152{
153 switch (item->dynamic_type) {
154 case SIDE_DYNAMIC_TYPE_U8:
155 case SIDE_DYNAMIC_TYPE_S8:
156 case SIDE_DYNAMIC_TYPE_BYTE:
157 return false;
158 case SIDE_DYNAMIC_TYPE_U16:
159 case SIDE_DYNAMIC_TYPE_U32:
160 case SIDE_DYNAMIC_TYPE_U64:
161 case SIDE_DYNAMIC_TYPE_S16:
162 case SIDE_DYNAMIC_TYPE_S32:
163 case SIDE_DYNAMIC_TYPE_S64:
dd6e76cb
MD
164 case SIDE_DYNAMIC_TYPE_POINTER32:
165 case SIDE_DYNAMIC_TYPE_POINTER64:
d2be7696 166 if (item->u.side_integer.type.byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
8bdd5c12
MD
167 return true;
168 else
169 return false;
170 break;
171 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
172 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
173 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
174 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
aac52685 175 if (item->u.side_float.type.byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST)
8bdd5c12
MD
176 return true;
177 else
178 return false;
179 break;
180 default:
181 fprintf(stderr, "Unexpected type\n");
182 abort();
183 }
184}
185
bc3c89b3 186static
905c328e 187void tracer_print_attr_type(const char *separator, const struct side_attr *attr)
bc3c89b3 188{
905c328e 189 printf("{ key%s \"%s\", value%s ", separator, attr->key, separator);
bc3c89b3
MD
190 switch (attr->value.type) {
191 case SIDE_ATTR_TYPE_BOOL:
192 printf("%s", attr->value.u.side_bool ? "true" : "false");
193 break;
194 case SIDE_ATTR_TYPE_U8:
43d85239 195 printf("%" PRIu8, attr->value.u.integer_value.side_u8);
bc3c89b3
MD
196 break;
197 case SIDE_ATTR_TYPE_U16:
43d85239 198 printf("%" PRIu16, attr->value.u.integer_value.side_u16);
bc3c89b3
MD
199 break;
200 case SIDE_ATTR_TYPE_U32:
43d85239 201 printf("%" PRIu32, attr->value.u.integer_value.side_u32);
bc3c89b3
MD
202 break;
203 case SIDE_ATTR_TYPE_U64:
43d85239 204 printf("%" PRIu64, attr->value.u.integer_value.side_u64);
bc3c89b3
MD
205 break;
206 case SIDE_ATTR_TYPE_S8:
43d85239 207 printf("%" PRId8, attr->value.u.integer_value.side_s8);
bc3c89b3
MD
208 break;
209 case SIDE_ATTR_TYPE_S16:
43d85239 210 printf("%" PRId16, attr->value.u.integer_value.side_s16);
bc3c89b3
MD
211 break;
212 case SIDE_ATTR_TYPE_S32:
43d85239 213 printf("%" PRId32, attr->value.u.integer_value.side_s32);
bc3c89b3
MD
214 break;
215 case SIDE_ATTR_TYPE_S64:
43d85239 216 printf("%" PRId64, attr->value.u.integer_value.side_s64);
bc3c89b3 217 break;
dd6e76cb 218 case SIDE_ATTR_TYPE_POINTER32:
43d85239 219 printf("0x%" PRIx32, attr->value.u.integer_value.side_u32);
dd6e76cb
MD
220 break;
221 case SIDE_ATTR_TYPE_POINTER64:
43d85239 222 printf("0x%" PRIx64, attr->value.u.integer_value.side_u64);
f5e650d7 223 break;
bc3c89b3
MD
224 case SIDE_ATTR_TYPE_FLOAT_BINARY16:
225#if __HAVE_FLOAT16
a4969f31 226 printf("%g", (double) attr->value.u.float_value.side_float_binary16);
bc3c89b3
MD
227 break;
228#else
de1b3cd2 229 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
bc3c89b3
MD
230 abort();
231#endif
232 case SIDE_ATTR_TYPE_FLOAT_BINARY32:
233#if __HAVE_FLOAT32
a4969f31 234 printf("%g", (double) attr->value.u.float_value.side_float_binary32);
bc3c89b3
MD
235 break;
236#else
de1b3cd2 237 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
bc3c89b3
MD
238 abort();
239#endif
240 case SIDE_ATTR_TYPE_FLOAT_BINARY64:
241#if __HAVE_FLOAT64
a4969f31 242 printf("%g", (double) attr->value.u.float_value.side_float_binary64);
bc3c89b3
MD
243 break;
244#else
de1b3cd2 245 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
bc3c89b3
MD
246 abort();
247#endif
248 case SIDE_ATTR_TYPE_FLOAT_BINARY128:
249#if __HAVE_FLOAT128
a4969f31 250 printf("%Lg", (long double) attr->value.u.float_value.side_float_binary128);
bc3c89b3
MD
251 break;
252#else
de1b3cd2 253 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
bc3c89b3
MD
254 abort();
255#endif
256 case SIDE_ATTR_TYPE_STRING:
8549e629 257 printf("\"%s\"", (const char *)(uintptr_t) attr->value.u.string);
bc3c89b3
MD
258 break;
259 default:
de1b3cd2 260 fprintf(stderr, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
bc3c89b3
MD
261 abort();
262 }
263 printf(" }");
264}
265
7d21cf51 266static
905c328e
MD
267void print_attributes(const char *prefix_str, const char *separator,
268 const struct side_attr *attr, uint32_t nr_attr)
7d21cf51
MD
269{
270 int i;
271
272 if (!nr_attr)
273 return;
905c328e 274 printf("%s%s [ ", prefix_str, separator);
7d21cf51
MD
275 for (i = 0; i < nr_attr; i++) {
276 printf("%s", i ? ", " : "");
905c328e 277 tracer_print_attr_type(separator, &attr[i]);
7d21cf51
MD
278 }
279 printf(" ]");
280}
281
79f677ba 282static
d8be25de 283void print_enum(const struct side_type_description *type_desc, const struct side_arg_vec *item)
79f677ba 284{
d8be25de 285 const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings;
8bdd5c12 286 const struct side_type_description *elem_type = type_desc->u.side_enum.elem_type;
79f677ba 287 int i, print_count = 0;
d8be25de 288 int64_t value;
79f677ba 289
8bdd5c12 290 if (elem_type->type != item->type) {
de1b3cd2 291 fprintf(stderr, "ERROR: Unexpected enum element type\n");
d8be25de
MD
292 abort();
293 }
294 switch (item->type) {
295 case SIDE_TYPE_U8:
43d85239 296 value = (int64_t) item->u.integer_value.side_u8;
d8be25de
MD
297 break;
298 case SIDE_TYPE_U16:
8bdd5c12
MD
299 {
300 uint16_t v;
301
43d85239 302 v = item->u.integer_value.side_u16;
8bdd5c12
MD
303 if (type_to_host_reverse_bo(elem_type))
304 v = side_bswap_16(v);
305 value = (int64_t) v;
d8be25de 306 break;
8bdd5c12 307 }
d8be25de 308 case SIDE_TYPE_U32:
8bdd5c12
MD
309 {
310 uint32_t v;
311
43d85239 312 v = item->u.integer_value.side_u32;
8bdd5c12
MD
313 if (type_to_host_reverse_bo(elem_type))
314 v = side_bswap_32(v);
315 value = (int64_t) v;
d8be25de 316 break;
8bdd5c12 317 }
d8be25de 318 case SIDE_TYPE_U64:
8bdd5c12
MD
319 {
320 uint64_t v;
321
43d85239 322 v = item->u.integer_value.side_u64;
8bdd5c12
MD
323 if (type_to_host_reverse_bo(elem_type))
324 v = side_bswap_64(v);
325 value = (int64_t) v;
d8be25de 326 break;
8bdd5c12 327 }
d8be25de 328 case SIDE_TYPE_S8:
43d85239 329 value = (int64_t) item->u.integer_value.side_s8;
d8be25de
MD
330 break;
331 case SIDE_TYPE_S16:
8bdd5c12
MD
332 {
333 int16_t v;
334
43d85239 335 v = item->u.integer_value.side_s16;
8bdd5c12
MD
336 if (type_to_host_reverse_bo(elem_type))
337 v = side_bswap_16(v);
338 value = (int64_t) v;
d8be25de 339 break;
8bdd5c12 340 }
d8be25de 341 case SIDE_TYPE_S32:
8bdd5c12
MD
342 {
343 int32_t v;
344
43d85239 345 v = item->u.integer_value.side_s32;
8bdd5c12
MD
346 if (type_to_host_reverse_bo(elem_type))
347 v = side_bswap_32(v);
348 value = (int64_t) v;
d8be25de 349 break;
8bdd5c12 350 }
d8be25de 351 case SIDE_TYPE_S64:
8bdd5c12
MD
352 {
353 int64_t v;
354
43d85239 355 v = item->u.integer_value.side_s64;
8bdd5c12
MD
356 if (type_to_host_reverse_bo(elem_type))
357 v = side_bswap_64(v);
358 value = v;
d8be25de 359 break;
8bdd5c12 360 }
d8be25de 361 default:
de1b3cd2 362 fprintf(stderr, "ERROR: Unexpected enum element type\n");
d8be25de
MD
363 abort();
364 }
905c328e 365 print_attributes("attr", ":", mappings->attr, mappings->nr_attr);
d8be25de
MD
366 printf("%s", mappings->nr_attr ? ", " : "");
367 tracer_print_type(type_desc->u.side_enum.elem_type, item);
368 printf(", labels: [ ");
369 for (i = 0; i < mappings->nr_mappings; i++) {
370 const struct side_enum_mapping *mapping = &mappings->mappings[i];
79f677ba 371
ea32e5fc 372 if (mapping->range_end < mapping->range_begin) {
de1b3cd2 373 fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n",
ea32e5fc
MD
374 mapping->range_begin, mapping->range_end);
375 abort();
376 }
79f677ba
MD
377 if (value >= mapping->range_begin && value <= mapping->range_end) {
378 printf("%s", print_count++ ? ", " : "");
379 printf("\"%s\"", mapping->label);
380 }
381 }
382 if (!print_count)
383 printf("<NO LABEL>");
384 printf(" ]");
385}
386
ea32e5fc 387static
bab5d6e4 388uint32_t enum_elem_type_to_stride(const struct side_type_description *elem_type)
ea32e5fc 389{
af6aa6e1
MD
390 uint32_t stride_bit;
391
bab5d6e4 392 switch (elem_type->type) {
4cc2880b
MD
393 case SIDE_TYPE_U8: /* Fall-through */
394 case SIDE_TYPE_BYTE:
af6aa6e1
MD
395 stride_bit = 8;
396 break;
af6aa6e1 397 case SIDE_TYPE_U16:
af6aa6e1
MD
398 stride_bit = 16;
399 break;
af6aa6e1 400 case SIDE_TYPE_U32:
af6aa6e1
MD
401 stride_bit = 32;
402 break;
af6aa6e1 403 case SIDE_TYPE_U64:
af6aa6e1
MD
404 stride_bit = 64;
405 break;
af6aa6e1 406 default:
de1b3cd2 407 fprintf(stderr, "ERROR: Unexpected enum element type\n");
af6aa6e1
MD
408 abort();
409 }
410 return stride_bit;
411}
412
413static
414void print_enum_bitmap(const struct side_type_description *type_desc,
415 const struct side_arg_vec *item)
416{
bab5d6e4
MD
417 const struct side_type_description *elem_type = type_desc->u.side_enum_bitmap.elem_type;
418 const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings;
ea32e5fc 419 int i, print_count = 0;
af6aa6e1 420 uint32_t stride_bit, nr_items;
8bdd5c12 421 bool reverse_byte_order = false;
af6aa6e1
MD
422 const struct side_arg_vec *array_item;
423
bab5d6e4
MD
424 switch (elem_type->type) {
425 case SIDE_TYPE_U8: /* Fall-through */
4cc2880b 426 case SIDE_TYPE_BYTE: /* Fall-through */
bab5d6e4
MD
427 case SIDE_TYPE_U16: /* Fall-through */
428 case SIDE_TYPE_U32: /* Fall-through */
4cc2880b 429 case SIDE_TYPE_U64:
45392033 430 stride_bit = enum_elem_type_to_stride(elem_type);
8bdd5c12 431 reverse_byte_order = type_to_host_reverse_bo(elem_type);
af6aa6e1
MD
432 array_item = item;
433 nr_items = 1;
af6aa6e1 434 break;
bab5d6e4 435 case SIDE_TYPE_ARRAY:
45392033 436 stride_bit = enum_elem_type_to_stride(elem_type->u.side_array.elem_type);
8bdd5c12 437 reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_array.elem_type);
af6aa6e1 438 array_item = item->u.side_array->sav;
bab5d6e4 439 nr_items = type_desc->u.side_array.length;
af6aa6e1 440 break;
bab5d6e4 441 case SIDE_TYPE_VLA:
45392033 442 stride_bit = enum_elem_type_to_stride(elem_type->u.side_vla.elem_type);
8bdd5c12 443 reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_vla.elem_type);
af6aa6e1 444 array_item = item->u.side_vla->sav;
bab5d6e4 445 nr_items = item->u.side_vla->len;
af6aa6e1
MD
446 break;
447 default:
de1b3cd2 448 fprintf(stderr, "ERROR: Unexpected enum element type\n");
af6aa6e1
MD
449 abort();
450 }
ea32e5fc 451
905c328e 452 print_attributes("attr", ":", side_enum_mappings->attr, side_enum_mappings->nr_attr);
d4328528 453 printf("%s", side_enum_mappings->nr_attr ? ", " : "");
af6aa6e1 454 printf("labels: [ ");
ea32e5fc 455 for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
66cff328 456 const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i];
ea32e5fc 457 bool match = false;
9ff49ee4 458 uint64_t bit;
ea32e5fc 459
9ff49ee4 460 if (mapping->range_end < mapping->range_begin) {
de1b3cd2 461 fprintf(stderr, "ERROR: Unexpected enum bitmap range: %" PRIu64 "-%" PRIu64 "\n",
ea32e5fc
MD
462 mapping->range_begin, mapping->range_end);
463 abort();
464 }
465 for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) {
af6aa6e1
MD
466 if (bit > (nr_items * stride_bit) - 1)
467 break;
468 switch (stride_bit) {
469 case 8:
470 {
43d85239 471 uint8_t v = array_item[bit / 8].u.integer_value.side_u8;
af6aa6e1
MD
472 if (v & (1ULL << (bit % 8))) {
473 match = true;
474 goto match;
475 }
476 break;
477 }
478 case 16:
479 {
43d85239 480 uint16_t v = array_item[bit / 16].u.integer_value.side_u16;
8bdd5c12
MD
481 if (reverse_byte_order)
482 v = side_bswap_16(v);
af6aa6e1
MD
483 if (v & (1ULL << (bit % 16))) {
484 match = true;
485 goto match;
486 }
487 break;
488 }
489 case 32:
490 {
43d85239 491 uint32_t v = array_item[bit / 32].u.integer_value.side_u32;
8bdd5c12
MD
492 if (reverse_byte_order)
493 v = side_bswap_32(v);
af6aa6e1
MD
494 if (v & (1ULL << (bit % 32))) {
495 match = true;
496 goto match;
497 }
ea32e5fc
MD
498 break;
499 }
af6aa6e1
MD
500 case 64:
501 {
43d85239 502 uint64_t v = array_item[bit / 64].u.integer_value.side_u64;
8bdd5c12
MD
503 if (reverse_byte_order)
504 v = side_bswap_64(v);
af6aa6e1
MD
505 if (v & (1ULL << (bit % 64))) {
506 match = true;
507 goto match;
508 }
509 break;
510 }
511 default:
512 abort();
513 }
ea32e5fc 514 }
af6aa6e1 515match:
ea32e5fc
MD
516 if (match) {
517 printf("%s", print_count++ ? ", " : "");
518 printf("\"%s\"", mapping->label);
519 }
520 }
521 if (!print_count)
522 printf("<NO LABEL>");
523 printf(" ]");
524}
525
1d9c515c
MD
526static
527void print_integer_binary(uint64_t v, int bits)
528{
529 int i;
530
531 printf("0b");
532 v <<= 64 - bits;
533 for (i = 0; i < bits; i++) {
534 printf("%c", v & (1ULL << 63) ? '1' : '0');
535 v <<= 1;
536 }
537}
538
0e9be766 539static
aac52685
MD
540void tracer_print_type_header(const char *separator,
541 const struct side_attr *attr, uint32_t nr_attr)
ac81c466 542{
aac52685
MD
543 print_attributes("attr", separator, attr, nr_attr);
544 printf("%s", nr_attr ? ", " : "");
545 printf("value%s ", separator);
ac81c466
MD
546}
547
56c21987 548static
e3080b2a
MD
549void tracer_print_type_integer(const char *separator,
550 const struct side_type_integer *type_integer,
87405d12
MD
551 const union side_integer_value *value,
552 uint16_t offset_bits)
56c21987
MD
553{
554 enum tracer_display_base base;
cb589216 555 bool reverse_bo;
56c21987
MD
556 union {
557 uint64_t v_unsigned;
558 int64_t v_signed;
559 } v;
560
e3080b2a 561 if (!type_integer->len_bits ||
87405d12 562 type_integer->len_bits + offset_bits > type_integer->integer_size_bits)
56c21987 563 abort();
cb589216 564 reverse_bo = type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST;
e3080b2a
MD
565 base = get_attr_display_base(type_integer->attr,
566 type_integer->nr_attr);
567 switch (type_integer->integer_size_bits) {
568 case 8:
569 if (type_integer->signedness)
570 v.v_signed = value->side_s8;
571 else
572 v.v_unsigned = value->side_u8;
56c21987 573 break;
e3080b2a
MD
574 case 16:
575 if (type_integer->signedness) {
576 int16_t side_s16;
56c21987 577
e3080b2a 578 side_s16 = value->side_s16;
cb589216 579 if (reverse_bo)
e3080b2a
MD
580 side_s16 = side_bswap_16(side_s16);
581 v.v_signed = side_s16;
582 } else {
583 uint16_t side_u16;
56c21987 584
e3080b2a 585 side_u16 = value->side_u16;
cb589216 586 if (reverse_bo)
e3080b2a
MD
587 side_u16 = side_bswap_16(side_u16);
588 v.v_unsigned = side_u16;
589 }
56c21987 590 break;
e3080b2a
MD
591 case 32:
592 if (type_integer->signedness) {
593 int32_t side_s32;
56c21987 594
e3080b2a 595 side_s32 = value->side_s32;
cb589216 596 if (reverse_bo)
e3080b2a
MD
597 side_s32 = side_bswap_32(side_s32);
598 v.v_signed = side_s32;
599 } else {
600 uint32_t side_u32;
56c21987 601
e3080b2a 602 side_u32 = value->side_u32;
cb589216 603 if (reverse_bo)
e3080b2a
MD
604 side_u32 = side_bswap_32(side_u32);
605 v.v_unsigned = side_u32;
606 }
56c21987 607 break;
e3080b2a
MD
608 case 64:
609 if (type_integer->signedness) {
610 int64_t side_s64;
56c21987 611
e3080b2a 612 side_s64 = value->side_s64;
cb589216 613 if (reverse_bo)
e3080b2a
MD
614 side_s64 = side_bswap_64(side_s64);
615 v.v_signed = side_s64;
616 } else {
617 uint64_t side_u64;
56c21987 618
e3080b2a 619 side_u64 = value->side_u64;
cb589216 620 if (reverse_bo)
e3080b2a
MD
621 side_u64 = side_bswap_64(side_u64);
622 v.v_unsigned = side_u64;
623 }
56c21987 624 break;
56c21987
MD
625 default:
626 abort();
627 }
87405d12 628 v.v_unsigned >>= offset_bits;
e3080b2a
MD
629 if (type_integer->len_bits < 64)
630 v.v_unsigned &= (1ULL << type_integer->len_bits) - 1;
631 tracer_print_type_header(separator, type_integer->attr, type_integer->nr_attr);
56c21987
MD
632 switch (base) {
633 case TRACER_DISPLAY_BASE_2:
e3080b2a 634 print_integer_binary(v.v_unsigned, type_integer->len_bits);
56c21987
MD
635 break;
636 case TRACER_DISPLAY_BASE_8:
637 printf("0%" PRIo64, v.v_unsigned);
638 break;
639 case TRACER_DISPLAY_BASE_10:
e3080b2a 640 if (type_integer->signedness) {
56c21987 641 /* Sign-extend. */
e3080b2a
MD
642 if (type_integer->len_bits < 64) {
643 if (v.v_unsigned & (1ULL << (type_integer->len_bits - 1)))
644 v.v_unsigned |= ~((1ULL << type_integer->len_bits) - 1);
56c21987
MD
645 }
646 printf("%" PRId64, v.v_signed);
647 } else {
648 printf("%" PRIu64, v.v_unsigned);
649 }
650 break;
651 case TRACER_DISPLAY_BASE_16:
652 printf("0x%" PRIx64, v.v_unsigned);
653 break;
654 default:
655 abort();
656 }
657}
658
3aa7ca5e
MD
659static
660void tracer_print_type_float(const char *separator,
661 const struct side_type_float *type_float,
662 const union side_float_value *value)
663{
664 bool reverse_bo;
665
666 reverse_bo = type_float->byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST;
667 tracer_print_type_header(separator, type_float->attr, type_float->nr_attr);
668 switch (type_float->float_size_bits) {
669 case 16:
670 {
671#if __HAVE_FLOAT16
672 union {
673 _Float16 f;
674 uint16_t u;
675 } float16 = {
676 .f = value->side_float_binary16,
677 };
678
679 if (reverse_bo)
680 float16.u = side_bswap_16(float16.u);
681 tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr);
682 printf("%g", (double) float16.f);
683 break;
684#else
685 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
686 abort();
687#endif
688 }
689 case 32:
690 {
691#if __HAVE_FLOAT32
692 union {
693 _Float32 f;
694 uint32_t u;
695 } float32 = {
696 .f = value->side_float_binary32,
697 };
698
699 if (reverse_bo)
700 float32.u = side_bswap_32(float32.u);
701 printf("%g", (double) float32.f);
702 break;
703#else
704 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
705 abort();
706#endif
707 }
708 case 64:
709 {
710#if __HAVE_FLOAT64
711 union {
712 _Float64 f;
713 uint64_t u;
714 } float64 = {
715 .f = value->side_float_binary64,
716 };
717
718 if (reverse_bo)
719 float64.u = side_bswap_64(float64.u);
720 printf("%g", (double) float64.f);
721 break;
722#else
723 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
724 abort();
725#endif
726 }
727 case 128:
728 {
729#if __HAVE_FLOAT128
730 union {
731 _Float128 f;
732 char arr[16];
733 } float128 = {
734 .f = value->side_float_binary128,
735 };
736
737 if (reverse_bo)
738 side_bswap_128p(float128.arr);
739 printf("%Lg", (long double) float128.f);
740 break;
741#else
742 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
743 abort();
744#endif
745 }
746 default:
747 fprintf(stderr, "ERROR: Unknown float size\n");
748 abort();
749 }
750}
751
f611d0c3
MD
752static
753void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item)
754{
d8be25de
MD
755 enum side_type type;
756
45392033
MD
757 switch (type_desc->type) {
758 case SIDE_TYPE_ARRAY:
759 switch (item->type) {
760 case SIDE_TYPE_ARRAY_U8:
761 case SIDE_TYPE_ARRAY_U16:
762 case SIDE_TYPE_ARRAY_U32:
763 case SIDE_TYPE_ARRAY_U64:
764 case SIDE_TYPE_ARRAY_S8:
765 case SIDE_TYPE_ARRAY_S16:
766 case SIDE_TYPE_ARRAY_S32:
767 case SIDE_TYPE_ARRAY_S64:
dd6e76cb
MD
768 case SIDE_TYPE_ARRAY_POINTER32:
769 case SIDE_TYPE_ARRAY_POINTER64:
f7653b43 770 case SIDE_TYPE_ARRAY_BYTE:
45392033
MD
771 case SIDE_TYPE_ARRAY:
772 break;
773 default:
de1b3cd2 774 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
ba845af5 775 abort();
45392033 776 break;
ba845af5
MD
777 }
778 break;
45392033
MD
779
780 case SIDE_TYPE_VLA:
781 switch (item->type) {
782 case SIDE_TYPE_VLA_U8:
783 case SIDE_TYPE_VLA_U16:
784 case SIDE_TYPE_VLA_U32:
785 case SIDE_TYPE_VLA_U64:
786 case SIDE_TYPE_VLA_S8:
787 case SIDE_TYPE_VLA_S16:
788 case SIDE_TYPE_VLA_S32:
789 case SIDE_TYPE_VLA_S64:
f7653b43 790 case SIDE_TYPE_VLA_BYTE:
dd6e76cb
MD
791 case SIDE_TYPE_VLA_POINTER32:
792 case SIDE_TYPE_VLA_POINTER64:
45392033
MD
793 case SIDE_TYPE_VLA:
794 break;
795 default:
de1b3cd2 796 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
1533629f 797 abort();
45392033 798 break;
1533629f
MD
799 }
800 break;
801
45392033
MD
802 case SIDE_TYPE_ENUM:
803 switch (item->type) {
804 case SIDE_TYPE_U8:
805 case SIDE_TYPE_U16:
806 case SIDE_TYPE_U32:
807 case SIDE_TYPE_U64:
808 case SIDE_TYPE_S8:
809 case SIDE_TYPE_S16:
810 case SIDE_TYPE_S32:
811 case SIDE_TYPE_S64:
bab5d6e4
MD
812 break;
813 default:
de1b3cd2 814 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
45392033
MD
815 abort();
816 break;
817 }
818 break;
819
820 case SIDE_TYPE_ENUM_BITMAP:
821 switch (item->type) {
822 case SIDE_TYPE_U8:
4cc2880b 823 case SIDE_TYPE_BYTE:
45392033
MD
824 case SIDE_TYPE_U16:
825 case SIDE_TYPE_U32:
826 case SIDE_TYPE_U64:
827 case SIDE_TYPE_ARRAY:
828 case SIDE_TYPE_VLA:
829 break;
830 default:
de1b3cd2 831 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
45392033
MD
832 abort();
833 break;
d8be25de
MD
834 }
835 break;
836
ba845af5 837 default:
a2e2357e 838 if (type_desc->type != item->type) {
de1b3cd2 839 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
ba845af5
MD
840 abort();
841 }
842 break;
f611d0c3 843 }
d8be25de 844
bab5d6e4
MD
845 if (type_desc->type == SIDE_TYPE_ENUM || type_desc->type == SIDE_TYPE_ENUM_BITMAP)
846 type = type_desc->type;
d8be25de
MD
847 else
848 type = item->type;
849
a848763d 850 printf("{ ");
d8be25de 851 switch (type) {
4f40d951 852 case SIDE_TYPE_BOOL:
aac52685 853 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
4f40d951
MD
854 printf("%s", item->u.side_bool ? "true" : "false");
855 break;
1d9c515c 856
56c21987 857 case SIDE_TYPE_U8:
f611d0c3 858 case SIDE_TYPE_U16:
f611d0c3 859 case SIDE_TYPE_U32:
f611d0c3 860 case SIDE_TYPE_U64:
f611d0c3 861 case SIDE_TYPE_S8:
f611d0c3 862 case SIDE_TYPE_S16:
f611d0c3 863 case SIDE_TYPE_S32:
f611d0c3 864 case SIDE_TYPE_S64:
87405d12 865 tracer_print_type_integer(":", &type_desc->u.side_integer, &item->u.integer_value, 0);
f611d0c3 866 break;
56c21987 867
dd6e76cb 868 case SIDE_TYPE_POINTER32:
f5e650d7 869 {
dd6e76cb 870 uint32_t v;
f5e650d7 871
43d85239 872 v = item->u.integer_value.side_u32;
f5e650d7 873 if (type_to_host_reverse_bo(type_desc))
dd6e76cb 874 v = side_bswap_32(v);
aac52685 875 tracer_print_type_header(":", type_desc->u.side_integer.attr, type_desc->u.side_integer.nr_attr);
dd6e76cb
MD
876 printf("0x%" PRIx32, v);
877 break;
878 }
879 case SIDE_TYPE_POINTER64:
880 {
881 uint64_t v;
882
43d85239 883 v = item->u.integer_value.side_u64;
dd6e76cb
MD
884 if (type_to_host_reverse_bo(type_desc))
885 v = side_bswap_64(v);
aac52685 886 tracer_print_type_header(":", type_desc->u.side_integer.attr, type_desc->u.side_integer.nr_attr);
dd6e76cb 887 printf("0x%" PRIx64, v);
f5e650d7
MD
888 break;
889 }
f7653b43 890 case SIDE_TYPE_BYTE:
aac52685 891 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
f7653b43 892 printf("0x%" PRIx8, item->u.side_byte);
7aec0d09 893 break;
79f677ba 894
d8be25de
MD
895 case SIDE_TYPE_ENUM:
896 print_enum(type_desc, item);
79f677ba
MD
897 break;
898
bab5d6e4 899 case SIDE_TYPE_ENUM_BITMAP:
af6aa6e1 900 print_enum_bitmap(type_desc, item);
ea32e5fc
MD
901 break;
902
fb25b355 903 case SIDE_TYPE_FLOAT_BINARY16:
fb25b355 904 case SIDE_TYPE_FLOAT_BINARY32:
fb25b355 905 case SIDE_TYPE_FLOAT_BINARY64:
fb25b355 906 case SIDE_TYPE_FLOAT_BINARY128:
3aa7ca5e
MD
907 tracer_print_type_float(":", &type_desc->u.side_float,
908 &item->u.float_value);
fb25b355 909 break;
3aa7ca5e 910
f611d0c3 911 case SIDE_TYPE_STRING:
aac52685 912 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
8549e629 913 printf("\"%s\"", (const char *)(uintptr_t) item->u.string);
f611d0c3
MD
914 break;
915 case SIDE_TYPE_STRUCT:
916 tracer_print_struct(type_desc, item->u.side_struct);
917 break;
7a1cb105
MD
918 case SIDE_TYPE_STRUCT_SG:
919 tracer_print_struct_sg(type_desc, item->u.side_struct_sg_ptr);
920 break;
f611d0c3
MD
921 case SIDE_TYPE_ARRAY:
922 tracer_print_array(type_desc, item->u.side_array);
923 break;
924 case SIDE_TYPE_VLA:
925 tracer_print_vla(type_desc, item->u.side_vla);
926 break;
927 case SIDE_TYPE_VLA_VISITOR:
352a4b77 928 tracer_print_vla_visitor(type_desc, item->u.side_vla_app_visitor_ctx);
f611d0c3 929 break;
ba845af5
MD
930 case SIDE_TYPE_ARRAY_U8:
931 case SIDE_TYPE_ARRAY_U16:
932 case SIDE_TYPE_ARRAY_U32:
933 case SIDE_TYPE_ARRAY_U64:
934 case SIDE_TYPE_ARRAY_S8:
935 case SIDE_TYPE_ARRAY_S16:
936 case SIDE_TYPE_ARRAY_S32:
937 case SIDE_TYPE_ARRAY_S64:
f7653b43 938 case SIDE_TYPE_ARRAY_BYTE:
dd6e76cb
MD
939 case SIDE_TYPE_ARRAY_POINTER32:
940 case SIDE_TYPE_ARRAY_POINTER64:
ba845af5
MD
941 tracer_print_array_fixint(type_desc, item);
942 break;
1533629f
MD
943 case SIDE_TYPE_VLA_U8:
944 case SIDE_TYPE_VLA_U16:
945 case SIDE_TYPE_VLA_U32:
946 case SIDE_TYPE_VLA_U64:
947 case SIDE_TYPE_VLA_S8:
948 case SIDE_TYPE_VLA_S16:
949 case SIDE_TYPE_VLA_S32:
950 case SIDE_TYPE_VLA_S64:
f7653b43 951 case SIDE_TYPE_VLA_BYTE:
dd6e76cb
MD
952 case SIDE_TYPE_VLA_POINTER32:
953 case SIDE_TYPE_VLA_POINTER64:
1533629f
MD
954 tracer_print_vla_fixint(type_desc, item);
955 break;
a2e2357e 956 case SIDE_TYPE_DYNAMIC:
aac52685 957 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
a2e2357e
MD
958 tracer_print_dynamic(&item->u.dynamic);
959 break;
f611d0c3 960 default:
de1b3cd2 961 fprintf(stderr, "<UNKNOWN TYPE>");
f611d0c3
MD
962 abort();
963 }
a848763d 964 printf(" }");
f611d0c3
MD
965}
966
967static
968void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg_vec *item)
969{
19fa6aa2 970 printf("%s: ", item_desc->field_name);
f611d0c3 971 tracer_print_type(&item_desc->side_type, item);
f611d0c3
MD
972}
973
974static
975void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
976{
977 const struct side_arg_vec *sav = sav_desc->sav;
978 uint32_t side_sav_len = sav_desc->len;
979 int i;
980
c7a14585 981 if (type_desc->u.side_struct->nr_fields != side_sav_len) {
de1b3cd2 982 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments of structure\n");
f611d0c3
MD
983 abort();
984 }
905c328e 985 print_attributes("attr", ":", type_desc->u.side_struct->attr, type_desc->u.side_struct->nr_attr);
73b2b0c2
MD
986 printf("%s", type_desc->u.side_struct->nr_attr ? ", " : "");
987 printf("fields: { ");
f611d0c3
MD
988 for (i = 0; i < side_sav_len; i++) {
989 printf("%s", i ? ", " : "");
c7a14585 990 tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]);
f611d0c3 991 }
d4328528 992 printf(" }");
f611d0c3
MD
993}
994
7a1cb105
MD
995static
996void tracer_print_sg_type(const struct side_type_sg_description *sg_type, void *_ptr)
997{
7a1cb105 998 const char *ptr = (const char *) _ptr;
87405d12 999 union side_integer_value value;
7a1cb105
MD
1000
1001 printf("{ ");
1002 switch (sg_type->type) {
1003 case SIDE_TYPE_SG_UNSIGNED_INT:
7a1cb105 1004 case SIDE_TYPE_SG_SIGNED_INT:
87405d12 1005 switch (sg_type->u.side_integer.type.integer_size_bits) {
7a1cb105 1006 case 8:
7a1cb105 1007 case 16:
7a1cb105 1008 case 32:
7a1cb105 1009 case 64:
7a1cb105 1010 break;
7a1cb105 1011 default:
7a1cb105
MD
1012 abort();
1013 }
7a1cb105 1014 }
87405d12
MD
1015 memcpy(&value, ptr + sg_type->offset, sg_type->u.side_integer.type.integer_size_bits >> 3);
1016 tracer_print_type_integer(":", &sg_type->u.side_integer.type, &value,
1017 sg_type->u.side_integer.offset_bits);
7a1cb105
MD
1018 printf(" }");
1019}
1020
1021static
1022void tracer_print_sg_field(const struct side_struct_field_sg *field_sg, void *ptr)
1023{
1024 printf("%s: ", field_sg->field_name);
1025 tracer_print_sg_type(&field_sg->side_type, ptr);
1026}
1027
1028static
1029void tracer_print_struct_sg(const struct side_type_description *type_desc, void *ptr)
1030{
1031 const struct side_type_struct_sg *struct_sg = type_desc->u.side_struct_sg;
1032 int i;
1033
1034 print_attributes("attr", ":", struct_sg->attr, struct_sg->nr_attr);
1035 printf("%s", struct_sg->nr_attr ? ", " : "");
1036 printf("fields: { ");
1037 for (i = 0; i < struct_sg->nr_fields; i++) {
1038 printf("%s", i ? ", " : "");
1039 tracer_print_sg_field(&struct_sg->fields_sg[i], ptr);
1040 }
1041 printf(" }");
1042}
1043
f611d0c3
MD
1044static
1045void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
1046{
1047 const struct side_arg_vec *sav = sav_desc->sav;
1048 uint32_t side_sav_len = sav_desc->len;
1049 int i;
1050
1051 if (type_desc->u.side_array.length != side_sav_len) {
de1b3cd2 1052 fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n");
f611d0c3
MD
1053 abort();
1054 }
905c328e 1055 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
d4328528 1056 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
20574104 1057 printf("elements: ");
f611d0c3
MD
1058 printf("[ ");
1059 for (i = 0; i < side_sav_len; i++) {
1060 printf("%s", i ? ", " : "");
1061 tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]);
1062 }
1063 printf(" ]");
1064}
1065
1066static
1067void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
1068{
1069 const struct side_arg_vec *sav = sav_desc->sav;
1070 uint32_t side_sav_len = sav_desc->len;
1071 int i;
1072
905c328e 1073 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
d4328528 1074 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
20574104 1075 printf("elements: ");
f611d0c3
MD
1076 printf("[ ");
1077 for (i = 0; i < side_sav_len; i++) {
1078 printf("%s", i ? ", " : "");
1079 tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]);
1080 }
1081 printf(" ]");
1082}
1083
352a4b77
MD
1084struct tracer_visitor_priv {
1085 const struct side_type_description *elem_type;
1086 int i;
1087};
1088
1089static
1090enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx,
1091 const struct side_arg_vec *elem)
1092{
1093 struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv;
1094
1095 printf("%s", tracer_priv->i++ ? ", " : "");
1096 tracer_print_type(tracer_priv->elem_type, elem);
1097 return SIDE_VISITOR_STATUS_OK;
1098}
1099
f611d0c3 1100static
352a4b77 1101void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx)
f611d0c3
MD
1102{
1103 enum side_visitor_status status;
352a4b77
MD
1104 struct tracer_visitor_priv tracer_priv = {
1105 .elem_type = type_desc->u.side_vla_visitor.elem_type,
1106 .i = 0,
1107 };
1108 const struct side_tracer_visitor_ctx tracer_ctx = {
1109 .write_elem = tracer_write_elem_cb,
1110 .priv = &tracer_priv,
1111 };
f611d0c3 1112
905c328e 1113 print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr);
d4328528 1114 printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : "");
20574104 1115 printf("elements: ");
352a4b77
MD
1116 printf("[ ");
1117 status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx);
1118 switch (status) {
1119 case SIDE_VISITOR_STATUS_OK:
1120 break;
1121 case SIDE_VISITOR_STATUS_ERROR:
de1b3cd2 1122 fprintf(stderr, "ERROR: Visitor error\n");
f611d0c3 1123 abort();
f611d0c3
MD
1124 }
1125 printf(" ]");
f611d0c3
MD
1126}
1127
ba845af5
MD
1128void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
1129{
1130 const struct side_type_description *elem_type = type_desc->u.side_array.elem_type;
1131 uint32_t side_sav_len = type_desc->u.side_array.length;
1132 void *p = item->u.side_array_fixint;
1133 enum side_type side_type;
1134 int i;
1135
905c328e 1136 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
d4328528 1137 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
20574104 1138 printf("elements: ");
1e8256c9
MD
1139 switch (item->type) {
1140 case SIDE_TYPE_ARRAY_U8:
1141 if (elem_type->type != SIDE_TYPE_U8)
1142 goto type_error;
1143 break;
1144 case SIDE_TYPE_ARRAY_U16:
1145 if (elem_type->type != SIDE_TYPE_U16)
1146 goto type_error;
1147 break;
1148 case SIDE_TYPE_ARRAY_U32:
1149 if (elem_type->type != SIDE_TYPE_U32)
1150 goto type_error;
1151 break;
1152 case SIDE_TYPE_ARRAY_U64:
1153 if (elem_type->type != SIDE_TYPE_U64)
1154 goto type_error;
1155 break;
1156 case SIDE_TYPE_ARRAY_S8:
1157 if (elem_type->type != SIDE_TYPE_S8)
1158 goto type_error;
1159 break;
1160 case SIDE_TYPE_ARRAY_S16:
1161 if (elem_type->type != SIDE_TYPE_S16)
1162 goto type_error;
1163 break;
1164 case SIDE_TYPE_ARRAY_S32:
1165 if (elem_type->type != SIDE_TYPE_S32)
1166 goto type_error;
1167 break;
1168 case SIDE_TYPE_ARRAY_S64:
1169 if (elem_type->type != SIDE_TYPE_S64)
1170 goto type_error;
1171 break;
f7653b43
MD
1172 case SIDE_TYPE_ARRAY_BYTE:
1173 if (elem_type->type != SIDE_TYPE_BYTE)
7aec0d09
MD
1174 goto type_error;
1175 break;
dd6e76cb
MD
1176 case SIDE_TYPE_ARRAY_POINTER32:
1177 if (elem_type->type != SIDE_TYPE_POINTER32)
1178 goto type_error;
1179 case SIDE_TYPE_ARRAY_POINTER64:
1180 if (elem_type->type != SIDE_TYPE_POINTER64)
f5e650d7
MD
1181 goto type_error;
1182 break;
1e8256c9
MD
1183 default:
1184 goto type_error;
ba845af5 1185 }
1e8256c9 1186 side_type = elem_type->type;
ba845af5 1187
1533629f
MD
1188 printf("[ ");
1189 for (i = 0; i < side_sav_len; i++) {
1190 struct side_arg_vec sav_elem = {
1191 .type = side_type,
1192 };
1193
1194 switch (side_type) {
1195 case SIDE_TYPE_U8:
43d85239 1196 sav_elem.u.integer_value.side_u8 = ((const uint8_t *) p)[i];
1533629f
MD
1197 break;
1198 case SIDE_TYPE_S8:
43d85239 1199 sav_elem.u.integer_value.side_s8 = ((const int8_t *) p)[i];
1533629f
MD
1200 break;
1201 case SIDE_TYPE_U16:
43d85239 1202 sav_elem.u.integer_value.side_u16 = ((const uint16_t *) p)[i];
1533629f
MD
1203 break;
1204 case SIDE_TYPE_S16:
43d85239 1205 sav_elem.u.integer_value.side_s16 = ((const int16_t *) p)[i];
1533629f
MD
1206 break;
1207 case SIDE_TYPE_U32:
43d85239 1208 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
1533629f
MD
1209 break;
1210 case SIDE_TYPE_S32:
43d85239 1211 sav_elem.u.integer_value.side_s32 = ((const int32_t *) p)[i];
1533629f
MD
1212 break;
1213 case SIDE_TYPE_U64:
43d85239 1214 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
1533629f
MD
1215 break;
1216 case SIDE_TYPE_S64:
43d85239 1217 sav_elem.u.integer_value.side_s64 = ((const int64_t *) p)[i];
1533629f 1218 break;
f7653b43
MD
1219 case SIDE_TYPE_BYTE:
1220 sav_elem.u.side_byte = ((const uint8_t *) p)[i];
7aec0d09 1221 break;
dd6e76cb 1222 case SIDE_TYPE_POINTER32:
43d85239 1223 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
dd6e76cb
MD
1224 break;
1225 case SIDE_TYPE_POINTER64:
43d85239 1226 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
f5e650d7 1227 break;
1533629f
MD
1228
1229 default:
de1b3cd2 1230 fprintf(stderr, "ERROR: Unexpected type\n");
1533629f
MD
1231 abort();
1232 }
1233
1234 printf("%s", i ? ", " : "");
1235 tracer_print_type(elem_type, &sav_elem);
1236 }
1237 printf(" ]");
1238 return;
1239
1240type_error:
de1b3cd2 1241 fprintf(stderr, "ERROR: type mismatch\n");
1533629f
MD
1242 abort();
1243}
1244
1245void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
1246{
1247 const struct side_type_description *elem_type = type_desc->u.side_vla.elem_type;
1248 uint32_t side_sav_len = item->u.side_vla_fixint.length;
1249 void *p = item->u.side_vla_fixint.p;
1250 enum side_type side_type;
1251 int i;
1252
905c328e 1253 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
d4328528 1254 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
20574104 1255 printf("elements: ");
a2e2357e
MD
1256 switch (item->type) {
1257 case SIDE_TYPE_VLA_U8:
1258 if (elem_type->type != SIDE_TYPE_U8)
1533629f 1259 goto type_error;
a2e2357e
MD
1260 break;
1261 case SIDE_TYPE_VLA_U16:
1262 if (elem_type->type != SIDE_TYPE_U16)
1533629f 1263 goto type_error;
a2e2357e
MD
1264 break;
1265 case SIDE_TYPE_VLA_U32:
1266 if (elem_type->type != SIDE_TYPE_U32)
1267 goto type_error;
1268 break;
1269 case SIDE_TYPE_VLA_U64:
1270 if (elem_type->type != SIDE_TYPE_U64)
1271 goto type_error;
1272 break;
1273 case SIDE_TYPE_VLA_S8:
1274 if (elem_type->type != SIDE_TYPE_S8)
1275 goto type_error;
1276 break;
1277 case SIDE_TYPE_VLA_S16:
1278 if (elem_type->type != SIDE_TYPE_S16)
1279 goto type_error;
1280 break;
1281 case SIDE_TYPE_VLA_S32:
1282 if (elem_type->type != SIDE_TYPE_S32)
1283 goto type_error;
1284 break;
1285 case SIDE_TYPE_VLA_S64:
1286 if (elem_type->type != SIDE_TYPE_S64)
1287 goto type_error;
1288 break;
f7653b43
MD
1289 case SIDE_TYPE_VLA_BYTE:
1290 if (elem_type->type != SIDE_TYPE_BYTE)
7aec0d09
MD
1291 goto type_error;
1292 break;
dd6e76cb
MD
1293 case SIDE_TYPE_VLA_POINTER32:
1294 if (elem_type->type != SIDE_TYPE_POINTER32)
1295 goto type_error;
1296 case SIDE_TYPE_VLA_POINTER64:
1297 if (elem_type->type != SIDE_TYPE_POINTER64)
f5e650d7
MD
1298 goto type_error;
1299 break;
a2e2357e
MD
1300 default:
1301 goto type_error;
1533629f 1302 }
a2e2357e 1303 side_type = elem_type->type;
1533629f 1304
ba845af5
MD
1305 printf("[ ");
1306 for (i = 0; i < side_sav_len; i++) {
1307 struct side_arg_vec sav_elem = {
1308 .type = side_type,
1309 };
1310
1311 switch (side_type) {
1312 case SIDE_TYPE_U8:
43d85239 1313 sav_elem.u.integer_value.side_u8 = ((const uint8_t *) p)[i];
ba845af5
MD
1314 break;
1315 case SIDE_TYPE_S8:
43d85239 1316 sav_elem.u.integer_value.side_s8 = ((const int8_t *) p)[i];
ba845af5
MD
1317 break;
1318 case SIDE_TYPE_U16:
43d85239 1319 sav_elem.u.integer_value.side_u16 = ((const uint16_t *) p)[i];
ba845af5
MD
1320 break;
1321 case SIDE_TYPE_S16:
43d85239 1322 sav_elem.u.integer_value.side_s16 = ((const int16_t *) p)[i];
ba845af5
MD
1323 break;
1324 case SIDE_TYPE_U32:
43d85239 1325 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
ba845af5
MD
1326 break;
1327 case SIDE_TYPE_S32:
43d85239 1328 sav_elem.u.integer_value.side_s32 = ((const int32_t *) p)[i];
ba845af5
MD
1329 break;
1330 case SIDE_TYPE_U64:
43d85239 1331 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
ba845af5
MD
1332 break;
1333 case SIDE_TYPE_S64:
43d85239 1334 sav_elem.u.integer_value.side_s64 = ((const int64_t *) p)[i];
ba845af5 1335 break;
f7653b43
MD
1336 case SIDE_TYPE_BYTE:
1337 sav_elem.u.side_byte = ((const uint8_t *) p)[i];
7aec0d09 1338 break;
dd6e76cb 1339 case SIDE_TYPE_POINTER32:
43d85239 1340 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
dd6e76cb
MD
1341 break;
1342 case SIDE_TYPE_POINTER64:
43d85239 1343 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
f5e650d7 1344 break;
ba845af5
MD
1345
1346 default:
de1b3cd2 1347 fprintf(stderr, "ERROR: Unexpected type\n");
ba845af5
MD
1348 abort();
1349 }
1350
1351 printf("%s", i ? ", " : "");
1352 tracer_print_type(elem_type, &sav_elem);
1353 }
1354 printf(" ]");
1355 return;
1356
1357type_error:
de1b3cd2 1358 fprintf(stderr, "ERROR: type mismatch\n");
ba845af5
MD
1359 abort();
1360}
1361
a2e2357e 1362static
c208889e 1363void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct)
a2e2357e 1364{
c208889e
MD
1365 const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields;
1366 uint32_t len = dynamic_struct->len;
465e5e7e
MD
1367 int i;
1368
905c328e 1369 print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr);
8d20e708 1370 printf("%s", dynamic_struct->nr_attr ? ", " : "");
f0061366 1371 printf("fields:: ");
465e5e7e
MD
1372 printf("[ ");
1373 for (i = 0; i < len; i++) {
1374 printf("%s", i ? ", " : "");
1375 printf("%s:: ", fields[i].field_name);
1376 tracer_print_dynamic(&fields[i].elem);
1377 }
1378 printf(" ]");
a2e2357e
MD
1379}
1380
2b359235
MD
1381struct tracer_dynamic_struct_visitor_priv {
1382 int i;
1383};
1384
1385static
1386enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
1387 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
1388 const struct side_arg_dynamic_event_field *dynamic_field)
1389{
1390 struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv;
1391
1392 printf("%s", tracer_priv->i++ ? ", " : "");
1393 printf("%s:: ", dynamic_field->field_name);
1394 tracer_print_dynamic(&dynamic_field->elem);
1395 return SIDE_VISITOR_STATUS_OK;
1396}
1397
a2e2357e 1398static
c208889e 1399void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item)
a2e2357e 1400{
2b359235
MD
1401 enum side_visitor_status status;
1402 struct tracer_dynamic_struct_visitor_priv tracer_priv = {
1403 .i = 0,
1404 };
1405 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = {
1406 .write_field = tracer_dynamic_struct_write_elem_cb,
1407 .priv = &tracer_priv,
1408 };
1409 void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx;
1410
905c328e 1411 print_attributes("attr", "::", item->u.side_dynamic_struct_visitor.attr, item->u.side_dynamic_struct_visitor.nr_attr);
8d20e708 1412 printf("%s", item->u.side_dynamic_struct_visitor.nr_attr ? ", " : "");
f0061366 1413 printf("fields:: ");
2b359235
MD
1414 printf("[ ");
1415 status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx);
1416 switch (status) {
1417 case SIDE_VISITOR_STATUS_OK:
1418 break;
1419 case SIDE_VISITOR_STATUS_ERROR:
de1b3cd2 1420 fprintf(stderr, "ERROR: Visitor error\n");
2b359235
MD
1421 abort();
1422 }
1423 printf(" ]");
a2e2357e
MD
1424}
1425
1426static
1427void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla *vla)
1428{
1429 const struct side_arg_dynamic_vec *sav = vla->sav;
1430 uint32_t side_sav_len = vla->len;
1431 int i;
1432
905c328e 1433 print_attributes("attr", "::", vla->attr, vla->nr_attr);
8d20e708 1434 printf("%s", vla->nr_attr ? ", " : "");
f0061366 1435 printf("elements:: ");
a2e2357e
MD
1436 printf("[ ");
1437 for (i = 0; i < side_sav_len; i++) {
1438 printf("%s", i ? ", " : "");
1439 tracer_print_dynamic(&sav[i]);
1440 }
1441 printf(" ]");
1442}
1443
8ceca0cd
MD
1444struct tracer_dynamic_vla_visitor_priv {
1445 int i;
1446};
1447
1448static
1449enum side_visitor_status tracer_dynamic_vla_write_elem_cb(
1450 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
1451 const struct side_arg_dynamic_vec *elem)
1452{
1453 struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv;
1454
1455 printf("%s", tracer_priv->i++ ? ", " : "");
1456 tracer_print_dynamic(elem);
1457 return SIDE_VISITOR_STATUS_OK;
1458}
1459
a2e2357e
MD
1460static
1461void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec *item)
1462{
8ceca0cd
MD
1463 enum side_visitor_status status;
1464 struct tracer_dynamic_vla_visitor_priv tracer_priv = {
1465 .i = 0,
1466 };
1467 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = {
1468 .write_elem = tracer_dynamic_vla_write_elem_cb,
1469 .priv = &tracer_priv,
1470 };
1471 void *app_ctx = item->u.side_dynamic_vla_visitor.app_ctx;
1472
905c328e 1473 print_attributes("attr", "::", item->u.side_dynamic_vla_visitor.attr, item->u.side_dynamic_vla_visitor.nr_attr);
8d20e708 1474 printf("%s", item->u.side_dynamic_vla_visitor.nr_attr ? ", " : "");
f0061366 1475 printf("elements:: ");
8ceca0cd
MD
1476 printf("[ ");
1477 status = item->u.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx);
1478 switch (status) {
1479 case SIDE_VISITOR_STATUS_OK:
1480 break;
1481 case SIDE_VISITOR_STATUS_ERROR:
de1b3cd2 1482 fprintf(stderr, "ERROR: Visitor error\n");
8ceca0cd
MD
1483 abort();
1484 }
1485 printf(" ]");
a2e2357e
MD
1486}
1487
1488static
1489void tracer_print_dynamic(const struct side_arg_dynamic_vec *item)
1490{
808bd9bf 1491 printf("{ ");
1e8256c9 1492 switch (item->dynamic_type) {
a2e2357e 1493 case SIDE_DYNAMIC_TYPE_NULL:
aac52685 1494 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
a2e2357e
MD
1495 printf("<NULL TYPE>");
1496 break;
4f40d951 1497 case SIDE_DYNAMIC_TYPE_BOOL:
aac52685 1498 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
8d20e708 1499 printf("%s", item->u.side_basic.u.side_bool ? "true" : "false");
4f40d951 1500 break;
a2e2357e 1501 case SIDE_DYNAMIC_TYPE_U8:
a2e2357e 1502 case SIDE_DYNAMIC_TYPE_U16:
a2e2357e 1503 case SIDE_DYNAMIC_TYPE_U32:
a2e2357e 1504 case SIDE_DYNAMIC_TYPE_U64:
a2e2357e 1505 case SIDE_DYNAMIC_TYPE_S8:
a2e2357e 1506 case SIDE_DYNAMIC_TYPE_S16:
a2e2357e 1507 case SIDE_DYNAMIC_TYPE_S32:
a2e2357e 1508 case SIDE_DYNAMIC_TYPE_S64:
f2b1aa0b 1509 tracer_print_type_integer("::", &item->u.side_integer.type,
87405d12 1510 &item->u.side_integer.value, 0);
a2e2357e 1511 break;
f7653b43 1512 case SIDE_DYNAMIC_TYPE_BYTE:
aac52685 1513 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
f7653b43 1514 printf("0x%" PRIx8, item->u.side_basic.u.side_byte);
199e7aa9 1515 break;
dd6e76cb 1516 case SIDE_DYNAMIC_TYPE_POINTER32:
f5e650d7 1517 {
dd6e76cb 1518 uint32_t v;
f5e650d7 1519
d2be7696 1520 v = item->u.side_integer.value.side_u32;
f5e650d7 1521 if (dynamic_type_to_host_reverse_bo(item))
dd6e76cb 1522 v = side_bswap_32(v);
aac52685 1523 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
dd6e76cb
MD
1524 printf("0x%" PRIx32, v);
1525 break;
1526 }
1527
1528 case SIDE_DYNAMIC_TYPE_POINTER64:
1529 {
1530 uint64_t v;
1531
d2be7696 1532 v = item->u.side_integer.value.side_u64;
dd6e76cb
MD
1533 if (dynamic_type_to_host_reverse_bo(item))
1534 v = side_bswap_64(v);
aac52685 1535 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
dd6e76cb 1536 printf("0x%" PRIx64, v);
f5e650d7
MD
1537 break;
1538 }
199e7aa9 1539
fb25b355 1540 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
fb25b355 1541 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
fb25b355 1542 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
fb25b355 1543 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
3aa7ca5e
MD
1544 tracer_print_type_float("::", &item->u.side_float.type,
1545 &item->u.side_float.value);
fb25b355 1546 break;
3aa7ca5e 1547
a2e2357e 1548 case SIDE_DYNAMIC_TYPE_STRING:
aac52685 1549 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
8549e629 1550 printf("\"%s\"", (const char *)(uintptr_t) item->u.side_basic.u.string);
a2e2357e 1551 break;
c208889e
MD
1552 case SIDE_DYNAMIC_TYPE_STRUCT:
1553 tracer_print_dynamic_struct(item->u.side_dynamic_struct);
a2e2357e 1554 break;
c208889e
MD
1555 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR:
1556 tracer_print_dynamic_struct_visitor(item);
a2e2357e
MD
1557 break;
1558 case SIDE_DYNAMIC_TYPE_VLA:
1559 tracer_print_dynamic_vla(item->u.side_dynamic_vla);
1560 break;
1561 case SIDE_DYNAMIC_TYPE_VLA_VISITOR:
1562 tracer_print_dynamic_vla_visitor(item);
1563 break;
1564 default:
de1b3cd2 1565 fprintf(stderr, "<UNKNOWN TYPE>");
a2e2357e
MD
1566 abort();
1567 }
808bd9bf 1568 printf(" }");
a2e2357e
MD
1569}
1570
68f8cfbe
MD
1571static
1572void tracer_print_static_fields(const struct side_event_description *desc,
1573 const struct side_arg_vec_description *sav_desc,
1574 int *nr_items)
f611d0c3
MD
1575{
1576 const struct side_arg_vec *sav = sav_desc->sav;
1577 uint32_t side_sav_len = sav_desc->len;
1578 int i;
1579
65010f43 1580 printf("provider: %s, event: %s", desc->provider_name, desc->event_name);
f611d0c3 1581 if (desc->nr_fields != side_sav_len) {
de1b3cd2 1582 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n");
f611d0c3
MD
1583 abort();
1584 }
905c328e 1585 print_attributes(", attr", ":", desc->attr, desc->nr_attr);
a848763d 1586 printf("%s", side_sav_len ? ", fields: [ " : "");
f611d0c3
MD
1587 for (i = 0; i < side_sav_len; i++) {
1588 printf("%s", i ? ", " : "");
1589 tracer_print_field(&desc->fields[i], &sav[i]);
1590 }
68f8cfbe
MD
1591 if (nr_items)
1592 *nr_items = i;
c7d338e2
MD
1593 if (side_sav_len)
1594 printf(" ]");
68f8cfbe
MD
1595}
1596
4a7d8700
MD
1597void tracer_call(const struct side_event_description *desc,
1598 const struct side_arg_vec_description *sav_desc,
1599 void *priv __attribute__((unused)))
68f8cfbe 1600{
a848763d
MD
1601 int nr_fields = 0;
1602
a848763d 1603 tracer_print_static_fields(desc, sav_desc, &nr_fields);
f611d0c3
MD
1604 printf("\n");
1605}
19fa6aa2
MD
1606
1607void tracer_call_variadic(const struct side_event_description *desc,
4a7d8700
MD
1608 const struct side_arg_vec_description *sav_desc,
1609 const struct side_arg_dynamic_event_struct *var_struct,
1610 void *priv __attribute__((unused)))
19fa6aa2 1611{
68f8cfbe
MD
1612 uint32_t var_struct_len = var_struct->len;
1613 int nr_fields = 0, i;
19fa6aa2 1614
68f8cfbe
MD
1615 tracer_print_static_fields(desc, sav_desc, &nr_fields);
1616
8a25ce77 1617 if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) {
de1b3cd2 1618 fprintf(stderr, "ERROR: unexpected non-variadic event description\n");
8a25ce77
MD
1619 abort();
1620 }
905c328e
MD
1621 print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr);
1622 printf("%s", var_struct_len ? ", fields:: [ " : "");
68f8cfbe 1623 for (i = 0; i < var_struct_len; i++, nr_fields++) {
c7d338e2 1624 printf("%s", i ? ", " : "");
68f8cfbe
MD
1625 printf("%s:: ", var_struct->fields[i].field_name);
1626 tracer_print_dynamic(&var_struct->fields[i].elem);
19fa6aa2 1627 }
a848763d
MD
1628 if (i)
1629 printf(" ]");
19fa6aa2
MD
1630 printf("\n");
1631}
1e8aec23
MD
1632
1633void tracer_event_notification(enum side_tracer_notification notif,
1634 struct side_event_description **events, uint32_t nr_events, void *priv)
1635{
1636 uint32_t i;
314c22c3 1637 int ret;
1e8aec23
MD
1638
1639 printf("----------------------------------------------------------\n");
1640 printf("Tracer notified of events %s\n",
314c22c3 1641 notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS ? "inserted" : "removed");
1e8aec23
MD
1642 for (i = 0; i < nr_events; i++) {
1643 struct side_event_description *event = events[i];
1644
1645 /* Skip NULL pointers */
1646 if (!event)
1647 continue;
1648 printf("provider: %s, event: %s\n",
1649 event->provider_name, event->event_name);
314c22c3
MD
1650 if (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) {
1651 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
1652 ret = side_tracer_callback_variadic_register(event, tracer_call_variadic, NULL);
1653 if (ret)
1654 abort();
1655 } else {
1656 ret = side_tracer_callback_register(event, tracer_call, NULL);
1657 if (ret)
1658 abort();
1659 }
1660 } else {
1661 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
1662 ret = side_tracer_callback_variadic_unregister(event, tracer_call_variadic, NULL);
1663 if (ret)
1664 abort();
1665 } else {
1666 ret = side_tracer_callback_unregister(event, tracer_call, NULL);
1667 if (ret)
1668 abort();
1669 }
1670 }
1e8aec23
MD
1671 }
1672 printf("----------------------------------------------------------\n");
1673}
1674
1675static __attribute__((constructor))
1676void tracer_init(void);
1677static
1678void tracer_init(void)
1679{
1680 tracer_handle = side_tracer_event_notification_register(tracer_event_notification, NULL);
1681 if (!tracer_handle)
1682 abort();
1683}
1684
1685static __attribute__((destructor))
1686void tracer_exit(void);
1687static
1688void tracer_exit(void)
1689{
1690 side_tracer_event_notification_unregister(tracer_handle);
1691}
This page took 0.108619 seconds and 4 git commands to generate.