Commit | Line | Data |
---|---|---|
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> |
f611d0c3 MD |
11 | |
12 | #include <side/trace.h> | |
13 | ||
14 | static | |
15 | void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc); | |
16 | static | |
17 | void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc); | |
18 | static | |
19 | void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc); | |
20 | static | |
352a4b77 | 21 | void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx); |
ba845af5 MD |
22 | static |
23 | void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item); | |
1533629f MD |
24 | static |
25 | void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item); | |
a2e2357e MD |
26 | static |
27 | void tracer_print_dynamic(const struct side_arg_dynamic_vec *dynamic_item); | |
d8be25de MD |
28 | static |
29 | void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item); | |
f611d0c3 | 30 | |
bc3c89b3 | 31 | static |
905c328e | 32 | void tracer_print_attr_type(const char *separator, const struct side_attr *attr) |
bc3c89b3 | 33 | { |
905c328e | 34 | printf("{ key%s \"%s\", value%s ", separator, attr->key, separator); |
bc3c89b3 MD |
35 | switch (attr->value.type) { |
36 | case SIDE_ATTR_TYPE_BOOL: | |
37 | printf("%s", attr->value.u.side_bool ? "true" : "false"); | |
38 | break; | |
39 | case SIDE_ATTR_TYPE_U8: | |
40 | printf("%" PRIu8, attr->value.u.side_u8); | |
41 | break; | |
42 | case SIDE_ATTR_TYPE_U16: | |
43 | printf("%" PRIu16, attr->value.u.side_u16); | |
44 | break; | |
45 | case SIDE_ATTR_TYPE_U32: | |
46 | printf("%" PRIu32, attr->value.u.side_u32); | |
47 | break; | |
48 | case SIDE_ATTR_TYPE_U64: | |
49 | printf("%" PRIu64, attr->value.u.side_u64); | |
50 | break; | |
51 | case SIDE_ATTR_TYPE_S8: | |
52 | printf("%" PRId8, attr->value.u.side_s8); | |
53 | break; | |
54 | case SIDE_ATTR_TYPE_S16: | |
55 | printf("%" PRId16, attr->value.u.side_s16); | |
56 | break; | |
57 | case SIDE_ATTR_TYPE_S32: | |
58 | printf("%" PRId32, attr->value.u.side_s32); | |
59 | break; | |
60 | case SIDE_ATTR_TYPE_S64: | |
61 | printf("%" PRId64, attr->value.u.side_s64); | |
62 | break; | |
63 | case SIDE_ATTR_TYPE_FLOAT_BINARY16: | |
64 | #if __HAVE_FLOAT16 | |
65 | printf("%g", (double) attr->value.u.side_float_binary16); | |
66 | break; | |
67 | #else | |
de1b3cd2 | 68 | fprintf(stderr, "ERROR: Unsupported binary16 float type\n"); |
bc3c89b3 MD |
69 | abort(); |
70 | #endif | |
71 | case SIDE_ATTR_TYPE_FLOAT_BINARY32: | |
72 | #if __HAVE_FLOAT32 | |
73 | printf("%g", (double) attr->value.u.side_float_binary32); | |
74 | break; | |
75 | #else | |
de1b3cd2 | 76 | fprintf(stderr, "ERROR: Unsupported binary32 float type\n"); |
bc3c89b3 MD |
77 | abort(); |
78 | #endif | |
79 | case SIDE_ATTR_TYPE_FLOAT_BINARY64: | |
80 | #if __HAVE_FLOAT64 | |
81 | printf("%g", (double) attr->value.u.side_float_binary64); | |
82 | break; | |
83 | #else | |
de1b3cd2 | 84 | fprintf(stderr, "ERROR: Unsupported binary64 float type\n"); |
bc3c89b3 MD |
85 | abort(); |
86 | #endif | |
87 | case SIDE_ATTR_TYPE_FLOAT_BINARY128: | |
88 | #if __HAVE_FLOAT128 | |
89 | printf("%Lg", (long double) attr->value.u.side_float_binary128); | |
90 | break; | |
91 | #else | |
de1b3cd2 | 92 | fprintf(stderr, "ERROR: Unsupported binary128 float type\n"); |
bc3c89b3 MD |
93 | abort(); |
94 | #endif | |
95 | case SIDE_ATTR_TYPE_STRING: | |
96 | printf("\"%s\"", attr->value.u.string); | |
97 | break; | |
98 | default: | |
de1b3cd2 | 99 | fprintf(stderr, "ERROR: <UNKNOWN ATTRIBUTE TYPE>"); |
bc3c89b3 MD |
100 | abort(); |
101 | } | |
102 | printf(" }"); | |
103 | } | |
104 | ||
7d21cf51 | 105 | static |
905c328e MD |
106 | void print_attributes(const char *prefix_str, const char *separator, |
107 | const struct side_attr *attr, uint32_t nr_attr) | |
7d21cf51 MD |
108 | { |
109 | int i; | |
110 | ||
111 | if (!nr_attr) | |
112 | return; | |
905c328e | 113 | printf("%s%s [ ", prefix_str, separator); |
7d21cf51 MD |
114 | for (i = 0; i < nr_attr; i++) { |
115 | printf("%s", i ? ", " : ""); | |
905c328e | 116 | tracer_print_attr_type(separator, &attr[i]); |
7d21cf51 MD |
117 | } |
118 | printf(" ]"); | |
119 | } | |
120 | ||
79f677ba | 121 | static |
d8be25de | 122 | void print_enum(const struct side_type_description *type_desc, const struct side_arg_vec *item) |
79f677ba | 123 | { |
d8be25de | 124 | const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings; |
79f677ba | 125 | int i, print_count = 0; |
d8be25de | 126 | int64_t value; |
79f677ba | 127 | |
d8be25de | 128 | if (type_desc->u.side_enum.elem_type->type != item->type) { |
de1b3cd2 | 129 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
d8be25de MD |
130 | abort(); |
131 | } | |
132 | switch (item->type) { | |
133 | case SIDE_TYPE_U8: | |
134 | value = (int64_t) item->u.side_u8; | |
135 | break; | |
136 | case SIDE_TYPE_U16: | |
137 | value = (int64_t) item->u.side_u16; | |
138 | break; | |
139 | case SIDE_TYPE_U32: | |
140 | value = (int64_t) item->u.side_u32; | |
141 | break; | |
142 | case SIDE_TYPE_U64: | |
143 | value = (int64_t) item->u.side_u64; | |
144 | break; | |
145 | case SIDE_TYPE_S8: | |
146 | value = (int64_t) item->u.side_s8; | |
147 | break; | |
148 | case SIDE_TYPE_S16: | |
149 | value = (int64_t) item->u.side_s16; | |
150 | break; | |
151 | case SIDE_TYPE_S32: | |
152 | value = (int64_t) item->u.side_s32; | |
153 | break; | |
154 | case SIDE_TYPE_S64: | |
155 | value = (int64_t) item->u.side_s64; | |
156 | break; | |
157 | default: | |
de1b3cd2 | 158 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
d8be25de MD |
159 | abort(); |
160 | } | |
905c328e | 161 | print_attributes("attr", ":", mappings->attr, mappings->nr_attr); |
d8be25de MD |
162 | printf("%s", mappings->nr_attr ? ", " : ""); |
163 | tracer_print_type(type_desc->u.side_enum.elem_type, item); | |
164 | printf(", labels: [ "); | |
165 | for (i = 0; i < mappings->nr_mappings; i++) { | |
166 | const struct side_enum_mapping *mapping = &mappings->mappings[i]; | |
79f677ba | 167 | |
ea32e5fc | 168 | if (mapping->range_end < mapping->range_begin) { |
de1b3cd2 | 169 | fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n", |
ea32e5fc MD |
170 | mapping->range_begin, mapping->range_end); |
171 | abort(); | |
172 | } | |
79f677ba MD |
173 | if (value >= mapping->range_begin && value <= mapping->range_end) { |
174 | printf("%s", print_count++ ? ", " : ""); | |
175 | printf("\"%s\"", mapping->label); | |
176 | } | |
177 | } | |
178 | if (!print_count) | |
179 | printf("<NO LABEL>"); | |
180 | printf(" ]"); | |
181 | } | |
182 | ||
ea32e5fc | 183 | static |
bab5d6e4 | 184 | uint32_t enum_elem_type_to_stride(const struct side_type_description *elem_type) |
ea32e5fc | 185 | { |
af6aa6e1 MD |
186 | uint32_t stride_bit; |
187 | ||
bab5d6e4 | 188 | switch (elem_type->type) { |
4cc2880b MD |
189 | case SIDE_TYPE_U8: /* Fall-through */ |
190 | case SIDE_TYPE_BYTE: | |
af6aa6e1 MD |
191 | stride_bit = 8; |
192 | break; | |
af6aa6e1 | 193 | case SIDE_TYPE_U16: |
af6aa6e1 MD |
194 | stride_bit = 16; |
195 | break; | |
af6aa6e1 | 196 | case SIDE_TYPE_U32: |
af6aa6e1 MD |
197 | stride_bit = 32; |
198 | break; | |
af6aa6e1 | 199 | case SIDE_TYPE_U64: |
af6aa6e1 MD |
200 | stride_bit = 64; |
201 | break; | |
af6aa6e1 | 202 | default: |
de1b3cd2 | 203 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
af6aa6e1 MD |
204 | abort(); |
205 | } | |
206 | return stride_bit; | |
207 | } | |
208 | ||
209 | static | |
210 | void print_enum_bitmap(const struct side_type_description *type_desc, | |
211 | const struct side_arg_vec *item) | |
212 | { | |
bab5d6e4 MD |
213 | const struct side_type_description *elem_type = type_desc->u.side_enum_bitmap.elem_type; |
214 | const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings; | |
ea32e5fc | 215 | int i, print_count = 0; |
af6aa6e1 MD |
216 | uint32_t stride_bit, nr_items; |
217 | const struct side_arg_vec *array_item; | |
218 | ||
bab5d6e4 MD |
219 | switch (elem_type->type) { |
220 | case SIDE_TYPE_U8: /* Fall-through */ | |
4cc2880b | 221 | case SIDE_TYPE_BYTE: /* Fall-through */ |
bab5d6e4 MD |
222 | case SIDE_TYPE_U16: /* Fall-through */ |
223 | case SIDE_TYPE_U32: /* Fall-through */ | |
4cc2880b | 224 | case SIDE_TYPE_U64: |
45392033 | 225 | stride_bit = enum_elem_type_to_stride(elem_type); |
af6aa6e1 MD |
226 | array_item = item; |
227 | nr_items = 1; | |
af6aa6e1 | 228 | break; |
bab5d6e4 | 229 | case SIDE_TYPE_ARRAY: |
45392033 | 230 | stride_bit = enum_elem_type_to_stride(elem_type->u.side_array.elem_type); |
af6aa6e1 | 231 | array_item = item->u.side_array->sav; |
bab5d6e4 | 232 | nr_items = type_desc->u.side_array.length; |
af6aa6e1 | 233 | break; |
bab5d6e4 | 234 | case SIDE_TYPE_VLA: |
45392033 | 235 | stride_bit = enum_elem_type_to_stride(elem_type->u.side_vla.elem_type); |
af6aa6e1 | 236 | array_item = item->u.side_vla->sav; |
bab5d6e4 | 237 | nr_items = item->u.side_vla->len; |
af6aa6e1 MD |
238 | break; |
239 | default: | |
de1b3cd2 | 240 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
af6aa6e1 MD |
241 | abort(); |
242 | } | |
ea32e5fc | 243 | |
905c328e | 244 | print_attributes("attr", ":", side_enum_mappings->attr, side_enum_mappings->nr_attr); |
d4328528 | 245 | printf("%s", side_enum_mappings->nr_attr ? ", " : ""); |
af6aa6e1 | 246 | printf("labels: [ "); |
ea32e5fc | 247 | for (i = 0; i < side_enum_mappings->nr_mappings; i++) { |
66cff328 | 248 | const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i]; |
ea32e5fc | 249 | bool match = false; |
9ff49ee4 | 250 | uint64_t bit; |
ea32e5fc | 251 | |
9ff49ee4 | 252 | if (mapping->range_end < mapping->range_begin) { |
de1b3cd2 | 253 | fprintf(stderr, "ERROR: Unexpected enum bitmap range: %" PRIu64 "-%" PRIu64 "\n", |
ea32e5fc MD |
254 | mapping->range_begin, mapping->range_end); |
255 | abort(); | |
256 | } | |
257 | for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) { | |
af6aa6e1 MD |
258 | if (bit > (nr_items * stride_bit) - 1) |
259 | break; | |
260 | switch (stride_bit) { | |
261 | case 8: | |
262 | { | |
263 | uint8_t v = array_item[bit / 8].u.side_u8; | |
264 | if (v & (1ULL << (bit % 8))) { | |
265 | match = true; | |
266 | goto match; | |
267 | } | |
268 | break; | |
269 | } | |
270 | case 16: | |
271 | { | |
272 | uint16_t v = array_item[bit / 16].u.side_u16; | |
273 | if (v & (1ULL << (bit % 16))) { | |
274 | match = true; | |
275 | goto match; | |
276 | } | |
277 | break; | |
278 | } | |
279 | case 32: | |
280 | { | |
281 | uint32_t v = array_item[bit / 32].u.side_u32; | |
282 | if (v & (1ULL << (bit % 32))) { | |
283 | match = true; | |
284 | goto match; | |
285 | } | |
ea32e5fc MD |
286 | break; |
287 | } | |
af6aa6e1 MD |
288 | case 64: |
289 | { | |
290 | uint64_t v = array_item[bit / 64].u.side_u64; | |
291 | if (v & (1ULL << (bit % 64))) { | |
292 | match = true; | |
293 | goto match; | |
294 | } | |
295 | break; | |
296 | } | |
297 | default: | |
298 | abort(); | |
299 | } | |
ea32e5fc | 300 | } |
af6aa6e1 | 301 | match: |
ea32e5fc MD |
302 | if (match) { |
303 | printf("%s", print_count++ ? ", " : ""); | |
304 | printf("\"%s\"", mapping->label); | |
305 | } | |
306 | } | |
307 | if (!print_count) | |
308 | printf("<NO LABEL>"); | |
309 | printf(" ]"); | |
310 | } | |
311 | ||
0e9be766 MD |
312 | static |
313 | void tracer_print_basic_type_header(const struct side_type_description *type_desc) | |
314 | { | |
905c328e | 315 | print_attributes("attr", ":", type_desc->u.side_basic.attr, type_desc->u.side_basic.nr_attr); |
0e9be766 MD |
316 | printf("%s", type_desc->u.side_basic.nr_attr ? ", " : ""); |
317 | printf("value: "); | |
318 | } | |
319 | ||
f611d0c3 MD |
320 | static |
321 | void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item) | |
322 | { | |
d8be25de MD |
323 | enum side_type type; |
324 | ||
45392033 MD |
325 | switch (type_desc->type) { |
326 | case SIDE_TYPE_ARRAY: | |
327 | switch (item->type) { | |
328 | case SIDE_TYPE_ARRAY_U8: | |
329 | case SIDE_TYPE_ARRAY_U16: | |
330 | case SIDE_TYPE_ARRAY_U32: | |
331 | case SIDE_TYPE_ARRAY_U64: | |
332 | case SIDE_TYPE_ARRAY_S8: | |
333 | case SIDE_TYPE_ARRAY_S16: | |
334 | case SIDE_TYPE_ARRAY_S32: | |
335 | case SIDE_TYPE_ARRAY_S64: | |
f7653b43 | 336 | case SIDE_TYPE_ARRAY_BYTE: |
45392033 MD |
337 | case SIDE_TYPE_ARRAY: |
338 | break; | |
339 | default: | |
de1b3cd2 | 340 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
ba845af5 | 341 | abort(); |
45392033 | 342 | break; |
ba845af5 MD |
343 | } |
344 | break; | |
45392033 MD |
345 | |
346 | case SIDE_TYPE_VLA: | |
347 | switch (item->type) { | |
348 | case SIDE_TYPE_VLA_U8: | |
349 | case SIDE_TYPE_VLA_U16: | |
350 | case SIDE_TYPE_VLA_U32: | |
351 | case SIDE_TYPE_VLA_U64: | |
352 | case SIDE_TYPE_VLA_S8: | |
353 | case SIDE_TYPE_VLA_S16: | |
354 | case SIDE_TYPE_VLA_S32: | |
355 | case SIDE_TYPE_VLA_S64: | |
f7653b43 | 356 | case SIDE_TYPE_VLA_BYTE: |
45392033 MD |
357 | case SIDE_TYPE_VLA: |
358 | break; | |
359 | default: | |
de1b3cd2 | 360 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
1533629f | 361 | abort(); |
45392033 | 362 | break; |
1533629f MD |
363 | } |
364 | break; | |
365 | ||
45392033 MD |
366 | case SIDE_TYPE_ENUM: |
367 | switch (item->type) { | |
368 | case SIDE_TYPE_U8: | |
369 | case SIDE_TYPE_U16: | |
370 | case SIDE_TYPE_U32: | |
371 | case SIDE_TYPE_U64: | |
372 | case SIDE_TYPE_S8: | |
373 | case SIDE_TYPE_S16: | |
374 | case SIDE_TYPE_S32: | |
375 | case SIDE_TYPE_S64: | |
bab5d6e4 MD |
376 | break; |
377 | default: | |
de1b3cd2 | 378 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
45392033 MD |
379 | abort(); |
380 | break; | |
381 | } | |
382 | break; | |
383 | ||
384 | case SIDE_TYPE_ENUM_BITMAP: | |
385 | switch (item->type) { | |
386 | case SIDE_TYPE_U8: | |
4cc2880b | 387 | case SIDE_TYPE_BYTE: |
45392033 MD |
388 | case SIDE_TYPE_U16: |
389 | case SIDE_TYPE_U32: | |
390 | case SIDE_TYPE_U64: | |
391 | case SIDE_TYPE_ARRAY: | |
392 | case SIDE_TYPE_VLA: | |
393 | break; | |
394 | default: | |
de1b3cd2 | 395 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
45392033 MD |
396 | abort(); |
397 | break; | |
d8be25de MD |
398 | } |
399 | break; | |
400 | ||
ba845af5 | 401 | default: |
a2e2357e | 402 | if (type_desc->type != item->type) { |
de1b3cd2 | 403 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
ba845af5 MD |
404 | abort(); |
405 | } | |
406 | break; | |
f611d0c3 | 407 | } |
d8be25de | 408 | |
bab5d6e4 MD |
409 | if (type_desc->type == SIDE_TYPE_ENUM || type_desc->type == SIDE_TYPE_ENUM_BITMAP) |
410 | type = type_desc->type; | |
d8be25de MD |
411 | else |
412 | type = item->type; | |
413 | ||
a848763d | 414 | printf("{ "); |
d8be25de | 415 | switch (type) { |
4f40d951 | 416 | case SIDE_TYPE_BOOL: |
0e9be766 | 417 | tracer_print_basic_type_header(type_desc); |
4f40d951 MD |
418 | printf("%s", item->u.side_bool ? "true" : "false"); |
419 | break; | |
f611d0c3 | 420 | case SIDE_TYPE_U8: |
0e9be766 | 421 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
422 | printf("%" PRIu8, item->u.side_u8); |
423 | break; | |
424 | case SIDE_TYPE_U16: | |
0e9be766 | 425 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
426 | printf("%" PRIu16, item->u.side_u16); |
427 | break; | |
428 | case SIDE_TYPE_U32: | |
0e9be766 | 429 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
430 | printf("%" PRIu32, item->u.side_u32); |
431 | break; | |
432 | case SIDE_TYPE_U64: | |
0e9be766 | 433 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
434 | printf("%" PRIu64, item->u.side_u64); |
435 | break; | |
436 | case SIDE_TYPE_S8: | |
0e9be766 | 437 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
438 | printf("%" PRId8, item->u.side_s8); |
439 | break; | |
440 | case SIDE_TYPE_S16: | |
0e9be766 | 441 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
442 | printf("%" PRId16, item->u.side_s16); |
443 | break; | |
444 | case SIDE_TYPE_S32: | |
0e9be766 | 445 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
446 | printf("%" PRId32, item->u.side_s32); |
447 | break; | |
448 | case SIDE_TYPE_S64: | |
0e9be766 | 449 | tracer_print_basic_type_header(type_desc); |
f611d0c3 MD |
450 | printf("%" PRId64, item->u.side_s64); |
451 | break; | |
f7653b43 | 452 | case SIDE_TYPE_BYTE: |
0e9be766 | 453 | tracer_print_basic_type_header(type_desc); |
f7653b43 | 454 | printf("0x%" PRIx8, item->u.side_byte); |
7aec0d09 | 455 | break; |
79f677ba | 456 | |
d8be25de MD |
457 | case SIDE_TYPE_ENUM: |
458 | print_enum(type_desc, item); | |
79f677ba MD |
459 | break; |
460 | ||
bab5d6e4 | 461 | case SIDE_TYPE_ENUM_BITMAP: |
af6aa6e1 | 462 | print_enum_bitmap(type_desc, item); |
ea32e5fc MD |
463 | break; |
464 | ||
fb25b355 | 465 | case SIDE_TYPE_FLOAT_BINARY16: |
0e9be766 | 466 | tracer_print_basic_type_header(type_desc); |
fb25b355 MD |
467 | #if __HAVE_FLOAT16 |
468 | printf("%g", (double) item->u.side_float_binary16); | |
469 | break; | |
470 | #else | |
de1b3cd2 | 471 | fprintf(stderr, "ERROR: Unsupported binary16 float type\n"); |
fb25b355 MD |
472 | abort(); |
473 | #endif | |
474 | case SIDE_TYPE_FLOAT_BINARY32: | |
0e9be766 | 475 | tracer_print_basic_type_header(type_desc); |
fb25b355 MD |
476 | #if __HAVE_FLOAT32 |
477 | printf("%g", (double) item->u.side_float_binary32); | |
478 | break; | |
479 | #else | |
de1b3cd2 | 480 | fprintf(stderr, "ERROR: Unsupported binary32 float type\n"); |
fb25b355 MD |
481 | abort(); |
482 | #endif | |
483 | case SIDE_TYPE_FLOAT_BINARY64: | |
0e9be766 | 484 | tracer_print_basic_type_header(type_desc); |
fb25b355 MD |
485 | #if __HAVE_FLOAT64 |
486 | printf("%g", (double) item->u.side_float_binary64); | |
487 | break; | |
488 | #else | |
de1b3cd2 | 489 | fprintf(stderr, "ERROR: Unsupported binary64 float type\n"); |
fb25b355 MD |
490 | abort(); |
491 | #endif | |
492 | case SIDE_TYPE_FLOAT_BINARY128: | |
0e9be766 | 493 | tracer_print_basic_type_header(type_desc); |
fb25b355 MD |
494 | #if __HAVE_FLOAT128 |
495 | printf("%Lg", (long double) item->u.side_float_binary128); | |
496 | break; | |
497 | #else | |
de1b3cd2 | 498 | fprintf(stderr, "ERROR: Unsupported binary128 float type\n"); |
fb25b355 MD |
499 | abort(); |
500 | #endif | |
f611d0c3 | 501 | case SIDE_TYPE_STRING: |
0e9be766 | 502 | tracer_print_basic_type_header(type_desc); |
a2e2357e | 503 | printf("\"%s\"", item->u.string); |
f611d0c3 MD |
504 | break; |
505 | case SIDE_TYPE_STRUCT: | |
506 | tracer_print_struct(type_desc, item->u.side_struct); | |
507 | break; | |
508 | case SIDE_TYPE_ARRAY: | |
509 | tracer_print_array(type_desc, item->u.side_array); | |
510 | break; | |
511 | case SIDE_TYPE_VLA: | |
512 | tracer_print_vla(type_desc, item->u.side_vla); | |
513 | break; | |
514 | case SIDE_TYPE_VLA_VISITOR: | |
352a4b77 | 515 | tracer_print_vla_visitor(type_desc, item->u.side_vla_app_visitor_ctx); |
f611d0c3 | 516 | break; |
ba845af5 MD |
517 | case SIDE_TYPE_ARRAY_U8: |
518 | case SIDE_TYPE_ARRAY_U16: | |
519 | case SIDE_TYPE_ARRAY_U32: | |
520 | case SIDE_TYPE_ARRAY_U64: | |
521 | case SIDE_TYPE_ARRAY_S8: | |
522 | case SIDE_TYPE_ARRAY_S16: | |
523 | case SIDE_TYPE_ARRAY_S32: | |
524 | case SIDE_TYPE_ARRAY_S64: | |
f7653b43 | 525 | case SIDE_TYPE_ARRAY_BYTE: |
ba845af5 MD |
526 | tracer_print_array_fixint(type_desc, item); |
527 | break; | |
1533629f MD |
528 | case SIDE_TYPE_VLA_U8: |
529 | case SIDE_TYPE_VLA_U16: | |
530 | case SIDE_TYPE_VLA_U32: | |
531 | case SIDE_TYPE_VLA_U64: | |
532 | case SIDE_TYPE_VLA_S8: | |
533 | case SIDE_TYPE_VLA_S16: | |
534 | case SIDE_TYPE_VLA_S32: | |
535 | case SIDE_TYPE_VLA_S64: | |
f7653b43 | 536 | case SIDE_TYPE_VLA_BYTE: |
1533629f MD |
537 | tracer_print_vla_fixint(type_desc, item); |
538 | break; | |
a2e2357e | 539 | case SIDE_TYPE_DYNAMIC: |
0e9be766 | 540 | tracer_print_basic_type_header(type_desc); |
a2e2357e MD |
541 | tracer_print_dynamic(&item->u.dynamic); |
542 | break; | |
f611d0c3 | 543 | default: |
de1b3cd2 | 544 | fprintf(stderr, "<UNKNOWN TYPE>"); |
f611d0c3 MD |
545 | abort(); |
546 | } | |
a848763d | 547 | printf(" }"); |
f611d0c3 MD |
548 | } |
549 | ||
550 | static | |
551 | void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg_vec *item) | |
552 | { | |
19fa6aa2 | 553 | printf("%s: ", item_desc->field_name); |
f611d0c3 | 554 | tracer_print_type(&item_desc->side_type, item); |
f611d0c3 MD |
555 | } |
556 | ||
557 | static | |
558 | void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc) | |
559 | { | |
560 | const struct side_arg_vec *sav = sav_desc->sav; | |
561 | uint32_t side_sav_len = sav_desc->len; | |
562 | int i; | |
563 | ||
c7a14585 | 564 | if (type_desc->u.side_struct->nr_fields != side_sav_len) { |
de1b3cd2 | 565 | fprintf(stderr, "ERROR: number of fields mismatch between description and arguments of structure\n"); |
f611d0c3 MD |
566 | abort(); |
567 | } | |
905c328e | 568 | print_attributes("attr", ":", type_desc->u.side_struct->attr, type_desc->u.side_struct->nr_attr); |
73b2b0c2 MD |
569 | printf("%s", type_desc->u.side_struct->nr_attr ? ", " : ""); |
570 | printf("fields: { "); | |
f611d0c3 MD |
571 | for (i = 0; i < side_sav_len; i++) { |
572 | printf("%s", i ? ", " : ""); | |
c7a14585 | 573 | tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]); |
f611d0c3 | 574 | } |
d4328528 | 575 | printf(" }"); |
f611d0c3 MD |
576 | } |
577 | ||
578 | static | |
579 | void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc) | |
580 | { | |
581 | const struct side_arg_vec *sav = sav_desc->sav; | |
582 | uint32_t side_sav_len = sav_desc->len; | |
583 | int i; | |
584 | ||
585 | if (type_desc->u.side_array.length != side_sav_len) { | |
de1b3cd2 | 586 | fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n"); |
f611d0c3 MD |
587 | abort(); |
588 | } | |
905c328e | 589 | print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr); |
d4328528 | 590 | printf("%s", type_desc->u.side_array.nr_attr ? ", " : ""); |
20574104 | 591 | printf("elements: "); |
f611d0c3 MD |
592 | printf("[ "); |
593 | for (i = 0; i < side_sav_len; i++) { | |
594 | printf("%s", i ? ", " : ""); | |
595 | tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]); | |
596 | } | |
597 | printf(" ]"); | |
598 | } | |
599 | ||
600 | static | |
601 | void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc) | |
602 | { | |
603 | const struct side_arg_vec *sav = sav_desc->sav; | |
604 | uint32_t side_sav_len = sav_desc->len; | |
605 | int i; | |
606 | ||
905c328e | 607 | print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr); |
d4328528 | 608 | printf("%s", type_desc->u.side_vla.nr_attr ? ", " : ""); |
20574104 | 609 | printf("elements: "); |
f611d0c3 MD |
610 | printf("[ "); |
611 | for (i = 0; i < side_sav_len; i++) { | |
612 | printf("%s", i ? ", " : ""); | |
613 | tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]); | |
614 | } | |
615 | printf(" ]"); | |
616 | } | |
617 | ||
352a4b77 MD |
618 | struct tracer_visitor_priv { |
619 | const struct side_type_description *elem_type; | |
620 | int i; | |
621 | }; | |
622 | ||
623 | static | |
624 | enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx, | |
625 | const struct side_arg_vec *elem) | |
626 | { | |
627 | struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv; | |
628 | ||
629 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
630 | tracer_print_type(tracer_priv->elem_type, elem); | |
631 | return SIDE_VISITOR_STATUS_OK; | |
632 | } | |
633 | ||
f611d0c3 | 634 | static |
352a4b77 | 635 | void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx) |
f611d0c3 MD |
636 | { |
637 | enum side_visitor_status status; | |
352a4b77 MD |
638 | struct tracer_visitor_priv tracer_priv = { |
639 | .elem_type = type_desc->u.side_vla_visitor.elem_type, | |
640 | .i = 0, | |
641 | }; | |
642 | const struct side_tracer_visitor_ctx tracer_ctx = { | |
643 | .write_elem = tracer_write_elem_cb, | |
644 | .priv = &tracer_priv, | |
645 | }; | |
f611d0c3 | 646 | |
905c328e | 647 | print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr); |
d4328528 | 648 | printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : ""); |
20574104 | 649 | printf("elements: "); |
352a4b77 MD |
650 | printf("[ "); |
651 | status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx); | |
652 | switch (status) { | |
653 | case SIDE_VISITOR_STATUS_OK: | |
654 | break; | |
655 | case SIDE_VISITOR_STATUS_ERROR: | |
de1b3cd2 | 656 | fprintf(stderr, "ERROR: Visitor error\n"); |
f611d0c3 | 657 | abort(); |
f611d0c3 MD |
658 | } |
659 | printf(" ]"); | |
f611d0c3 MD |
660 | } |
661 | ||
ba845af5 MD |
662 | void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item) |
663 | { | |
664 | const struct side_type_description *elem_type = type_desc->u.side_array.elem_type; | |
665 | uint32_t side_sav_len = type_desc->u.side_array.length; | |
666 | void *p = item->u.side_array_fixint; | |
667 | enum side_type side_type; | |
668 | int i; | |
669 | ||
905c328e | 670 | print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr); |
d4328528 | 671 | printf("%s", type_desc->u.side_array.nr_attr ? ", " : ""); |
20574104 | 672 | printf("elements: "); |
1e8256c9 MD |
673 | switch (item->type) { |
674 | case SIDE_TYPE_ARRAY_U8: | |
675 | if (elem_type->type != SIDE_TYPE_U8) | |
676 | goto type_error; | |
677 | break; | |
678 | case SIDE_TYPE_ARRAY_U16: | |
679 | if (elem_type->type != SIDE_TYPE_U16) | |
680 | goto type_error; | |
681 | break; | |
682 | case SIDE_TYPE_ARRAY_U32: | |
683 | if (elem_type->type != SIDE_TYPE_U32) | |
684 | goto type_error; | |
685 | break; | |
686 | case SIDE_TYPE_ARRAY_U64: | |
687 | if (elem_type->type != SIDE_TYPE_U64) | |
688 | goto type_error; | |
689 | break; | |
690 | case SIDE_TYPE_ARRAY_S8: | |
691 | if (elem_type->type != SIDE_TYPE_S8) | |
692 | goto type_error; | |
693 | break; | |
694 | case SIDE_TYPE_ARRAY_S16: | |
695 | if (elem_type->type != SIDE_TYPE_S16) | |
696 | goto type_error; | |
697 | break; | |
698 | case SIDE_TYPE_ARRAY_S32: | |
699 | if (elem_type->type != SIDE_TYPE_S32) | |
700 | goto type_error; | |
701 | break; | |
702 | case SIDE_TYPE_ARRAY_S64: | |
703 | if (elem_type->type != SIDE_TYPE_S64) | |
704 | goto type_error; | |
705 | break; | |
f7653b43 MD |
706 | case SIDE_TYPE_ARRAY_BYTE: |
707 | if (elem_type->type != SIDE_TYPE_BYTE) | |
7aec0d09 MD |
708 | goto type_error; |
709 | break; | |
1e8256c9 MD |
710 | default: |
711 | goto type_error; | |
ba845af5 | 712 | } |
1e8256c9 | 713 | side_type = elem_type->type; |
ba845af5 | 714 | |
1533629f MD |
715 | printf("[ "); |
716 | for (i = 0; i < side_sav_len; i++) { | |
717 | struct side_arg_vec sav_elem = { | |
718 | .type = side_type, | |
719 | }; | |
720 | ||
721 | switch (side_type) { | |
722 | case SIDE_TYPE_U8: | |
723 | sav_elem.u.side_u8 = ((const uint8_t *) p)[i]; | |
724 | break; | |
725 | case SIDE_TYPE_S8: | |
726 | sav_elem.u.side_s8 = ((const int8_t *) p)[i]; | |
727 | break; | |
728 | case SIDE_TYPE_U16: | |
729 | sav_elem.u.side_u16 = ((const uint16_t *) p)[i]; | |
730 | break; | |
731 | case SIDE_TYPE_S16: | |
732 | sav_elem.u.side_s16 = ((const int16_t *) p)[i]; | |
733 | break; | |
734 | case SIDE_TYPE_U32: | |
735 | sav_elem.u.side_u32 = ((const uint32_t *) p)[i]; | |
736 | break; | |
737 | case SIDE_TYPE_S32: | |
738 | sav_elem.u.side_s32 = ((const int32_t *) p)[i]; | |
739 | break; | |
740 | case SIDE_TYPE_U64: | |
741 | sav_elem.u.side_u64 = ((const uint64_t *) p)[i]; | |
742 | break; | |
743 | case SIDE_TYPE_S64: | |
744 | sav_elem.u.side_s64 = ((const int64_t *) p)[i]; | |
745 | break; | |
f7653b43 MD |
746 | case SIDE_TYPE_BYTE: |
747 | sav_elem.u.side_byte = ((const uint8_t *) p)[i]; | |
7aec0d09 | 748 | break; |
1533629f MD |
749 | |
750 | default: | |
de1b3cd2 | 751 | fprintf(stderr, "ERROR: Unexpected type\n"); |
1533629f MD |
752 | abort(); |
753 | } | |
754 | ||
755 | printf("%s", i ? ", " : ""); | |
756 | tracer_print_type(elem_type, &sav_elem); | |
757 | } | |
758 | printf(" ]"); | |
759 | return; | |
760 | ||
761 | type_error: | |
de1b3cd2 | 762 | fprintf(stderr, "ERROR: type mismatch\n"); |
1533629f MD |
763 | abort(); |
764 | } | |
765 | ||
766 | void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item) | |
767 | { | |
768 | const struct side_type_description *elem_type = type_desc->u.side_vla.elem_type; | |
769 | uint32_t side_sav_len = item->u.side_vla_fixint.length; | |
770 | void *p = item->u.side_vla_fixint.p; | |
771 | enum side_type side_type; | |
772 | int i; | |
773 | ||
905c328e | 774 | print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr); |
d4328528 | 775 | printf("%s", type_desc->u.side_vla.nr_attr ? ", " : ""); |
20574104 | 776 | printf("elements: "); |
a2e2357e MD |
777 | switch (item->type) { |
778 | case SIDE_TYPE_VLA_U8: | |
779 | if (elem_type->type != SIDE_TYPE_U8) | |
1533629f | 780 | goto type_error; |
a2e2357e MD |
781 | break; |
782 | case SIDE_TYPE_VLA_U16: | |
783 | if (elem_type->type != SIDE_TYPE_U16) | |
1533629f | 784 | goto type_error; |
a2e2357e MD |
785 | break; |
786 | case SIDE_TYPE_VLA_U32: | |
787 | if (elem_type->type != SIDE_TYPE_U32) | |
788 | goto type_error; | |
789 | break; | |
790 | case SIDE_TYPE_VLA_U64: | |
791 | if (elem_type->type != SIDE_TYPE_U64) | |
792 | goto type_error; | |
793 | break; | |
794 | case SIDE_TYPE_VLA_S8: | |
795 | if (elem_type->type != SIDE_TYPE_S8) | |
796 | goto type_error; | |
797 | break; | |
798 | case SIDE_TYPE_VLA_S16: | |
799 | if (elem_type->type != SIDE_TYPE_S16) | |
800 | goto type_error; | |
801 | break; | |
802 | case SIDE_TYPE_VLA_S32: | |
803 | if (elem_type->type != SIDE_TYPE_S32) | |
804 | goto type_error; | |
805 | break; | |
806 | case SIDE_TYPE_VLA_S64: | |
807 | if (elem_type->type != SIDE_TYPE_S64) | |
808 | goto type_error; | |
809 | break; | |
f7653b43 MD |
810 | case SIDE_TYPE_VLA_BYTE: |
811 | if (elem_type->type != SIDE_TYPE_BYTE) | |
7aec0d09 MD |
812 | goto type_error; |
813 | break; | |
a2e2357e MD |
814 | default: |
815 | goto type_error; | |
1533629f | 816 | } |
a2e2357e | 817 | side_type = elem_type->type; |
1533629f | 818 | |
ba845af5 MD |
819 | printf("[ "); |
820 | for (i = 0; i < side_sav_len; i++) { | |
821 | struct side_arg_vec sav_elem = { | |
822 | .type = side_type, | |
823 | }; | |
824 | ||
825 | switch (side_type) { | |
826 | case SIDE_TYPE_U8: | |
827 | sav_elem.u.side_u8 = ((const uint8_t *) p)[i]; | |
828 | break; | |
829 | case SIDE_TYPE_S8: | |
830 | sav_elem.u.side_s8 = ((const int8_t *) p)[i]; | |
831 | break; | |
832 | case SIDE_TYPE_U16: | |
833 | sav_elem.u.side_u16 = ((const uint16_t *) p)[i]; | |
834 | break; | |
835 | case SIDE_TYPE_S16: | |
836 | sav_elem.u.side_s16 = ((const int16_t *) p)[i]; | |
837 | break; | |
838 | case SIDE_TYPE_U32: | |
839 | sav_elem.u.side_u32 = ((const uint32_t *) p)[i]; | |
840 | break; | |
841 | case SIDE_TYPE_S32: | |
842 | sav_elem.u.side_s32 = ((const int32_t *) p)[i]; | |
843 | break; | |
844 | case SIDE_TYPE_U64: | |
845 | sav_elem.u.side_u64 = ((const uint64_t *) p)[i]; | |
846 | break; | |
847 | case SIDE_TYPE_S64: | |
848 | sav_elem.u.side_s64 = ((const int64_t *) p)[i]; | |
849 | break; | |
f7653b43 MD |
850 | case SIDE_TYPE_BYTE: |
851 | sav_elem.u.side_byte = ((const uint8_t *) p)[i]; | |
7aec0d09 | 852 | break; |
ba845af5 MD |
853 | |
854 | default: | |
de1b3cd2 | 855 | fprintf(stderr, "ERROR: Unexpected type\n"); |
ba845af5 MD |
856 | abort(); |
857 | } | |
858 | ||
859 | printf("%s", i ? ", " : ""); | |
860 | tracer_print_type(elem_type, &sav_elem); | |
861 | } | |
862 | printf(" ]"); | |
863 | return; | |
864 | ||
865 | type_error: | |
de1b3cd2 | 866 | fprintf(stderr, "ERROR: type mismatch\n"); |
ba845af5 MD |
867 | abort(); |
868 | } | |
869 | ||
a2e2357e | 870 | static |
c208889e | 871 | void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct) |
a2e2357e | 872 | { |
c208889e MD |
873 | const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields; |
874 | uint32_t len = dynamic_struct->len; | |
465e5e7e MD |
875 | int i; |
876 | ||
905c328e | 877 | print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr); |
8d20e708 | 878 | printf("%s", dynamic_struct->nr_attr ? ", " : ""); |
f0061366 | 879 | printf("fields:: "); |
465e5e7e MD |
880 | printf("[ "); |
881 | for (i = 0; i < len; i++) { | |
882 | printf("%s", i ? ", " : ""); | |
883 | printf("%s:: ", fields[i].field_name); | |
884 | tracer_print_dynamic(&fields[i].elem); | |
885 | } | |
886 | printf(" ]"); | |
a2e2357e MD |
887 | } |
888 | ||
2b359235 MD |
889 | struct tracer_dynamic_struct_visitor_priv { |
890 | int i; | |
891 | }; | |
892 | ||
893 | static | |
894 | enum side_visitor_status tracer_dynamic_struct_write_elem_cb( | |
895 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
896 | const struct side_arg_dynamic_event_field *dynamic_field) | |
897 | { | |
898 | struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv; | |
899 | ||
900 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
901 | printf("%s:: ", dynamic_field->field_name); | |
902 | tracer_print_dynamic(&dynamic_field->elem); | |
903 | return SIDE_VISITOR_STATUS_OK; | |
904 | } | |
905 | ||
a2e2357e | 906 | static |
c208889e | 907 | void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item) |
a2e2357e | 908 | { |
2b359235 MD |
909 | enum side_visitor_status status; |
910 | struct tracer_dynamic_struct_visitor_priv tracer_priv = { | |
911 | .i = 0, | |
912 | }; | |
913 | const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = { | |
914 | .write_field = tracer_dynamic_struct_write_elem_cb, | |
915 | .priv = &tracer_priv, | |
916 | }; | |
917 | void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx; | |
918 | ||
905c328e | 919 | print_attributes("attr", "::", item->u.side_dynamic_struct_visitor.attr, item->u.side_dynamic_struct_visitor.nr_attr); |
8d20e708 | 920 | printf("%s", item->u.side_dynamic_struct_visitor.nr_attr ? ", " : ""); |
f0061366 | 921 | printf("fields:: "); |
2b359235 MD |
922 | printf("[ "); |
923 | status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx); | |
924 | switch (status) { | |
925 | case SIDE_VISITOR_STATUS_OK: | |
926 | break; | |
927 | case SIDE_VISITOR_STATUS_ERROR: | |
de1b3cd2 | 928 | fprintf(stderr, "ERROR: Visitor error\n"); |
2b359235 MD |
929 | abort(); |
930 | } | |
931 | printf(" ]"); | |
a2e2357e MD |
932 | } |
933 | ||
934 | static | |
935 | void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla *vla) | |
936 | { | |
937 | const struct side_arg_dynamic_vec *sav = vla->sav; | |
938 | uint32_t side_sav_len = vla->len; | |
939 | int i; | |
940 | ||
905c328e | 941 | print_attributes("attr", "::", vla->attr, vla->nr_attr); |
8d20e708 | 942 | printf("%s", vla->nr_attr ? ", " : ""); |
f0061366 | 943 | printf("elements:: "); |
a2e2357e MD |
944 | printf("[ "); |
945 | for (i = 0; i < side_sav_len; i++) { | |
946 | printf("%s", i ? ", " : ""); | |
947 | tracer_print_dynamic(&sav[i]); | |
948 | } | |
949 | printf(" ]"); | |
950 | } | |
951 | ||
8ceca0cd MD |
952 | struct tracer_dynamic_vla_visitor_priv { |
953 | int i; | |
954 | }; | |
955 | ||
956 | static | |
957 | enum side_visitor_status tracer_dynamic_vla_write_elem_cb( | |
958 | const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, | |
959 | const struct side_arg_dynamic_vec *elem) | |
960 | { | |
961 | struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv; | |
962 | ||
963 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
964 | tracer_print_dynamic(elem); | |
965 | return SIDE_VISITOR_STATUS_OK; | |
966 | } | |
967 | ||
a2e2357e MD |
968 | static |
969 | void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec *item) | |
970 | { | |
8ceca0cd MD |
971 | enum side_visitor_status status; |
972 | struct tracer_dynamic_vla_visitor_priv tracer_priv = { | |
973 | .i = 0, | |
974 | }; | |
975 | const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = { | |
976 | .write_elem = tracer_dynamic_vla_write_elem_cb, | |
977 | .priv = &tracer_priv, | |
978 | }; | |
979 | void *app_ctx = item->u.side_dynamic_vla_visitor.app_ctx; | |
980 | ||
905c328e | 981 | print_attributes("attr", "::", item->u.side_dynamic_vla_visitor.attr, item->u.side_dynamic_vla_visitor.nr_attr); |
8d20e708 | 982 | printf("%s", item->u.side_dynamic_vla_visitor.nr_attr ? ", " : ""); |
f0061366 | 983 | printf("elements:: "); |
8ceca0cd MD |
984 | printf("[ "); |
985 | status = item->u.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx); | |
986 | switch (status) { | |
987 | case SIDE_VISITOR_STATUS_OK: | |
988 | break; | |
989 | case SIDE_VISITOR_STATUS_ERROR: | |
de1b3cd2 | 990 | fprintf(stderr, "ERROR: Visitor error\n"); |
8ceca0cd MD |
991 | abort(); |
992 | } | |
993 | printf(" ]"); | |
a2e2357e MD |
994 | } |
995 | ||
0e9be766 MD |
996 | static |
997 | void tracer_print_dynamic_basic_type_header(const struct side_arg_dynamic_vec *item) | |
998 | { | |
905c328e | 999 | print_attributes("attr", "::", item->u.side_basic.attr, item->u.side_basic.nr_attr); |
0e9be766 MD |
1000 | printf("%s", item->u.side_basic.nr_attr ? ", " : ""); |
1001 | printf("value:: "); | |
1002 | } | |
1003 | ||
a2e2357e MD |
1004 | static |
1005 | void tracer_print_dynamic(const struct side_arg_dynamic_vec *item) | |
1006 | { | |
808bd9bf | 1007 | printf("{ "); |
1e8256c9 | 1008 | switch (item->dynamic_type) { |
a2e2357e | 1009 | case SIDE_DYNAMIC_TYPE_NULL: |
0e9be766 | 1010 | tracer_print_dynamic_basic_type_header(item); |
a2e2357e MD |
1011 | printf("<NULL TYPE>"); |
1012 | break; | |
4f40d951 | 1013 | case SIDE_DYNAMIC_TYPE_BOOL: |
0e9be766 | 1014 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1015 | printf("%s", item->u.side_basic.u.side_bool ? "true" : "false"); |
4f40d951 | 1016 | break; |
a2e2357e | 1017 | case SIDE_DYNAMIC_TYPE_U8: |
0e9be766 | 1018 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1019 | printf("%" PRIu8, item->u.side_basic.u.side_u8); |
a2e2357e MD |
1020 | break; |
1021 | case SIDE_DYNAMIC_TYPE_U16: | |
0e9be766 | 1022 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1023 | printf("%" PRIu16, item->u.side_basic.u.side_u16); |
a2e2357e MD |
1024 | break; |
1025 | case SIDE_DYNAMIC_TYPE_U32: | |
0e9be766 | 1026 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1027 | printf("%" PRIu32, item->u.side_basic.u.side_u32); |
a2e2357e MD |
1028 | break; |
1029 | case SIDE_DYNAMIC_TYPE_U64: | |
0e9be766 | 1030 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1031 | printf("%" PRIu64, item->u.side_basic.u.side_u64); |
a2e2357e MD |
1032 | break; |
1033 | case SIDE_DYNAMIC_TYPE_S8: | |
0e9be766 | 1034 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1035 | printf("%" PRId8, item->u.side_basic.u.side_s8); |
a2e2357e MD |
1036 | break; |
1037 | case SIDE_DYNAMIC_TYPE_S16: | |
0e9be766 | 1038 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1039 | printf("%" PRId16, item->u.side_basic.u.side_s16); |
a2e2357e MD |
1040 | break; |
1041 | case SIDE_DYNAMIC_TYPE_S32: | |
0e9be766 | 1042 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1043 | printf("%" PRId32, item->u.side_basic.u.side_s32); |
a2e2357e MD |
1044 | break; |
1045 | case SIDE_DYNAMIC_TYPE_S64: | |
0e9be766 | 1046 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1047 | printf("%" PRId64, item->u.side_basic.u.side_s64); |
a2e2357e | 1048 | break; |
f7653b43 | 1049 | case SIDE_DYNAMIC_TYPE_BYTE: |
0e9be766 | 1050 | tracer_print_dynamic_basic_type_header(item); |
f7653b43 | 1051 | printf("0x%" PRIx8, item->u.side_basic.u.side_byte); |
199e7aa9 MD |
1052 | break; |
1053 | ||
fb25b355 | 1054 | case SIDE_DYNAMIC_TYPE_FLOAT_BINARY16: |
0e9be766 | 1055 | tracer_print_dynamic_basic_type_header(item); |
fb25b355 | 1056 | #if __HAVE_FLOAT16 |
8d20e708 | 1057 | printf("%g", (double) item->u.side_basic.u.side_float_binary16); |
fb25b355 MD |
1058 | break; |
1059 | #else | |
de1b3cd2 | 1060 | fprintf(stderr, "ERROR: Unsupported binary16 float type\n"); |
fb25b355 MD |
1061 | abort(); |
1062 | #endif | |
1063 | case SIDE_DYNAMIC_TYPE_FLOAT_BINARY32: | |
0e9be766 | 1064 | tracer_print_dynamic_basic_type_header(item); |
fb25b355 | 1065 | #if __HAVE_FLOAT32 |
8d20e708 | 1066 | printf("%g", (double) item->u.side_basic.u.side_float_binary32); |
fb25b355 MD |
1067 | break; |
1068 | #else | |
de1b3cd2 | 1069 | fprintf(stderr, "ERROR: Unsupported binary32 float type\n"); |
fb25b355 MD |
1070 | abort(); |
1071 | #endif | |
1072 | case SIDE_DYNAMIC_TYPE_FLOAT_BINARY64: | |
0e9be766 | 1073 | tracer_print_dynamic_basic_type_header(item); |
fb25b355 | 1074 | #if __HAVE_FLOAT64 |
8d20e708 | 1075 | printf("%g", (double) item->u.side_basic.u.side_float_binary64); |
fb25b355 MD |
1076 | break; |
1077 | #else | |
de1b3cd2 | 1078 | fprintf(stderr, "ERROR: Unsupported binary64 float type\n"); |
fb25b355 MD |
1079 | abort(); |
1080 | #endif | |
1081 | case SIDE_DYNAMIC_TYPE_FLOAT_BINARY128: | |
0e9be766 | 1082 | tracer_print_dynamic_basic_type_header(item); |
fb25b355 | 1083 | #if __HAVE_FLOAT128 |
8d20e708 | 1084 | printf("%Lg", (long double) item->u.side_basic.u.side_float_binary128); |
fb25b355 MD |
1085 | break; |
1086 | #else | |
de1b3cd2 | 1087 | fprintf(stderr, "ERROR: Unsupported binary128 float type\n"); |
fb25b355 MD |
1088 | abort(); |
1089 | #endif | |
a2e2357e | 1090 | case SIDE_DYNAMIC_TYPE_STRING: |
0e9be766 | 1091 | tracer_print_dynamic_basic_type_header(item); |
8d20e708 | 1092 | printf("\"%s\"", item->u.side_basic.u.string); |
a2e2357e | 1093 | break; |
c208889e MD |
1094 | case SIDE_DYNAMIC_TYPE_STRUCT: |
1095 | tracer_print_dynamic_struct(item->u.side_dynamic_struct); | |
a2e2357e | 1096 | break; |
c208889e MD |
1097 | case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR: |
1098 | tracer_print_dynamic_struct_visitor(item); | |
a2e2357e MD |
1099 | break; |
1100 | case SIDE_DYNAMIC_TYPE_VLA: | |
1101 | tracer_print_dynamic_vla(item->u.side_dynamic_vla); | |
1102 | break; | |
1103 | case SIDE_DYNAMIC_TYPE_VLA_VISITOR: | |
1104 | tracer_print_dynamic_vla_visitor(item); | |
1105 | break; | |
1106 | default: | |
de1b3cd2 | 1107 | fprintf(stderr, "<UNKNOWN TYPE>"); |
a2e2357e MD |
1108 | abort(); |
1109 | } | |
808bd9bf | 1110 | printf(" }"); |
a2e2357e MD |
1111 | } |
1112 | ||
68f8cfbe MD |
1113 | static |
1114 | void tracer_print_static_fields(const struct side_event_description *desc, | |
1115 | const struct side_arg_vec_description *sav_desc, | |
1116 | int *nr_items) | |
f611d0c3 MD |
1117 | { |
1118 | const struct side_arg_vec *sav = sav_desc->sav; | |
1119 | uint32_t side_sav_len = sav_desc->len; | |
1120 | int i; | |
1121 | ||
65010f43 | 1122 | printf("provider: %s, event: %s", desc->provider_name, desc->event_name); |
f611d0c3 | 1123 | if (desc->nr_fields != side_sav_len) { |
de1b3cd2 | 1124 | fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n"); |
f611d0c3 MD |
1125 | abort(); |
1126 | } | |
905c328e | 1127 | print_attributes(", attr", ":", desc->attr, desc->nr_attr); |
a848763d | 1128 | printf("%s", side_sav_len ? ", fields: [ " : ""); |
f611d0c3 MD |
1129 | for (i = 0; i < side_sav_len; i++) { |
1130 | printf("%s", i ? ", " : ""); | |
1131 | tracer_print_field(&desc->fields[i], &sav[i]); | |
1132 | } | |
68f8cfbe MD |
1133 | if (nr_items) |
1134 | *nr_items = i; | |
c7d338e2 MD |
1135 | if (side_sav_len) |
1136 | printf(" ]"); | |
68f8cfbe MD |
1137 | } |
1138 | ||
4a7d8700 MD |
1139 | void tracer_call(const struct side_event_description *desc, |
1140 | const struct side_arg_vec_description *sav_desc, | |
1141 | void *priv __attribute__((unused))) | |
68f8cfbe | 1142 | { |
a848763d MD |
1143 | int nr_fields = 0; |
1144 | ||
a848763d | 1145 | tracer_print_static_fields(desc, sav_desc, &nr_fields); |
f611d0c3 MD |
1146 | printf("\n"); |
1147 | } | |
19fa6aa2 MD |
1148 | |
1149 | void tracer_call_variadic(const struct side_event_description *desc, | |
4a7d8700 MD |
1150 | const struct side_arg_vec_description *sav_desc, |
1151 | const struct side_arg_dynamic_event_struct *var_struct, | |
1152 | void *priv __attribute__((unused))) | |
19fa6aa2 | 1153 | { |
68f8cfbe MD |
1154 | uint32_t var_struct_len = var_struct->len; |
1155 | int nr_fields = 0, i; | |
19fa6aa2 | 1156 | |
68f8cfbe MD |
1157 | tracer_print_static_fields(desc, sav_desc, &nr_fields); |
1158 | ||
8a25ce77 | 1159 | if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) { |
de1b3cd2 | 1160 | fprintf(stderr, "ERROR: unexpected non-variadic event description\n"); |
8a25ce77 MD |
1161 | abort(); |
1162 | } | |
905c328e MD |
1163 | print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr); |
1164 | printf("%s", var_struct_len ? ", fields:: [ " : ""); | |
68f8cfbe | 1165 | for (i = 0; i < var_struct_len; i++, nr_fields++) { |
c7d338e2 | 1166 | printf("%s", i ? ", " : ""); |
68f8cfbe MD |
1167 | printf("%s:: ", var_struct->fields[i].field_name); |
1168 | tracer_print_dynamic(&var_struct->fields[i].elem); | |
19fa6aa2 | 1169 | } |
a848763d MD |
1170 | if (i) |
1171 | printf(" ]"); | |
19fa6aa2 MD |
1172 | printf("\n"); |
1173 | } |