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