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