Refactor tracer_print_type_integer for re-use
[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
7a1cb105
MD
150static
151bool sg_type_to_host_reverse_bo(const struct side_type_sg_description *sg_type)
152{
153 switch (sg_type->type) {
154 case SIDE_TYPE_SG_UNSIGNED_INT:
155 case SIDE_TYPE_SG_SIGNED_INT:
156 if (sg_type->u.side_basic.byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
157 return true;
158 else
159 return false;
160 break;
161 default:
162 fprintf(stderr, "Unexpected type\n");
163 abort();
164 }
165}
166
8bdd5c12
MD
167static
168bool dynamic_type_to_host_reverse_bo(const struct side_arg_dynamic_vec *item)
169{
170 switch (item->dynamic_type) {
171 case SIDE_DYNAMIC_TYPE_U8:
172 case SIDE_DYNAMIC_TYPE_S8:
173 case SIDE_DYNAMIC_TYPE_BYTE:
174 return false;
175 case SIDE_DYNAMIC_TYPE_U16:
176 case SIDE_DYNAMIC_TYPE_U32:
177 case SIDE_DYNAMIC_TYPE_U64:
178 case SIDE_DYNAMIC_TYPE_S16:
179 case SIDE_DYNAMIC_TYPE_S32:
180 case SIDE_DYNAMIC_TYPE_S64:
dd6e76cb
MD
181 case SIDE_DYNAMIC_TYPE_POINTER32:
182 case SIDE_DYNAMIC_TYPE_POINTER64:
d2be7696 183 if (item->u.side_integer.type.byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
8bdd5c12
MD
184 return true;
185 else
186 return false;
187 break;
188 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
189 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
190 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
191 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
aac52685 192 if (item->u.side_float.type.byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST)
8bdd5c12
MD
193 return true;
194 else
195 return false;
196 break;
197 default:
198 fprintf(stderr, "Unexpected type\n");
199 abort();
200 }
201}
202
bc3c89b3 203static
905c328e 204void tracer_print_attr_type(const char *separator, const struct side_attr *attr)
bc3c89b3 205{
905c328e 206 printf("{ key%s \"%s\", value%s ", separator, attr->key, separator);
bc3c89b3
MD
207 switch (attr->value.type) {
208 case SIDE_ATTR_TYPE_BOOL:
209 printf("%s", attr->value.u.side_bool ? "true" : "false");
210 break;
211 case SIDE_ATTR_TYPE_U8:
43d85239 212 printf("%" PRIu8, attr->value.u.integer_value.side_u8);
bc3c89b3
MD
213 break;
214 case SIDE_ATTR_TYPE_U16:
43d85239 215 printf("%" PRIu16, attr->value.u.integer_value.side_u16);
bc3c89b3
MD
216 break;
217 case SIDE_ATTR_TYPE_U32:
43d85239 218 printf("%" PRIu32, attr->value.u.integer_value.side_u32);
bc3c89b3
MD
219 break;
220 case SIDE_ATTR_TYPE_U64:
43d85239 221 printf("%" PRIu64, attr->value.u.integer_value.side_u64);
bc3c89b3
MD
222 break;
223 case SIDE_ATTR_TYPE_S8:
43d85239 224 printf("%" PRId8, attr->value.u.integer_value.side_s8);
bc3c89b3
MD
225 break;
226 case SIDE_ATTR_TYPE_S16:
43d85239 227 printf("%" PRId16, attr->value.u.integer_value.side_s16);
bc3c89b3
MD
228 break;
229 case SIDE_ATTR_TYPE_S32:
43d85239 230 printf("%" PRId32, attr->value.u.integer_value.side_s32);
bc3c89b3
MD
231 break;
232 case SIDE_ATTR_TYPE_S64:
43d85239 233 printf("%" PRId64, attr->value.u.integer_value.side_s64);
bc3c89b3 234 break;
dd6e76cb 235 case SIDE_ATTR_TYPE_POINTER32:
43d85239 236 printf("0x%" PRIx32, attr->value.u.integer_value.side_u32);
dd6e76cb
MD
237 break;
238 case SIDE_ATTR_TYPE_POINTER64:
43d85239 239 printf("0x%" PRIx64, attr->value.u.integer_value.side_u64);
f5e650d7 240 break;
bc3c89b3
MD
241 case SIDE_ATTR_TYPE_FLOAT_BINARY16:
242#if __HAVE_FLOAT16
a4969f31 243 printf("%g", (double) attr->value.u.float_value.side_float_binary16);
bc3c89b3
MD
244 break;
245#else
de1b3cd2 246 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
bc3c89b3
MD
247 abort();
248#endif
249 case SIDE_ATTR_TYPE_FLOAT_BINARY32:
250#if __HAVE_FLOAT32
a4969f31 251 printf("%g", (double) attr->value.u.float_value.side_float_binary32);
bc3c89b3
MD
252 break;
253#else
de1b3cd2 254 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
bc3c89b3
MD
255 abort();
256#endif
257 case SIDE_ATTR_TYPE_FLOAT_BINARY64:
258#if __HAVE_FLOAT64
a4969f31 259 printf("%g", (double) attr->value.u.float_value.side_float_binary64);
bc3c89b3
MD
260 break;
261#else
de1b3cd2 262 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
bc3c89b3
MD
263 abort();
264#endif
265 case SIDE_ATTR_TYPE_FLOAT_BINARY128:
266#if __HAVE_FLOAT128
a4969f31 267 printf("%Lg", (long double) attr->value.u.float_value.side_float_binary128);
bc3c89b3
MD
268 break;
269#else
de1b3cd2 270 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
bc3c89b3
MD
271 abort();
272#endif
273 case SIDE_ATTR_TYPE_STRING:
8549e629 274 printf("\"%s\"", (const char *)(uintptr_t) attr->value.u.string);
bc3c89b3
MD
275 break;
276 default:
de1b3cd2 277 fprintf(stderr, "ERROR: <UNKNOWN ATTRIBUTE TYPE>");
bc3c89b3
MD
278 abort();
279 }
280 printf(" }");
281}
282
7d21cf51 283static
905c328e
MD
284void print_attributes(const char *prefix_str, const char *separator,
285 const struct side_attr *attr, uint32_t nr_attr)
7d21cf51
MD
286{
287 int i;
288
289 if (!nr_attr)
290 return;
905c328e 291 printf("%s%s [ ", prefix_str, separator);
7d21cf51
MD
292 for (i = 0; i < nr_attr; i++) {
293 printf("%s", i ? ", " : "");
905c328e 294 tracer_print_attr_type(separator, &attr[i]);
7d21cf51
MD
295 }
296 printf(" ]");
297}
298
79f677ba 299static
d8be25de 300void print_enum(const struct side_type_description *type_desc, const struct side_arg_vec *item)
79f677ba 301{
d8be25de 302 const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings;
8bdd5c12 303 const struct side_type_description *elem_type = type_desc->u.side_enum.elem_type;
79f677ba 304 int i, print_count = 0;
d8be25de 305 int64_t value;
79f677ba 306
8bdd5c12 307 if (elem_type->type != item->type) {
de1b3cd2 308 fprintf(stderr, "ERROR: Unexpected enum element type\n");
d8be25de
MD
309 abort();
310 }
311 switch (item->type) {
312 case SIDE_TYPE_U8:
43d85239 313 value = (int64_t) item->u.integer_value.side_u8;
d8be25de
MD
314 break;
315 case SIDE_TYPE_U16:
8bdd5c12
MD
316 {
317 uint16_t v;
318
43d85239 319 v = item->u.integer_value.side_u16;
8bdd5c12
MD
320 if (type_to_host_reverse_bo(elem_type))
321 v = side_bswap_16(v);
322 value = (int64_t) v;
d8be25de 323 break;
8bdd5c12 324 }
d8be25de 325 case SIDE_TYPE_U32:
8bdd5c12
MD
326 {
327 uint32_t v;
328
43d85239 329 v = item->u.integer_value.side_u32;
8bdd5c12
MD
330 if (type_to_host_reverse_bo(elem_type))
331 v = side_bswap_32(v);
332 value = (int64_t) v;
d8be25de 333 break;
8bdd5c12 334 }
d8be25de 335 case SIDE_TYPE_U64:
8bdd5c12
MD
336 {
337 uint64_t v;
338
43d85239 339 v = item->u.integer_value.side_u64;
8bdd5c12
MD
340 if (type_to_host_reverse_bo(elem_type))
341 v = side_bswap_64(v);
342 value = (int64_t) v;
d8be25de 343 break;
8bdd5c12 344 }
d8be25de 345 case SIDE_TYPE_S8:
43d85239 346 value = (int64_t) item->u.integer_value.side_s8;
d8be25de
MD
347 break;
348 case SIDE_TYPE_S16:
8bdd5c12
MD
349 {
350 int16_t v;
351
43d85239 352 v = item->u.integer_value.side_s16;
8bdd5c12
MD
353 if (type_to_host_reverse_bo(elem_type))
354 v = side_bswap_16(v);
355 value = (int64_t) v;
d8be25de 356 break;
8bdd5c12 357 }
d8be25de 358 case SIDE_TYPE_S32:
8bdd5c12
MD
359 {
360 int32_t v;
361
43d85239 362 v = item->u.integer_value.side_s32;
8bdd5c12
MD
363 if (type_to_host_reverse_bo(elem_type))
364 v = side_bswap_32(v);
365 value = (int64_t) v;
d8be25de 366 break;
8bdd5c12 367 }
d8be25de 368 case SIDE_TYPE_S64:
8bdd5c12
MD
369 {
370 int64_t v;
371
43d85239 372 v = item->u.integer_value.side_s64;
8bdd5c12
MD
373 if (type_to_host_reverse_bo(elem_type))
374 v = side_bswap_64(v);
375 value = v;
d8be25de 376 break;
8bdd5c12 377 }
d8be25de 378 default:
de1b3cd2 379 fprintf(stderr, "ERROR: Unexpected enum element type\n");
d8be25de
MD
380 abort();
381 }
905c328e 382 print_attributes("attr", ":", mappings->attr, mappings->nr_attr);
d8be25de
MD
383 printf("%s", mappings->nr_attr ? ", " : "");
384 tracer_print_type(type_desc->u.side_enum.elem_type, item);
385 printf(", labels: [ ");
386 for (i = 0; i < mappings->nr_mappings; i++) {
387 const struct side_enum_mapping *mapping = &mappings->mappings[i];
79f677ba 388
ea32e5fc 389 if (mapping->range_end < mapping->range_begin) {
de1b3cd2 390 fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n",
ea32e5fc
MD
391 mapping->range_begin, mapping->range_end);
392 abort();
393 }
79f677ba
MD
394 if (value >= mapping->range_begin && value <= mapping->range_end) {
395 printf("%s", print_count++ ? ", " : "");
396 printf("\"%s\"", mapping->label);
397 }
398 }
399 if (!print_count)
400 printf("<NO LABEL>");
401 printf(" ]");
402}
403
ea32e5fc 404static
bab5d6e4 405uint32_t enum_elem_type_to_stride(const struct side_type_description *elem_type)
ea32e5fc 406{
af6aa6e1
MD
407 uint32_t stride_bit;
408
bab5d6e4 409 switch (elem_type->type) {
4cc2880b
MD
410 case SIDE_TYPE_U8: /* Fall-through */
411 case SIDE_TYPE_BYTE:
af6aa6e1
MD
412 stride_bit = 8;
413 break;
af6aa6e1 414 case SIDE_TYPE_U16:
af6aa6e1
MD
415 stride_bit = 16;
416 break;
af6aa6e1 417 case SIDE_TYPE_U32:
af6aa6e1
MD
418 stride_bit = 32;
419 break;
af6aa6e1 420 case SIDE_TYPE_U64:
af6aa6e1
MD
421 stride_bit = 64;
422 break;
af6aa6e1 423 default:
de1b3cd2 424 fprintf(stderr, "ERROR: Unexpected enum element type\n");
af6aa6e1
MD
425 abort();
426 }
427 return stride_bit;
428}
429
430static
431void print_enum_bitmap(const struct side_type_description *type_desc,
432 const struct side_arg_vec *item)
433{
bab5d6e4
MD
434 const struct side_type_description *elem_type = type_desc->u.side_enum_bitmap.elem_type;
435 const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings;
ea32e5fc 436 int i, print_count = 0;
af6aa6e1 437 uint32_t stride_bit, nr_items;
8bdd5c12 438 bool reverse_byte_order = false;
af6aa6e1
MD
439 const struct side_arg_vec *array_item;
440
bab5d6e4
MD
441 switch (elem_type->type) {
442 case SIDE_TYPE_U8: /* Fall-through */
4cc2880b 443 case SIDE_TYPE_BYTE: /* Fall-through */
bab5d6e4
MD
444 case SIDE_TYPE_U16: /* Fall-through */
445 case SIDE_TYPE_U32: /* Fall-through */
4cc2880b 446 case SIDE_TYPE_U64:
45392033 447 stride_bit = enum_elem_type_to_stride(elem_type);
8bdd5c12 448 reverse_byte_order = type_to_host_reverse_bo(elem_type);
af6aa6e1
MD
449 array_item = item;
450 nr_items = 1;
af6aa6e1 451 break;
bab5d6e4 452 case SIDE_TYPE_ARRAY:
45392033 453 stride_bit = enum_elem_type_to_stride(elem_type->u.side_array.elem_type);
8bdd5c12 454 reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_array.elem_type);
af6aa6e1 455 array_item = item->u.side_array->sav;
bab5d6e4 456 nr_items = type_desc->u.side_array.length;
af6aa6e1 457 break;
bab5d6e4 458 case SIDE_TYPE_VLA:
45392033 459 stride_bit = enum_elem_type_to_stride(elem_type->u.side_vla.elem_type);
8bdd5c12 460 reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_vla.elem_type);
af6aa6e1 461 array_item = item->u.side_vla->sav;
bab5d6e4 462 nr_items = item->u.side_vla->len;
af6aa6e1
MD
463 break;
464 default:
de1b3cd2 465 fprintf(stderr, "ERROR: Unexpected enum element type\n");
af6aa6e1
MD
466 abort();
467 }
ea32e5fc 468
905c328e 469 print_attributes("attr", ":", side_enum_mappings->attr, side_enum_mappings->nr_attr);
d4328528 470 printf("%s", side_enum_mappings->nr_attr ? ", " : "");
af6aa6e1 471 printf("labels: [ ");
ea32e5fc 472 for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
66cff328 473 const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i];
ea32e5fc 474 bool match = false;
9ff49ee4 475 uint64_t bit;
ea32e5fc 476
9ff49ee4 477 if (mapping->range_end < mapping->range_begin) {
de1b3cd2 478 fprintf(stderr, "ERROR: Unexpected enum bitmap range: %" PRIu64 "-%" PRIu64 "\n",
ea32e5fc
MD
479 mapping->range_begin, mapping->range_end);
480 abort();
481 }
482 for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) {
af6aa6e1
MD
483 if (bit > (nr_items * stride_bit) - 1)
484 break;
485 switch (stride_bit) {
486 case 8:
487 {
43d85239 488 uint8_t v = array_item[bit / 8].u.integer_value.side_u8;
af6aa6e1
MD
489 if (v & (1ULL << (bit % 8))) {
490 match = true;
491 goto match;
492 }
493 break;
494 }
495 case 16:
496 {
43d85239 497 uint16_t v = array_item[bit / 16].u.integer_value.side_u16;
8bdd5c12
MD
498 if (reverse_byte_order)
499 v = side_bswap_16(v);
af6aa6e1
MD
500 if (v & (1ULL << (bit % 16))) {
501 match = true;
502 goto match;
503 }
504 break;
505 }
506 case 32:
507 {
43d85239 508 uint32_t v = array_item[bit / 32].u.integer_value.side_u32;
8bdd5c12
MD
509 if (reverse_byte_order)
510 v = side_bswap_32(v);
af6aa6e1
MD
511 if (v & (1ULL << (bit % 32))) {
512 match = true;
513 goto match;
514 }
ea32e5fc
MD
515 break;
516 }
af6aa6e1
MD
517 case 64:
518 {
43d85239 519 uint64_t v = array_item[bit / 64].u.integer_value.side_u64;
8bdd5c12
MD
520 if (reverse_byte_order)
521 v = side_bswap_64(v);
af6aa6e1
MD
522 if (v & (1ULL << (bit % 64))) {
523 match = true;
524 goto match;
525 }
526 break;
527 }
528 default:
529 abort();
530 }
ea32e5fc 531 }
af6aa6e1 532match:
ea32e5fc
MD
533 if (match) {
534 printf("%s", print_count++ ? ", " : "");
535 printf("\"%s\"", mapping->label);
536 }
537 }
538 if (!print_count)
539 printf("<NO LABEL>");
540 printf(" ]");
541}
542
1d9c515c
MD
543static
544void print_integer_binary(uint64_t v, int bits)
545{
546 int i;
547
548 printf("0b");
549 v <<= 64 - bits;
550 for (i = 0; i < bits; i++) {
551 printf("%c", v & (1ULL << 63) ? '1' : '0');
552 v <<= 1;
553 }
554}
555
0e9be766 556static
aac52685
MD
557void tracer_print_type_header(const char *separator,
558 const struct side_attr *attr, uint32_t nr_attr)
ac81c466 559{
aac52685
MD
560 print_attributes("attr", separator, attr, nr_attr);
561 printf("%s", nr_attr ? ", " : "");
562 printf("value%s ", separator);
ac81c466
MD
563}
564
56c21987 565static
e3080b2a
MD
566void tracer_print_type_integer(const char *separator,
567 const struct side_type_integer *type_integer,
568 const union side_integer_value *value)
56c21987
MD
569{
570 enum tracer_display_base base;
571 union {
572 uint64_t v_unsigned;
573 int64_t v_signed;
574 } v;
575
e3080b2a
MD
576 if (!type_integer->len_bits ||
577 type_integer->len_bits > type_integer->integer_size_bits)
56c21987 578 abort();
e3080b2a
MD
579 base = get_attr_display_base(type_integer->attr,
580 type_integer->nr_attr);
581 switch (type_integer->integer_size_bits) {
582 case 8:
583 if (type_integer->signedness)
584 v.v_signed = value->side_s8;
585 else
586 v.v_unsigned = value->side_u8;
56c21987 587 break;
e3080b2a
MD
588 case 16:
589 if (type_integer->signedness) {
590 int16_t side_s16;
56c21987 591
e3080b2a
MD
592 side_s16 = value->side_s16;
593 if (type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
594 side_s16 = side_bswap_16(side_s16);
595 v.v_signed = side_s16;
596 } else {
597 uint16_t side_u16;
56c21987 598
e3080b2a
MD
599 side_u16 = value->side_u16;
600 if (type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
601 side_u16 = side_bswap_16(side_u16);
602 v.v_unsigned = side_u16;
603 }
56c21987 604 break;
e3080b2a
MD
605 case 32:
606 if (type_integer->signedness) {
607 int32_t side_s32;
56c21987 608
e3080b2a
MD
609 side_s32 = value->side_s32;
610 if (type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
611 side_s32 = side_bswap_32(side_s32);
612 v.v_signed = side_s32;
613 } else {
614 uint32_t side_u32;
56c21987 615
e3080b2a
MD
616 side_u32 = value->side_u32;
617 if (type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
618 side_u32 = side_bswap_32(side_u32);
619 v.v_unsigned = side_u32;
620 }
56c21987 621 break;
e3080b2a
MD
622 case 64:
623 if (type_integer->signedness) {
624 int64_t side_s64;
56c21987 625
e3080b2a
MD
626 side_s64 = value->side_s64;
627 if (type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
628 side_s64 = side_bswap_64(side_s64);
629 v.v_signed = side_s64;
630 } else {
631 uint64_t side_u64;
56c21987 632
e3080b2a
MD
633 side_u64 = value->side_u64;
634 if (type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST)
635 side_u64 = side_bswap_64(side_u64);
636 v.v_unsigned = side_u64;
637 }
56c21987 638 break;
56c21987
MD
639 default:
640 abort();
641 }
e3080b2a
MD
642 if (type_integer->len_bits < 64)
643 v.v_unsigned &= (1ULL << type_integer->len_bits) - 1;
644 tracer_print_type_header(separator, type_integer->attr, type_integer->nr_attr);
56c21987
MD
645 switch (base) {
646 case TRACER_DISPLAY_BASE_2:
e3080b2a 647 print_integer_binary(v.v_unsigned, type_integer->len_bits);
56c21987
MD
648 break;
649 case TRACER_DISPLAY_BASE_8:
650 printf("0%" PRIo64, v.v_unsigned);
651 break;
652 case TRACER_DISPLAY_BASE_10:
e3080b2a 653 if (type_integer->signedness) {
56c21987 654 /* Sign-extend. */
e3080b2a
MD
655 if (type_integer->len_bits < 64) {
656 if (v.v_unsigned & (1ULL << (type_integer->len_bits - 1)))
657 v.v_unsigned |= ~((1ULL << type_integer->len_bits) - 1);
56c21987
MD
658 }
659 printf("%" PRId64, v.v_signed);
660 } else {
661 printf("%" PRIu64, v.v_unsigned);
662 }
663 break;
664 case TRACER_DISPLAY_BASE_16:
665 printf("0x%" PRIx64, v.v_unsigned);
666 break;
667 default:
668 abort();
669 }
670}
671
f611d0c3
MD
672static
673void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item)
674{
d8be25de
MD
675 enum side_type type;
676
45392033
MD
677 switch (type_desc->type) {
678 case SIDE_TYPE_ARRAY:
679 switch (item->type) {
680 case SIDE_TYPE_ARRAY_U8:
681 case SIDE_TYPE_ARRAY_U16:
682 case SIDE_TYPE_ARRAY_U32:
683 case SIDE_TYPE_ARRAY_U64:
684 case SIDE_TYPE_ARRAY_S8:
685 case SIDE_TYPE_ARRAY_S16:
686 case SIDE_TYPE_ARRAY_S32:
687 case SIDE_TYPE_ARRAY_S64:
dd6e76cb
MD
688 case SIDE_TYPE_ARRAY_POINTER32:
689 case SIDE_TYPE_ARRAY_POINTER64:
f7653b43 690 case SIDE_TYPE_ARRAY_BYTE:
45392033
MD
691 case SIDE_TYPE_ARRAY:
692 break;
693 default:
de1b3cd2 694 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
ba845af5 695 abort();
45392033 696 break;
ba845af5
MD
697 }
698 break;
45392033
MD
699
700 case SIDE_TYPE_VLA:
701 switch (item->type) {
702 case SIDE_TYPE_VLA_U8:
703 case SIDE_TYPE_VLA_U16:
704 case SIDE_TYPE_VLA_U32:
705 case SIDE_TYPE_VLA_U64:
706 case SIDE_TYPE_VLA_S8:
707 case SIDE_TYPE_VLA_S16:
708 case SIDE_TYPE_VLA_S32:
709 case SIDE_TYPE_VLA_S64:
f7653b43 710 case SIDE_TYPE_VLA_BYTE:
dd6e76cb
MD
711 case SIDE_TYPE_VLA_POINTER32:
712 case SIDE_TYPE_VLA_POINTER64:
45392033
MD
713 case SIDE_TYPE_VLA:
714 break;
715 default:
de1b3cd2 716 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
1533629f 717 abort();
45392033 718 break;
1533629f
MD
719 }
720 break;
721
45392033
MD
722 case SIDE_TYPE_ENUM:
723 switch (item->type) {
724 case SIDE_TYPE_U8:
725 case SIDE_TYPE_U16:
726 case SIDE_TYPE_U32:
727 case SIDE_TYPE_U64:
728 case SIDE_TYPE_S8:
729 case SIDE_TYPE_S16:
730 case SIDE_TYPE_S32:
731 case SIDE_TYPE_S64:
bab5d6e4
MD
732 break;
733 default:
de1b3cd2 734 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
45392033
MD
735 abort();
736 break;
737 }
738 break;
739
740 case SIDE_TYPE_ENUM_BITMAP:
741 switch (item->type) {
742 case SIDE_TYPE_U8:
4cc2880b 743 case SIDE_TYPE_BYTE:
45392033
MD
744 case SIDE_TYPE_U16:
745 case SIDE_TYPE_U32:
746 case SIDE_TYPE_U64:
747 case SIDE_TYPE_ARRAY:
748 case SIDE_TYPE_VLA:
749 break;
750 default:
de1b3cd2 751 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
45392033
MD
752 abort();
753 break;
d8be25de
MD
754 }
755 break;
756
ba845af5 757 default:
a2e2357e 758 if (type_desc->type != item->type) {
de1b3cd2 759 fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
ba845af5
MD
760 abort();
761 }
762 break;
f611d0c3 763 }
d8be25de 764
bab5d6e4
MD
765 if (type_desc->type == SIDE_TYPE_ENUM || type_desc->type == SIDE_TYPE_ENUM_BITMAP)
766 type = type_desc->type;
d8be25de
MD
767 else
768 type = item->type;
769
a848763d 770 printf("{ ");
d8be25de 771 switch (type) {
4f40d951 772 case SIDE_TYPE_BOOL:
aac52685 773 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
4f40d951
MD
774 printf("%s", item->u.side_bool ? "true" : "false");
775 break;
1d9c515c 776
56c21987 777 case SIDE_TYPE_U8:
f611d0c3 778 case SIDE_TYPE_U16:
f611d0c3 779 case SIDE_TYPE_U32:
f611d0c3 780 case SIDE_TYPE_U64:
f611d0c3 781 case SIDE_TYPE_S8:
f611d0c3 782 case SIDE_TYPE_S16:
f611d0c3 783 case SIDE_TYPE_S32:
f611d0c3 784 case SIDE_TYPE_S64:
e3080b2a
MD
785 tracer_print_type_integer(":", &type_desc->u.side_integer,
786 &item->u.integer_value);
f611d0c3 787 break;
56c21987 788
dd6e76cb 789 case SIDE_TYPE_POINTER32:
f5e650d7 790 {
dd6e76cb 791 uint32_t v;
f5e650d7 792
43d85239 793 v = item->u.integer_value.side_u32;
f5e650d7 794 if (type_to_host_reverse_bo(type_desc))
dd6e76cb 795 v = side_bswap_32(v);
aac52685 796 tracer_print_type_header(":", type_desc->u.side_integer.attr, type_desc->u.side_integer.nr_attr);
dd6e76cb
MD
797 printf("0x%" PRIx32, v);
798 break;
799 }
800 case SIDE_TYPE_POINTER64:
801 {
802 uint64_t v;
803
43d85239 804 v = item->u.integer_value.side_u64;
dd6e76cb
MD
805 if (type_to_host_reverse_bo(type_desc))
806 v = side_bswap_64(v);
aac52685 807 tracer_print_type_header(":", type_desc->u.side_integer.attr, type_desc->u.side_integer.nr_attr);
dd6e76cb 808 printf("0x%" PRIx64, v);
f5e650d7
MD
809 break;
810 }
f7653b43 811 case SIDE_TYPE_BYTE:
aac52685 812 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
f7653b43 813 printf("0x%" PRIx8, item->u.side_byte);
7aec0d09 814 break;
79f677ba 815
d8be25de
MD
816 case SIDE_TYPE_ENUM:
817 print_enum(type_desc, item);
79f677ba
MD
818 break;
819
bab5d6e4 820 case SIDE_TYPE_ENUM_BITMAP:
af6aa6e1 821 print_enum_bitmap(type_desc, item);
ea32e5fc
MD
822 break;
823
fb25b355 824 case SIDE_TYPE_FLOAT_BINARY16:
8bdd5c12 825 {
fb25b355 826#if __HAVE_FLOAT16
8bdd5c12
MD
827 union {
828 _Float16 f;
829 uint16_t u;
830 } float16 = {
a4969f31 831 .f = item->u.float_value.side_float_binary16,
8bdd5c12
MD
832 };
833
834 if (type_to_host_reverse_bo(type_desc))
835 float16.u = side_bswap_16(float16.u);
aac52685 836 tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr);
8bdd5c12 837 printf("%g", (double) float16.f);
fb25b355
MD
838 break;
839#else
de1b3cd2 840 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
fb25b355
MD
841 abort();
842#endif
8bdd5c12 843 }
fb25b355 844 case SIDE_TYPE_FLOAT_BINARY32:
8bdd5c12 845 {
fb25b355 846#if __HAVE_FLOAT32
8bdd5c12
MD
847 union {
848 _Float32 f;
849 uint32_t u;
850 } float32 = {
a4969f31 851 .f = item->u.float_value.side_float_binary32,
8bdd5c12
MD
852 };
853
854 if (type_to_host_reverse_bo(type_desc))
855 float32.u = side_bswap_32(float32.u);
aac52685 856 tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr);
8bdd5c12 857 printf("%g", (double) float32.f);
fb25b355
MD
858 break;
859#else
de1b3cd2 860 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
fb25b355
MD
861 abort();
862#endif
8bdd5c12 863 }
fb25b355 864 case SIDE_TYPE_FLOAT_BINARY64:
8bdd5c12 865 {
fb25b355 866#if __HAVE_FLOAT64
8bdd5c12
MD
867 union {
868 _Float64 f;
869 uint64_t u;
870 } float64 = {
a4969f31 871 .f = item->u.float_value.side_float_binary64,
8bdd5c12
MD
872 };
873
874 if (type_to_host_reverse_bo(type_desc))
875 float64.u = side_bswap_64(float64.u);
aac52685 876 tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr);
8bdd5c12 877 printf("%g", (double) float64.f);
fb25b355
MD
878 break;
879#else
de1b3cd2 880 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
fb25b355
MD
881 abort();
882#endif
8bdd5c12 883 }
fb25b355 884 case SIDE_TYPE_FLOAT_BINARY128:
8bdd5c12 885 {
fb25b355 886#if __HAVE_FLOAT128
8bdd5c12
MD
887 union {
888 _Float128 f;
889 char arr[16];
890 } float128 = {
a4969f31 891 .f = item->u.float_value.side_float_binary128,
8bdd5c12
MD
892 };
893
894 if (type_to_host_reverse_bo(type_desc))
895 side_bswap_128p(float128.arr);
aac52685 896 tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr);
8bdd5c12 897 printf("%Lg", (long double) float128.f);
fb25b355
MD
898 break;
899#else
de1b3cd2 900 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
fb25b355
MD
901 abort();
902#endif
8bdd5c12 903 }
f611d0c3 904 case SIDE_TYPE_STRING:
aac52685 905 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
8549e629 906 printf("\"%s\"", (const char *)(uintptr_t) item->u.string);
f611d0c3
MD
907 break;
908 case SIDE_TYPE_STRUCT:
909 tracer_print_struct(type_desc, item->u.side_struct);
910 break;
7a1cb105
MD
911 case SIDE_TYPE_STRUCT_SG:
912 tracer_print_struct_sg(type_desc, item->u.side_struct_sg_ptr);
913 break;
f611d0c3
MD
914 case SIDE_TYPE_ARRAY:
915 tracer_print_array(type_desc, item->u.side_array);
916 break;
917 case SIDE_TYPE_VLA:
918 tracer_print_vla(type_desc, item->u.side_vla);
919 break;
920 case SIDE_TYPE_VLA_VISITOR:
352a4b77 921 tracer_print_vla_visitor(type_desc, item->u.side_vla_app_visitor_ctx);
f611d0c3 922 break;
ba845af5
MD
923 case SIDE_TYPE_ARRAY_U8:
924 case SIDE_TYPE_ARRAY_U16:
925 case SIDE_TYPE_ARRAY_U32:
926 case SIDE_TYPE_ARRAY_U64:
927 case SIDE_TYPE_ARRAY_S8:
928 case SIDE_TYPE_ARRAY_S16:
929 case SIDE_TYPE_ARRAY_S32:
930 case SIDE_TYPE_ARRAY_S64:
f7653b43 931 case SIDE_TYPE_ARRAY_BYTE:
dd6e76cb
MD
932 case SIDE_TYPE_ARRAY_POINTER32:
933 case SIDE_TYPE_ARRAY_POINTER64:
ba845af5
MD
934 tracer_print_array_fixint(type_desc, item);
935 break;
1533629f
MD
936 case SIDE_TYPE_VLA_U8:
937 case SIDE_TYPE_VLA_U16:
938 case SIDE_TYPE_VLA_U32:
939 case SIDE_TYPE_VLA_U64:
940 case SIDE_TYPE_VLA_S8:
941 case SIDE_TYPE_VLA_S16:
942 case SIDE_TYPE_VLA_S32:
943 case SIDE_TYPE_VLA_S64:
f7653b43 944 case SIDE_TYPE_VLA_BYTE:
dd6e76cb
MD
945 case SIDE_TYPE_VLA_POINTER32:
946 case SIDE_TYPE_VLA_POINTER64:
1533629f
MD
947 tracer_print_vla_fixint(type_desc, item);
948 break;
a2e2357e 949 case SIDE_TYPE_DYNAMIC:
aac52685 950 tracer_print_type_header(":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr);
a2e2357e
MD
951 tracer_print_dynamic(&item->u.dynamic);
952 break;
f611d0c3 953 default:
de1b3cd2 954 fprintf(stderr, "<UNKNOWN TYPE>");
f611d0c3
MD
955 abort();
956 }
a848763d 957 printf(" }");
f611d0c3
MD
958}
959
960static
961void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg_vec *item)
962{
19fa6aa2 963 printf("%s: ", item_desc->field_name);
f611d0c3 964 tracer_print_type(&item_desc->side_type, item);
f611d0c3
MD
965}
966
967static
968void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
969{
970 const struct side_arg_vec *sav = sav_desc->sav;
971 uint32_t side_sav_len = sav_desc->len;
972 int i;
973
c7a14585 974 if (type_desc->u.side_struct->nr_fields != side_sav_len) {
de1b3cd2 975 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments of structure\n");
f611d0c3
MD
976 abort();
977 }
905c328e 978 print_attributes("attr", ":", type_desc->u.side_struct->attr, type_desc->u.side_struct->nr_attr);
73b2b0c2
MD
979 printf("%s", type_desc->u.side_struct->nr_attr ? ", " : "");
980 printf("fields: { ");
f611d0c3
MD
981 for (i = 0; i < side_sav_len; i++) {
982 printf("%s", i ? ", " : "");
c7a14585 983 tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]);
f611d0c3 984 }
d4328528 985 printf(" }");
f611d0c3
MD
986}
987
7a1cb105
MD
988static
989void tracer_print_sg_integer_type_header(const struct side_type_sg_description *sg_type)
990{
991 print_attributes("attr", ":", sg_type->u.side_basic.attr, sg_type->u.side_basic.nr_attr);
992 printf("%s", sg_type->u.side_basic.nr_attr ? ", " : "");
993 printf("value: ");
994}
995
996static
997void tracer_print_sg_type(const struct side_type_sg_description *sg_type, void *_ptr)
998{
999 enum tracer_display_base base = TRACER_DISPLAY_BASE_10;
1000 const char *ptr = (const char *) _ptr;
1001
1002 switch (sg_type->type) {
1003 case SIDE_TYPE_SG_UNSIGNED_INT:
1004 case SIDE_TYPE_SG_SIGNED_INT:
1005 base = get_attr_display_base(sg_type->u.side_basic.attr,
1006 sg_type->u.side_basic.nr_attr);
1007 break;
1008 default:
1009 break;
1010 }
1011
1012 printf("{ ");
1013 switch (sg_type->type) {
1014 case SIDE_TYPE_SG_UNSIGNED_INT:
1015 {
1016 tracer_print_sg_integer_type_header(sg_type);
1017 switch (sg_type->u.side_basic.integer_size_bits) {
1018 case 8:
1019 {
1020 uint8_t v;
1021
bc0b21eb
MD
1022 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 8)
1023 abort();
7a1cb105
MD
1024 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1025 v >>= sg_type->u.side_basic.offset_bits;
1026 if (sg_type->u.side_basic.len_bits < 8)
1027 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1028 switch (base) {
1029 case TRACER_DISPLAY_BASE_2:
1030 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1031 break;
1032 case TRACER_DISPLAY_BASE_8:
1033 printf("0%" PRIo8, v);
1034 break;
1035 case TRACER_DISPLAY_BASE_10:
1036 printf("%" PRIu8, v);
1037 break;
1038 case TRACER_DISPLAY_BASE_16:
1039 printf("0x%" PRIx8, v);
1040 break;
1041 default:
1042 abort();
1043 }
1044 break;
1045 }
1046 case 16:
1047 {
1048 uint16_t v;
1049
bc0b21eb
MD
1050 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 16)
1051 abort();
7a1cb105
MD
1052 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1053 if (sg_type_to_host_reverse_bo(sg_type))
1054 v = side_bswap_16(v);
1055 v >>= sg_type->u.side_basic.offset_bits;
1056 if (sg_type->u.side_basic.len_bits < 16)
1057 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1058 switch (base) {
1059 case TRACER_DISPLAY_BASE_2:
1060 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1061 break;
1062 case TRACER_DISPLAY_BASE_8:
1063 printf("0%" PRIo16, v);
1064 break;
1065 case TRACER_DISPLAY_BASE_10:
1066 printf("%" PRIu16, v);
1067 break;
1068 case TRACER_DISPLAY_BASE_16:
1069 printf("0x%" PRIx16, v);
1070 break;
1071 default:
1072 abort();
1073 }
1074 break;
1075 }
1076 case 32:
1077 {
1078 uint32_t v;
1079
bc0b21eb
MD
1080 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 32)
1081 abort();
7a1cb105
MD
1082 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1083 if (sg_type_to_host_reverse_bo(sg_type))
1084 v = side_bswap_32(v);
1085 v >>= sg_type->u.side_basic.offset_bits;
1086 if (sg_type->u.side_basic.len_bits < 32)
1087 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1088 switch (base) {
1089 case TRACER_DISPLAY_BASE_2:
1090 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1091 break;
1092 case TRACER_DISPLAY_BASE_8:
1093 printf("0%" PRIo32, v);
1094 break;
1095 case TRACER_DISPLAY_BASE_10:
1096 printf("%" PRIu32, v);
1097 break;
1098 case TRACER_DISPLAY_BASE_16:
1099 printf("0x%" PRIx32, v);
1100 break;
1101 default:
1102 abort();
1103 }
1104 break;
1105 }
1106 case 64:
1107 {
1108 uint64_t v;
1109
bc0b21eb
MD
1110 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 64)
1111 abort();
7a1cb105
MD
1112 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1113 if (sg_type_to_host_reverse_bo(sg_type))
1114 v = side_bswap_64(v);
1115 v >>= sg_type->u.side_basic.offset_bits;
1116 if (sg_type->u.side_basic.len_bits < 64)
1117 v &= (1ULL << sg_type->u.side_basic.len_bits) - 1;
1118 switch (base) {
1119 case TRACER_DISPLAY_BASE_2:
1120 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1121 break;
1122 case TRACER_DISPLAY_BASE_8:
1123 printf("0%" PRIo64, v);
1124 break;
1125 case TRACER_DISPLAY_BASE_10:
1126 printf("%" PRIu64, v);
1127 break;
1128 case TRACER_DISPLAY_BASE_16:
1129 printf("0x%" PRIx64, v);
1130 break;
1131 default:
1132 abort();
1133 }
1134 break;
1135 }
1136 default:
1137 fprintf(stderr, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1138 abort();
1139 }
1140 break;
1141 }
1142 case SIDE_TYPE_SG_SIGNED_INT:
1143 {
1144 tracer_print_sg_integer_type_header(sg_type);
1145 switch (sg_type->u.side_basic.integer_size_bits) {
1146 case 8:
1147 {
1148 int8_t v;
1149
bc0b21eb
MD
1150 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 8)
1151 abort();
7a1cb105
MD
1152 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1153 v >>= sg_type->u.side_basic.offset_bits;
1154 if (sg_type->u.side_basic.len_bits < 8)
1155 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1156 switch (base) {
1157 case TRACER_DISPLAY_BASE_2:
1158 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1159 break;
1160 case TRACER_DISPLAY_BASE_8:
1161 printf("0%" PRIo8, v);
1162 break;
1163 case TRACER_DISPLAY_BASE_10:
bc0b21eb
MD
1164 /* Sign-extend. */
1165 if (sg_type->u.side_basic.len_bits < 8) {
1166 if (v & (1U << (sg_type->u.side_basic.len_bits - 1)))
1167 v |= ~((1U << sg_type->u.side_basic.len_bits) - 1);
1168 }
7a1cb105
MD
1169 printf("%" PRId8, v);
1170 break;
1171 case TRACER_DISPLAY_BASE_16:
1172 printf("0x%" PRIx8, v);
1173 break;
1174 default:
1175 abort();
1176 }
1177 break;
1178 }
1179 case 16:
1180 {
1181 int16_t v;
1182
bc0b21eb
MD
1183 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 16)
1184 abort();
7a1cb105
MD
1185 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1186 if (sg_type_to_host_reverse_bo(sg_type))
1187 v = side_bswap_16(v);
1188 v >>= sg_type->u.side_basic.offset_bits;
1189 if (sg_type->u.side_basic.len_bits < 16)
1190 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1191 switch (base) {
1192 case TRACER_DISPLAY_BASE_2:
1193 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1194 break;
1195 case TRACER_DISPLAY_BASE_8:
1196 printf("0%" PRIo16, v);
1197 break;
1198 case TRACER_DISPLAY_BASE_10:
bc0b21eb
MD
1199 /* Sign-extend. */
1200 if (sg_type->u.side_basic.len_bits < 16) {
1201 if (v & (1U << (sg_type->u.side_basic.len_bits - 1)))
1202 v |= ~((1U << sg_type->u.side_basic.len_bits) - 1);
1203 }
7a1cb105
MD
1204 printf("%" PRId16, v);
1205 break;
1206 case TRACER_DISPLAY_BASE_16:
1207 printf("0x%" PRIx16, v);
1208 break;
1209 default:
1210 abort();
1211 }
1212 break;
1213 }
1214 case 32:
1215 {
1216 uint32_t v;
1217
bc0b21eb
MD
1218 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 32)
1219 abort();
7a1cb105
MD
1220 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1221 if (sg_type_to_host_reverse_bo(sg_type))
1222 v = side_bswap_32(v);
1223 v >>= sg_type->u.side_basic.offset_bits;
1224 if (sg_type->u.side_basic.len_bits < 32)
1225 v &= (1U << sg_type->u.side_basic.len_bits) - 1;
1226 switch (base) {
1227 case TRACER_DISPLAY_BASE_2:
1228 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1229 break;
1230 case TRACER_DISPLAY_BASE_8:
1231 printf("0%" PRIo32, v);
1232 break;
1233 case TRACER_DISPLAY_BASE_10:
bc0b21eb
MD
1234 /* Sign-extend. */
1235 if (sg_type->u.side_basic.len_bits < 32) {
1236 if (v & (1U << (sg_type->u.side_basic.len_bits - 1)))
1237 v |= ~((1U << sg_type->u.side_basic.len_bits) - 1);
1238 }
7a1cb105
MD
1239 printf("%" PRId32, v);
1240 break;
1241 case TRACER_DISPLAY_BASE_16:
1242 printf("0x%" PRIx32, v);
1243 break;
1244 default:
1245 abort();
1246 }
1247 break;
1248 }
1249 case 64:
1250 {
1251 uint64_t v;
1252
bc0b21eb
MD
1253 if (!sg_type->u.side_basic.len_bits || sg_type->u.side_basic.len_bits + sg_type->u.side_basic.offset_bits > 64)
1254 abort();
7a1cb105
MD
1255 memcpy(&v, ptr + sg_type->u.side_basic.integer_offset, sizeof(v));
1256 if (sg_type_to_host_reverse_bo(sg_type))
1257 v = side_bswap_64(v);
1258 v >>= sg_type->u.side_basic.offset_bits;
1259 if (sg_type->u.side_basic.len_bits < 64)
1260 v &= (1ULL << sg_type->u.side_basic.len_bits) - 1;
1261 switch (base) {
1262 case TRACER_DISPLAY_BASE_2:
1263 print_integer_binary(v, sg_type->u.side_basic.len_bits);
1264 break;
1265 case TRACER_DISPLAY_BASE_8:
1266 printf("0%" PRIo64, v);
1267 break;
1268 case TRACER_DISPLAY_BASE_10:
bc0b21eb
MD
1269 /* Sign-extend. */
1270 if (sg_type->u.side_basic.len_bits < 64) {
1271 if (v & (1ULL << (sg_type->u.side_basic.len_bits - 1)))
1272 v |= ~((1ULL << sg_type->u.side_basic.len_bits) - 1);
1273 }
7a1cb105
MD
1274 printf("%" PRId64, v);
1275 break;
1276 case TRACER_DISPLAY_BASE_16:
1277 printf("0x%" PRIx64, v);
1278 break;
1279 default:
1280 abort();
1281 }
1282 break;
1283 }
1284 default:
1285 fprintf(stderr, "<UNKNOWN SCATTER-GATHER INTEGER SIZE>");
1286 abort();
1287 }
1288 break;
1289 }
1290 default:
1291 fprintf(stderr, "<UNKNOWN SCATTER-GATHER TYPE>");
1292 abort();
1293 }
1294 printf(" }");
1295}
1296
1297static
1298void tracer_print_sg_field(const struct side_struct_field_sg *field_sg, void *ptr)
1299{
1300 printf("%s: ", field_sg->field_name);
1301 tracer_print_sg_type(&field_sg->side_type, ptr);
1302}
1303
1304static
1305void tracer_print_struct_sg(const struct side_type_description *type_desc, void *ptr)
1306{
1307 const struct side_type_struct_sg *struct_sg = type_desc->u.side_struct_sg;
1308 int i;
1309
1310 print_attributes("attr", ":", struct_sg->attr, struct_sg->nr_attr);
1311 printf("%s", struct_sg->nr_attr ? ", " : "");
1312 printf("fields: { ");
1313 for (i = 0; i < struct_sg->nr_fields; i++) {
1314 printf("%s", i ? ", " : "");
1315 tracer_print_sg_field(&struct_sg->fields_sg[i], ptr);
1316 }
1317 printf(" }");
1318}
1319
f611d0c3
MD
1320static
1321void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
1322{
1323 const struct side_arg_vec *sav = sav_desc->sav;
1324 uint32_t side_sav_len = sav_desc->len;
1325 int i;
1326
1327 if (type_desc->u.side_array.length != side_sav_len) {
de1b3cd2 1328 fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n");
f611d0c3
MD
1329 abort();
1330 }
905c328e 1331 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
d4328528 1332 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
20574104 1333 printf("elements: ");
f611d0c3
MD
1334 printf("[ ");
1335 for (i = 0; i < side_sav_len; i++) {
1336 printf("%s", i ? ", " : "");
1337 tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]);
1338 }
1339 printf(" ]");
1340}
1341
1342static
1343void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc)
1344{
1345 const struct side_arg_vec *sav = sav_desc->sav;
1346 uint32_t side_sav_len = sav_desc->len;
1347 int i;
1348
905c328e 1349 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
d4328528 1350 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
20574104 1351 printf("elements: ");
f611d0c3
MD
1352 printf("[ ");
1353 for (i = 0; i < side_sav_len; i++) {
1354 printf("%s", i ? ", " : "");
1355 tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]);
1356 }
1357 printf(" ]");
1358}
1359
352a4b77
MD
1360struct tracer_visitor_priv {
1361 const struct side_type_description *elem_type;
1362 int i;
1363};
1364
1365static
1366enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx,
1367 const struct side_arg_vec *elem)
1368{
1369 struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv;
1370
1371 printf("%s", tracer_priv->i++ ? ", " : "");
1372 tracer_print_type(tracer_priv->elem_type, elem);
1373 return SIDE_VISITOR_STATUS_OK;
1374}
1375
f611d0c3 1376static
352a4b77 1377void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx)
f611d0c3
MD
1378{
1379 enum side_visitor_status status;
352a4b77
MD
1380 struct tracer_visitor_priv tracer_priv = {
1381 .elem_type = type_desc->u.side_vla_visitor.elem_type,
1382 .i = 0,
1383 };
1384 const struct side_tracer_visitor_ctx tracer_ctx = {
1385 .write_elem = tracer_write_elem_cb,
1386 .priv = &tracer_priv,
1387 };
f611d0c3 1388
905c328e 1389 print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr);
d4328528 1390 printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : "");
20574104 1391 printf("elements: ");
352a4b77
MD
1392 printf("[ ");
1393 status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx);
1394 switch (status) {
1395 case SIDE_VISITOR_STATUS_OK:
1396 break;
1397 case SIDE_VISITOR_STATUS_ERROR:
de1b3cd2 1398 fprintf(stderr, "ERROR: Visitor error\n");
f611d0c3 1399 abort();
f611d0c3
MD
1400 }
1401 printf(" ]");
f611d0c3
MD
1402}
1403
ba845af5
MD
1404void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
1405{
1406 const struct side_type_description *elem_type = type_desc->u.side_array.elem_type;
1407 uint32_t side_sav_len = type_desc->u.side_array.length;
1408 void *p = item->u.side_array_fixint;
1409 enum side_type side_type;
1410 int i;
1411
905c328e 1412 print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
d4328528 1413 printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
20574104 1414 printf("elements: ");
1e8256c9
MD
1415 switch (item->type) {
1416 case SIDE_TYPE_ARRAY_U8:
1417 if (elem_type->type != SIDE_TYPE_U8)
1418 goto type_error;
1419 break;
1420 case SIDE_TYPE_ARRAY_U16:
1421 if (elem_type->type != SIDE_TYPE_U16)
1422 goto type_error;
1423 break;
1424 case SIDE_TYPE_ARRAY_U32:
1425 if (elem_type->type != SIDE_TYPE_U32)
1426 goto type_error;
1427 break;
1428 case SIDE_TYPE_ARRAY_U64:
1429 if (elem_type->type != SIDE_TYPE_U64)
1430 goto type_error;
1431 break;
1432 case SIDE_TYPE_ARRAY_S8:
1433 if (elem_type->type != SIDE_TYPE_S8)
1434 goto type_error;
1435 break;
1436 case SIDE_TYPE_ARRAY_S16:
1437 if (elem_type->type != SIDE_TYPE_S16)
1438 goto type_error;
1439 break;
1440 case SIDE_TYPE_ARRAY_S32:
1441 if (elem_type->type != SIDE_TYPE_S32)
1442 goto type_error;
1443 break;
1444 case SIDE_TYPE_ARRAY_S64:
1445 if (elem_type->type != SIDE_TYPE_S64)
1446 goto type_error;
1447 break;
f7653b43
MD
1448 case SIDE_TYPE_ARRAY_BYTE:
1449 if (elem_type->type != SIDE_TYPE_BYTE)
7aec0d09
MD
1450 goto type_error;
1451 break;
dd6e76cb
MD
1452 case SIDE_TYPE_ARRAY_POINTER32:
1453 if (elem_type->type != SIDE_TYPE_POINTER32)
1454 goto type_error;
1455 case SIDE_TYPE_ARRAY_POINTER64:
1456 if (elem_type->type != SIDE_TYPE_POINTER64)
f5e650d7
MD
1457 goto type_error;
1458 break;
1e8256c9
MD
1459 default:
1460 goto type_error;
ba845af5 1461 }
1e8256c9 1462 side_type = elem_type->type;
ba845af5 1463
1533629f
MD
1464 printf("[ ");
1465 for (i = 0; i < side_sav_len; i++) {
1466 struct side_arg_vec sav_elem = {
1467 .type = side_type,
1468 };
1469
1470 switch (side_type) {
1471 case SIDE_TYPE_U8:
43d85239 1472 sav_elem.u.integer_value.side_u8 = ((const uint8_t *) p)[i];
1533629f
MD
1473 break;
1474 case SIDE_TYPE_S8:
43d85239 1475 sav_elem.u.integer_value.side_s8 = ((const int8_t *) p)[i];
1533629f
MD
1476 break;
1477 case SIDE_TYPE_U16:
43d85239 1478 sav_elem.u.integer_value.side_u16 = ((const uint16_t *) p)[i];
1533629f
MD
1479 break;
1480 case SIDE_TYPE_S16:
43d85239 1481 sav_elem.u.integer_value.side_s16 = ((const int16_t *) p)[i];
1533629f
MD
1482 break;
1483 case SIDE_TYPE_U32:
43d85239 1484 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
1533629f
MD
1485 break;
1486 case SIDE_TYPE_S32:
43d85239 1487 sav_elem.u.integer_value.side_s32 = ((const int32_t *) p)[i];
1533629f
MD
1488 break;
1489 case SIDE_TYPE_U64:
43d85239 1490 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
1533629f
MD
1491 break;
1492 case SIDE_TYPE_S64:
43d85239 1493 sav_elem.u.integer_value.side_s64 = ((const int64_t *) p)[i];
1533629f 1494 break;
f7653b43
MD
1495 case SIDE_TYPE_BYTE:
1496 sav_elem.u.side_byte = ((const uint8_t *) p)[i];
7aec0d09 1497 break;
dd6e76cb 1498 case SIDE_TYPE_POINTER32:
43d85239 1499 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
dd6e76cb
MD
1500 break;
1501 case SIDE_TYPE_POINTER64:
43d85239 1502 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
f5e650d7 1503 break;
1533629f
MD
1504
1505 default:
de1b3cd2 1506 fprintf(stderr, "ERROR: Unexpected type\n");
1533629f
MD
1507 abort();
1508 }
1509
1510 printf("%s", i ? ", " : "");
1511 tracer_print_type(elem_type, &sav_elem);
1512 }
1513 printf(" ]");
1514 return;
1515
1516type_error:
de1b3cd2 1517 fprintf(stderr, "ERROR: type mismatch\n");
1533629f
MD
1518 abort();
1519}
1520
1521void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item)
1522{
1523 const struct side_type_description *elem_type = type_desc->u.side_vla.elem_type;
1524 uint32_t side_sav_len = item->u.side_vla_fixint.length;
1525 void *p = item->u.side_vla_fixint.p;
1526 enum side_type side_type;
1527 int i;
1528
905c328e 1529 print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
d4328528 1530 printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
20574104 1531 printf("elements: ");
a2e2357e
MD
1532 switch (item->type) {
1533 case SIDE_TYPE_VLA_U8:
1534 if (elem_type->type != SIDE_TYPE_U8)
1533629f 1535 goto type_error;
a2e2357e
MD
1536 break;
1537 case SIDE_TYPE_VLA_U16:
1538 if (elem_type->type != SIDE_TYPE_U16)
1533629f 1539 goto type_error;
a2e2357e
MD
1540 break;
1541 case SIDE_TYPE_VLA_U32:
1542 if (elem_type->type != SIDE_TYPE_U32)
1543 goto type_error;
1544 break;
1545 case SIDE_TYPE_VLA_U64:
1546 if (elem_type->type != SIDE_TYPE_U64)
1547 goto type_error;
1548 break;
1549 case SIDE_TYPE_VLA_S8:
1550 if (elem_type->type != SIDE_TYPE_S8)
1551 goto type_error;
1552 break;
1553 case SIDE_TYPE_VLA_S16:
1554 if (elem_type->type != SIDE_TYPE_S16)
1555 goto type_error;
1556 break;
1557 case SIDE_TYPE_VLA_S32:
1558 if (elem_type->type != SIDE_TYPE_S32)
1559 goto type_error;
1560 break;
1561 case SIDE_TYPE_VLA_S64:
1562 if (elem_type->type != SIDE_TYPE_S64)
1563 goto type_error;
1564 break;
f7653b43
MD
1565 case SIDE_TYPE_VLA_BYTE:
1566 if (elem_type->type != SIDE_TYPE_BYTE)
7aec0d09
MD
1567 goto type_error;
1568 break;
dd6e76cb
MD
1569 case SIDE_TYPE_VLA_POINTER32:
1570 if (elem_type->type != SIDE_TYPE_POINTER32)
1571 goto type_error;
1572 case SIDE_TYPE_VLA_POINTER64:
1573 if (elem_type->type != SIDE_TYPE_POINTER64)
f5e650d7
MD
1574 goto type_error;
1575 break;
a2e2357e
MD
1576 default:
1577 goto type_error;
1533629f 1578 }
a2e2357e 1579 side_type = elem_type->type;
1533629f 1580
ba845af5
MD
1581 printf("[ ");
1582 for (i = 0; i < side_sav_len; i++) {
1583 struct side_arg_vec sav_elem = {
1584 .type = side_type,
1585 };
1586
1587 switch (side_type) {
1588 case SIDE_TYPE_U8:
43d85239 1589 sav_elem.u.integer_value.side_u8 = ((const uint8_t *) p)[i];
ba845af5
MD
1590 break;
1591 case SIDE_TYPE_S8:
43d85239 1592 sav_elem.u.integer_value.side_s8 = ((const int8_t *) p)[i];
ba845af5
MD
1593 break;
1594 case SIDE_TYPE_U16:
43d85239 1595 sav_elem.u.integer_value.side_u16 = ((const uint16_t *) p)[i];
ba845af5
MD
1596 break;
1597 case SIDE_TYPE_S16:
43d85239 1598 sav_elem.u.integer_value.side_s16 = ((const int16_t *) p)[i];
ba845af5
MD
1599 break;
1600 case SIDE_TYPE_U32:
43d85239 1601 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
ba845af5
MD
1602 break;
1603 case SIDE_TYPE_S32:
43d85239 1604 sav_elem.u.integer_value.side_s32 = ((const int32_t *) p)[i];
ba845af5
MD
1605 break;
1606 case SIDE_TYPE_U64:
43d85239 1607 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
ba845af5
MD
1608 break;
1609 case SIDE_TYPE_S64:
43d85239 1610 sav_elem.u.integer_value.side_s64 = ((const int64_t *) p)[i];
ba845af5 1611 break;
f7653b43
MD
1612 case SIDE_TYPE_BYTE:
1613 sav_elem.u.side_byte = ((const uint8_t *) p)[i];
7aec0d09 1614 break;
dd6e76cb 1615 case SIDE_TYPE_POINTER32:
43d85239 1616 sav_elem.u.integer_value.side_u32 = ((const uint32_t *) p)[i];
dd6e76cb
MD
1617 break;
1618 case SIDE_TYPE_POINTER64:
43d85239 1619 sav_elem.u.integer_value.side_u64 = ((const uint64_t *) p)[i];
f5e650d7 1620 break;
ba845af5
MD
1621
1622 default:
de1b3cd2 1623 fprintf(stderr, "ERROR: Unexpected type\n");
ba845af5
MD
1624 abort();
1625 }
1626
1627 printf("%s", i ? ", " : "");
1628 tracer_print_type(elem_type, &sav_elem);
1629 }
1630 printf(" ]");
1631 return;
1632
1633type_error:
de1b3cd2 1634 fprintf(stderr, "ERROR: type mismatch\n");
ba845af5
MD
1635 abort();
1636}
1637
a2e2357e 1638static
c208889e 1639void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct)
a2e2357e 1640{
c208889e
MD
1641 const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields;
1642 uint32_t len = dynamic_struct->len;
465e5e7e
MD
1643 int i;
1644
905c328e 1645 print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr);
8d20e708 1646 printf("%s", dynamic_struct->nr_attr ? ", " : "");
f0061366 1647 printf("fields:: ");
465e5e7e
MD
1648 printf("[ ");
1649 for (i = 0; i < len; i++) {
1650 printf("%s", i ? ", " : "");
1651 printf("%s:: ", fields[i].field_name);
1652 tracer_print_dynamic(&fields[i].elem);
1653 }
1654 printf(" ]");
a2e2357e
MD
1655}
1656
2b359235
MD
1657struct tracer_dynamic_struct_visitor_priv {
1658 int i;
1659};
1660
1661static
1662enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
1663 const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
1664 const struct side_arg_dynamic_event_field *dynamic_field)
1665{
1666 struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv;
1667
1668 printf("%s", tracer_priv->i++ ? ", " : "");
1669 printf("%s:: ", dynamic_field->field_name);
1670 tracer_print_dynamic(&dynamic_field->elem);
1671 return SIDE_VISITOR_STATUS_OK;
1672}
1673
a2e2357e 1674static
c208889e 1675void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item)
a2e2357e 1676{
2b359235
MD
1677 enum side_visitor_status status;
1678 struct tracer_dynamic_struct_visitor_priv tracer_priv = {
1679 .i = 0,
1680 };
1681 const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = {
1682 .write_field = tracer_dynamic_struct_write_elem_cb,
1683 .priv = &tracer_priv,
1684 };
1685 void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx;
1686
905c328e 1687 print_attributes("attr", "::", item->u.side_dynamic_struct_visitor.attr, item->u.side_dynamic_struct_visitor.nr_attr);
8d20e708 1688 printf("%s", item->u.side_dynamic_struct_visitor.nr_attr ? ", " : "");
f0061366 1689 printf("fields:: ");
2b359235
MD
1690 printf("[ ");
1691 status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx);
1692 switch (status) {
1693 case SIDE_VISITOR_STATUS_OK:
1694 break;
1695 case SIDE_VISITOR_STATUS_ERROR:
de1b3cd2 1696 fprintf(stderr, "ERROR: Visitor error\n");
2b359235
MD
1697 abort();
1698 }
1699 printf(" ]");
a2e2357e
MD
1700}
1701
1702static
1703void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla *vla)
1704{
1705 const struct side_arg_dynamic_vec *sav = vla->sav;
1706 uint32_t side_sav_len = vla->len;
1707 int i;
1708
905c328e 1709 print_attributes("attr", "::", vla->attr, vla->nr_attr);
8d20e708 1710 printf("%s", vla->nr_attr ? ", " : "");
f0061366 1711 printf("elements:: ");
a2e2357e
MD
1712 printf("[ ");
1713 for (i = 0; i < side_sav_len; i++) {
1714 printf("%s", i ? ", " : "");
1715 tracer_print_dynamic(&sav[i]);
1716 }
1717 printf(" ]");
1718}
1719
8ceca0cd
MD
1720struct tracer_dynamic_vla_visitor_priv {
1721 int i;
1722};
1723
1724static
1725enum side_visitor_status tracer_dynamic_vla_write_elem_cb(
1726 const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx,
1727 const struct side_arg_dynamic_vec *elem)
1728{
1729 struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv;
1730
1731 printf("%s", tracer_priv->i++ ? ", " : "");
1732 tracer_print_dynamic(elem);
1733 return SIDE_VISITOR_STATUS_OK;
1734}
1735
a2e2357e
MD
1736static
1737void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec *item)
1738{
8ceca0cd
MD
1739 enum side_visitor_status status;
1740 struct tracer_dynamic_vla_visitor_priv tracer_priv = {
1741 .i = 0,
1742 };
1743 const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = {
1744 .write_elem = tracer_dynamic_vla_write_elem_cb,
1745 .priv = &tracer_priv,
1746 };
1747 void *app_ctx = item->u.side_dynamic_vla_visitor.app_ctx;
1748
905c328e 1749 print_attributes("attr", "::", item->u.side_dynamic_vla_visitor.attr, item->u.side_dynamic_vla_visitor.nr_attr);
8d20e708 1750 printf("%s", item->u.side_dynamic_vla_visitor.nr_attr ? ", " : "");
f0061366 1751 printf("elements:: ");
8ceca0cd
MD
1752 printf("[ ");
1753 status = item->u.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx);
1754 switch (status) {
1755 case SIDE_VISITOR_STATUS_OK:
1756 break;
1757 case SIDE_VISITOR_STATUS_ERROR:
de1b3cd2 1758 fprintf(stderr, "ERROR: Visitor error\n");
8ceca0cd
MD
1759 abort();
1760 }
1761 printf(" ]");
a2e2357e
MD
1762}
1763
1764static
1765void tracer_print_dynamic(const struct side_arg_dynamic_vec *item)
1766{
1d9c515c
MD
1767 enum tracer_display_base base = TRACER_DISPLAY_BASE_10;
1768
1769 switch (item->dynamic_type) {
1770 case SIDE_DYNAMIC_TYPE_U8:
1771 case SIDE_DYNAMIC_TYPE_U16:
1772 case SIDE_DYNAMIC_TYPE_U32:
1773 case SIDE_DYNAMIC_TYPE_U64:
1774 case SIDE_DYNAMIC_TYPE_S8:
1775 case SIDE_DYNAMIC_TYPE_S16:
1776 case SIDE_DYNAMIC_TYPE_S32:
1777 case SIDE_DYNAMIC_TYPE_S64:
d2be7696
MD
1778 base = get_attr_display_base(item->u.side_integer.type.attr,
1779 item->u.side_integer.type.nr_attr);
1d9c515c
MD
1780 break;
1781 default:
1782 break;
1783 }
1784
808bd9bf 1785 printf("{ ");
1e8256c9 1786 switch (item->dynamic_type) {
a2e2357e 1787 case SIDE_DYNAMIC_TYPE_NULL:
aac52685 1788 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
a2e2357e
MD
1789 printf("<NULL TYPE>");
1790 break;
4f40d951 1791 case SIDE_DYNAMIC_TYPE_BOOL:
aac52685 1792 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
8d20e708 1793 printf("%s", item->u.side_basic.u.side_bool ? "true" : "false");
4f40d951 1794 break;
a2e2357e 1795 case SIDE_DYNAMIC_TYPE_U8:
1d9c515c
MD
1796 {
1797 uint8_t v;
1798
d2be7696 1799 v = item->u.side_integer.value.side_u8;
aac52685 1800 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1801 switch (base) {
1802 case TRACER_DISPLAY_BASE_2:
1803 print_integer_binary(v, 8);
1804 break;
1805 case TRACER_DISPLAY_BASE_8:
1806 printf("0%" PRIo8, v);
1807 break;
1808 case TRACER_DISPLAY_BASE_10:
1809 printf("%" PRIu8, v);
1810 break;
1811 case TRACER_DISPLAY_BASE_16:
1812 printf("0x%" PRIx8, v);
1813 break;
1814 default:
1815 abort();
1816 }
a2e2357e 1817 break;
1d9c515c 1818 }
a2e2357e 1819 case SIDE_DYNAMIC_TYPE_U16:
8bdd5c12
MD
1820 {
1821 uint16_t v;
1822
d2be7696 1823 v = item->u.side_integer.value.side_u16;
8bdd5c12
MD
1824 if (dynamic_type_to_host_reverse_bo(item))
1825 v = side_bswap_16(v);
aac52685 1826 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1827 switch (base) {
1828 case TRACER_DISPLAY_BASE_2:
1829 print_integer_binary(v, 16);
1830 break;
1831 case TRACER_DISPLAY_BASE_8:
1832 printf("0%" PRIo16, v);
1833 break;
1834 case TRACER_DISPLAY_BASE_10:
1835 printf("%" PRIu16, v);
1836 break;
1837 case TRACER_DISPLAY_BASE_16:
1838 printf("0x%" PRIx16, v);
1839 break;
1840 default:
1841 abort();
1842 }
a2e2357e 1843 break;
8bdd5c12 1844 }
a2e2357e 1845 case SIDE_DYNAMIC_TYPE_U32:
8bdd5c12
MD
1846 {
1847 uint32_t v;
1848
d2be7696 1849 v = item->u.side_integer.value.side_u32;
8bdd5c12
MD
1850 if (dynamic_type_to_host_reverse_bo(item))
1851 v = side_bswap_32(v);
aac52685 1852 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1853 switch (base) {
1854 case TRACER_DISPLAY_BASE_2:
1855 print_integer_binary(v, 32);
1856 break;
1857 case TRACER_DISPLAY_BASE_8:
1858 printf("0%" PRIo32, v);
1859 break;
1860 case TRACER_DISPLAY_BASE_10:
1861 printf("%" PRIu32, v);
1862 break;
1863 case TRACER_DISPLAY_BASE_16:
1864 printf("0x%" PRIx32, v);
1865 break;
1866 default:
1867 abort();
1868 }
a2e2357e 1869 break;
8bdd5c12 1870 }
a2e2357e 1871 case SIDE_DYNAMIC_TYPE_U64:
8bdd5c12
MD
1872 {
1873 uint64_t v;
1874
d2be7696 1875 v = item->u.side_integer.value.side_u64;
8bdd5c12
MD
1876 if (dynamic_type_to_host_reverse_bo(item))
1877 v = side_bswap_64(v);
aac52685 1878 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1879 switch (base) {
1880 case TRACER_DISPLAY_BASE_2:
1881 print_integer_binary(v, 64);
1882 break;
1883 case TRACER_DISPLAY_BASE_8:
1884 printf("0%" PRIo64, v);
1885 break;
1886 case TRACER_DISPLAY_BASE_10:
1887 printf("%" PRIu64, v);
1888 break;
1889 case TRACER_DISPLAY_BASE_16:
1890 printf("0x%" PRIx64, v);
1891 break;
1892 default:
1893 abort();
1894 }
a2e2357e 1895 break;
8bdd5c12 1896 }
a2e2357e 1897 case SIDE_DYNAMIC_TYPE_S8:
1d9c515c
MD
1898 {
1899 int8_t v;
1900
d2be7696 1901 v = item->u.side_integer.value.side_s8;
aac52685 1902 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1903 switch (base) {
1904 case TRACER_DISPLAY_BASE_2:
1905 print_integer_binary(v, 8);
1906 break;
1907 case TRACER_DISPLAY_BASE_8:
1908 printf("0%" PRIo8, v);
1909 break;
1910 case TRACER_DISPLAY_BASE_10:
1911 printf("%" PRId8, v);
1912 break;
1913 case TRACER_DISPLAY_BASE_16:
1914 printf("0x%" PRIx8, v);
1915 break;
1916 default:
1917 abort();
1918 }
a2e2357e 1919 break;
1d9c515c 1920 }
a2e2357e 1921 case SIDE_DYNAMIC_TYPE_S16:
8bdd5c12
MD
1922 {
1923 int16_t v;
1924
d2be7696 1925 v = item->u.side_integer.value.side_s16;
8bdd5c12
MD
1926 if (dynamic_type_to_host_reverse_bo(item))
1927 v = side_bswap_16(v);
aac52685 1928 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1929 switch (base) {
1930 case TRACER_DISPLAY_BASE_2:
1931 print_integer_binary(v, 16);
1932 break;
1933 case TRACER_DISPLAY_BASE_8:
1934 printf("0%" PRIo16, v);
1935 break;
1936 case TRACER_DISPLAY_BASE_10:
1937 printf("%" PRId16, v);
1938 break;
1939 case TRACER_DISPLAY_BASE_16:
1940 printf("0x%" PRIx16, v);
1941 break;
1942 default:
1943 abort();
1944 }
a2e2357e 1945 break;
8bdd5c12 1946 }
a2e2357e 1947 case SIDE_DYNAMIC_TYPE_S32:
8bdd5c12
MD
1948 {
1949 int32_t v;
1950
d2be7696 1951 v = item->u.side_integer.value.side_s32;
8bdd5c12
MD
1952 if (dynamic_type_to_host_reverse_bo(item))
1953 v = side_bswap_32(v);
aac52685 1954 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1955 switch (base) {
1956 case TRACER_DISPLAY_BASE_2:
1957 print_integer_binary(v, 32);
1958 break;
1959 case TRACER_DISPLAY_BASE_8:
1960 printf("0%" PRIo32, v);
1961 break;
1962 case TRACER_DISPLAY_BASE_10:
1963 printf("%" PRId32, v);
1964 break;
1965 case TRACER_DISPLAY_BASE_16:
1966 printf("0x%" PRIx32, v);
1967 break;
1968 default:
1969 abort();
1970 }
a2e2357e 1971 break;
8bdd5c12 1972 }
a2e2357e 1973 case SIDE_DYNAMIC_TYPE_S64:
8bdd5c12
MD
1974 {
1975 int64_t v;
1976
d2be7696 1977 v = item->u.side_integer.value.side_s64;
8bdd5c12
MD
1978 if (dynamic_type_to_host_reverse_bo(item))
1979 v = side_bswap_64(v);
aac52685 1980 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
1d9c515c
MD
1981 switch (base) {
1982 case TRACER_DISPLAY_BASE_2:
1983 print_integer_binary(v, 64);
1984 break;
1985 case TRACER_DISPLAY_BASE_8:
1986 printf("0%" PRIo64, v);
1987 break;
1988 case TRACER_DISPLAY_BASE_10:
1989 printf("%" PRId64, v);
1990 break;
1991 case TRACER_DISPLAY_BASE_16:
1992 printf("0x%" PRIx64, v);
1993 break;
1994 default:
1995 abort();
1996 }
a2e2357e 1997 break;
8bdd5c12 1998 }
f7653b43 1999 case SIDE_DYNAMIC_TYPE_BYTE:
aac52685 2000 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
f7653b43 2001 printf("0x%" PRIx8, item->u.side_basic.u.side_byte);
199e7aa9 2002 break;
dd6e76cb 2003 case SIDE_DYNAMIC_TYPE_POINTER32:
f5e650d7 2004 {
dd6e76cb 2005 uint32_t v;
f5e650d7 2006
d2be7696 2007 v = item->u.side_integer.value.side_u32;
f5e650d7 2008 if (dynamic_type_to_host_reverse_bo(item))
dd6e76cb 2009 v = side_bswap_32(v);
aac52685 2010 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
dd6e76cb
MD
2011 printf("0x%" PRIx32, v);
2012 break;
2013 }
2014
2015 case SIDE_DYNAMIC_TYPE_POINTER64:
2016 {
2017 uint64_t v;
2018
d2be7696 2019 v = item->u.side_integer.value.side_u64;
dd6e76cb
MD
2020 if (dynamic_type_to_host_reverse_bo(item))
2021 v = side_bswap_64(v);
aac52685 2022 tracer_print_type_header("::", item->u.side_integer.type.attr, item->u.side_integer.type.nr_attr);
dd6e76cb 2023 printf("0x%" PRIx64, v);
f5e650d7
MD
2024 break;
2025 }
199e7aa9 2026
fb25b355 2027 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16:
8bdd5c12 2028 {
fb25b355 2029#if __HAVE_FLOAT16
8bdd5c12
MD
2030 union {
2031 _Float16 f;
2032 uint16_t u;
2033 } float16 = {
aac52685 2034 .f = item->u.side_float.value.side_float_binary16,
8bdd5c12
MD
2035 };
2036
2037 if (dynamic_type_to_host_reverse_bo(item))
2038 float16.u = side_bswap_16(float16.u);
aac52685 2039 tracer_print_type_header("::", item->u.side_float.type.attr, item->u.side_float.type.nr_attr);
8bdd5c12 2040 printf("%g", (double) float16.f);
fb25b355
MD
2041 break;
2042#else
de1b3cd2 2043 fprintf(stderr, "ERROR: Unsupported binary16 float type\n");
fb25b355
MD
2044 abort();
2045#endif
8bdd5c12 2046 }
fb25b355 2047 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32:
8bdd5c12 2048 {
fb25b355 2049#if __HAVE_FLOAT32
8bdd5c12
MD
2050 union {
2051 _Float32 f;
2052 uint32_t u;
2053 } float32 = {
aac52685 2054 .f = item->u.side_float.value.side_float_binary32,
8bdd5c12
MD
2055 };
2056
2057 if (dynamic_type_to_host_reverse_bo(item))
2058 float32.u = side_bswap_32(float32.u);
aac52685 2059 tracer_print_type_header("::", item->u.side_float.type.attr, item->u.side_float.type.nr_attr);
8bdd5c12 2060 printf("%g", (double) float32.f);
fb25b355
MD
2061 break;
2062#else
de1b3cd2 2063 fprintf(stderr, "ERROR: Unsupported binary32 float type\n");
fb25b355
MD
2064 abort();
2065#endif
8bdd5c12 2066 }
fb25b355 2067 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64:
8bdd5c12 2068 {
fb25b355 2069#if __HAVE_FLOAT64
8bdd5c12
MD
2070 union {
2071 _Float64 f;
2072 uint64_t u;
2073 } float64 = {
aac52685 2074 .f = item->u.side_float.value.side_float_binary64,
8bdd5c12
MD
2075 };
2076
2077 if (dynamic_type_to_host_reverse_bo(item))
2078 float64.u = side_bswap_64(float64.u);
aac52685 2079 tracer_print_type_header("::", item->u.side_float.type.attr, item->u.side_float.type.nr_attr);
8bdd5c12 2080 printf("%g", (double) float64.f);
fb25b355
MD
2081 break;
2082#else
de1b3cd2 2083 fprintf(stderr, "ERROR: Unsupported binary64 float type\n");
fb25b355
MD
2084 abort();
2085#endif
8bdd5c12 2086 }
fb25b355 2087 case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128:
8bdd5c12 2088 {
fb25b355 2089#if __HAVE_FLOAT128
8bdd5c12
MD
2090 union {
2091 _Float128 f;
2092 char arr[16];
2093 } float128 = {
aac52685 2094 .f = item->u.side_float.value.side_float_binary128,
8bdd5c12
MD
2095 };
2096
2097 if (dynamic_type_to_host_reverse_bo(item))
2098 side_bswap_128p(float128.arr);
aac52685 2099 tracer_print_type_header("::", item->u.side_float.type.attr, item->u.side_float.type.nr_attr);
8bdd5c12 2100 printf("%Lg", (long double) float128.f);
fb25b355
MD
2101 break;
2102#else
de1b3cd2 2103 fprintf(stderr, "ERROR: Unsupported binary128 float type\n");
fb25b355
MD
2104 abort();
2105#endif
8bdd5c12 2106 }
a2e2357e 2107 case SIDE_DYNAMIC_TYPE_STRING:
aac52685 2108 tracer_print_type_header("::", item->u.side_basic.attr, item->u.side_basic.nr_attr);
8549e629 2109 printf("\"%s\"", (const char *)(uintptr_t) item->u.side_basic.u.string);
a2e2357e 2110 break;
c208889e
MD
2111 case SIDE_DYNAMIC_TYPE_STRUCT:
2112 tracer_print_dynamic_struct(item->u.side_dynamic_struct);
a2e2357e 2113 break;
c208889e
MD
2114 case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR:
2115 tracer_print_dynamic_struct_visitor(item);
a2e2357e
MD
2116 break;
2117 case SIDE_DYNAMIC_TYPE_VLA:
2118 tracer_print_dynamic_vla(item->u.side_dynamic_vla);
2119 break;
2120 case SIDE_DYNAMIC_TYPE_VLA_VISITOR:
2121 tracer_print_dynamic_vla_visitor(item);
2122 break;
2123 default:
de1b3cd2 2124 fprintf(stderr, "<UNKNOWN TYPE>");
a2e2357e
MD
2125 abort();
2126 }
808bd9bf 2127 printf(" }");
a2e2357e
MD
2128}
2129
68f8cfbe
MD
2130static
2131void tracer_print_static_fields(const struct side_event_description *desc,
2132 const struct side_arg_vec_description *sav_desc,
2133 int *nr_items)
f611d0c3
MD
2134{
2135 const struct side_arg_vec *sav = sav_desc->sav;
2136 uint32_t side_sav_len = sav_desc->len;
2137 int i;
2138
65010f43 2139 printf("provider: %s, event: %s", desc->provider_name, desc->event_name);
f611d0c3 2140 if (desc->nr_fields != side_sav_len) {
de1b3cd2 2141 fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n");
f611d0c3
MD
2142 abort();
2143 }
905c328e 2144 print_attributes(", attr", ":", desc->attr, desc->nr_attr);
a848763d 2145 printf("%s", side_sav_len ? ", fields: [ " : "");
f611d0c3
MD
2146 for (i = 0; i < side_sav_len; i++) {
2147 printf("%s", i ? ", " : "");
2148 tracer_print_field(&desc->fields[i], &sav[i]);
2149 }
68f8cfbe
MD
2150 if (nr_items)
2151 *nr_items = i;
c7d338e2
MD
2152 if (side_sav_len)
2153 printf(" ]");
68f8cfbe
MD
2154}
2155
4a7d8700
MD
2156void tracer_call(const struct side_event_description *desc,
2157 const struct side_arg_vec_description *sav_desc,
2158 void *priv __attribute__((unused)))
68f8cfbe 2159{
a848763d
MD
2160 int nr_fields = 0;
2161
a848763d 2162 tracer_print_static_fields(desc, sav_desc, &nr_fields);
f611d0c3
MD
2163 printf("\n");
2164}
19fa6aa2
MD
2165
2166void tracer_call_variadic(const struct side_event_description *desc,
4a7d8700
MD
2167 const struct side_arg_vec_description *sav_desc,
2168 const struct side_arg_dynamic_event_struct *var_struct,
2169 void *priv __attribute__((unused)))
19fa6aa2 2170{
68f8cfbe
MD
2171 uint32_t var_struct_len = var_struct->len;
2172 int nr_fields = 0, i;
19fa6aa2 2173
68f8cfbe
MD
2174 tracer_print_static_fields(desc, sav_desc, &nr_fields);
2175
8a25ce77 2176 if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) {
de1b3cd2 2177 fprintf(stderr, "ERROR: unexpected non-variadic event description\n");
8a25ce77
MD
2178 abort();
2179 }
905c328e
MD
2180 print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr);
2181 printf("%s", var_struct_len ? ", fields:: [ " : "");
68f8cfbe 2182 for (i = 0; i < var_struct_len; i++, nr_fields++) {
c7d338e2 2183 printf("%s", i ? ", " : "");
68f8cfbe
MD
2184 printf("%s:: ", var_struct->fields[i].field_name);
2185 tracer_print_dynamic(&var_struct->fields[i].elem);
19fa6aa2 2186 }
a848763d
MD
2187 if (i)
2188 printf(" ]");
19fa6aa2
MD
2189 printf("\n");
2190}
1e8aec23
MD
2191
2192void tracer_event_notification(enum side_tracer_notification notif,
2193 struct side_event_description **events, uint32_t nr_events, void *priv)
2194{
2195 uint32_t i;
314c22c3 2196 int ret;
1e8aec23
MD
2197
2198 printf("----------------------------------------------------------\n");
2199 printf("Tracer notified of events %s\n",
314c22c3 2200 notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS ? "inserted" : "removed");
1e8aec23
MD
2201 for (i = 0; i < nr_events; i++) {
2202 struct side_event_description *event = events[i];
2203
2204 /* Skip NULL pointers */
2205 if (!event)
2206 continue;
2207 printf("provider: %s, event: %s\n",
2208 event->provider_name, event->event_name);
314c22c3
MD
2209 if (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) {
2210 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
2211 ret = side_tracer_callback_variadic_register(event, tracer_call_variadic, NULL);
2212 if (ret)
2213 abort();
2214 } else {
2215 ret = side_tracer_callback_register(event, tracer_call, NULL);
2216 if (ret)
2217 abort();
2218 }
2219 } else {
2220 if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
2221 ret = side_tracer_callback_variadic_unregister(event, tracer_call_variadic, NULL);
2222 if (ret)
2223 abort();
2224 } else {
2225 ret = side_tracer_callback_unregister(event, tracer_call, NULL);
2226 if (ret)
2227 abort();
2228 }
2229 }
1e8aec23
MD
2230 }
2231 printf("----------------------------------------------------------\n");
2232}
2233
2234static __attribute__((constructor))
2235void tracer_init(void);
2236static
2237void tracer_init(void)
2238{
2239 tracer_handle = side_tracer_event_notification_register(tracer_event_notification, NULL);
2240 if (!tracer_handle)
2241 abort();
2242}
2243
2244static __attribute__((destructor))
2245void tracer_exit(void);
2246static
2247void tracer_exit(void)
2248{
2249 side_tracer_event_notification_unregister(tracer_handle);
2250}
This page took 0.19237 seconds and 4 git commands to generate.