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> | |
10 | ||
11 | #include <side/trace.h> | |
12 | ||
13 | static | |
14 | void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc); | |
15 | static | |
16 | void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc); | |
17 | static | |
18 | void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc); | |
19 | static | |
352a4b77 | 20 | void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx); |
ba845af5 MD |
21 | static |
22 | void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item); | |
1533629f MD |
23 | static |
24 | void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item); | |
a2e2357e MD |
25 | static |
26 | void tracer_print_dynamic(const struct side_arg_dynamic_vec *dynamic_item); | |
f611d0c3 MD |
27 | |
28 | static | |
29 | void tracer_print_type(const struct side_type_description *type_desc, const struct side_arg_vec *item) | |
30 | { | |
ba845af5 MD |
31 | switch (item->type) { |
32 | case SIDE_TYPE_ARRAY_U8: | |
33 | case SIDE_TYPE_ARRAY_U16: | |
34 | case SIDE_TYPE_ARRAY_U32: | |
35 | case SIDE_TYPE_ARRAY_U64: | |
36 | case SIDE_TYPE_ARRAY_S8: | |
37 | case SIDE_TYPE_ARRAY_S16: | |
38 | case SIDE_TYPE_ARRAY_S32: | |
39 | case SIDE_TYPE_ARRAY_S64: | |
40 | if (type_desc->type != SIDE_TYPE_ARRAY) { | |
41 | printf("ERROR: type mismatch between description and arguments\n"); | |
42 | abort(); | |
43 | } | |
44 | break; | |
1533629f MD |
45 | case SIDE_TYPE_VLA_U8: |
46 | case SIDE_TYPE_VLA_U16: | |
47 | case SIDE_TYPE_VLA_U32: | |
48 | case SIDE_TYPE_VLA_U64: | |
49 | case SIDE_TYPE_VLA_S8: | |
50 | case SIDE_TYPE_VLA_S16: | |
51 | case SIDE_TYPE_VLA_S32: | |
52 | case SIDE_TYPE_VLA_S64: | |
53 | if (type_desc->type != SIDE_TYPE_VLA) { | |
54 | printf("ERROR: type mismatch between description and arguments\n"); | |
55 | abort(); | |
56 | } | |
57 | break; | |
58 | ||
ba845af5 | 59 | default: |
a2e2357e | 60 | if (type_desc->type != item->type) { |
ba845af5 MD |
61 | printf("ERROR: type mismatch between description and arguments\n"); |
62 | abort(); | |
63 | } | |
64 | break; | |
f611d0c3 | 65 | } |
f611d0c3 | 66 | switch (item->type) { |
4f40d951 MD |
67 | case SIDE_TYPE_BOOL: |
68 | printf("%s", item->u.side_bool ? "true" : "false"); | |
69 | break; | |
f611d0c3 MD |
70 | case SIDE_TYPE_U8: |
71 | printf("%" PRIu8, item->u.side_u8); | |
72 | break; | |
73 | case SIDE_TYPE_U16: | |
74 | printf("%" PRIu16, item->u.side_u16); | |
75 | break; | |
76 | case SIDE_TYPE_U32: | |
77 | printf("%" PRIu32, item->u.side_u32); | |
78 | break; | |
79 | case SIDE_TYPE_U64: | |
80 | printf("%" PRIu64, item->u.side_u64); | |
81 | break; | |
82 | case SIDE_TYPE_S8: | |
83 | printf("%" PRId8, item->u.side_s8); | |
84 | break; | |
85 | case SIDE_TYPE_S16: | |
86 | printf("%" PRId16, item->u.side_s16); | |
87 | break; | |
88 | case SIDE_TYPE_S32: | |
89 | printf("%" PRId32, item->u.side_s32); | |
90 | break; | |
91 | case SIDE_TYPE_S64: | |
92 | printf("%" PRId64, item->u.side_s64); | |
93 | break; | |
94 | case SIDE_TYPE_STRING: | |
a2e2357e | 95 | printf("\"%s\"", item->u.string); |
f611d0c3 MD |
96 | break; |
97 | case SIDE_TYPE_STRUCT: | |
98 | tracer_print_struct(type_desc, item->u.side_struct); | |
99 | break; | |
100 | case SIDE_TYPE_ARRAY: | |
101 | tracer_print_array(type_desc, item->u.side_array); | |
102 | break; | |
103 | case SIDE_TYPE_VLA: | |
104 | tracer_print_vla(type_desc, item->u.side_vla); | |
105 | break; | |
106 | case SIDE_TYPE_VLA_VISITOR: | |
352a4b77 | 107 | tracer_print_vla_visitor(type_desc, item->u.side_vla_app_visitor_ctx); |
f611d0c3 | 108 | break; |
ba845af5 MD |
109 | case SIDE_TYPE_ARRAY_U8: |
110 | case SIDE_TYPE_ARRAY_U16: | |
111 | case SIDE_TYPE_ARRAY_U32: | |
112 | case SIDE_TYPE_ARRAY_U64: | |
113 | case SIDE_TYPE_ARRAY_S8: | |
114 | case SIDE_TYPE_ARRAY_S16: | |
115 | case SIDE_TYPE_ARRAY_S32: | |
116 | case SIDE_TYPE_ARRAY_S64: | |
117 | tracer_print_array_fixint(type_desc, item); | |
118 | break; | |
1533629f MD |
119 | case SIDE_TYPE_VLA_U8: |
120 | case SIDE_TYPE_VLA_U16: | |
121 | case SIDE_TYPE_VLA_U32: | |
122 | case SIDE_TYPE_VLA_U64: | |
123 | case SIDE_TYPE_VLA_S8: | |
124 | case SIDE_TYPE_VLA_S16: | |
125 | case SIDE_TYPE_VLA_S32: | |
126 | case SIDE_TYPE_VLA_S64: | |
127 | tracer_print_vla_fixint(type_desc, item); | |
128 | break; | |
a2e2357e MD |
129 | case SIDE_TYPE_DYNAMIC: |
130 | tracer_print_dynamic(&item->u.dynamic); | |
131 | break; | |
f611d0c3 MD |
132 | default: |
133 | printf("<UNKNOWN TYPE>"); | |
134 | abort(); | |
135 | } | |
136 | } | |
137 | ||
138 | static | |
139 | void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg_vec *item) | |
140 | { | |
19fa6aa2 | 141 | printf("%s: ", item_desc->field_name); |
f611d0c3 | 142 | tracer_print_type(&item_desc->side_type, item); |
f611d0c3 MD |
143 | } |
144 | ||
145 | static | |
146 | void tracer_print_struct(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc) | |
147 | { | |
148 | const struct side_arg_vec *sav = sav_desc->sav; | |
149 | uint32_t side_sav_len = sav_desc->len; | |
150 | int i; | |
151 | ||
152 | if (type_desc->u.side_struct.nr_fields != side_sav_len) { | |
153 | printf("ERROR: number of fields mismatch between description and arguments of structure\n"); | |
154 | abort(); | |
155 | } | |
156 | printf("{ "); | |
157 | for (i = 0; i < side_sav_len; i++) { | |
158 | printf("%s", i ? ", " : ""); | |
159 | tracer_print_field(&type_desc->u.side_struct.fields[i], &sav[i]); | |
160 | } | |
161 | printf(" }"); | |
162 | } | |
163 | ||
164 | static | |
165 | void tracer_print_array(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc) | |
166 | { | |
167 | const struct side_arg_vec *sav = sav_desc->sav; | |
168 | uint32_t side_sav_len = sav_desc->len; | |
169 | int i; | |
170 | ||
171 | if (type_desc->u.side_array.length != side_sav_len) { | |
172 | printf("ERROR: length mismatch between description and arguments of array\n"); | |
173 | abort(); | |
174 | } | |
175 | printf("[ "); | |
176 | for (i = 0; i < side_sav_len; i++) { | |
177 | printf("%s", i ? ", " : ""); | |
178 | tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]); | |
179 | } | |
180 | printf(" ]"); | |
181 | } | |
182 | ||
183 | static | |
184 | void tracer_print_vla(const struct side_type_description *type_desc, const struct side_arg_vec_description *sav_desc) | |
185 | { | |
186 | const struct side_arg_vec *sav = sav_desc->sav; | |
187 | uint32_t side_sav_len = sav_desc->len; | |
188 | int i; | |
189 | ||
190 | printf("[ "); | |
191 | for (i = 0; i < side_sav_len; i++) { | |
192 | printf("%s", i ? ", " : ""); | |
193 | tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]); | |
194 | } | |
195 | printf(" ]"); | |
196 | } | |
197 | ||
352a4b77 MD |
198 | struct tracer_visitor_priv { |
199 | const struct side_type_description *elem_type; | |
200 | int i; | |
201 | }; | |
202 | ||
203 | static | |
204 | enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx, | |
205 | const struct side_arg_vec *elem) | |
206 | { | |
207 | struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv; | |
208 | ||
209 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
210 | tracer_print_type(tracer_priv->elem_type, elem); | |
211 | return SIDE_VISITOR_STATUS_OK; | |
212 | } | |
213 | ||
f611d0c3 | 214 | static |
352a4b77 | 215 | void tracer_print_vla_visitor(const struct side_type_description *type_desc, void *app_ctx) |
f611d0c3 MD |
216 | { |
217 | enum side_visitor_status status; | |
352a4b77 MD |
218 | struct tracer_visitor_priv tracer_priv = { |
219 | .elem_type = type_desc->u.side_vla_visitor.elem_type, | |
220 | .i = 0, | |
221 | }; | |
222 | const struct side_tracer_visitor_ctx tracer_ctx = { | |
223 | .write_elem = tracer_write_elem_cb, | |
224 | .priv = &tracer_priv, | |
225 | }; | |
f611d0c3 | 226 | |
352a4b77 MD |
227 | printf("[ "); |
228 | status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx); | |
229 | switch (status) { | |
230 | case SIDE_VISITOR_STATUS_OK: | |
231 | break; | |
232 | case SIDE_VISITOR_STATUS_ERROR: | |
f611d0c3 MD |
233 | printf("ERROR: Visitor error\n"); |
234 | abort(); | |
f611d0c3 MD |
235 | } |
236 | printf(" ]"); | |
f611d0c3 MD |
237 | } |
238 | ||
ba845af5 MD |
239 | void tracer_print_array_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item) |
240 | { | |
241 | const struct side_type_description *elem_type = type_desc->u.side_array.elem_type; | |
242 | uint32_t side_sav_len = type_desc->u.side_array.length; | |
243 | void *p = item->u.side_array_fixint; | |
244 | enum side_type side_type; | |
245 | int i; | |
246 | ||
1e8256c9 MD |
247 | switch (item->type) { |
248 | case SIDE_TYPE_ARRAY_U8: | |
249 | if (elem_type->type != SIDE_TYPE_U8) | |
250 | goto type_error; | |
251 | break; | |
252 | case SIDE_TYPE_ARRAY_U16: | |
253 | if (elem_type->type != SIDE_TYPE_U16) | |
254 | goto type_error; | |
255 | break; | |
256 | case SIDE_TYPE_ARRAY_U32: | |
257 | if (elem_type->type != SIDE_TYPE_U32) | |
258 | goto type_error; | |
259 | break; | |
260 | case SIDE_TYPE_ARRAY_U64: | |
261 | if (elem_type->type != SIDE_TYPE_U64) | |
262 | goto type_error; | |
263 | break; | |
264 | case SIDE_TYPE_ARRAY_S8: | |
265 | if (elem_type->type != SIDE_TYPE_S8) | |
266 | goto type_error; | |
267 | break; | |
268 | case SIDE_TYPE_ARRAY_S16: | |
269 | if (elem_type->type != SIDE_TYPE_S16) | |
270 | goto type_error; | |
271 | break; | |
272 | case SIDE_TYPE_ARRAY_S32: | |
273 | if (elem_type->type != SIDE_TYPE_S32) | |
274 | goto type_error; | |
275 | break; | |
276 | case SIDE_TYPE_ARRAY_S64: | |
277 | if (elem_type->type != SIDE_TYPE_S64) | |
278 | goto type_error; | |
279 | break; | |
280 | default: | |
281 | goto type_error; | |
ba845af5 | 282 | } |
1e8256c9 | 283 | side_type = elem_type->type; |
ba845af5 | 284 | |
1533629f MD |
285 | printf("[ "); |
286 | for (i = 0; i < side_sav_len; i++) { | |
287 | struct side_arg_vec sav_elem = { | |
288 | .type = side_type, | |
289 | }; | |
290 | ||
291 | switch (side_type) { | |
292 | case SIDE_TYPE_U8: | |
293 | sav_elem.u.side_u8 = ((const uint8_t *) p)[i]; | |
294 | break; | |
295 | case SIDE_TYPE_S8: | |
296 | sav_elem.u.side_s8 = ((const int8_t *) p)[i]; | |
297 | break; | |
298 | case SIDE_TYPE_U16: | |
299 | sav_elem.u.side_u16 = ((const uint16_t *) p)[i]; | |
300 | break; | |
301 | case SIDE_TYPE_S16: | |
302 | sav_elem.u.side_s16 = ((const int16_t *) p)[i]; | |
303 | break; | |
304 | case SIDE_TYPE_U32: | |
305 | sav_elem.u.side_u32 = ((const uint32_t *) p)[i]; | |
306 | break; | |
307 | case SIDE_TYPE_S32: | |
308 | sav_elem.u.side_s32 = ((const int32_t *) p)[i]; | |
309 | break; | |
310 | case SIDE_TYPE_U64: | |
311 | sav_elem.u.side_u64 = ((const uint64_t *) p)[i]; | |
312 | break; | |
313 | case SIDE_TYPE_S64: | |
314 | sav_elem.u.side_s64 = ((const int64_t *) p)[i]; | |
315 | break; | |
316 | ||
317 | default: | |
318 | printf("ERROR: Unexpected type\n"); | |
319 | abort(); | |
320 | } | |
321 | ||
322 | printf("%s", i ? ", " : ""); | |
323 | tracer_print_type(elem_type, &sav_elem); | |
324 | } | |
325 | printf(" ]"); | |
326 | return; | |
327 | ||
328 | type_error: | |
329 | printf("ERROR: type mismatch\n"); | |
330 | abort(); | |
331 | } | |
332 | ||
333 | void tracer_print_vla_fixint(const struct side_type_description *type_desc, const struct side_arg_vec *item) | |
334 | { | |
335 | const struct side_type_description *elem_type = type_desc->u.side_vla.elem_type; | |
336 | uint32_t side_sav_len = item->u.side_vla_fixint.length; | |
337 | void *p = item->u.side_vla_fixint.p; | |
338 | enum side_type side_type; | |
339 | int i; | |
340 | ||
a2e2357e MD |
341 | switch (item->type) { |
342 | case SIDE_TYPE_VLA_U8: | |
343 | if (elem_type->type != SIDE_TYPE_U8) | |
1533629f | 344 | goto type_error; |
a2e2357e MD |
345 | break; |
346 | case SIDE_TYPE_VLA_U16: | |
347 | if (elem_type->type != SIDE_TYPE_U16) | |
1533629f | 348 | goto type_error; |
a2e2357e MD |
349 | break; |
350 | case SIDE_TYPE_VLA_U32: | |
351 | if (elem_type->type != SIDE_TYPE_U32) | |
352 | goto type_error; | |
353 | break; | |
354 | case SIDE_TYPE_VLA_U64: | |
355 | if (elem_type->type != SIDE_TYPE_U64) | |
356 | goto type_error; | |
357 | break; | |
358 | case SIDE_TYPE_VLA_S8: | |
359 | if (elem_type->type != SIDE_TYPE_S8) | |
360 | goto type_error; | |
361 | break; | |
362 | case SIDE_TYPE_VLA_S16: | |
363 | if (elem_type->type != SIDE_TYPE_S16) | |
364 | goto type_error; | |
365 | break; | |
366 | case SIDE_TYPE_VLA_S32: | |
367 | if (elem_type->type != SIDE_TYPE_S32) | |
368 | goto type_error; | |
369 | break; | |
370 | case SIDE_TYPE_VLA_S64: | |
371 | if (elem_type->type != SIDE_TYPE_S64) | |
372 | goto type_error; | |
373 | break; | |
374 | default: | |
375 | goto type_error; | |
1533629f | 376 | } |
a2e2357e | 377 | side_type = elem_type->type; |
1533629f | 378 | |
ba845af5 MD |
379 | printf("[ "); |
380 | for (i = 0; i < side_sav_len; i++) { | |
381 | struct side_arg_vec sav_elem = { | |
382 | .type = side_type, | |
383 | }; | |
384 | ||
385 | switch (side_type) { | |
386 | case SIDE_TYPE_U8: | |
387 | sav_elem.u.side_u8 = ((const uint8_t *) p)[i]; | |
388 | break; | |
389 | case SIDE_TYPE_S8: | |
390 | sav_elem.u.side_s8 = ((const int8_t *) p)[i]; | |
391 | break; | |
392 | case SIDE_TYPE_U16: | |
393 | sav_elem.u.side_u16 = ((const uint16_t *) p)[i]; | |
394 | break; | |
395 | case SIDE_TYPE_S16: | |
396 | sav_elem.u.side_s16 = ((const int16_t *) p)[i]; | |
397 | break; | |
398 | case SIDE_TYPE_U32: | |
399 | sav_elem.u.side_u32 = ((const uint32_t *) p)[i]; | |
400 | break; | |
401 | case SIDE_TYPE_S32: | |
402 | sav_elem.u.side_s32 = ((const int32_t *) p)[i]; | |
403 | break; | |
404 | case SIDE_TYPE_U64: | |
405 | sav_elem.u.side_u64 = ((const uint64_t *) p)[i]; | |
406 | break; | |
407 | case SIDE_TYPE_S64: | |
408 | sav_elem.u.side_s64 = ((const int64_t *) p)[i]; | |
409 | break; | |
410 | ||
411 | default: | |
412 | printf("ERROR: Unexpected type\n"); | |
413 | abort(); | |
414 | } | |
415 | ||
416 | printf("%s", i ? ", " : ""); | |
417 | tracer_print_type(elem_type, &sav_elem); | |
418 | } | |
419 | printf(" ]"); | |
420 | return; | |
421 | ||
422 | type_error: | |
423 | printf("ERROR: type mismatch\n"); | |
424 | abort(); | |
425 | } | |
426 | ||
a2e2357e | 427 | static |
c208889e | 428 | void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct) |
a2e2357e | 429 | { |
c208889e MD |
430 | const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields; |
431 | uint32_t len = dynamic_struct->len; | |
465e5e7e MD |
432 | int i; |
433 | ||
434 | printf("[ "); | |
435 | for (i = 0; i < len; i++) { | |
436 | printf("%s", i ? ", " : ""); | |
437 | printf("%s:: ", fields[i].field_name); | |
438 | tracer_print_dynamic(&fields[i].elem); | |
439 | } | |
440 | printf(" ]"); | |
a2e2357e MD |
441 | } |
442 | ||
2b359235 MD |
443 | struct tracer_dynamic_struct_visitor_priv { |
444 | int i; | |
445 | }; | |
446 | ||
447 | static | |
448 | enum side_visitor_status tracer_dynamic_struct_write_elem_cb( | |
449 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
450 | const struct side_arg_dynamic_event_field *dynamic_field) | |
451 | { | |
452 | struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv; | |
453 | ||
454 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
455 | printf("%s:: ", dynamic_field->field_name); | |
456 | tracer_print_dynamic(&dynamic_field->elem); | |
457 | return SIDE_VISITOR_STATUS_OK; | |
458 | } | |
459 | ||
a2e2357e | 460 | static |
c208889e | 461 | void tracer_print_dynamic_struct_visitor(const struct side_arg_dynamic_vec *item) |
a2e2357e | 462 | { |
2b359235 MD |
463 | enum side_visitor_status status; |
464 | struct tracer_dynamic_struct_visitor_priv tracer_priv = { | |
465 | .i = 0, | |
466 | }; | |
467 | const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = { | |
468 | .write_field = tracer_dynamic_struct_write_elem_cb, | |
469 | .priv = &tracer_priv, | |
470 | }; | |
471 | void *app_ctx = item->u.side_dynamic_struct_visitor.app_ctx; | |
472 | ||
473 | printf("[ "); | |
474 | status = item->u.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx); | |
475 | switch (status) { | |
476 | case SIDE_VISITOR_STATUS_OK: | |
477 | break; | |
478 | case SIDE_VISITOR_STATUS_ERROR: | |
479 | printf("ERROR: Visitor error\n"); | |
480 | abort(); | |
481 | } | |
482 | printf(" ]"); | |
a2e2357e MD |
483 | } |
484 | ||
485 | static | |
486 | void tracer_print_dynamic_vla(const struct side_arg_dynamic_vec_vla *vla) | |
487 | { | |
488 | const struct side_arg_dynamic_vec *sav = vla->sav; | |
489 | uint32_t side_sav_len = vla->len; | |
490 | int i; | |
491 | ||
492 | printf("[ "); | |
493 | for (i = 0; i < side_sav_len; i++) { | |
494 | printf("%s", i ? ", " : ""); | |
495 | tracer_print_dynamic(&sav[i]); | |
496 | } | |
497 | printf(" ]"); | |
498 | } | |
499 | ||
8ceca0cd MD |
500 | struct tracer_dynamic_vla_visitor_priv { |
501 | int i; | |
502 | }; | |
503 | ||
504 | static | |
505 | enum side_visitor_status tracer_dynamic_vla_write_elem_cb( | |
506 | const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, | |
507 | const struct side_arg_dynamic_vec *elem) | |
508 | { | |
509 | struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv; | |
510 | ||
511 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
512 | tracer_print_dynamic(elem); | |
513 | return SIDE_VISITOR_STATUS_OK; | |
514 | } | |
515 | ||
a2e2357e MD |
516 | static |
517 | void tracer_print_dynamic_vla_visitor(const struct side_arg_dynamic_vec *item) | |
518 | { | |
8ceca0cd MD |
519 | enum side_visitor_status status; |
520 | struct tracer_dynamic_vla_visitor_priv tracer_priv = { | |
521 | .i = 0, | |
522 | }; | |
523 | const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = { | |
524 | .write_elem = tracer_dynamic_vla_write_elem_cb, | |
525 | .priv = &tracer_priv, | |
526 | }; | |
527 | void *app_ctx = item->u.side_dynamic_vla_visitor.app_ctx; | |
528 | ||
529 | printf("[ "); | |
530 | status = item->u.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx); | |
531 | switch (status) { | |
532 | case SIDE_VISITOR_STATUS_OK: | |
533 | break; | |
534 | case SIDE_VISITOR_STATUS_ERROR: | |
535 | printf("ERROR: Visitor error\n"); | |
536 | abort(); | |
537 | } | |
538 | printf(" ]"); | |
a2e2357e MD |
539 | } |
540 | ||
541 | static | |
542 | void tracer_print_dynamic(const struct side_arg_dynamic_vec *item) | |
543 | { | |
1e8256c9 | 544 | switch (item->dynamic_type) { |
a2e2357e MD |
545 | case SIDE_DYNAMIC_TYPE_NULL: |
546 | printf("<NULL TYPE>"); | |
547 | break; | |
4f40d951 MD |
548 | case SIDE_DYNAMIC_TYPE_BOOL: |
549 | printf("%s", item->u.side_bool ? "true" : "false"); | |
550 | break; | |
a2e2357e MD |
551 | case SIDE_DYNAMIC_TYPE_U8: |
552 | printf("%" PRIu8, item->u.side_u8); | |
553 | break; | |
554 | case SIDE_DYNAMIC_TYPE_U16: | |
555 | printf("%" PRIu16, item->u.side_u16); | |
556 | break; | |
557 | case SIDE_DYNAMIC_TYPE_U32: | |
558 | printf("%" PRIu32, item->u.side_u32); | |
559 | break; | |
560 | case SIDE_DYNAMIC_TYPE_U64: | |
561 | printf("%" PRIu64, item->u.side_u64); | |
562 | break; | |
563 | case SIDE_DYNAMIC_TYPE_S8: | |
564 | printf("%" PRId8, item->u.side_s8); | |
565 | break; | |
566 | case SIDE_DYNAMIC_TYPE_S16: | |
567 | printf("%" PRId16, item->u.side_s16); | |
568 | break; | |
569 | case SIDE_DYNAMIC_TYPE_S32: | |
570 | printf("%" PRId32, item->u.side_s32); | |
571 | break; | |
572 | case SIDE_DYNAMIC_TYPE_S64: | |
573 | printf("%" PRId64, item->u.side_s64); | |
574 | break; | |
575 | case SIDE_DYNAMIC_TYPE_STRING: | |
576 | printf("\"%s\"", item->u.string); | |
577 | break; | |
c208889e MD |
578 | case SIDE_DYNAMIC_TYPE_STRUCT: |
579 | tracer_print_dynamic_struct(item->u.side_dynamic_struct); | |
a2e2357e | 580 | break; |
c208889e MD |
581 | case SIDE_DYNAMIC_TYPE_STRUCT_VISITOR: |
582 | tracer_print_dynamic_struct_visitor(item); | |
a2e2357e MD |
583 | break; |
584 | case SIDE_DYNAMIC_TYPE_VLA: | |
585 | tracer_print_dynamic_vla(item->u.side_dynamic_vla); | |
586 | break; | |
587 | case SIDE_DYNAMIC_TYPE_VLA_VISITOR: | |
588 | tracer_print_dynamic_vla_visitor(item); | |
589 | break; | |
590 | default: | |
591 | printf("<UNKNOWN TYPE>"); | |
592 | abort(); | |
593 | } | |
594 | } | |
595 | ||
68f8cfbe MD |
596 | static |
597 | void tracer_print_static_fields(const struct side_event_description *desc, | |
598 | const struct side_arg_vec_description *sav_desc, | |
599 | int *nr_items) | |
f611d0c3 MD |
600 | { |
601 | const struct side_arg_vec *sav = sav_desc->sav; | |
602 | uint32_t side_sav_len = sav_desc->len; | |
603 | int i; | |
604 | ||
605 | printf("provider: %s, event: %s, ", desc->provider_name, desc->event_name); | |
606 | if (desc->nr_fields != side_sav_len) { | |
607 | printf("ERROR: number of fields mismatch between description and arguments\n"); | |
608 | abort(); | |
609 | } | |
610 | for (i = 0; i < side_sav_len; i++) { | |
611 | printf("%s", i ? ", " : ""); | |
612 | tracer_print_field(&desc->fields[i], &sav[i]); | |
613 | } | |
68f8cfbe MD |
614 | if (nr_items) |
615 | *nr_items = i; | |
616 | } | |
617 | ||
618 | void tracer_call(const struct side_event_description *desc, const struct side_arg_vec_description *sav_desc) | |
619 | { | |
8a25ce77 MD |
620 | if (side_unlikely(desc->flags & SIDE_EVENT_FLAG_VARIADIC)) { |
621 | printf("ERROR: unexpected variadic event description\n"); | |
622 | abort(); | |
623 | } | |
68f8cfbe | 624 | tracer_print_static_fields(desc, sav_desc, NULL); |
f611d0c3 MD |
625 | printf("\n"); |
626 | } | |
19fa6aa2 MD |
627 | |
628 | void tracer_call_variadic(const struct side_event_description *desc, | |
629 | const struct side_arg_vec_description *sav_desc, | |
630 | const struct side_arg_dynamic_event_struct *var_struct) | |
631 | { | |
68f8cfbe MD |
632 | uint32_t var_struct_len = var_struct->len; |
633 | int nr_fields = 0, i; | |
19fa6aa2 | 634 | |
68f8cfbe MD |
635 | tracer_print_static_fields(desc, sav_desc, &nr_fields); |
636 | ||
8a25ce77 MD |
637 | if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) { |
638 | printf("ERROR: unexpected non-variadic event description\n"); | |
639 | abort(); | |
640 | } | |
68f8cfbe MD |
641 | for (i = 0; i < var_struct_len; i++, nr_fields++) { |
642 | printf("%s", nr_fields ? ", " : ""); | |
643 | printf("%s:: ", var_struct->fields[i].field_name); | |
644 | tracer_print_dynamic(&var_struct->fields[i].elem); | |
19fa6aa2 MD |
645 | } |
646 | printf("\n"); | |
647 | } |