trace.h: Use side_enum_t for side_attr_type enum
[libside.git] / src / tracer.c
index 32e49697976a2411e6b2e8bbc1772cfc530b9fdf..b11db80f06f79e2ff37c2105e2117aac7ebb725b 100644 (file)
@@ -186,7 +186,7 @@ int64_t get_attr_integer_value(const struct side_attr *attr)
 {
        int64_t val;
 
-       switch (attr->value.type) {
+       switch (side_enum_get(attr->value.type)) {
        case SIDE_ATTR_TYPE_U8:
                val = attr->value.u.integer_value.side_u8;
                break;
@@ -229,10 +229,10 @@ enum tracer_display_base get_attr_display_base(const struct side_attr *_attr, ui
                char *utf8_str = NULL;
                bool cmp;
 
-               tracer_convert_string_to_utf8(attr->key.p, attr->key.unit_size,
+               tracer_convert_string_to_utf8(side_ptr_get(attr->key.p), attr->key.unit_size,
                        attr->key.byte_order, NULL, &utf8_str);
                cmp = strcmp(utf8_str, "std.integer.base");
-               if (utf8_str != attr->key.p)
+               if (utf8_str != side_ptr_get(attr->key.p))
                        free(utf8_str);
                if (!cmp) {
                        int64_t val = get_attr_integer_value(attr);
@@ -260,12 +260,12 @@ void tracer_print_attr_type(const char *separator, const struct side_attr *attr)
 {
        char *utf8_str = NULL;
 
-       tracer_convert_string_to_utf8(attr->key.p, attr->key.unit_size,
+       tracer_convert_string_to_utf8(side_ptr_get(attr->key.p), attr->key.unit_size,
                attr->key.byte_order, NULL, &utf8_str);
        printf("{ key%s \"%s\", value%s ", separator, utf8_str, separator);
-       if (utf8_str != attr->key.p)
+       if (utf8_str != side_ptr_get(attr->key.p))
                free(utf8_str);
-       switch (attr->value.type) {
+       switch (side_enum_get(attr->value.type)) {
        case SIDE_ATTR_TYPE_BOOL:
                printf("%s", attr->value.u.bool_value ? "true" : "false");
                break;
@@ -326,7 +326,7 @@ void tracer_print_attr_type(const char *separator, const struct side_attr *attr)
                abort();
 #endif
        case SIDE_ATTR_TYPE_STRING:
-               tracer_print_string(attr->value.u.string_value.p,
+               tracer_print_string(side_ptr_get(attr->value.u.string_value.p),
                                attr->value.u.string_value.unit_size,
                                attr->value.u.string_value.byte_order, NULL);
                break;
@@ -451,7 +451,7 @@ void print_enum_labels(const struct side_enum_mappings *mappings, union int64_va
 
        printf(", labels: [ ");
        for (i = 0; i < mappings->nr_mappings; i++) {
-               const struct side_enum_mapping *mapping = &mappings->mappings[i];
+               const struct side_enum_mapping *mapping = &side_ptr_get(mappings->mappings)[i];
 
                if (mapping->range_end < mapping->range_begin) {
                        fprintf(stderr, "ERROR: Unexpected enum range: %" PRIu64 "-%" PRIu64 "\n",
@@ -460,7 +460,7 @@ void print_enum_labels(const struct side_enum_mappings *mappings, union int64_va
                }
                if (v64.s >= mapping->range_begin && v64.s <= mapping->range_end) {
                        printf("%s", print_count++ ? ", " : "");
-                       tracer_print_string(mapping->label.p, mapping->label.unit_size, mapping->label.byte_order, NULL);
+                       tracer_print_string(side_ptr_get(mapping->label.p), mapping->label.unit_size, mapping->label.byte_order, NULL);
                }
        }
        if (!print_count)
@@ -471,17 +471,17 @@ void print_enum_labels(const struct side_enum_mappings *mappings, union int64_va
 static
 void tracer_print_enum(const struct side_type *type_desc, const struct side_arg *item)
 {
-       const struct side_enum_mappings *mappings = type_desc->u.side_enum.mappings;
-       const struct side_type *elem_type = type_desc->u.side_enum.elem_type;
+       const struct side_enum_mappings *mappings = side_ptr_get(type_desc->u.side_enum.mappings);
+       const struct side_type *elem_type = side_ptr_get(type_desc->u.side_enum.elem_type);
        union int64_value v64;
 
-       if (elem_type->type != item->type) {
+       if (side_enum_get(elem_type->type) != side_enum_get(item->type)) {
                fprintf(stderr, "ERROR: Unexpected enum element type\n");
                abort();
        }
        v64 = tracer_load_integer_value(&elem_type->u.side_integer,
                        &item->u.side_static.integer_value, 0, NULL);
-       print_attributes("attr", ":", mappings->attr, mappings->nr_attr);
+       print_attributes("attr", ":", side_ptr_get(mappings->attr), mappings->nr_attr);
        printf("%s", mappings->nr_attr ? ", " : "");
        tracer_print_type(elem_type, item);
        print_enum_labels(mappings, v64);
@@ -492,7 +492,7 @@ uint32_t elem_type_to_stride(const struct side_type *elem_type)
 {
        uint32_t stride_bit;
 
-       switch (elem_type->type) {
+       switch (side_enum_get(elem_type->type)) {
        case SIDE_TYPE_BYTE:
                stride_bit = 8;
                break;
@@ -517,12 +517,12 @@ static
 void tracer_print_enum_bitmap(const struct side_type *type_desc,
                const struct side_arg *item)
 {
-       const struct side_enum_bitmap_mappings *side_enum_mappings = type_desc->u.side_enum_bitmap.mappings;
-       const struct side_type *enum_elem_type = type_desc->u.side_enum_bitmap.elem_type, *elem_type;
+       const struct side_enum_bitmap_mappings *side_enum_mappings = side_ptr_get(type_desc->u.side_enum_bitmap.mappings);
+       const struct side_type *enum_elem_type = side_ptr_get(type_desc->u.side_enum_bitmap.elem_type), *elem_type;
        uint32_t i, print_count = 0, stride_bit, nr_items;
        const struct side_arg *array_item;
 
-       switch (enum_elem_type->type) {
+       switch (side_enum_get(enum_elem_type->type)) {
        case SIDE_TYPE_U8:              /* Fall-through */
        case SIDE_TYPE_BYTE:            /* Fall-through */
        case SIDE_TYPE_U16:             /* Fall-through */
@@ -537,14 +537,14 @@ void tracer_print_enum_bitmap(const struct side_type *type_desc,
                nr_items = 1;
                break;
        case SIDE_TYPE_ARRAY:
-               elem_type = enum_elem_type->u.side_array.elem_type;
-               array_item = item->u.side_static.side_array->sav;
+               elem_type = side_ptr_get(enum_elem_type->u.side_array.elem_type);
+               array_item = side_ptr_get(side_ptr_get(item->u.side_static.side_array)->sav);
                nr_items = type_desc->u.side_array.length;
                break;
        case SIDE_TYPE_VLA:
-               elem_type = enum_elem_type->u.side_vla.elem_type;
-               array_item = item->u.side_static.side_vla->sav;
-               nr_items = item->u.side_static.side_vla->len;
+               elem_type = side_ptr_get(enum_elem_type->u.side_vla.elem_type);
+               array_item = side_ptr_get(side_ptr_get(item->u.side_static.side_vla)->sav);
+               nr_items = side_ptr_get(item->u.side_static.side_vla)->len;
                break;
        default:
                fprintf(stderr, "ERROR: Unexpected enum element type\n");
@@ -552,11 +552,11 @@ void tracer_print_enum_bitmap(const struct side_type *type_desc,
        }
        stride_bit = elem_type_to_stride(elem_type);
 
-       print_attributes("attr", ":", side_enum_mappings->attr, side_enum_mappings->nr_attr);
+       print_attributes("attr", ":", side_ptr_get(side_enum_mappings->attr), side_enum_mappings->nr_attr);
        printf("%s", side_enum_mappings->nr_attr ? ", " : "");
        printf("labels: [ ");
        for (i = 0; i < side_enum_mappings->nr_mappings; i++) {
-               const struct side_enum_bitmap_mapping *mapping = &side_enum_mappings->mappings[i];
+               const struct side_enum_bitmap_mapping *mapping = &side_ptr_get(side_enum_mappings->mappings)[i];
                bool match = false;
                uint64_t bit;
 
@@ -568,7 +568,7 @@ void tracer_print_enum_bitmap(const struct side_type *type_desc,
                for (bit = mapping->range_begin; bit <= mapping->range_end; bit++) {
                        if (bit > (nr_items * stride_bit) - 1)
                                break;
-                       if (elem_type->type == SIDE_TYPE_BYTE) {
+                       if (side_enum_get(elem_type->type) == SIDE_TYPE_BYTE) {
                                uint8_t v = array_item[bit / 8].u.side_static.byte_value;
                                if (v & (1ULL << (bit % 8))) {
                                        match = true;
@@ -589,7 +589,7 @@ void tracer_print_enum_bitmap(const struct side_type *type_desc,
 match:
                if (match) {
                        printf("%s", print_count++ ? ", " : "");
-                       tracer_print_string(mapping->label.p, mapping->label.unit_size, mapping->label.byte_order, NULL);
+                       tracer_print_string(side_ptr_get(mapping->label.p), mapping->label.unit_size, mapping->label.byte_order, NULL);
                }
        }
        if (!print_count)
@@ -676,7 +676,7 @@ void tracer_print_type_bool(const char *separator,
        v >>= offset_bits;
        if (len_bits < 64)
                v &= (1ULL << len_bits) - 1;
-       tracer_print_type_header(separator, type_bool->attr, type_bool->nr_attr);
+       tracer_print_type_header(separator, side_ptr_get(type_bool->attr), type_bool->nr_attr);
        printf("%s", v ? "true" : "false");
 }
 
@@ -692,8 +692,8 @@ void tracer_print_type_integer(const char *separator,
        uint16_t len_bits;
 
        v64 = tracer_load_integer_value(type_integer, value, offset_bits, &len_bits);
-       tracer_print_type_header(separator, type_integer->attr, type_integer->nr_attr);
-       base = get_attr_display_base(type_integer->attr, type_integer->nr_attr, default_base);
+       tracer_print_type_header(separator, side_ptr_get(type_integer->attr), type_integer->nr_attr);
+       base = get_attr_display_base(side_ptr_get(type_integer->attr), type_integer->nr_attr, default_base);
        switch (base) {
        case TRACER_DISPLAY_BASE_2:
                print_integer_binary(v64.u, len_bits);
@@ -728,7 +728,7 @@ void tracer_print_type_float(const char *separator,
 {
        bool reverse_bo;
 
-       tracer_print_type_header(separator, type_float->attr, type_float->nr_attr);
+       tracer_print_type_header(separator, side_ptr_get(type_float->attr), type_float->nr_attr);
        reverse_bo = type_float->byte_order != SIDE_TYPE_FLOAT_WORD_ORDER_HOST;
        switch (type_float->float_size) {
        case 2:
@@ -818,9 +818,9 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
 {
        enum side_type_label type;
 
-       switch (type_desc->type) {
+       switch (side_enum_get(type_desc->type)) {
        case SIDE_TYPE_ENUM:
-               switch (item->type) {
+               switch (side_enum_get(item->type)) {
                case SIDE_TYPE_U8:
                case SIDE_TYPE_U16:
                case SIDE_TYPE_U32:
@@ -838,7 +838,7 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
                break;
 
        case SIDE_TYPE_ENUM_BITMAP:
-               switch (item->type) {
+               switch (side_enum_get(item->type)) {
                case SIDE_TYPE_U8:
                case SIDE_TYPE_BYTE:
                case SIDE_TYPE_U16:
@@ -855,7 +855,7 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
                break;
 
        case SIDE_TYPE_GATHER_ENUM:
-               switch (item->type) {
+               switch (side_enum_get(item->type)) {
                case SIDE_TYPE_GATHER_INTEGER:
                        break;
                default:
@@ -866,7 +866,7 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
                break;
 
        case SIDE_TYPE_DYNAMIC:
-               switch (item->type) {
+               switch (side_enum_get(item->type)) {
                case SIDE_TYPE_DYNAMIC_NULL:
                case SIDE_TYPE_DYNAMIC_BOOL:
                case SIDE_TYPE_DYNAMIC_INTEGER:
@@ -887,24 +887,24 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
                break;
 
        default:
-               if (type_desc->type != item->type) {
+               if (side_enum_get(type_desc->type) != side_enum_get(item->type)) {
                        fprintf(stderr, "ERROR: type mismatch between description and arguments\n");
                        abort();
                }
                break;
        }
 
-       if (type_desc->type == SIDE_TYPE_ENUM || type_desc->type == SIDE_TYPE_ENUM_BITMAP ||
-                       type_desc->type == SIDE_TYPE_GATHER_ENUM)
-               type = (enum side_type_label) type_desc->type;
+       if (side_enum_get(type_desc->type) == SIDE_TYPE_ENUM || side_enum_get(type_desc->type) == SIDE_TYPE_ENUM_BITMAP || side_enum_get(type_desc->type) == SIDE_TYPE_GATHER_ENUM)
+               type = side_enum_get(type_desc->type);
        else
-               type = (enum side_type_label) item->type;
+               type = side_enum_get(item->type);
 
        printf("{ ");
        switch (type) {
                /* Stack-copy basic types */
        case SIDE_TYPE_NULL:
-               tracer_print_type_header(":", type_desc->u.side_null.attr, type_desc->u.side_null.nr_attr);
+               tracer_print_type_header(":", side_ptr_get(type_desc->u.side_null.attr),
+                       type_desc->u.side_null.nr_attr);
                printf("<NULL TYPE>");
                break;
 
@@ -925,7 +925,7 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
                break;
 
        case SIDE_TYPE_BYTE:
-               tracer_print_type_header(":", type_desc->u.side_byte.attr, type_desc->u.side_byte.nr_attr);
+               tracer_print_type_header(":", side_ptr_get(type_desc->u.side_byte.attr), type_desc->u.side_byte.nr_attr);
                printf("0x%" PRIx8, item->u.side_static.byte_value);
                break;
 
@@ -944,23 +944,23 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
        case SIDE_TYPE_STRING_UTF8:
        case SIDE_TYPE_STRING_UTF16:
        case SIDE_TYPE_STRING_UTF32:
-               tracer_print_type_header(":", type_desc->u.side_string.attr, type_desc->u.side_string.nr_attr);
-               tracer_print_string((const void *)(uintptr_t) item->u.side_static.string_value,
+               tracer_print_type_header(":", side_ptr_get(type_desc->u.side_string.attr), type_desc->u.side_string.nr_attr);
+               tracer_print_string(side_ptr_get(item->u.side_static.string_value),
                                type_desc->u.side_string.unit_size, type_desc->u.side_string.byte_order, NULL);
                break;
 
                /* Stack-copy compound types */
        case SIDE_TYPE_STRUCT:
-               tracer_print_struct(type_desc, item->u.side_static.side_struct);
+               tracer_print_struct(type_desc, side_ptr_get(item->u.side_static.side_struct));
                break;
        case SIDE_TYPE_VARIANT:
-               tracer_print_variant(type_desc, item->u.side_static.side_variant);
+               tracer_print_variant(type_desc, side_ptr_get(item->u.side_static.side_variant));
                break;
        case SIDE_TYPE_ARRAY:
-               tracer_print_array(type_desc, item->u.side_static.side_array);
+               tracer_print_array(type_desc, side_ptr_get(item->u.side_static.side_array));
                break;
        case SIDE_TYPE_VLA:
-               tracer_print_vla(type_desc, item->u.side_static.side_vla);
+               tracer_print_vla(type_desc, side_ptr_get(item->u.side_static.side_vla));
                break;
        case SIDE_TYPE_VLA_VISITOR:
                tracer_print_vla_visitor(type_desc, item->u.side_static.side_vla_app_visitor_ctx);
@@ -976,41 +976,41 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
 
                /* Gather basic types */
        case SIDE_TYPE_GATHER_BOOL:
-               (void) tracer_print_gather_bool_type(&type_desc->u.side_gather, item->u.side_static.side_bool_gather_ptr);
+               (void) tracer_print_gather_bool_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_bool_gather_ptr));
                break;
        case SIDE_TYPE_GATHER_INTEGER:
-               (void) tracer_print_gather_integer_type(&type_desc->u.side_gather, item->u.side_static.side_integer_gather_ptr,
+               (void) tracer_print_gather_integer_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_integer_gather_ptr),
                                        TRACER_DISPLAY_BASE_10);
                break;
        case SIDE_TYPE_GATHER_BYTE:
-               (void) tracer_print_gather_byte_type(&type_desc->u.side_gather, item->u.side_static.side_byte_gather_ptr);
+               (void) tracer_print_gather_byte_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_byte_gather_ptr));
                break;
        case SIDE_TYPE_GATHER_POINTER:
-               (void) tracer_print_gather_integer_type(&type_desc->u.side_gather, item->u.side_static.side_integer_gather_ptr,
+               (void) tracer_print_gather_integer_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_integer_gather_ptr),
                                        TRACER_DISPLAY_BASE_16);
                break;
        case SIDE_TYPE_GATHER_FLOAT:
-               (void) tracer_print_gather_float_type(&type_desc->u.side_gather, item->u.side_static.side_float_gather_ptr);
+               (void) tracer_print_gather_float_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_float_gather_ptr));
                break;
        case SIDE_TYPE_GATHER_STRING:
-               (void) tracer_print_gather_string_type(&type_desc->u.side_gather, item->u.side_static.side_string_gather_ptr);
+               (void) tracer_print_gather_string_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_string_gather_ptr));
                break;
 
                /* Gather compound type */
        case SIDE_TYPE_GATHER_STRUCT:
-               (void) tracer_print_gather_struct(&type_desc->u.side_gather, item->u.side_static.side_struct_gather_ptr);
+               (void) tracer_print_gather_struct(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_struct_gather_ptr));
                break;
        case SIDE_TYPE_GATHER_ARRAY:
-               (void) tracer_print_gather_array(&type_desc->u.side_gather, item->u.side_static.side_array_gather_ptr);
+               (void) tracer_print_gather_array(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_array_gather_ptr));
                break;
        case SIDE_TYPE_GATHER_VLA:
-               (void) tracer_print_gather_vla(&type_desc->u.side_gather, item->u.side_static.side_vla_gather.ptr,
-                               item->u.side_static.side_vla_gather.length_ptr);
+               (void) tracer_print_gather_vla(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_vla_gather.ptr),
+                               side_ptr_get(item->u.side_static.side_vla_gather.length_ptr));
                break;
 
                /* Gather enumeration types */
        case SIDE_TYPE_GATHER_ENUM:
-               (void) tracer_print_gather_enum_type(&type_desc->u.side_gather, item->u.side_static.side_integer_gather_ptr);
+               (void) tracer_print_gather_enum_type(&type_desc->u.side_gather, side_ptr_get(item->u.side_static.side_integer_gather_ptr));
                break;
 
        /* Dynamic basic types */
@@ -1039,26 +1039,27 @@ void tracer_print_type(const struct side_type *type_desc, const struct side_arg
 static
 void tracer_print_field(const struct side_event_field *item_desc, const struct side_arg *item)
 {
-       printf("%s: ", item_desc->field_name);
+       printf("%s: ", side_ptr_get(item_desc->field_name));
        tracer_print_type(&item_desc->side_type, item);
 }
 
 static
 void tracer_print_struct(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec)
 {
-       const struct side_arg *sav = side_arg_vec->sav;
+       const struct side_arg *sav = side_ptr_get(side_arg_vec->sav);
+       const struct side_type_struct *side_struct = side_ptr_get(type_desc->u.side_struct);
        uint32_t i, side_sav_len = side_arg_vec->len;
 
-       if (type_desc->u.side_struct->nr_fields != side_sav_len) {
+       if (side_struct->nr_fields != side_sav_len) {
                fprintf(stderr, "ERROR: number of fields mismatch between description and arguments of structure\n");
                abort();
        }
-       print_attributes("attr", ":", type_desc->u.side_struct->attr, type_desc->u.side_struct->nr_attr);
-       printf("%s", type_desc->u.side_struct->nr_attr ? ", " : "");
+       print_attributes("attr", ":", side_ptr_get(side_struct->attr), side_struct->nr_attr);
+       printf("%s", side_struct->nr_attr ? ", " : "");
        printf("fields: { ");
        for (i = 0; i < side_sav_len; i++) {
                printf("%s", i ? ", " : "");
-               tracer_print_field(&type_desc->u.side_struct->fields[i], &sav[i]);
+               tracer_print_field(&side_ptr_get(side_struct->fields)[i], &sav[i]);
        }
        printf(" }");
 }
@@ -1066,16 +1067,16 @@ void tracer_print_struct(const struct side_type *type_desc, const struct side_ar
 static
 void tracer_print_variant(const struct side_type *type_desc, const struct side_arg_variant *side_arg_variant)
 {
-       const struct side_type_variant *side_type_variant = type_desc->u.side_variant;
+       const struct side_type_variant *side_type_variant = side_ptr_get(type_desc->u.side_variant);
        const struct side_type *selector_type = &side_type_variant->selector;
        union int64_value v64;
        uint32_t i;
 
-       if (selector_type->type != side_arg_variant->selector.type) {
+       if (side_enum_get(selector_type->type) != side_enum_get(side_arg_variant->selector.type)) {
                fprintf(stderr, "ERROR: Unexpected variant selector type\n");
                abort();
        }
-       switch (selector_type->type) {
+       switch (side_enum_get(selector_type->type)) {
        case SIDE_TYPE_U8:
        case SIDE_TYPE_U16:
        case SIDE_TYPE_U32:
@@ -1092,7 +1093,7 @@ void tracer_print_variant(const struct side_type *type_desc, const struct side_a
        v64 = tracer_load_integer_value(&selector_type->u.side_integer,
                        &side_arg_variant->selector.u.side_static.integer_value, 0, NULL);
        for (i = 0; i < side_type_variant->nr_options; i++) {
-               const struct side_variant_option *option = &side_type_variant->options[i];
+               const struct side_variant_option *option = &side_ptr_get(side_type_variant->options)[i];
 
                if (v64.s >= option->range_begin && v64.s <= option->range_end) {
                        tracer_print_type(&option->side_type, &side_arg_variant->option);
@@ -1106,20 +1107,20 @@ void tracer_print_variant(const struct side_type *type_desc, const struct side_a
 static
 void tracer_print_array(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec)
 {
-       const struct side_arg *sav = side_arg_vec->sav;
+       const struct side_arg *sav = side_ptr_get(side_arg_vec->sav);
        uint32_t i, side_sav_len = side_arg_vec->len;
 
        if (type_desc->u.side_array.length != side_sav_len) {
                fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n");
                abort();
        }
-       print_attributes("attr", ":", type_desc->u.side_array.attr, type_desc->u.side_array.nr_attr);
+       print_attributes("attr", ":", side_ptr_get(type_desc->u.side_array.attr), type_desc->u.side_array.nr_attr);
        printf("%s", type_desc->u.side_array.nr_attr ? ", " : "");
        printf("elements: ");
        printf("[ ");
        for (i = 0; i < side_sav_len; i++) {
                printf("%s", i ? ", " : "");
-               tracer_print_type(type_desc->u.side_array.elem_type, &sav[i]);
+               tracer_print_type(side_ptr_get(type_desc->u.side_array.elem_type), &sav[i]);
        }
        printf(" ]");
 }
@@ -1127,16 +1128,16 @@ void tracer_print_array(const struct side_type *type_desc, const struct side_arg
 static
 void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_vec *side_arg_vec)
 {
-       const struct side_arg *sav = side_arg_vec->sav;
+       const struct side_arg *sav = side_ptr_get(side_arg_vec->sav);
        uint32_t i, side_sav_len = side_arg_vec->len;
 
-       print_attributes("attr", ":", type_desc->u.side_vla.attr, type_desc->u.side_vla.nr_attr);
+       print_attributes("attr", ":", side_ptr_get(type_desc->u.side_vla.attr), type_desc->u.side_vla.nr_attr);
        printf("%s", type_desc->u.side_vla.nr_attr ? ", " : "");
        printf("elements: ");
        printf("[ ");
        for (i = 0; i < side_sav_len; i++) {
                printf("%s", i ? ", " : "");
-               tracer_print_type(type_desc->u.side_vla.elem_type, &sav[i]);
+               tracer_print_type(side_ptr_get(type_desc->u.side_vla.elem_type), &sav[i]);
        }
        printf(" ]");
 }
@@ -1149,7 +1150,7 @@ const char *tracer_gather_access(enum side_type_gather_access_mode access_mode,
                return ptr;
        case SIDE_TYPE_GATHER_ACCESS_POINTER:
                /* Dereference pointer */
-               memcpy(&ptr, ptr, sizeof(ptr));
+               memcpy(&ptr, ptr, sizeof(const char *));
                return ptr;
        default:
                abort();
@@ -1220,7 +1221,7 @@ uint32_t tracer_print_gather_byte_type(const struct side_type_gather *type_gathe
 
        ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_byte.offset);
        memcpy(&value, ptr, 1);
-       tracer_print_type_header(":", type_gather->u.side_byte.type.attr,
+       tracer_print_type_header(":", side_ptr_get(type_gather->u.side_byte.type.attr),
                        type_gather->u.side_byte.type.nr_attr);
        printf("0x%" PRIx8, value);
        return tracer_gather_size(access_mode, 1);
@@ -1285,7 +1286,7 @@ uint32_t tracer_print_gather_string_type(const struct side_type_gather *type_gat
        size_t string_len;
 
        ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_string.offset);
-       tracer_print_type_header(":", type_gather->u.side_string.type.attr,
+       tracer_print_type_header(":", side_ptr_get(type_gather->u.side_string.type.attr),
                        type_gather->u.side_string.type.nr_attr);
        if (ptr) {
                tracer_print_string(ptr, type_gather->u.side_string.type.unit_size,
@@ -1303,7 +1304,7 @@ uint32_t tracer_print_gather_type(const struct side_type *type_desc, const void
        uint32_t len;
 
        printf("{ ");
-       switch (type_desc->type) {
+       switch (side_enum_get(type_desc->type)) {
                /* Gather basic types */
        case SIDE_TYPE_GATHER_BOOL:
                len = tracer_print_gather_bool_type(&type_desc->u.side_gather, ptr);
@@ -1352,8 +1353,8 @@ uint32_t tracer_print_gather_type(const struct side_type *type_desc, const void
 static
 uint32_t tracer_print_gather_enum_type(const struct side_type_gather *type_gather, const void *_ptr)
 {
-       const struct side_enum_mappings *mappings = type_gather->u.side_enum.mappings;
-       const struct side_type *enum_elem_type = type_gather->u.side_enum.elem_type;
+       const struct side_enum_mappings *mappings = side_ptr_get(type_gather->u.side_enum.mappings);
+       const struct side_type *enum_elem_type = side_ptr_get(type_gather->u.side_enum.elem_type);
        const struct side_type_gather_integer *side_integer = &enum_elem_type->u.side_gather.u.side_integer;
        enum side_type_gather_access_mode access_mode =
                (enum side_type_gather_access_mode) side_integer->access_mode;
@@ -1374,7 +1375,7 @@ uint32_t tracer_print_gather_enum_type(const struct side_type_gather *type_gathe
        ptr = tracer_gather_access(access_mode, ptr + side_integer->offset);
        memcpy(&value, ptr, integer_size_bytes);
        v64 = tracer_load_gather_integer_value(side_integer, &value);
-       print_attributes("attr", ":", mappings->attr, mappings->nr_attr);
+       print_attributes("attr", ":", side_ptr_get(mappings->attr), mappings->nr_attr);
        printf("%s", mappings->nr_attr ? ", " : "");
        tracer_print_gather_type(enum_elem_type, ptr);
        print_enum_labels(mappings, v64);
@@ -1384,7 +1385,7 @@ uint32_t tracer_print_gather_enum_type(const struct side_type_gather *type_gathe
 static
 void tracer_print_gather_field(const struct side_event_field *field, const void *ptr)
 {
-       printf("%s: ", field->field_name);
+       printf("%s: ", side_ptr_get(field->field_name));
        (void) tracer_print_gather_type(&field->side_type, ptr);
 }
 
@@ -1393,16 +1394,17 @@ uint32_t tracer_print_gather_struct(const struct side_type_gather *type_gather,
 {
        enum side_type_gather_access_mode access_mode =
                (enum side_type_gather_access_mode) type_gather->u.side_struct.access_mode;
+       const struct side_type_struct *side_struct = side_ptr_get(type_gather->u.side_struct.type);
        const char *ptr = (const char *) _ptr;
        uint32_t i;
 
        ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_struct.offset);
-       print_attributes("attr", ":", type_gather->u.side_struct.type->attr, type_gather->u.side_struct.type->nr_attr);
-       printf("%s", type_gather->u.side_struct.type->nr_attr ? ", " : "");
+       print_attributes("attr", ":", side_ptr_get(side_struct->attr), side_struct->nr_attr);
+       printf("%s", side_struct->nr_attr ? ", " : "");
        printf("fields: { ");
-       for (i = 0; i < type_gather->u.side_struct.type->nr_fields; i++) {
+       for (i = 0; i < side_struct->nr_fields; i++) {
                printf("%s", i ? ", " : "");
-               tracer_print_gather_field(&type_gather->u.side_struct.type->fields[i], ptr);
+               tracer_print_gather_field(&side_ptr_get(side_struct->fields)[i], ptr);
        }
        printf(" }");
        return tracer_gather_size(access_mode, type_gather->u.side_struct.size);
@@ -1418,12 +1420,14 @@ uint32_t tracer_print_gather_array(const struct side_type_gather *type_gather, c
 
        ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_array.offset);
        orig_ptr = ptr;
-       print_attributes("attr", ":", type_gather->u.side_array.type.attr, type_gather->u.side_array.type.nr_attr);
+       print_attributes("attr", ":", side_ptr_get(type_gather->u.side_array.type.attr), type_gather->u.side_array.type.nr_attr);
        printf("%s", type_gather->u.side_array.type.nr_attr ? ", " : "");
        printf("elements: ");
        printf("[ ");
        for (i = 0; i < type_gather->u.side_array.type.length; i++) {
-               switch (type_gather->u.side_array.type.elem_type->type) {
+               const struct side_type *elem_type = side_ptr_get(type_gather->u.side_array.type.elem_type);
+
+               switch (side_enum_get(elem_type->type)) {
                case SIDE_TYPE_GATHER_VLA:
                        fprintf(stderr, "<gather VLA only supported within gather structures>\n");
                        abort();
@@ -1431,7 +1435,7 @@ uint32_t tracer_print_gather_array(const struct side_type_gather *type_gather, c
                        break;
                }
                printf("%s", i ? ", " : "");
-               ptr += tracer_print_gather_type(type_gather->u.side_array.type.elem_type, ptr);
+               ptr += tracer_print_gather_type(elem_type, ptr);
        }
        printf(" ]");
        return tracer_gather_size(access_mode, ptr - orig_ptr);
@@ -1443,30 +1447,33 @@ uint32_t tracer_print_gather_vla(const struct side_type_gather *type_gather, con
 {
        enum side_type_gather_access_mode access_mode =
                (enum side_type_gather_access_mode) type_gather->u.side_vla.access_mode;
+       const struct side_type *length_type = side_ptr_get(type_gather->u.side_vla.length_type);
        const char *ptr = (const char *) _ptr, *orig_ptr;
        const char *length_ptr = (const char *) _length_ptr;
        union int64_value v64;
        uint32_t i, length;
 
        /* Access length */
-       switch (type_gather->u.side_vla.length_type->type) {
+       switch (side_enum_get(length_type->type)) {
        case SIDE_TYPE_GATHER_INTEGER:
                break;
        default:
                fprintf(stderr, "<gather VLA expects integer gather length type>\n");
                abort();
        }
-       v64 = tracer_load_gather_integer_value(&type_gather->u.side_vla.length_type->u.side_gather.u.side_integer,
+       v64 = tracer_load_gather_integer_value(&length_type->u.side_gather.u.side_integer,
                                        length_ptr);
        length = (uint32_t) v64.u;
        ptr = tracer_gather_access(access_mode, ptr + type_gather->u.side_vla.offset);
        orig_ptr = ptr;
-       print_attributes("attr", ":", type_gather->u.side_vla.type.attr, type_gather->u.side_vla.type.nr_attr);
+       print_attributes("attr", ":", side_ptr_get(type_gather->u.side_vla.type.attr), type_gather->u.side_vla.type.nr_attr);
        printf("%s", type_gather->u.side_vla.type.nr_attr ? ", " : "");
        printf("elements: ");
        printf("[ ");
        for (i = 0; i < length; i++) {
-               switch (type_gather->u.side_vla.type.elem_type->type) {
+               const struct side_type *elem_type = side_ptr_get(type_gather->u.side_vla.type.elem_type);
+
+               switch (side_enum_get(elem_type->type)) {
                case SIDE_TYPE_GATHER_VLA:
                        fprintf(stderr, "<gather VLA only supported within gather structures>\n");
                        abort();
@@ -1474,7 +1481,7 @@ uint32_t tracer_print_gather_vla(const struct side_type_gather *type_gather, con
                        break;
                }
                printf("%s", i ? ", " : "");
-               ptr += tracer_print_gather_type(type_gather->u.side_vla.type.elem_type, ptr);
+               ptr += tracer_print_gather_type(elem_type, ptr);
        }
        printf(" ]");
        return tracer_gather_size(access_mode, ptr - orig_ptr);
@@ -1501,7 +1508,7 @@ void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx)
 {
        enum side_visitor_status status;
        struct tracer_visitor_priv tracer_priv = {
-               .elem_type = type_desc->u.side_vla_visitor.elem_type,
+               .elem_type = side_ptr_get(type_desc->u.side_vla_visitor.elem_type),
                .i = 0,
        };
        const struct side_tracer_visitor_ctx tracer_ctx = {
@@ -1509,7 +1516,7 @@ void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx)
                .priv = &tracer_priv,
        };
 
-       print_attributes("attr", ":", type_desc->u.side_vla_visitor.attr, type_desc->u.side_vla_visitor.nr_attr);
+       print_attributes("attr", ":", side_ptr_get(type_desc->u.side_vla_visitor.attr), type_desc->u.side_vla_visitor.nr_attr);
        printf("%s", type_desc->u.side_vla_visitor.nr_attr ? ", " : "");
        printf("elements: ");
        printf("[ ");
@@ -1527,16 +1534,16 @@ void tracer_print_vla_visitor(const struct side_type *type_desc, void *app_ctx)
 static
 void tracer_print_dynamic_struct(const struct side_arg_dynamic_struct *dynamic_struct)
 {
-       const struct side_arg_dynamic_field *fields = dynamic_struct->fields;
+       const struct side_arg_dynamic_field *fields = side_ptr_get(dynamic_struct->fields);
        uint32_t i, len = dynamic_struct->len;
 
-       print_attributes("attr", "::", dynamic_struct->attr, dynamic_struct->nr_attr);
+       print_attributes("attr", "::", side_ptr_get(dynamic_struct->attr), dynamic_struct->nr_attr);
        printf("%s", dynamic_struct->nr_attr ? ", " : "");
        printf("fields:: ");
        printf("[ ");
        for (i = 0; i < len; i++) {
                printf("%s", i ? ", " : "");
-               printf("%s:: ", fields[i].field_name);
+               printf("%s:: ", side_ptr_get(fields[i].field_name));
                tracer_print_dynamic(&fields[i].elem);
        }
        printf(" ]");
@@ -1555,7 +1562,7 @@ enum side_visitor_status tracer_dynamic_struct_write_elem_cb(
                (struct tracer_dynamic_struct_visitor_priv *) tracer_ctx->priv;
 
        printf("%s", tracer_priv->i++ ? ", " : "");
-       printf("%s:: ", dynamic_field->field_name);
+       printf("%s:: ", side_ptr_get(dynamic_field->field_name));
        tracer_print_dynamic(&dynamic_field->elem);
        return SIDE_VISITOR_STATUS_OK;
 }
@@ -1573,7 +1580,7 @@ void tracer_print_dynamic_struct_visitor(const struct side_arg *item)
        };
        void *app_ctx = item->u.side_dynamic.side_dynamic_struct_visitor.app_ctx;
 
-       print_attributes("attr", "::", item->u.side_dynamic.side_dynamic_struct_visitor.attr, item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr);
+       print_attributes("attr", "::", side_ptr_get(item->u.side_dynamic.side_dynamic_struct_visitor.attr), item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr);
        printf("%s", item->u.side_dynamic.side_dynamic_struct_visitor.nr_attr ? ", " : "");
        printf("fields:: ");
        printf("[ ");
@@ -1591,10 +1598,10 @@ void tracer_print_dynamic_struct_visitor(const struct side_arg *item)
 static
 void tracer_print_dynamic_vla(const struct side_arg_dynamic_vla *vla)
 {
-       const struct side_arg *sav = vla->sav;
+       const struct side_arg *sav = side_ptr_get(vla->sav);
        uint32_t i, side_sav_len = vla->len;
 
-       print_attributes("attr", "::", vla->attr, vla->nr_attr);
+       print_attributes("attr", "::", side_ptr_get(vla->attr), vla->nr_attr);
        printf("%s", vla->nr_attr ? ", " : "");
        printf("elements:: ");
        printf("[ ");
@@ -1635,7 +1642,7 @@ void tracer_print_dynamic_vla_visitor(const struct side_arg *item)
        };
        void *app_ctx = item->u.side_dynamic.side_dynamic_vla_visitor.app_ctx;
 
-       print_attributes("attr", "::", item->u.side_dynamic.side_dynamic_vla_visitor.attr, item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr);
+       print_attributes("attr", "::", side_ptr_get(item->u.side_dynamic.side_dynamic_vla_visitor.attr), item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr);
        printf("%s", item->u.side_dynamic.side_dynamic_vla_visitor.nr_attr ? ", " : "");
        printf("elements:: ");
        printf("[ ");
@@ -1654,10 +1661,11 @@ static
 void tracer_print_dynamic(const struct side_arg *item)
 {
        printf("{ ");
-       switch (item->type) {
+       switch (side_enum_get(item->type)) {
                /* Dynamic basic types */
        case SIDE_TYPE_DYNAMIC_NULL:
-               tracer_print_type_header("::", item->u.side_dynamic.side_null.attr, item->u.side_dynamic.side_null.nr_attr);
+               tracer_print_type_header("::", side_ptr_get(item->u.side_dynamic.side_null.attr),
+                       item->u.side_dynamic.side_null.nr_attr);
                printf("<NULL TYPE>");
                break;
        case SIDE_TYPE_DYNAMIC_BOOL:
@@ -1668,7 +1676,7 @@ void tracer_print_dynamic(const struct side_arg *item)
                                TRACER_DISPLAY_BASE_10);
                break;
        case SIDE_TYPE_DYNAMIC_BYTE:
-               tracer_print_type_header("::", item->u.side_dynamic.side_byte.type.attr, item->u.side_dynamic.side_byte.type.nr_attr);
+               tracer_print_type_header("::", side_ptr_get(item->u.side_dynamic.side_byte.type.attr), item->u.side_dynamic.side_byte.type.nr_attr);
                printf("0x%" PRIx8, item->u.side_dynamic.side_byte.value);
                break;
        case SIDE_TYPE_DYNAMIC_POINTER:
@@ -1680,7 +1688,7 @@ void tracer_print_dynamic(const struct side_arg *item)
                                        &item->u.side_dynamic.side_float.value);
                break;
        case SIDE_TYPE_DYNAMIC_STRING:
-               tracer_print_type_header("::", item->u.side_dynamic.side_string.type.attr, item->u.side_dynamic.side_string.type.nr_attr);
+               tracer_print_type_header("::", side_ptr_get(item->u.side_dynamic.side_string.type.attr), item->u.side_dynamic.side_string.type.nr_attr);
                tracer_print_string((const char *)(uintptr_t) item->u.side_dynamic.side_string.value,
                                item->u.side_dynamic.side_string.type.unit_size,
                                item->u.side_dynamic.side_string.type.byte_order, NULL);
@@ -1688,13 +1696,13 @@ void tracer_print_dynamic(const struct side_arg *item)
 
                /* Dynamic compound types */
        case SIDE_TYPE_DYNAMIC_STRUCT:
-               tracer_print_dynamic_struct(item->u.side_dynamic.side_dynamic_struct);
+               tracer_print_dynamic_struct(side_ptr_get(item->u.side_dynamic.side_dynamic_struct));
                break;
        case SIDE_TYPE_DYNAMIC_STRUCT_VISITOR:
                tracer_print_dynamic_struct_visitor(item);
                break;
        case SIDE_TYPE_DYNAMIC_VLA:
-               tracer_print_dynamic_vla(item->u.side_dynamic.side_dynamic_vla);
+               tracer_print_dynamic_vla(side_ptr_get(item->u.side_dynamic.side_dynamic_vla));
                break;
        case SIDE_TYPE_DYNAMIC_VLA_VISITOR:
                tracer_print_dynamic_vla_visitor(item);
@@ -1711,19 +1719,19 @@ void tracer_print_static_fields(const struct side_event_description *desc,
                const struct side_arg_vec *side_arg_vec,
                uint32_t *nr_items)
 {
-       const struct side_arg *sav = side_arg_vec->sav;
+       const struct side_arg *sav = side_ptr_get(side_arg_vec->sav);
        uint32_t i, side_sav_len = side_arg_vec->len;
 
-       printf("provider: %s, event: %s", desc->provider_name, desc->event_name);
+       printf("provider: %s, event: %s", side_ptr_get(desc->provider_name), side_ptr_get(desc->event_name));
        if (desc->nr_fields != side_sav_len) {
                fprintf(stderr, "ERROR: number of fields mismatch between description and arguments\n");
                abort();
        }
-       print_attributes(", attr", ":", desc->attr, desc->nr_attr);
+       print_attributes(", attr", ":", side_ptr_get(desc->attr), desc->nr_attr);
        printf("%s", side_sav_len ? ", fields: [ " : "");
        for (i = 0; i < side_sav_len; i++) {
                printf("%s", i ? ", " : "");
-               tracer_print_field(&desc->fields[i], &sav[i]);
+               tracer_print_field(&side_ptr_get(desc->fields)[i], &sav[i]);
        }
        if (nr_items)
                *nr_items = i;
@@ -1756,12 +1764,12 @@ void tracer_call_variadic(const struct side_event_description *desc,
                fprintf(stderr, "ERROR: unexpected non-variadic event description\n");
                abort();
        }
-       print_attributes(", attr ", "::", var_struct->attr, var_struct->nr_attr);
+       print_attributes(", attr ", "::", side_ptr_get(var_struct->attr), var_struct->nr_attr);
        printf("%s", var_struct_len ? ", fields:: [ " : "");
        for (i = 0; i < var_struct_len; i++, nr_fields++) {
                printf("%s", i ? ", " : "");
-               printf("%s:: ", var_struct->fields[i].field_name);
-               tracer_print_dynamic(&var_struct->fields[i].elem);
+               printf("%s:: ", side_ptr_get(side_ptr_get(var_struct->fields)[i].field_name));
+               tracer_print_dynamic(&side_ptr_get(var_struct->fields)[i].elem);
        }
        if (i)
                printf(" ]");
@@ -1786,8 +1794,8 @@ void tracer_event_notification(enum side_tracer_notification notif,
                if (!event)
                        continue;
                printf("provider: %s, event: %s\n",
-                       event->provider_name, event->event_name);
-               if  (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) {
+                       side_ptr_get(event->provider_name), side_ptr_get(event->event_name));
+               if (notif == SIDE_TRACER_NOTIFICATION_INSERT_EVENTS) {
                        if (event->flags & SIDE_EVENT_FLAG_VARIADIC) {
                                ret = side_tracer_callback_variadic_register(event, tracer_call_variadic, NULL);
                                if (ret)
This page took 0.036805 seconds and 4 git commands to generate.