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