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