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