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