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