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> |
1d9c515c | 11 | #include <string.h> |
f611d0c3 MD |
12 | |
13 | #include <side/trace.h> | |
14 | ||
1d9c515c MD |
15 | enum tracer_display_base { |
16 | TRACER_DISPLAY_BASE_2, | |
17 | TRACER_DISPLAY_BASE_8, | |
18 | TRACER_DISPLAY_BASE_10, | |
19 | TRACER_DISPLAY_BASE_16, | |
20 | }; | |
21 | ||
1e8aec23 MD |
22 | static struct side_tracer_handle *tracer_handle; |
23 | ||
f611d0c3 | 24 | static |
66de373e | 25 | void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *sav_desc); |
f611d0c3 | 26 | static |
66de373e | 27 | void tracer_print_struct_sg(const struct side_type *type_desc, void *ptr); |
7a1cb105 | 28 | static |
66de373e | 29 | void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *sav_desc); |
f611d0c3 | 30 | static |
66de373e | 31 | void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_vec *sav_desc); |
f611d0c3 | 32 | static |
66de373e | 33 | void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx); |
ba845af5 | 34 | static |
66de373e | 35 | void tracer_print_array_fixint(const struct side_type *type_desc, const struct side_arg *item); |
1533629f | 36 | static |
66de373e | 37 | void tracer_print_vla_fixint(const struct side_type *type_desc, const struct side_arg *item); |
a2e2357e | 38 | static |
66de373e | 39 | void tracer_print_dynamic(const struct side_arg *dynamic_item); |
d8be25de | 40 | static |
66de373e | 41 | void tracer_print_type(const struct side_type *type_desc, const struct side_arg *item); |
f611d0c3 | 42 | |
1d9c515c MD |
43 | static |
44 | int64_t get_attr_integer_value(const struct side_attr *attr) | |
45 | { | |
46 | int64_t val; | |
47 | ||
48 | switch (attr->value.type) { | |
49 | case SIDE_ATTR_TYPE_U8: | |
43d85239 | 50 | val = attr->value.u.integer_value.side_u8; |
1d9c515c MD |
51 | break; |
52 | case SIDE_ATTR_TYPE_U16: | |
43d85239 | 53 | val = attr->value.u.integer_value.side_u16; |
1d9c515c MD |
54 | break; |
55 | case SIDE_ATTR_TYPE_U32: | |
43d85239 | 56 | val = attr->value.u.integer_value.side_u32; |
1d9c515c MD |
57 | break; |
58 | case SIDE_ATTR_TYPE_U64: | |
43d85239 | 59 | val = attr->value.u.integer_value.side_u64; |
1d9c515c MD |
60 | break; |
61 | case SIDE_ATTR_TYPE_S8: | |
43d85239 | 62 | val = attr->value.u.integer_value.side_s8; |
1d9c515c MD |
63 | break; |
64 | case SIDE_ATTR_TYPE_S16: | |
43d85239 | 65 | val = attr->value.u.integer_value.side_s16; |
1d9c515c MD |
66 | break; |
67 | case SIDE_ATTR_TYPE_S32: | |
43d85239 | 68 | val = attr->value.u.integer_value.side_s32; |
1d9c515c MD |
69 | break; |
70 | case SIDE_ATTR_TYPE_S64: | |
43d85239 | 71 | val = attr->value.u.integer_value.side_s64; |
1d9c515c MD |
72 | break; |
73 | default: | |
74 | fprintf(stderr, "Unexpected attribute type\n"); | |
75 | abort(); | |
76 | } | |
77 | return val; | |
78 | } | |
79 | ||
80 | static | |
f0dafd60 MD |
81 | enum tracer_display_base get_attr_display_base(const struct side_attr *_attr, uint32_t nr_attr, |
82 | enum tracer_display_base default_base) | |
1d9c515c MD |
83 | { |
84 | uint32_t i; | |
85 | ||
86 | for (i = 0; i < nr_attr; i++) { | |
87 | const struct side_attr *attr = &_attr[i]; | |
88 | ||
89 | if (!strcmp(attr->key, "std.integer.base")) { | |
90 | int64_t val = get_attr_integer_value(attr); | |
91 | ||
92 | switch (val) { | |
93 | case 2: | |
94 | return TRACER_DISPLAY_BASE_2; | |
95 | case 8: | |
96 | return TRACER_DISPLAY_BASE_8; | |
97 | case 10: | |
98 | return TRACER_DISPLAY_BASE_10; | |
99 | case 16: | |
100 | return TRACER_DISPLAY_BASE_16; | |
101 | default: | |
102 | fprintf(stderr, "Unexpected integer display base: %" PRId64 "\n", val); | |
103 | abort(); | |
104 | } | |
105 | } | |
106 | } | |
f0dafd60 | 107 | return default_base; /* Default */ |
1d9c515c MD |
108 | } |
109 | ||
8bdd5c12 | 110 | static |
66de373e | 111 | bool type_to_host_reverse_bo(const struct side_type *type_desc) |
8bdd5c12 MD |
112 | { |
113 | switch (type_desc->type) { | |
114 | case SIDE_TYPE_U8: | |
115 | case SIDE_TYPE_S8: | |
116 | case SIDE_TYPE_BYTE: | |
117 | return false; | |
118 | case SIDE_TYPE_U16: | |
119 | case SIDE_TYPE_U32: | |
120 | case SIDE_TYPE_U64: | |
121 | case SIDE_TYPE_S16: | |
122 | case SIDE_TYPE_S32: | |
123 | case SIDE_TYPE_S64: | |
dd6e76cb MD |
124 | case SIDE_TYPE_POINTER32: |
125 | case SIDE_TYPE_POINTER64: | |
ac81c466 | 126 | if (type_desc->u.side_integer.byte_order != SIDE_TYPE_BYTE_ORDER_HOST) |
8bdd5c12 MD |
127 | return true; |
128 | else | |
129 | return false; | |
130 | break; | |
131 | case SIDE_TYPE_FLOAT_BINARY16: | |
132 | case SIDE_TYPE_FLOAT_BINARY32: | |
133 | case SIDE_TYPE_FLOAT_BINARY64: | |
134 | case SIDE_TYPE_FLOAT_BINARY128: | |
aac52685 | 135 | if (type_desc->u.side_float.byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST) |
8bdd5c12 MD |
136 | return true; |
137 | else | |
138 | return false; | |
139 | break; | |
140 | default: | |
141 | fprintf(stderr, "Unexpected type\n"); | |
142 | abort(); | |
143 | } | |
144 | } | |
145 | ||
bc3c89b3 | 146 | static |
905c328e | 147 | void tracer_print_attr_type(const char *separator, const struct side_attr *attr) |
bc3c89b3 | 148 | { |
905c328e | 149 | printf("{ key%s \"%s\", value%s ", separator, attr->key, separator); |
bc3c89b3 MD |
150 | switch (attr->value.type) { |
151 | case SIDE_ATTR_TYPE_BOOL: | |
5f82db91 | 152 | printf("%s", attr->value.u.bool_value ? "true" : "false"); |
bc3c89b3 MD |
153 | break; |
154 | case SIDE_ATTR_TYPE_U8: | |
43d85239 | 155 | printf("%" PRIu8, attr->value.u.integer_value.side_u8); |
bc3c89b3 MD |
156 | break; |
157 | case SIDE_ATTR_TYPE_U16: | |
43d85239 | 158 | printf("%" PRIu16, attr->value.u.integer_value.side_u16); |
bc3c89b3 MD |
159 | break; |
160 | case SIDE_ATTR_TYPE_U32: | |
43d85239 | 161 | printf("%" PRIu32, attr->value.u.integer_value.side_u32); |
bc3c89b3 MD |
162 | break; |
163 | case SIDE_ATTR_TYPE_U64: | |
43d85239 | 164 | printf("%" PRIu64, attr->value.u.integer_value.side_u64); |
bc3c89b3 MD |
165 | break; |
166 | case SIDE_ATTR_TYPE_S8: | |
43d85239 | 167 | printf("%" PRId8, attr->value.u.integer_value.side_s8); |
bc3c89b3 MD |
168 | break; |
169 | case SIDE_ATTR_TYPE_S16: | |
43d85239 | 170 | printf("%" PRId16, attr->value.u.integer_value.side_s16); |
bc3c89b3 MD |
171 | break; |
172 | case SIDE_ATTR_TYPE_S32: | |
43d85239 | 173 | printf("%" PRId32, attr->value.u.integer_value.side_s32); |
bc3c89b3 MD |
174 | break; |
175 | case SIDE_ATTR_TYPE_S64: | |
43d85239 | 176 | printf("%" PRId64, attr->value.u.integer_value.side_s64); |
bc3c89b3 | 177 | break; |
dd6e76cb | 178 | case SIDE_ATTR_TYPE_POINTER32: |
43d85239 | 179 | printf("0x%" PRIx32, attr->value.u.integer_value.side_u32); |
dd6e76cb MD |
180 | break; |
181 | case SIDE_ATTR_TYPE_POINTER64: | |
43d85239 | 182 | printf("0x%" PRIx64, attr->value.u.integer_value.side_u64); |
f5e650d7 | 183 | break; |
bc3c89b3 MD |
184 | case SIDE_ATTR_TYPE_FLOAT_BINARY16: |
185 | #if __HAVE_FLOAT16 | |
a4969f31 | 186 | printf("%g", (double) attr->value.u.float_value.side_float_binary16); |
bc3c89b3 MD |
187 | break; |
188 | #else | |
de1b3cd2 | 189 | fprintf(stderr, "ERROR: Unsupported binary16 float type\n"); |
bc3c89b3 MD |
190 | abort(); |
191 | #endif | |
192 | case SIDE_ATTR_TYPE_FLOAT_BINARY32: | |
193 | #if __HAVE_FLOAT32 | |
a4969f31 | 194 | printf("%g", (double) attr->value.u.float_value.side_float_binary32); |
bc3c89b3 MD |
195 | break; |
196 | #else | |
de1b3cd2 | 197 | fprintf(stderr, "ERROR: Unsupported binary32 float type\n"); |
bc3c89b3 MD |
198 | abort(); |
199 | #endif | |
200 | case SIDE_ATTR_TYPE_FLOAT_BINARY64: | |
201 | #if __HAVE_FLOAT64 | |
a4969f31 | 202 | printf("%g", (double) attr->value.u.float_value.side_float_binary64); |
bc3c89b3 MD |
203 | break; |
204 | #else | |
de1b3cd2 | 205 | fprintf(stderr, "ERROR: Unsupported binary64 float type\n"); |
bc3c89b3 MD |
206 | abort(); |
207 | #endif | |
208 | case SIDE_ATTR_TYPE_FLOAT_BINARY128: | |
209 | #if __HAVE_FLOAT128 | |
a4969f31 | 210 | printf("%Lg", (long double) attr->value.u.float_value.side_float_binary128); |
bc3c89b3 MD |
211 | break; |
212 | #else | |
de1b3cd2 | 213 | fprintf(stderr, "ERROR: Unsupported binary128 float type\n"); |
bc3c89b3 MD |
214 | abort(); |
215 | #endif | |
216 | case SIDE_ATTR_TYPE_STRING: | |
5f82db91 | 217 | printf("\"%s\"", (const char *)(uintptr_t) attr->value.u.string_value); |
bc3c89b3 MD |
218 | break; |
219 | default: | |
de1b3cd2 | 220 | fprintf(stderr, "ERROR: <UNKNOWN ATTRIBUTE TYPE>"); |
bc3c89b3 MD |
221 | abort(); |
222 | } | |
223 | printf(" }"); | |
224 | } | |
225 | ||
7d21cf51 | 226 | static |
905c328e MD |
227 | void print_attributes(const char *prefix_str, const char *separator, |
228 | const struct side_attr *attr, uint32_t nr_attr) | |
7d21cf51 MD |
229 | { |
230 | int i; | |
231 | ||
232 | if (!nr_attr) | |
233 | return; | |
905c328e | 234 | printf("%s%s [ ", prefix_str, separator); |
7d21cf51 MD |
235 | for (i = 0; i < nr_attr; i++) { |
236 | printf("%s", i ? ", " : ""); | |
905c328e | 237 | tracer_print_attr_type(separator, &attr[i]); |
7d21cf51 MD |
238 | } |
239 | printf(" ]"); | |
240 | } | |
241 | ||
79f677ba | 242 | static |
66de373e | 243 | void print_enum(const struct side_type *type_desc, const struct side_arg *item) |
79f677ba | 244 | { |
d8be25de | 245 | const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings; |
66de373e | 246 | const struct side_type *elem_type = type_desc->u.side_enum.elem_type; |
79f677ba | 247 | int i, print_count = 0; |
d8be25de | 248 | int64_t value; |
79f677ba | 249 | |
8bdd5c12 | 250 | if (elem_type->type != item->type) { |
de1b3cd2 | 251 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
d8be25de MD |
252 | abort(); |
253 | } | |
254 | switch (item->type) { | |
255 | case SIDE_TYPE_U8: | |
66de373e | 256 | value = (int64_t) item->u.side_static.integer_value.side_u8; |
d8be25de MD |
257 | break; |
258 | case SIDE_TYPE_U16: | |
8bdd5c12 MD |
259 | { |
260 | uint16_t v; | |
261 | ||
66de373e | 262 | v = item->u.side_static.integer_value.side_u16; |
8bdd5c12 MD |
263 | if (type_to_host_reverse_bo(elem_type)) |
264 | v = side_bswap_16(v); | |
265 | value = (int64_t) v; | |
d8be25de | 266 | break; |
8bdd5c12 | 267 | } |
d8be25de | 268 | case SIDE_TYPE_U32: |
8bdd5c12 MD |
269 | { |
270 | uint32_t v; | |
271 | ||
66de373e | 272 | v = item->u.side_static.integer_value.side_u32; |
8bdd5c12 MD |
273 | if (type_to_host_reverse_bo(elem_type)) |
274 | v = side_bswap_32(v); | |
275 | value = (int64_t) v; | |
d8be25de | 276 | break; |
8bdd5c12 | 277 | } |
d8be25de | 278 | case SIDE_TYPE_U64: |
8bdd5c12 MD |
279 | { |
280 | uint64_t v; | |
281 | ||
66de373e | 282 | v = item->u.side_static.integer_value.side_u64; |
8bdd5c12 MD |
283 | if (type_to_host_reverse_bo(elem_type)) |
284 | v = side_bswap_64(v); | |
285 | value = (int64_t) v; | |
d8be25de | 286 | break; |
8bdd5c12 | 287 | } |
d8be25de | 288 | case SIDE_TYPE_S8: |
66de373e | 289 | value = (int64_t) item->u.side_static.integer_value.side_s8; |
d8be25de MD |
290 | break; |
291 | case SIDE_TYPE_S16: | |
8bdd5c12 MD |
292 | { |
293 | int16_t v; | |
294 | ||
66de373e | 295 | v = item->u.side_static.integer_value.side_s16; |
8bdd5c12 MD |
296 | if (type_to_host_reverse_bo(elem_type)) |
297 | v = side_bswap_16(v); | |
298 | value = (int64_t) v; | |
d8be25de | 299 | break; |
8bdd5c12 | 300 | } |
d8be25de | 301 | case SIDE_TYPE_S32: |
8bdd5c12 MD |
302 | { |
303 | int32_t v; | |
304 | ||
66de373e | 305 | v = item->u.side_static.integer_value.side_s32; |
8bdd5c12 MD |
306 | if (type_to_host_reverse_bo(elem_type)) |
307 | v = side_bswap_32(v); | |
308 | value = (int64_t) v; | |
d8be25de | 309 | break; |
8bdd5c12 | 310 | } |
d8be25de | 311 | case SIDE_TYPE_S64: |
8bdd5c12 MD |
312 | { |
313 | int64_t v; | |
314 | ||
66de373e | 315 | v = item->u.side_static.integer_value.side_s64; |
8bdd5c12 MD |
316 | if (type_to_host_reverse_bo(elem_type)) |
317 | v = side_bswap_64(v); | |
318 | value = v; | |
d8be25de | 319 | break; |
8bdd5c12 | 320 | } |
d8be25de | 321 | default: |
de1b3cd2 | 322 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
d8be25de MD |
323 | abort(); |
324 | } | |
905c328e | 325 | print_attributes("attr", ":", mappings->attr, mappings->nr_attr); |
d8be25de MD |
326 | printf("%s", mappings->nr_attr ? ", " : ""); |
327 | tracer_print_type(type_desc->u.side_enum.elem_type, item); | |
328 | printf(", labels: [ "); | |
329 | for (i = 0; i < mappings->nr_mappings; i++) { | |
330 | const struct side_enum_mapping *mapping = &mappings->mappings[i]; | |
79f677ba | 331 | |
ea32e5fc | 332 | if (mapping->range_end < mapping->range_begin) { |
de1b3cd2 | 333 | fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n", |
ea32e5fc MD |
334 | mapping->range_begin, mapping->range_end); |
335 | abort(); | |
336 | } | |
79f677ba MD |
337 | if (value >= mapping->range_begin && value <= mapping->range_end) { |
338 | printf("%s", print_count++ ? ", " : ""); | |
339 | printf("\"%s\"", mapping->label); | |
340 | } | |
341 | } | |
342 | if (!print_count) | |
343 | printf("<NO LABEL>"); | |
344 | printf(" ]"); | |
345 | } | |
346 | ||
ea32e5fc | 347 | static |
66de373e | 348 | uint32_t enum_elem_type_to_stride(const struct side_type *elem_type) |
ea32e5fc | 349 | { |
af6aa6e1 MD |
350 | uint32_t stride_bit; |
351 | ||
bab5d6e4 | 352 | switch (elem_type->type) { |
4cc2880b MD |
353 | case SIDE_TYPE_U8: /* Fall-through */ |
354 | case SIDE_TYPE_BYTE: | |
af6aa6e1 MD |
355 | stride_bit = 8; |
356 | break; | |
af6aa6e1 | 357 | case SIDE_TYPE_U16: |
af6aa6e1 MD |
358 | stride_bit = 16; |
359 | break; | |
af6aa6e1 | 360 | case SIDE_TYPE_U32: |
af6aa6e1 MD |
361 | stride_bit = 32; |
362 | break; | |
af6aa6e1 | 363 | case SIDE_TYPE_U64: |
af6aa6e1 MD |
364 | stride_bit = 64; |
365 | break; | |
af6aa6e1 | 366 | default: |
de1b3cd2 | 367 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
af6aa6e1 MD |
368 | abort(); |
369 | } | |
370 | return stride_bit; | |
371 | } | |
372 | ||
373 | static | |
66de373e MD |
374 | void print_enum_bitmap(const struct side_type *type_desc, |
375 | const struct side_arg *item) | |
af6aa6e1 | 376 | { |
66de373e | 377 | const struct side_type *elem_type = type_desc->u.side_enum_bitmap.elem_type; |
bab5d6e4 | 378 | const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings; |
ea32e5fc | 379 | int i, print_count = 0; |
af6aa6e1 | 380 | uint32_t stride_bit, nr_items; |
8bdd5c12 | 381 | bool reverse_byte_order = false; |
66de373e | 382 | const struct side_arg *array_item; |
af6aa6e1 | 383 | |
bab5d6e4 MD |
384 | switch (elem_type->type) { |
385 | case SIDE_TYPE_U8: /* Fall-through */ | |
4cc2880b | 386 | case SIDE_TYPE_BYTE: /* Fall-through */ |
bab5d6e4 MD |
387 | case SIDE_TYPE_U16: /* Fall-through */ |
388 | case SIDE_TYPE_U32: /* Fall-through */ | |
4cc2880b | 389 | case SIDE_TYPE_U64: |
45392033 | 390 | stride_bit = enum_elem_type_to_stride(elem_type); |
8bdd5c12 | 391 | reverse_byte_order = type_to_host_reverse_bo(elem_type); |
af6aa6e1 MD |
392 | array_item = item; |
393 | nr_items = 1; | |
af6aa6e1 | 394 | break; |
bab5d6e4 | 395 | case SIDE_TYPE_ARRAY: |
45392033 | 396 | stride_bit = enum_elem_type_to_stride(elem_type->u.side_array.elem_type); |
8bdd5c12 | 397 | reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_array.elem_type); |
66de373e | 398 | array_item = item->u.side_static.side_array->sav; |
bab5d6e4 | 399 | nr_items = type_desc->u.side_array.length; |
af6aa6e1 | 400 | break; |
bab5d6e4 | 401 | case SIDE_TYPE_VLA: |
45392033 | 402 | stride_bit = enum_elem_type_to_stride(elem_type->u.side_vla.elem_type); |
8bdd5c12 | 403 | reverse_byte_order = type_to_host_reverse_bo(elem_type->u.side_vla.elem_type); |
66de373e MD |
404 | array_item = item->u.side_static.side_vla->sav; |
405 | nr_items = item->u.side_static.side_vla->len; | |
af6aa6e1 MD |
406 | break; |
407 | default: | |
de1b3cd2 | 408 | fprintf(stderr, "ERROR: Unexpected enum element type\n"); |
af6aa6e1 MD |
409 | abort(); |
410 | } | |
ea32e5fc | 411 | |
905c328e | 412 | print_attributes("attr", ":", side_enum_mappings->attr, side_enum_mappings->nr_attr); |
d4328528 | 413 | printf("%s", side_enum_mappings->nr_attr ? ", " : ""); |
af6aa6e1 | 414 | printf("labels: [ "); |
ea32e5fc | 415 | for (i = 0; i < side_enum_mappings->nr_mappings; i++) { |
66cff328 | 416 | const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i]; |
ea32e5fc | 417 | bool match = false; |
9ff49ee4 | 418 | uint64_t bit; |
ea32e5fc | 419 | |
9ff49ee4 | 420 | if (mapping->range_end < mapping->range_begin) { |
de1b3cd2 | 421 | fprintf(stderr, "ERROR: Unexpected enum bitmap range: %" PRIu64 "-%" PRIu64 "\n", |
ea32e5fc MD |
422 | mapping->range_begin, mapping->range_end); |
423 | abort(); | |
424 | } | |
425 | for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) { | |
af6aa6e1 MD |
426 | if (bit > (nr_items * stride_bit) - 1) |
427 | break; | |
428 | switch (stride_bit) { | |
429 | case 8: | |
430 | { | |
66de373e | 431 | uint8_t v = array_item[bit / 8].u.side_static.integer_value.side_u8; |
af6aa6e1 MD |
432 | if (v & (1ULL << (bit % 8))) { |
433 | match = true; | |
434 | goto match; | |
435 | } | |
436 | break; | |
437 | } | |
438 | case 16: | |
439 | { | |
66de373e | 440 | uint16_t v = array_item[bit / 16].u.side_static.integer_value.side_u16; |
8bdd5c12 MD |
441 | if (reverse_byte_order) |
442 | v = side_bswap_16(v); | |
af6aa6e1 MD |
443 | if (v & (1ULL << (bit % 16))) { |
444 | match = true; | |
445 | goto match; | |
446 | } | |
447 | break; | |
448 | } | |
449 | case 32: | |
450 | { | |
66de373e | 451 | uint32_t v = array_item[bit / 32].u.side_static.integer_value.side_u32; |
8bdd5c12 MD |
452 | if (reverse_byte_order) |
453 | v = side_bswap_32(v); | |
af6aa6e1 MD |
454 | if (v & (1ULL << (bit % 32))) { |
455 | match = true; | |
456 | goto match; | |
457 | } | |
ea32e5fc MD |
458 | break; |
459 | } | |
af6aa6e1 MD |
460 | case 64: |
461 | { | |
66de373e | 462 | uint64_t v = array_item[bit / 64].u.side_static.integer_value.side_u64; |
8bdd5c12 MD |
463 | if (reverse_byte_order) |
464 | v = side_bswap_64(v); | |
af6aa6e1 MD |
465 | if (v & (1ULL << (bit % 64))) { |
466 | match = true; | |
467 | goto match; | |
468 | } | |
469 | break; | |
470 | } | |
471 | default: | |
472 | abort(); | |
473 | } | |
ea32e5fc | 474 | } |
af6aa6e1 | 475 | match: |
ea32e5fc MD |
476 | if (match) { |
477 | printf("%s", print_count++ ? ", " : ""); | |
478 | printf("\"%s\"", mapping->label); | |
479 | } | |
480 | } | |
481 | if (!print_count) | |
482 | printf("<NO LABEL>"); | |
483 | printf(" ]"); | |
484 | } | |
485 | ||
1d9c515c MD |
486 | static |
487 | void print_integer_binary(uint64_t v, int bits) | |
488 | { | |
489 | int i; | |
490 | ||
491 | printf("0b"); | |
492 | v <<= 64 - bits; | |
493 | for (i = 0; i < bits; i++) { | |
494 | printf("%c", v & (1ULL << 63) ? '1' : '0'); | |
495 | v <<= 1; | |
496 | } | |
497 | } | |
498 | ||
0e9be766 | 499 | static |
aac52685 MD |
500 | void tracer_print_type_header(const char *separator, |
501 | const struct side_attr *attr, uint32_t nr_attr) | |
ac81c466 | 502 | { |
aac52685 MD |
503 | print_attributes("attr", separator, attr, nr_attr); |
504 | printf("%s", nr_attr ? ", " : ""); | |
505 | printf("value%s ", separator); | |
ac81c466 MD |
506 | } |
507 | ||
56c21987 | 508 | static |
e3080b2a MD |
509 | void tracer_print_type_integer(const char *separator, |
510 | const struct side_type_integer *type_integer, | |
87405d12 | 511 | const union side_integer_value *value, |
f0dafd60 MD |
512 | uint16_t offset_bits, |
513 | enum tracer_display_base default_base) | |
56c21987 MD |
514 | { |
515 | enum tracer_display_base base; | |
cb589216 | 516 | bool reverse_bo; |
56c21987 MD |
517 | union { |
518 | uint64_t v_unsigned; | |
519 | int64_t v_signed; | |
520 | } v; | |
521 | ||
e3080b2a | 522 | if (!type_integer->len_bits || |
87405d12 | 523 | type_integer->len_bits + offset_bits > type_integer->integer_size_bits) |
56c21987 | 524 | abort(); |
cb589216 | 525 | reverse_bo = type_integer->byte_order != SIDE_TYPE_BYTE_ORDER_HOST; |
e3080b2a | 526 | base = get_attr_display_base(type_integer->attr, |
f0dafd60 MD |
527 | type_integer->nr_attr, |
528 | default_base); | |
e3080b2a MD |
529 | switch (type_integer->integer_size_bits) { |
530 | case 8: | |
531 | if (type_integer->signedness) | |
532 | v.v_signed = value->side_s8; | |
533 | else | |
534 | v.v_unsigned = value->side_u8; | |
56c21987 | 535 | break; |
e3080b2a MD |
536 | case 16: |
537 | if (type_integer->signedness) { | |
538 | int16_t side_s16; | |
56c21987 | 539 | |
e3080b2a | 540 | side_s16 = value->side_s16; |
cb589216 | 541 | if (reverse_bo) |
e3080b2a MD |
542 | side_s16 = side_bswap_16(side_s16); |
543 | v.v_signed = side_s16; | |
544 | } else { | |
545 | uint16_t side_u16; | |
56c21987 | 546 | |
e3080b2a | 547 | side_u16 = value->side_u16; |
cb589216 | 548 | if (reverse_bo) |
e3080b2a MD |
549 | side_u16 = side_bswap_16(side_u16); |
550 | v.v_unsigned = side_u16; | |
551 | } | |
56c21987 | 552 | break; |
e3080b2a MD |
553 | case 32: |
554 | if (type_integer->signedness) { | |
555 | int32_t side_s32; | |
56c21987 | 556 | |
e3080b2a | 557 | side_s32 = value->side_s32; |
cb589216 | 558 | if (reverse_bo) |
e3080b2a MD |
559 | side_s32 = side_bswap_32(side_s32); |
560 | v.v_signed = side_s32; | |
561 | } else { | |
562 | uint32_t side_u32; | |
56c21987 | 563 | |
e3080b2a | 564 | side_u32 = value->side_u32; |
cb589216 | 565 | if (reverse_bo) |
e3080b2a MD |
566 | side_u32 = side_bswap_32(side_u32); |
567 | v.v_unsigned = side_u32; | |
568 | } | |
56c21987 | 569 | break; |
e3080b2a MD |
570 | case 64: |
571 | if (type_integer->signedness) { | |
572 | int64_t side_s64; | |
56c21987 | 573 | |
e3080b2a | 574 | side_s64 = value->side_s64; |
cb589216 | 575 | if (reverse_bo) |
e3080b2a MD |
576 | side_s64 = side_bswap_64(side_s64); |
577 | v.v_signed = side_s64; | |
578 | } else { | |
579 | uint64_t side_u64; | |
56c21987 | 580 | |
e3080b2a | 581 | side_u64 = value->side_u64; |
cb589216 | 582 | if (reverse_bo) |
e3080b2a MD |
583 | side_u64 = side_bswap_64(side_u64); |
584 | v.v_unsigned = side_u64; | |
585 | } | |
56c21987 | 586 | break; |
56c21987 MD |
587 | default: |
588 | abort(); | |
589 | } | |
87405d12 | 590 | v.v_unsigned >>= offset_bits; |
e3080b2a MD |
591 | if (type_integer->len_bits < 64) |
592 | v.v_unsigned &= (1ULL << type_integer->len_bits) - 1; | |
593 | tracer_print_type_header(separator, type_integer->attr, type_integer->nr_attr); | |
56c21987 MD |
594 | switch (base) { |
595 | case TRACER_DISPLAY_BASE_2: | |
e3080b2a | 596 | print_integer_binary(v.v_unsigned, type_integer->len_bits); |
56c21987 MD |
597 | break; |
598 | case TRACER_DISPLAY_BASE_8: | |
599 | printf("0%" PRIo64, v.v_unsigned); | |
600 | break; | |
601 | case TRACER_DISPLAY_BASE_10: | |
e3080b2a | 602 | if (type_integer->signedness) { |
56c21987 | 603 | /* Sign-extend. */ |
e3080b2a MD |
604 | if (type_integer->len_bits < 64) { |
605 | if (v.v_unsigned & (1ULL << (type_integer->len_bits - 1))) | |
606 | v.v_unsigned |= ~((1ULL << type_integer->len_bits) - 1); | |
56c21987 MD |
607 | } |
608 | printf("%" PRId64, v.v_signed); | |
609 | } else { | |
610 | printf("%" PRIu64, v.v_unsigned); | |
611 | } | |
612 | break; | |
613 | case TRACER_DISPLAY_BASE_16: | |
614 | printf("0x%" PRIx64, v.v_unsigned); | |
615 | break; | |
616 | default: | |
617 | abort(); | |
618 | } | |
619 | } | |
620 | ||
3aa7ca5e MD |
621 | static |
622 | void tracer_print_type_float(const char *separator, | |
623 | const struct side_type_float *type_float, | |
624 | const union side_float_value *value) | |
625 | { | |
626 | bool reverse_bo; | |
627 | ||
628 | reverse_bo = type_float->byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST; | |
629 | tracer_print_type_header(separator, type_float->attr, type_float->nr_attr); | |
630 | switch (type_float->float_size_bits) { | |
631 | case 16: | |
632 | { | |
633 | #if __HAVE_FLOAT16 | |
634 | union { | |
635 | _Float16 f; | |
636 | uint16_t u; | |
637 | } float16 = { | |
638 | .f = value->side_float_binary16, | |
639 | }; | |
640 | ||
641 | if (reverse_bo) | |
642 | float16.u = side_bswap_16(float16.u); | |
643 | tracer_print_type_header(":", type_desc->u.side_float.attr, type_desc->u.side_float.nr_attr); | |
644 | printf("%g", (double) float16.f); | |
645 | break; | |
646 | #else | |
647 | fprintf(stderr, "ERROR: Unsupported binary16 float type\n"); | |
648 | abort(); | |
649 | #endif | |
650 | } | |
651 | case 32: | |
652 | { | |
653 | #if __HAVE_FLOAT32 | |
654 | union { | |
655 | _Float32 f; | |
656 | uint32_t u; | |
657 | } float32 = { | |
658 | .f = value->side_float_binary32, | |
659 | }; | |
660 | ||
661 | if (reverse_bo) | |
662 | float32.u = side_bswap_32(float32.u); | |
663 | printf("%g", (double) float32.f); | |
664 | break; | |
665 | #else | |
666 | fprintf(stderr, "ERROR: Unsupported binary32 float type\n"); | |
667 | abort(); | |
668 | #endif | |
669 | } | |
670 | case 64: | |
671 | { | |
672 | #if __HAVE_FLOAT64 | |
673 | union { | |
674 | _Float64 f; | |
675 | uint64_t u; | |
676 | } float64 = { | |
677 | .f = value->side_float_binary64, | |
678 | }; | |
679 | ||
680 | if (reverse_bo) | |
681 | float64.u = side_bswap_64(float64.u); | |
682 | printf("%g", (double) float64.f); | |
683 | break; | |
684 | #else | |
685 | fprintf(stderr, "ERROR: Unsupported binary64 float type\n"); | |
686 | abort(); | |
687 | #endif | |
688 | } | |
689 | case 128: | |
690 | { | |
691 | #if __HAVE_FLOAT128 | |
692 | union { | |
693 | _Float128 f; | |
694 | char arr[16]; | |
695 | } float128 = { | |
696 | .f = value->side_float_binary128, | |
697 | }; | |
698 | ||
699 | if (reverse_bo) | |
700 | side_bswap_128p(float128.arr); | |
701 | printf("%Lg", (long double) float128.f); | |
702 | break; | |
703 | #else | |
704 | fprintf(stderr, "ERROR: Unsupported binary128 float type\n"); | |
705 | abort(); | |
706 | #endif | |
707 | } | |
708 | default: | |
709 | fprintf(stderr, "ERROR: Unknown float size\n"); | |
710 | abort(); | |
711 | } | |
712 | } | |
713 | ||
f611d0c3 | 714 | static |
66de373e | 715 | void tracer_print_type(const struct side_type *type_desc, const struct side_arg *item) |
f611d0c3 | 716 | { |
66de373e | 717 | enum side_type_label type; |
d8be25de | 718 | |
45392033 MD |
719 | switch (type_desc->type) { |
720 | case SIDE_TYPE_ARRAY: | |
721 | switch (item->type) { | |
722 | case SIDE_TYPE_ARRAY_U8: | |
723 | case SIDE_TYPE_ARRAY_U16: | |
724 | case SIDE_TYPE_ARRAY_U32: | |
725 | case SIDE_TYPE_ARRAY_U64: | |
726 | case SIDE_TYPE_ARRAY_S8: | |
727 | case SIDE_TYPE_ARRAY_S16: | |
728 | case SIDE_TYPE_ARRAY_S32: | |
729 | case SIDE_TYPE_ARRAY_S64: | |
dd6e76cb MD |
730 | case SIDE_TYPE_ARRAY_POINTER32: |
731 | case SIDE_TYPE_ARRAY_POINTER64: | |
f7653b43 | 732 | case SIDE_TYPE_ARRAY_BYTE: |
45392033 MD |
733 | case SIDE_TYPE_ARRAY: |
734 | break; | |
735 | default: | |
de1b3cd2 | 736 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
ba845af5 | 737 | abort(); |
45392033 | 738 | break; |
ba845af5 MD |
739 | } |
740 | break; | |
45392033 MD |
741 | |
742 | case SIDE_TYPE_VLA: | |
743 | switch (item->type) { | |
744 | case SIDE_TYPE_VLA_U8: | |
745 | case SIDE_TYPE_VLA_U16: | |
746 | case SIDE_TYPE_VLA_U32: | |
747 | case SIDE_TYPE_VLA_U64: | |
748 | case SIDE_TYPE_VLA_S8: | |
749 | case SIDE_TYPE_VLA_S16: | |
750 | case SIDE_TYPE_VLA_S32: | |
751 | case SIDE_TYPE_VLA_S64: | |
f7653b43 | 752 | case SIDE_TYPE_VLA_BYTE: |
dd6e76cb MD |
753 | case SIDE_TYPE_VLA_POINTER32: |
754 | case SIDE_TYPE_VLA_POINTER64: | |
45392033 MD |
755 | case SIDE_TYPE_VLA: |
756 | break; | |
757 | default: | |
de1b3cd2 | 758 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
1533629f | 759 | abort(); |
45392033 | 760 | break; |
1533629f MD |
761 | } |
762 | break; | |
763 | ||
45392033 MD |
764 | case SIDE_TYPE_ENUM: |
765 | switch (item->type) { | |
766 | case SIDE_TYPE_U8: | |
767 | case SIDE_TYPE_U16: | |
768 | case SIDE_TYPE_U32: | |
769 | case SIDE_TYPE_U64: | |
770 | case SIDE_TYPE_S8: | |
771 | case SIDE_TYPE_S16: | |
772 | case SIDE_TYPE_S32: | |
773 | case SIDE_TYPE_S64: | |
bab5d6e4 MD |
774 | break; |
775 | default: | |
de1b3cd2 | 776 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
45392033 MD |
777 | abort(); |
778 | break; | |
779 | } | |
780 | break; | |
781 | ||
782 | case SIDE_TYPE_ENUM_BITMAP: | |
783 | switch (item->type) { | |
784 | case SIDE_TYPE_U8: | |
4cc2880b | 785 | case SIDE_TYPE_BYTE: |
45392033 MD |
786 | case SIDE_TYPE_U16: |
787 | case SIDE_TYPE_U32: | |
788 | case SIDE_TYPE_U64: | |
789 | case SIDE_TYPE_ARRAY: | |
790 | case SIDE_TYPE_VLA: | |
791 | break; | |
792 | default: | |
de1b3cd2 | 793 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
45392033 MD |
794 | abort(); |
795 | break; | |
d8be25de MD |
796 | } |
797 | break; | |
798 | ||
66de373e MD |
799 | case SIDE_TYPE_DYNAMIC: |
800 | switch (item->type) { | |
801 | case SIDE_TYPE_DYNAMIC_NULL: | |
802 | case SIDE_TYPE_DYNAMIC_BOOL: | |
803 | case SIDE_TYPE_DYNAMIC_U8: | |
804 | case SIDE_TYPE_DYNAMIC_U16: | |
805 | case SIDE_TYPE_DYNAMIC_U32: | |
806 | case SIDE_TYPE_DYNAMIC_U64: | |
807 | case SIDE_TYPE_DYNAMIC_S8: | |
808 | case SIDE_TYPE_DYNAMIC_S16: | |
809 | case SIDE_TYPE_DYNAMIC_S32: | |
810 | case SIDE_TYPE_DYNAMIC_S64: | |
811 | case SIDE_TYPE_DYNAMIC_BYTE: | |
812 | case SIDE_TYPE_DYNAMIC_POINTER32: | |
813 | case SIDE_TYPE_DYNAMIC_POINTER64: | |
814 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16: | |
815 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32: | |
816 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64: | |
817 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128: | |
818 | case SIDE_TYPE_DYNAMIC_STRING: | |
819 | case SIDE_TYPE_DYNAMIC_STRUCT: | |
820 | case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR: | |
821 | case SIDE_TYPE_DYNAMIC_VLA: | |
822 | case SIDE_TYPE_DYNAMIC_VLA_VISITOR: | |
823 | break; | |
824 | default: | |
825 | fprintf(stderr, "ERROR: Unexpected dynamic type\n"); | |
826 | abort(); | |
827 | break; | |
828 | } | |
829 | break; | |
830 | ||
ba845af5 | 831 | default: |
a2e2357e | 832 | if (type_desc->type != item->type) { |
de1b3cd2 | 833 | fprintf(stderr, "ERROR: type mismatch between description and arguments\n"); |
ba845af5 MD |
834 | abort(); |
835 | } | |
836 | break; | |
f611d0c3 | 837 | } |
d8be25de | 838 | |
bab5d6e4 MD |
839 | if (type_desc->type == SIDE_TYPE_ENUM || type_desc->type == SIDE_TYPE_ENUM_BITMAP) |
840 | type = type_desc->type; | |
d8be25de MD |
841 | else |
842 | type = item->type; | |
843 | ||
a848763d | 844 | printf("{ "); |
d8be25de | 845 | switch (type) { |
9b641221 MD |
846 | case SIDE_TYPE_NULL: |
847 | tracer_print_type_header(":", type_desc->u.side_null.attr, type_desc->u.side_null.nr_attr); | |
848 | printf("<NULL TYPE>"); | |
849 | break; | |
850 | ||
4f40d951 | 851 | case SIDE_TYPE_BOOL: |
5f82db91 | 852 | tracer_print_type_header(":", type_desc->u.side_bool.attr, type_desc->u.side_bool.nr_attr); |
66de373e | 853 | printf("%s", item->u.side_static.bool_value ? "true" : "false"); |
4f40d951 | 854 | break; |
1d9c515c | 855 | |
56c21987 | 856 | case SIDE_TYPE_U8: |
f611d0c3 | 857 | case SIDE_TYPE_U16: |
f611d0c3 | 858 | case SIDE_TYPE_U32: |
f611d0c3 | 859 | case SIDE_TYPE_U64: |
f611d0c3 | 860 | case SIDE_TYPE_S8: |
f611d0c3 | 861 | case SIDE_TYPE_S16: |
f611d0c3 | 862 | case SIDE_TYPE_S32: |
f611d0c3 | 863 | case SIDE_TYPE_S64: |
66de373e | 864 | tracer_print_type_integer(":", &type_desc->u.side_integer, &item->u.side_static.integer_value, 0, |
f0dafd60 | 865 | TRACER_DISPLAY_BASE_10); |
f611d0c3 | 866 | break; |
56c21987 | 867 | |
dd6e76cb | 868 | case SIDE_TYPE_POINTER32: |
dd6e76cb | 869 | case SIDE_TYPE_POINTER64: |
66de373e | 870 | tracer_print_type_integer(":", &type_desc->u.side_integer, &item->u.side_static.integer_value, 0, |
f0dafd60 | 871 | TRACER_DISPLAY_BASE_16); |
f5e650d7 | 872 | break; |
f0dafd60 | 873 | |
f7653b43 | 874 | case SIDE_TYPE_BYTE: |
5f82db91 | 875 | tracer_print_type_header(":", type_desc->u.side_byte.attr, type_desc->u.side_byte.nr_attr); |
66de373e | 876 | printf("0x%" PRIx8, item->u.side_static.byte_value); |
7aec0d09 | 877 | break; |
79f677ba | 878 | |
d8be25de MD |
879 | case SIDE_TYPE_ENUM: |
880 | print_enum(type_desc, item); | |
79f677ba MD |
881 | break; |
882 | ||
bab5d6e4 | 883 | case SIDE_TYPE_ENUM_BITMAP: |
af6aa6e1 | 884 | print_enum_bitmap(type_desc, item); |
ea32e5fc MD |
885 | break; |
886 | ||
fb25b355 | 887 | case SIDE_TYPE_FLOAT_BINARY16: |
fb25b355 | 888 | case SIDE_TYPE_FLOAT_BINARY32: |
fb25b355 | 889 | case SIDE_TYPE_FLOAT_BINARY64: |
fb25b355 | 890 | case SIDE_TYPE_FLOAT_BINARY128: |
66de373e | 891 | tracer_print_type_float(":", &type_desc->u.side_float, &item->u.side_static.float_value); |
fb25b355 | 892 | break; |
3aa7ca5e | 893 | |
f611d0c3 | 894 | case SIDE_TYPE_STRING: |
5f82db91 | 895 | tracer_print_type_header(":", type_desc->u.side_string.attr, type_desc->u.side_string.nr_attr); |
66de373e | 896 | printf("\"%s\"", (const char *)(uintptr_t) item->u.side_static.string_value); |
f611d0c3 MD |
897 | break; |
898 | case SIDE_TYPE_STRUCT: | |
66de373e | 899 | tracer_print_struct(type_desc, item->u.side_static.side_struct); |
f611d0c3 | 900 | break; |
7a1cb105 | 901 | case SIDE_TYPE_STRUCT_SG: |
66de373e | 902 | tracer_print_struct_sg(type_desc, item->u.side_static.side_struct_sg_ptr); |
7a1cb105 | 903 | break; |
f611d0c3 | 904 | case SIDE_TYPE_ARRAY: |
66de373e | 905 | tracer_print_array(type_desc, item->u.side_static.side_array); |
f611d0c3 MD |
906 | break; |
907 | case SIDE_TYPE_VLA: | |
66de373e | 908 | tracer_print_vla(type_desc, item->u.side_static.side_vla); |
f611d0c3 MD |
909 | break; |
910 | case SIDE_TYPE_VLA_VISITOR: | |
66de373e | 911 | tracer_print_vla_visitor(type_desc, item->u.side_static.side_vla_app_visitor_ctx); |
f611d0c3 | 912 | break; |
ba845af5 MD |
913 | case SIDE_TYPE_ARRAY_U8: |
914 | case SIDE_TYPE_ARRAY_U16: | |
915 | case SIDE_TYPE_ARRAY_U32: | |
916 | case SIDE_TYPE_ARRAY_U64: | |
917 | case SIDE_TYPE_ARRAY_S8: | |
918 | case SIDE_TYPE_ARRAY_S16: | |
919 | case SIDE_TYPE_ARRAY_S32: | |
920 | case SIDE_TYPE_ARRAY_S64: | |
f7653b43 | 921 | case SIDE_TYPE_ARRAY_BYTE: |
dd6e76cb MD |
922 | case SIDE_TYPE_ARRAY_POINTER32: |
923 | case SIDE_TYPE_ARRAY_POINTER64: | |
ba845af5 MD |
924 | tracer_print_array_fixint(type_desc, item); |
925 | break; | |
1533629f MD |
926 | case SIDE_TYPE_VLA_U8: |
927 | case SIDE_TYPE_VLA_U16: | |
928 | case SIDE_TYPE_VLA_U32: | |
929 | case SIDE_TYPE_VLA_U64: | |
930 | case SIDE_TYPE_VLA_S8: | |
931 | case SIDE_TYPE_VLA_S16: | |
932 | case SIDE_TYPE_VLA_S32: | |
933 | case SIDE_TYPE_VLA_S64: | |
f7653b43 | 934 | case SIDE_TYPE_VLA_BYTE: |
dd6e76cb MD |
935 | case SIDE_TYPE_VLA_POINTER32: |
936 | case SIDE_TYPE_VLA_POINTER64: | |
1533629f MD |
937 | tracer_print_vla_fixint(type_desc, item); |
938 | break; | |
66de373e MD |
939 | |
940 | /* Dynamic types */ | |
941 | case SIDE_TYPE_DYNAMIC_NULL: | |
942 | case SIDE_TYPE_DYNAMIC_BOOL: | |
943 | case SIDE_TYPE_DYNAMIC_U8: | |
944 | case SIDE_TYPE_DYNAMIC_U16: | |
945 | case SIDE_TYPE_DYNAMIC_U32: | |
946 | case SIDE_TYPE_DYNAMIC_U64: | |
947 | case SIDE_TYPE_DYNAMIC_S8: | |
948 | case SIDE_TYPE_DYNAMIC_S16: | |
949 | case SIDE_TYPE_DYNAMIC_S32: | |
950 | case SIDE_TYPE_DYNAMIC_S64: | |
951 | case SIDE_TYPE_DYNAMIC_BYTE: | |
952 | case SIDE_TYPE_DYNAMIC_POINTER32: | |
953 | case SIDE_TYPE_DYNAMIC_POINTER64: | |
954 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16: | |
955 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32: | |
956 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64: | |
957 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128: | |
958 | case SIDE_TYPE_DYNAMIC_STRING: | |
959 | case SIDE_TYPE_DYNAMIC_STRUCT: | |
960 | case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR: | |
961 | case SIDE_TYPE_DYNAMIC_VLA: | |
962 | case SIDE_TYPE_DYNAMIC_VLA_VISITOR: | |
963 | tracer_print_dynamic(item); | |
a2e2357e | 964 | break; |
f611d0c3 | 965 | default: |
de1b3cd2 | 966 | fprintf(stderr, "<UNKNOWN TYPE>"); |
f611d0c3 MD |
967 | abort(); |
968 | } | |
a848763d | 969 | printf(" }"); |
f611d0c3 MD |
970 | } |
971 | ||
972 | static | |
66de373e | 973 | void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg *item) |
f611d0c3 | 974 | { |
19fa6aa2 | 975 | printf("%s: ", item_desc->field_name); |
f611d0c3 | 976 | tracer_print_type(&item_desc->side_type, item); |
f611d0c3 MD |
977 | } |
978 | ||
979 | static | |
66de373e | 980 | void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *sav_desc) |
f611d0c3 | 981 | { |
66de373e | 982 | const struct side_arg *sav = sav_desc->sav; |
f611d0c3 MD |
983 | uint32_t side_sav_len = sav_desc->len; |
984 | int i; | |
985 | ||
c7a14585 | 986 | if (type_desc->u.side_struct->nr_fields != side_sav_len) { |
de1b3cd2 | 987 | fprintf(stderr, "ERROR: number of fields mismatch between description and arguments of structure\n"); |
f611d0c3 MD |
988 | abort(); |
989 | } | |
905c328e | 990 | print_attributes("attr", ":", type_desc->u.side_struct->attr, type_desc->u.side_struct->nr_attr); |
73b2b0c2 MD |
991 | printf("%s", type_desc->u.side_struct->nr_attr ? ", " : ""); |
992 | printf("fields: { "); | |
f611d0c3 MD |
993 | for (i = 0; i < side_sav_len; i++) { |
994 | printf("%s", i ? ", " : ""); | |
c7a14585 | 995 | tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]); |
f611d0c3 | 996 | } |
d4328528 | 997 | printf(" }"); |
f611d0c3 MD |
998 | } |
999 | ||
7a1cb105 MD |
1000 | static |
1001 | void tracer_print_sg_type(const struct side_type_sg_description *sg_type, void *_ptr) | |
1002 | { | |
7a1cb105 | 1003 | const char *ptr = (const char *) _ptr; |
87405d12 | 1004 | union side_integer_value value; |
7a1cb105 MD |
1005 | |
1006 | printf("{ "); | |
1007 | switch (sg_type->type) { | |
9b641221 MD |
1008 | case SIDE_TYPE_SG_NULL: |
1009 | tracer_print_type_header(":", sg_type->u.side_null.attr, sg_type->u.side_null.nr_attr); | |
1010 | printf("<NULL TYPE>"); | |
1011 | break; | |
1012 | ||
7a1cb105 | 1013 | case SIDE_TYPE_SG_UNSIGNED_INT: |
7a1cb105 | 1014 | case SIDE_TYPE_SG_SIGNED_INT: |
87405d12 | 1015 | switch (sg_type->u.side_integer.type.integer_size_bits) { |
7a1cb105 | 1016 | case 8: |
7a1cb105 | 1017 | case 16: |
7a1cb105 | 1018 | case 32: |
7a1cb105 | 1019 | case 64: |
7a1cb105 | 1020 | break; |
7a1cb105 | 1021 | default: |
7a1cb105 MD |
1022 | abort(); |
1023 | } | |
9b641221 MD |
1024 | memcpy(&value, ptr + sg_type->offset, sg_type->u.side_integer.type.integer_size_bits >> 3); |
1025 | tracer_print_type_integer(":", &sg_type->u.side_integer.type, &value, | |
1026 | sg_type->u.side_integer.offset_bits, TRACER_DISPLAY_BASE_10); | |
1027 | break; | |
1028 | default: | |
1029 | fprintf(stderr, "<UNKNOWN TYPE>"); | |
1030 | abort(); | |
7a1cb105 MD |
1031 | } |
1032 | printf(" }"); | |
1033 | } | |
1034 | ||
1035 | static | |
1036 | void tracer_print_sg_field(const struct side_struct_field_sg *field_sg, void *ptr) | |
1037 | { | |
1038 | printf("%s: ", field_sg->field_name); | |
1039 | tracer_print_sg_type(&field_sg->side_type, ptr); | |
1040 | } | |
1041 | ||
1042 | static | |
66de373e | 1043 | void tracer_print_struct_sg(const struct side_type *type_desc, void *ptr) |
7a1cb105 MD |
1044 | { |
1045 | const struct side_type_struct_sg *struct_sg = type_desc->u.side_struct_sg; | |
1046 | int i; | |
1047 | ||
1048 | print_attributes("attr", ":", struct_sg->attr, struct_sg->nr_attr); | |
1049 | printf("%s", struct_sg->nr_attr ? ", " : ""); | |
1050 | printf("fields: { "); | |
1051 | for (i = 0; i < struct_sg->nr_fields; i++) { | |
1052 | printf("%s", i ? ", " : ""); | |
1053 | tracer_print_sg_field(&struct_sg->fields_sg[i], ptr); | |
1054 | } | |
1055 | printf(" }"); | |
1056 | } | |
1057 | ||
f611d0c3 | 1058 | static |
66de373e | 1059 | void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *sav_desc) |
f611d0c3 | 1060 | { |
66de373e | 1061 | const struct side_arg *sav = sav_desc->sav; |
f611d0c3 MD |
1062 | uint32_t side_sav_len = sav_desc->len; |
1063 | int i; | |
1064 | ||
1065 | if (type_desc->u.side_array.length != side_sav_len) { | |
de1b3cd2 | 1066 | fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n"); |
f611d0c3 MD |
1067 | abort(); |
1068 | } | |
905c328e | 1069 | print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr); |
d4328528 | 1070 | printf("%s", type_desc->u.side_array.nr_attr ? ", " : ""); |
20574104 | 1071 | printf("elements: "); |
f611d0c3 MD |
1072 | printf("[ "); |
1073 | for (i = 0; i < side_sav_len; i++) { | |
1074 | printf("%s", i ? ", " : ""); | |
1075 | tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]); | |
1076 | } | |
1077 | printf(" ]"); | |
1078 | } | |
1079 | ||
1080 | static | |
66de373e | 1081 | void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_vec *sav_desc) |
f611d0c3 | 1082 | { |
66de373e | 1083 | const struct side_arg *sav = sav_desc->sav; |
f611d0c3 MD |
1084 | uint32_t side_sav_len = sav_desc->len; |
1085 | int i; | |
1086 | ||
905c328e | 1087 | print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr); |
d4328528 | 1088 | printf("%s", type_desc->u.side_vla.nr_attr ? ", " : ""); |
20574104 | 1089 | printf("elements: "); |
f611d0c3 MD |
1090 | printf("[ "); |
1091 | for (i = 0; i < side_sav_len; i++) { | |
1092 | printf("%s", i ? ", " : ""); | |
1093 | tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]); | |
1094 | } | |
1095 | printf(" ]"); | |
1096 | } | |
1097 | ||
352a4b77 | 1098 | struct tracer_visitor_priv { |
66de373e | 1099 | const struct side_type *elem_type; |
352a4b77 MD |
1100 | int i; |
1101 | }; | |
1102 | ||
1103 | static | |
1104 | enum side_visitor_status tracer_write_elem_cb(const struct side_tracer_visitor_ctx *tracer_ctx, | |
66de373e | 1105 | const struct side_arg *elem) |
352a4b77 MD |
1106 | { |
1107 | struct tracer_visitor_priv *tracer_priv = tracer_ctx->priv; | |
1108 | ||
1109 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
1110 | tracer_print_type(tracer_priv->elem_type, elem); | |
1111 | return SIDE_VISITOR_STATUS_OK; | |
1112 | } | |
1113 | ||
f611d0c3 | 1114 | static |
66de373e | 1115 | void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx) |
f611d0c3 MD |
1116 | { |
1117 | enum side_visitor_status status; | |
352a4b77 MD |
1118 | struct tracer_visitor_priv tracer_priv = { |
1119 | .elem_type = type_desc->u.side_vla_visitor.elem_type, | |
1120 | .i = 0, | |
1121 | }; | |
1122 | const struct side_tracer_visitor_ctx tracer_ctx = { | |
1123 | .write_elem = tracer_write_elem_cb, | |
1124 | .priv = &tracer_priv, | |
1125 | }; | |
f611d0c3 | 1126 | |
905c328e | 1127 | print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr); |
d4328528 | 1128 | printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : ""); |
20574104 | 1129 | printf("elements: "); |
352a4b77 MD |
1130 | printf("[ "); |
1131 | status = type_desc->u.side_vla_visitor.visitor(&tracer_ctx, app_ctx); | |
1132 | switch (status) { | |
1133 | case SIDE_VISITOR_STATUS_OK: | |
1134 | break; | |
1135 | case SIDE_VISITOR_STATUS_ERROR: | |
de1b3cd2 | 1136 | fprintf(stderr, "ERROR: Visitor error\n"); |
f611d0c3 | 1137 | abort(); |
f611d0c3 MD |
1138 | } |
1139 | printf(" ]"); | |
f611d0c3 MD |
1140 | } |
1141 | ||
66de373e | 1142 | void tracer_print_array_fixint(const struct side_type *type_desc, const struct side_arg *item) |
ba845af5 | 1143 | { |
66de373e | 1144 | const struct side_type *elem_type = type_desc->u.side_array.elem_type; |
ba845af5 | 1145 | uint32_t side_sav_len = type_desc->u.side_array.length; |
66de373e MD |
1146 | void *p = item->u.side_static.side_array_fixint; |
1147 | enum side_type_label side_type; | |
ba845af5 MD |
1148 | int i; |
1149 | ||
905c328e | 1150 | print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr); |
d4328528 | 1151 | printf("%s", type_desc->u.side_array.nr_attr ? ", " : ""); |
20574104 | 1152 | printf("elements: "); |
1e8256c9 MD |
1153 | switch (item->type) { |
1154 | case SIDE_TYPE_ARRAY_U8: | |
1155 | if (elem_type->type != SIDE_TYPE_U8) | |
1156 | goto type_error; | |
1157 | break; | |
1158 | case SIDE_TYPE_ARRAY_U16: | |
1159 | if (elem_type->type != SIDE_TYPE_U16) | |
1160 | goto type_error; | |
1161 | break; | |
1162 | case SIDE_TYPE_ARRAY_U32: | |
1163 | if (elem_type->type != SIDE_TYPE_U32) | |
1164 | goto type_error; | |
1165 | break; | |
1166 | case SIDE_TYPE_ARRAY_U64: | |
1167 | if (elem_type->type != SIDE_TYPE_U64) | |
1168 | goto type_error; | |
1169 | break; | |
1170 | case SIDE_TYPE_ARRAY_S8: | |
1171 | if (elem_type->type != SIDE_TYPE_S8) | |
1172 | goto type_error; | |
1173 | break; | |
1174 | case SIDE_TYPE_ARRAY_S16: | |
1175 | if (elem_type->type != SIDE_TYPE_S16) | |
1176 | goto type_error; | |
1177 | break; | |
1178 | case SIDE_TYPE_ARRAY_S32: | |
1179 | if (elem_type->type != SIDE_TYPE_S32) | |
1180 | goto type_error; | |
1181 | break; | |
1182 | case SIDE_TYPE_ARRAY_S64: | |
1183 | if (elem_type->type != SIDE_TYPE_S64) | |
1184 | goto type_error; | |
1185 | break; | |
f7653b43 MD |
1186 | case SIDE_TYPE_ARRAY_BYTE: |
1187 | if (elem_type->type != SIDE_TYPE_BYTE) | |
7aec0d09 MD |
1188 | goto type_error; |
1189 | break; | |
dd6e76cb MD |
1190 | case SIDE_TYPE_ARRAY_POINTER32: |
1191 | if (elem_type->type != SIDE_TYPE_POINTER32) | |
1192 | goto type_error; | |
1193 | case SIDE_TYPE_ARRAY_POINTER64: | |
1194 | if (elem_type->type != SIDE_TYPE_POINTER64) | |
f5e650d7 MD |
1195 | goto type_error; |
1196 | break; | |
1e8256c9 MD |
1197 | default: |
1198 | goto type_error; | |
ba845af5 | 1199 | } |
1e8256c9 | 1200 | side_type = elem_type->type; |
ba845af5 | 1201 | |
1533629f MD |
1202 | printf("[ "); |
1203 | for (i = 0; i < side_sav_len; i++) { | |
66de373e | 1204 | struct side_arg sav_elem = { |
1533629f MD |
1205 | .type = side_type, |
1206 | }; | |
1207 | ||
1208 | switch (side_type) { | |
1209 | case SIDE_TYPE_U8: | |
66de373e | 1210 | sav_elem.u.side_static.integer_value.side_u8 = ((const uint8_t *) p)[i]; |
1533629f MD |
1211 | break; |
1212 | case SIDE_TYPE_S8: | |
66de373e | 1213 | sav_elem.u.side_static.integer_value.side_s8 = ((const int8_t *) p)[i]; |
1533629f MD |
1214 | break; |
1215 | case SIDE_TYPE_U16: | |
66de373e | 1216 | sav_elem.u.side_static.integer_value.side_u16 = ((const uint16_t *) p)[i]; |
1533629f MD |
1217 | break; |
1218 | case SIDE_TYPE_S16: | |
66de373e | 1219 | sav_elem.u.side_static.integer_value.side_s16 = ((const int16_t *) p)[i]; |
1533629f MD |
1220 | break; |
1221 | case SIDE_TYPE_U32: | |
66de373e | 1222 | sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i]; |
1533629f MD |
1223 | break; |
1224 | case SIDE_TYPE_S32: | |
66de373e | 1225 | sav_elem.u.side_static.integer_value.side_s32 = ((const int32_t *) p)[i]; |
1533629f MD |
1226 | break; |
1227 | case SIDE_TYPE_U64: | |
66de373e | 1228 | sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i]; |
1533629f MD |
1229 | break; |
1230 | case SIDE_TYPE_S64: | |
66de373e | 1231 | sav_elem.u.side_static.integer_value.side_s64 = ((const int64_t *) p)[i]; |
1533629f | 1232 | break; |
f7653b43 | 1233 | case SIDE_TYPE_BYTE: |
66de373e | 1234 | sav_elem.u.side_static.byte_value = ((const uint8_t *) p)[i]; |
7aec0d09 | 1235 | break; |
dd6e76cb | 1236 | case SIDE_TYPE_POINTER32: |
66de373e | 1237 | sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i]; |
dd6e76cb MD |
1238 | break; |
1239 | case SIDE_TYPE_POINTER64: | |
66de373e | 1240 | sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i]; |
f5e650d7 | 1241 | break; |
1533629f MD |
1242 | |
1243 | default: | |
de1b3cd2 | 1244 | fprintf(stderr, "ERROR: Unexpected type\n"); |
1533629f MD |
1245 | abort(); |
1246 | } | |
1247 | ||
1248 | printf("%s", i ? ", " : ""); | |
1249 | tracer_print_type(elem_type, &sav_elem); | |
1250 | } | |
1251 | printf(" ]"); | |
1252 | return; | |
1253 | ||
1254 | type_error: | |
de1b3cd2 | 1255 | fprintf(stderr, "ERROR: type mismatch\n"); |
1533629f MD |
1256 | abort(); |
1257 | } | |
1258 | ||
66de373e | 1259 | void tracer_print_vla_fixint(const struct side_type *type_desc, const struct side_arg *item) |
1533629f | 1260 | { |
66de373e MD |
1261 | const struct side_type *elem_type = type_desc->u.side_vla.elem_type; |
1262 | uint32_t side_sav_len = item->u.side_static.side_vla_fixint.length; | |
1263 | void *p = item->u.side_static.side_vla_fixint.p; | |
1264 | enum side_type_label side_type; | |
1533629f MD |
1265 | int i; |
1266 | ||
905c328e | 1267 | print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr); |
d4328528 | 1268 | printf("%s", type_desc->u.side_vla.nr_attr ? ", " : ""); |
20574104 | 1269 | printf("elements: "); |
a2e2357e MD |
1270 | switch (item->type) { |
1271 | case SIDE_TYPE_VLA_U8: | |
1272 | if (elem_type->type != SIDE_TYPE_U8) | |
1533629f | 1273 | goto type_error; |
a2e2357e MD |
1274 | break; |
1275 | case SIDE_TYPE_VLA_U16: | |
1276 | if (elem_type->type != SIDE_TYPE_U16) | |
1533629f | 1277 | goto type_error; |
a2e2357e MD |
1278 | break; |
1279 | case SIDE_TYPE_VLA_U32: | |
1280 | if (elem_type->type != SIDE_TYPE_U32) | |
1281 | goto type_error; | |
1282 | break; | |
1283 | case SIDE_TYPE_VLA_U64: | |
1284 | if (elem_type->type != SIDE_TYPE_U64) | |
1285 | goto type_error; | |
1286 | break; | |
1287 | case SIDE_TYPE_VLA_S8: | |
1288 | if (elem_type->type != SIDE_TYPE_S8) | |
1289 | goto type_error; | |
1290 | break; | |
1291 | case SIDE_TYPE_VLA_S16: | |
1292 | if (elem_type->type != SIDE_TYPE_S16) | |
1293 | goto type_error; | |
1294 | break; | |
1295 | case SIDE_TYPE_VLA_S32: | |
1296 | if (elem_type->type != SIDE_TYPE_S32) | |
1297 | goto type_error; | |
1298 | break; | |
1299 | case SIDE_TYPE_VLA_S64: | |
1300 | if (elem_type->type != SIDE_TYPE_S64) | |
1301 | goto type_error; | |
1302 | break; | |
f7653b43 MD |
1303 | case SIDE_TYPE_VLA_BYTE: |
1304 | if (elem_type->type != SIDE_TYPE_BYTE) | |
7aec0d09 MD |
1305 | goto type_error; |
1306 | break; | |
dd6e76cb MD |
1307 | case SIDE_TYPE_VLA_POINTER32: |
1308 | if (elem_type->type != SIDE_TYPE_POINTER32) | |
1309 | goto type_error; | |
1310 | case SIDE_TYPE_VLA_POINTER64: | |
1311 | if (elem_type->type != SIDE_TYPE_POINTER64) | |
f5e650d7 MD |
1312 | goto type_error; |
1313 | break; | |
a2e2357e MD |
1314 | default: |
1315 | goto type_error; | |
1533629f | 1316 | } |
a2e2357e | 1317 | side_type = elem_type->type; |
1533629f | 1318 | |
ba845af5 MD |
1319 | printf("[ "); |
1320 | for (i = 0; i < side_sav_len; i++) { | |
66de373e | 1321 | struct side_arg sav_elem = { |
ba845af5 MD |
1322 | .type = side_type, |
1323 | }; | |
1324 | ||
1325 | switch (side_type) { | |
1326 | case SIDE_TYPE_U8: | |
66de373e | 1327 | sav_elem.u.side_static.integer_value.side_u8 = ((const uint8_t *) p)[i]; |
ba845af5 MD |
1328 | break; |
1329 | case SIDE_TYPE_S8: | |
66de373e | 1330 | sav_elem.u.side_static.integer_value.side_s8 = ((const int8_t *) p)[i]; |
ba845af5 MD |
1331 | break; |
1332 | case SIDE_TYPE_U16: | |
66de373e | 1333 | sav_elem.u.side_static.integer_value.side_u16 = ((const uint16_t *) p)[i]; |
ba845af5 MD |
1334 | break; |
1335 | case SIDE_TYPE_S16: | |
66de373e | 1336 | sav_elem.u.side_static.integer_value.side_s16 = ((const int16_t *) p)[i]; |
ba845af5 MD |
1337 | break; |
1338 | case SIDE_TYPE_U32: | |
66de373e | 1339 | sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i]; |
ba845af5 MD |
1340 | break; |
1341 | case SIDE_TYPE_S32: | |
66de373e | 1342 | sav_elem.u.side_static.integer_value.side_s32 = ((const int32_t *) p)[i]; |
ba845af5 MD |
1343 | break; |
1344 | case SIDE_TYPE_U64: | |
66de373e | 1345 | sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i]; |
ba845af5 MD |
1346 | break; |
1347 | case SIDE_TYPE_S64: | |
66de373e | 1348 | sav_elem.u.side_static.integer_value.side_s64 = ((const int64_t *) p)[i]; |
ba845af5 | 1349 | break; |
f7653b43 | 1350 | case SIDE_TYPE_BYTE: |
66de373e | 1351 | sav_elem.u.side_static.byte_value = ((const uint8_t *) p)[i]; |
7aec0d09 | 1352 | break; |
dd6e76cb | 1353 | case SIDE_TYPE_POINTER32: |
66de373e | 1354 | sav_elem.u.side_static.integer_value.side_u32 = ((const uint32_t *) p)[i]; |
dd6e76cb MD |
1355 | break; |
1356 | case SIDE_TYPE_POINTER64: | |
66de373e | 1357 | sav_elem.u.side_static.integer_value.side_u64 = ((const uint64_t *) p)[i]; |
f5e650d7 | 1358 | break; |
ba845af5 MD |
1359 | |
1360 | default: | |
de1b3cd2 | 1361 | fprintf(stderr, "ERROR: Unexpected type\n"); |
ba845af5 MD |
1362 | abort(); |
1363 | } | |
1364 | ||
1365 | printf("%s", i ? ", " : ""); | |
1366 | tracer_print_type(elem_type, &sav_elem); | |
1367 | } | |
1368 | printf(" ]"); | |
1369 | return; | |
1370 | ||
1371 | type_error: | |
de1b3cd2 | 1372 | fprintf(stderr, "ERROR: type mismatch\n"); |
ba845af5 MD |
1373 | abort(); |
1374 | } | |
1375 | ||
a2e2357e | 1376 | static |
c208889e | 1377 | void tracer_print_dynamic_struct(const struct side_arg_dynamic_event_struct *dynamic_struct) |
a2e2357e | 1378 | { |
c208889e MD |
1379 | const struct side_arg_dynamic_event_field *fields = dynamic_struct->fields; |
1380 | uint32_t len = dynamic_struct->len; | |
465e5e7e MD |
1381 | int i; |
1382 | ||
905c328e | 1383 | print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr); |
8d20e708 | 1384 | printf("%s", dynamic_struct->nr_attr ? ", " : ""); |
f0061366 | 1385 | printf("fields:: "); |
465e5e7e MD |
1386 | printf("[ "); |
1387 | for (i = 0; i < len; i++) { | |
1388 | printf("%s", i ? ", " : ""); | |
1389 | printf("%s:: ", fields[i].field_name); | |
1390 | tracer_print_dynamic(&fields[i].elem); | |
1391 | } | |
1392 | printf(" ]"); | |
a2e2357e MD |
1393 | } |
1394 | ||
2b359235 MD |
1395 | struct tracer_dynamic_struct_visitor_priv { |
1396 | int i; | |
1397 | }; | |
1398 | ||
1399 | static | |
1400 | enum side_visitor_status tracer_dynamic_struct_write_elem_cb( | |
1401 | const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, | |
1402 | const struct side_arg_dynamic_event_field *dynamic_field) | |
1403 | { | |
1404 | struct tracer_dynamic_struct_visitor_priv *tracer_priv = tracer_ctx->priv; | |
1405 | ||
1406 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
1407 | printf("%s:: ", dynamic_field->field_name); | |
1408 | tracer_print_dynamic(&dynamic_field->elem); | |
1409 | return SIDE_VISITOR_STATUS_OK; | |
1410 | } | |
1411 | ||
a2e2357e | 1412 | static |
66de373e | 1413 | void tracer_print_dynamic_struct_visitor(const struct side_arg *item) |
a2e2357e | 1414 | { |
2b359235 MD |
1415 | enum side_visitor_status status; |
1416 | struct tracer_dynamic_struct_visitor_priv tracer_priv = { | |
1417 | .i = 0, | |
1418 | }; | |
1419 | const struct side_tracer_dynamic_struct_visitor_ctx tracer_ctx = { | |
1420 | .write_field = tracer_dynamic_struct_write_elem_cb, | |
1421 | .priv = &tracer_priv, | |
1422 | }; | |
66de373e | 1423 | void *app_ctx = item->u.side_dynamic.side_dynamic_struct_visitor.app_ctx; |
2b359235 | 1424 | |
66de373e MD |
1425 | print_attributes("attr", "::", item->u.side_dynamic.side_dynamic_struct_visitor.attr, item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr); |
1426 | printf("%s", item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr ? ", " : ""); | |
f0061366 | 1427 | printf("fields:: "); |
2b359235 | 1428 | printf("[ "); |
66de373e | 1429 | status = item->u.side_dynamic.side_dynamic_struct_visitor.visitor(&tracer_ctx, app_ctx); |
2b359235 MD |
1430 | switch (status) { |
1431 | case SIDE_VISITOR_STATUS_OK: | |
1432 | break; | |
1433 | case SIDE_VISITOR_STATUS_ERROR: | |
de1b3cd2 | 1434 | fprintf(stderr, "ERROR: Visitor error\n"); |
2b359235 MD |
1435 | abort(); |
1436 | } | |
1437 | printf(" ]"); | |
a2e2357e MD |
1438 | } |
1439 | ||
1440 | static | |
66de373e | 1441 | void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla *vla) |
a2e2357e | 1442 | { |
66de373e | 1443 | const struct side_arg *sav = vla->sav; |
a2e2357e MD |
1444 | uint32_t side_sav_len = vla->len; |
1445 | int i; | |
1446 | ||
905c328e | 1447 | print_attributes("attr", "::", vla->attr, vla->nr_attr); |
8d20e708 | 1448 | printf("%s", vla->nr_attr ? ", " : ""); |
f0061366 | 1449 | printf("elements:: "); |
a2e2357e MD |
1450 | printf("[ "); |
1451 | for (i = 0; i < side_sav_len; i++) { | |
1452 | printf("%s", i ? ", " : ""); | |
1453 | tracer_print_dynamic(&sav[i]); | |
1454 | } | |
1455 | printf(" ]"); | |
1456 | } | |
1457 | ||
8ceca0cd MD |
1458 | struct tracer_dynamic_vla_visitor_priv { |
1459 | int i; | |
1460 | }; | |
1461 | ||
1462 | static | |
1463 | enum side_visitor_status tracer_dynamic_vla_write_elem_cb( | |
1464 | const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, | |
66de373e | 1465 | const struct side_arg *elem) |
8ceca0cd MD |
1466 | { |
1467 | struct tracer_dynamic_vla_visitor_priv *tracer_priv = tracer_ctx->priv; | |
1468 | ||
1469 | printf("%s", tracer_priv->i++ ? ", " : ""); | |
1470 | tracer_print_dynamic(elem); | |
1471 | return SIDE_VISITOR_STATUS_OK; | |
1472 | } | |
1473 | ||
a2e2357e | 1474 | static |
66de373e | 1475 | void tracer_print_dynamic_vla_visitor(const struct side_arg *item) |
a2e2357e | 1476 | { |
8ceca0cd MD |
1477 | enum side_visitor_status status; |
1478 | struct tracer_dynamic_vla_visitor_priv tracer_priv = { | |
1479 | .i = 0, | |
1480 | }; | |
1481 | const struct side_tracer_dynamic_vla_visitor_ctx tracer_ctx = { | |
1482 | .write_elem = tracer_dynamic_vla_write_elem_cb, | |
1483 | .priv = &tracer_priv, | |
1484 | }; | |
66de373e | 1485 | void *app_ctx = item->u.side_dynamic.side_dynamic_vla_visitor.app_ctx; |
8ceca0cd | 1486 | |
66de373e MD |
1487 | print_attributes("attr", "::", item->u.side_dynamic.side_dynamic_vla_visitor.attr, item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr); |
1488 | printf("%s", item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr ? ", " : ""); | |
f0061366 | 1489 | printf("elements:: "); |
8ceca0cd | 1490 | printf("[ "); |
66de373e | 1491 | status = item->u.side_dynamic.side_dynamic_vla_visitor.visitor(&tracer_ctx, app_ctx); |
8ceca0cd MD |
1492 | switch (status) { |
1493 | case SIDE_VISITOR_STATUS_OK: | |
1494 | break; | |
1495 | case SIDE_VISITOR_STATUS_ERROR: | |
de1b3cd2 | 1496 | fprintf(stderr, "ERROR: Visitor error\n"); |
8ceca0cd MD |
1497 | abort(); |
1498 | } | |
1499 | printf(" ]"); | |
a2e2357e MD |
1500 | } |
1501 | ||
1502 | static | |
66de373e | 1503 | void tracer_print_dynamic(const struct side_arg *item) |
a2e2357e | 1504 | { |
808bd9bf | 1505 | printf("{ "); |
66de373e MD |
1506 | switch (item->type) { |
1507 | case SIDE_TYPE_DYNAMIC_NULL: | |
1508 | tracer_print_type_header("::", item->u.side_dynamic.side_null.attr, item->u.side_dynamic.side_null.nr_attr); | |
a2e2357e MD |
1509 | printf("<NULL TYPE>"); |
1510 | break; | |
66de373e MD |
1511 | case SIDE_TYPE_DYNAMIC_BOOL: |
1512 | tracer_print_type_header("::", item->u.side_dynamic.side_bool.type.attr, item->u.side_dynamic.side_bool.type.nr_attr); | |
1513 | printf("%s", item->u.side_dynamic.side_bool.value ? "true" : "false"); | |
1514 | break; | |
1515 | case SIDE_TYPE_DYNAMIC_U8: | |
1516 | case SIDE_TYPE_DYNAMIC_U16: | |
1517 | case SIDE_TYPE_DYNAMIC_U32: | |
1518 | case SIDE_TYPE_DYNAMIC_U64: | |
1519 | case SIDE_TYPE_DYNAMIC_S8: | |
1520 | case SIDE_TYPE_DYNAMIC_S16: | |
1521 | case SIDE_TYPE_DYNAMIC_S32: | |
1522 | case SIDE_TYPE_DYNAMIC_S64: | |
1523 | tracer_print_type_integer("::", &item->u.side_dynamic.side_integer.type, &item->u.side_dynamic.side_integer.value, 0, | |
f0dafd60 | 1524 | TRACER_DISPLAY_BASE_10); |
a2e2357e | 1525 | break; |
66de373e MD |
1526 | case SIDE_TYPE_DYNAMIC_BYTE: |
1527 | tracer_print_type_header("::", item->u.side_dynamic.side_byte.type.attr, item->u.side_dynamic.side_byte.type.nr_attr); | |
1528 | printf("0x%" PRIx8, item->u.side_dynamic.side_byte.value); | |
199e7aa9 | 1529 | break; |
dd6e76cb | 1530 | |
66de373e MD |
1531 | case SIDE_TYPE_DYNAMIC_POINTER32: |
1532 | case SIDE_TYPE_DYNAMIC_POINTER64: | |
1533 | tracer_print_type_integer("::", &item->u.side_dynamic.side_integer.type, &item->u.side_dynamic.side_integer.value, 0, | |
f0dafd60 | 1534 | TRACER_DISPLAY_BASE_16); |
f5e650d7 | 1535 | break; |
199e7aa9 | 1536 | |
66de373e MD |
1537 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY16: |
1538 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY32: | |
1539 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY64: | |
1540 | case SIDE_TYPE_DYNAMIC_FLOAT_BINARY128: | |
1541 | tracer_print_type_float("::", &item->u.side_dynamic.side_float.type, | |
1542 | &item->u.side_dynamic.side_float.value); | |
fb25b355 | 1543 | break; |
3aa7ca5e | 1544 | |
66de373e MD |
1545 | case SIDE_TYPE_DYNAMIC_STRING: |
1546 | tracer_print_type_header("::", item->u.side_dynamic.side_string.type.attr, item->u.side_dynamic.side_string.type.nr_attr); | |
1547 | printf("\"%s\"", (const char *)(uintptr_t) item->u.side_dynamic.side_string.value); | |
a2e2357e | 1548 | break; |
66de373e MD |
1549 | case SIDE_TYPE_DYNAMIC_STRUCT: |
1550 | tracer_print_dynamic_struct(item->u.side_dynamic.side_dynamic_struct); | |
a2e2357e | 1551 | break; |
66de373e | 1552 | case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR: |
c208889e | 1553 | tracer_print_dynamic_struct_visitor(item); |
a2e2357e | 1554 | break; |
66de373e MD |
1555 | case SIDE_TYPE_DYNAMIC_VLA: |
1556 | tracer_print_dynamic_vla(item->u.side_dynamic.side_dynamic_vla); | |
a2e2357e | 1557 | break; |
66de373e | 1558 | case SIDE_TYPE_DYNAMIC_VLA_VISITOR: |
a2e2357e MD |
1559 | tracer_print_dynamic_vla_visitor(item); |
1560 | break; | |
1561 | default: | |
de1b3cd2 | 1562 | fprintf(stderr, "<UNKNOWN TYPE>"); |
a2e2357e MD |
1563 | abort(); |
1564 | } | |
808bd9bf | 1565 | printf(" }"); |
a2e2357e MD |
1566 | } |
1567 | ||
68f8cfbe MD |
1568 | static |
1569 | void tracer_print_static_fields(const struct side_event_description *desc, | |
66de373e | 1570 | const struct side_arg_vec *sav_desc, |
68f8cfbe | 1571 | int *nr_items) |
f611d0c3 | 1572 | { |
66de373e | 1573 | const struct side_arg *sav = sav_desc->sav; |
f611d0c3 MD |
1574 | uint32_t side_sav_len = sav_desc->len; |
1575 | int i; | |
1576 | ||
65010f43 | 1577 | printf("provider: %s, event: %s", desc->provider_name, desc->event_name); |
f611d0c3 | 1578 | if (desc->nr_fields != side_sav_len) { |
de1b3cd2 | 1579 | fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n"); |
f611d0c3 MD |
1580 | abort(); |
1581 | } | |
905c328e | 1582 | print_attributes(", attr", ":", desc->attr, desc->nr_attr); |
a848763d | 1583 | printf("%s", side_sav_len ? ", fields: [ " : ""); |
f611d0c3 MD |
1584 | for (i = 0; i < side_sav_len; i++) { |
1585 | printf("%s", i ? ", " : ""); | |
1586 | tracer_print_field(&desc->fields[i], &sav[i]); | |
1587 | } | |
68f8cfbe MD |
1588 | if (nr_items) |
1589 | *nr_items = i; | |
c7d338e2 MD |
1590 | if (side_sav_len) |
1591 | printf(" ]"); | |
68f8cfbe MD |
1592 | } |
1593 | ||
4a7d8700 | 1594 | void tracer_call(const struct side_event_description *desc, |
66de373e | 1595 | const struct side_arg_vec *sav_desc, |
4a7d8700 | 1596 | void *priv __attribute__((unused))) |
68f8cfbe | 1597 | { |
a848763d MD |
1598 | int nr_fields = 0; |
1599 | ||
a848763d | 1600 | tracer_print_static_fields(desc, sav_desc, &nr_fields); |
f611d0c3 MD |
1601 | printf("\n"); |
1602 | } | |
19fa6aa2 MD |
1603 | |
1604 | void tracer_call_variadic(const struct side_event_description *desc, | |
66de373e | 1605 | const struct side_arg_vec *sav_desc, |
4a7d8700 MD |
1606 | const struct side_arg_dynamic_event_struct *var_struct, |
1607 | void *priv __attribute__((unused))) | |
19fa6aa2 | 1608 | { |
68f8cfbe MD |
1609 | uint32_t var_struct_len = var_struct->len; |
1610 | int nr_fields = 0, i; | |
19fa6aa2 | 1611 | |
68f8cfbe MD |
1612 | tracer_print_static_fields(desc, sav_desc, &nr_fields); |
1613 | ||
8a25ce77 | 1614 | if (side_unlikely(!(desc->flags & SIDE_EVENT_FLAG_VARIADIC))) { |
de1b3cd2 | 1615 | fprintf(stderr, "ERROR: unexpected non-variadic event description\n"); |
8a25ce77 MD |
1616 | abort(); |
1617 | } | |
905c328e MD |
1618 | print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr); |
1619 | printf("%s", var_struct_len ? ", fields:: [ " : ""); | |
68f8cfbe | 1620 | for (i = 0; i < var_struct_len; i++, nr_fields++) { |
c7d338e2 | 1621 | printf("%s", i ? ", " : ""); |
68f8cfbe MD |
1622 | printf("%s:: ", var_struct->fields[i].field_name); |
1623 | tracer_print_dynamic(&var_struct->fields[i].elem); | |
19fa6aa2 | 1624 | } |
a848763d MD |
1625 | if (i) |
1626 | printf(" ]"); | |
19fa6aa2 MD |
1627 | printf("\n"); |
1628 | } | |
1e8aec23 MD |
1629 | |
1630 | void tracer_event_notification(enum side_tracer_notification notif, | |
1631 | struct side_event_description **events, uint32_t nr_events, void *priv) | |
1632 | { | |
1633 | uint32_t i; | |
314c22c3 | 1634 | int ret; |
1e8aec23 MD |
1635 | |
1636 | printf("----------------------------------------------------------\n"); | |
1637 | printf("Tracer notified of events %s\n", | |
314c22c3 | 1638 | notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS ? "inserted" : "removed"); |
1e8aec23 MD |
1639 | for (i = 0; i < nr_events; i++) { |
1640 | struct side_event_description *event = events[i]; | |
1641 | ||
1642 | /* Skip NULL pointers */ | |
1643 | if (!event) | |
1644 | continue; | |
1645 | printf("provider: %s, event: %s\n", | |
1646 | event->provider_name, event->event_name); | |
314c22c3 MD |
1647 | if (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) { |
1648 | if (event->flags & SIDE_EVENT_FLAG_VARIADIC) { | |
1649 | ret = side_tracer_callback_variadic_register(event, tracer_call_variadic, NULL); | |
1650 | if (ret) | |
1651 | abort(); | |
1652 | } else { | |
1653 | ret = side_tracer_callback_register(event, tracer_call, NULL); | |
1654 | if (ret) | |
1655 | abort(); | |
1656 | } | |
1657 | } else { | |
1658 | if (event->flags & SIDE_EVENT_FLAG_VARIADIC) { | |
1659 | ret = side_tracer_callback_variadic_unregister(event, tracer_call_variadic, NULL); | |
1660 | if (ret) | |
1661 | abort(); | |
1662 | } else { | |
1663 | ret = side_tracer_callback_unregister(event, tracer_call, NULL); | |
1664 | if (ret) | |
1665 | abort(); | |
1666 | } | |
1667 | } | |
1e8aec23 MD |
1668 | } |
1669 | printf("----------------------------------------------------------\n"); | |
1670 | } | |
1671 | ||
1672 | static __attribute__((constructor)) | |
1673 | void tracer_init(void); | |
1674 | static | |
1675 | void tracer_init(void) | |
1676 | { | |
1677 | tracer_handle = side_tracer_event_notification_register(tracer_event_notification, NULL); | |
1678 | if (!tracer_handle) | |
1679 | abort(); | |
1680 | } | |
1681 | ||
1682 | static __attribute__((destructor)) | |
1683 | void tracer_exit(void); | |
1684 | static | |
1685 | void tracer_exit(void) | |
1686 | { | |
1687 | side_tracer_event_notification_unregister(tracer_handle); | |
1688 | } |