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