From: Mathieu Desnoyers Date: Thu, 21 Sep 2023 09:20:41 +0000 (+0100) Subject: trace.h: Use side_ptr_t for additional fields X-Git-Url: http://git.efficios.com/?p=libside.git;a=commitdiff_plain;h=c57892858fed2c8020c0271e0ce44f38514545ff trace.h: Use side_ptr_t for additional fields Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/trace.h b/include/side/trace.h index 210cb3f..42aba08 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -350,27 +350,27 @@ struct side_enum_bitmap_mappings { } SIDE_PACKED; struct side_type_struct { - const struct side_event_field *fields; + side_ptr_t(const struct side_event_field) fields; side_ptr_t(const struct side_attr) attr; uint32_t nr_fields; uint32_t nr_attr; } SIDE_PACKED; struct side_type_array { - const struct side_type *elem_type; + side_ptr_t(const struct side_type) elem_type; side_ptr_t(const struct side_attr) attr; uint32_t length; uint32_t nr_attr; } SIDE_PACKED; struct side_type_vla { - const struct side_type *elem_type; + side_ptr_t(const struct side_type) elem_type; side_ptr_t(const struct side_attr) attr; uint32_t nr_attr; } SIDE_PACKED; struct side_type_vla_visitor { - const struct side_type *elem_type; + side_ptr_t(const struct side_type) elem_type; side_visitor_func visitor; side_ptr_t(const struct side_attr) attr; uint32_t nr_attr; @@ -378,12 +378,12 @@ struct side_type_vla_visitor { struct side_type_enum { side_ptr_t(const struct side_enum_mappings) mappings; - const struct side_type *elem_type; + side_ptr_t(const struct side_type) elem_type; } SIDE_PACKED; struct side_type_enum_bitmap { side_ptr_t(const struct side_enum_bitmap_mappings) mappings; - const struct side_type *elem_type; + side_ptr_t(const struct side_type) elem_type; } SIDE_PACKED; struct side_type_gather_bool { @@ -420,13 +420,13 @@ struct side_type_gather_string { struct side_type_gather_enum { side_ptr_t(const struct side_enum_mappings) mappings; - const struct side_type *elem_type; + side_ptr_t(const struct side_type) elem_type; } SIDE_PACKED; struct side_type_gather_struct { uint64_t offset; /* bytes */ uint8_t access_mode; /* enum side_type_gather_access_mode */ - const struct side_type_struct *type; + side_ptr_t(const struct side_type_struct) type; uint32_t size; /* bytes */ } SIDE_PACKED; @@ -437,7 +437,7 @@ struct side_type_gather_array { } SIDE_PACKED; struct side_type_gather_vla { - const struct side_type *length_type; /* side_length() */ + side_ptr_t(const struct side_type) length_type; /* side_length() */ uint64_t offset; /* bytes */ uint8_t access_mode; /* enum side_type_gather_access_mode */ @@ -473,8 +473,8 @@ struct side_type { struct side_type_array side_array; struct side_type_vla side_vla; struct side_type_vla_visitor side_vla_visitor; - const struct side_type_struct *side_struct; - const struct side_type_variant *side_variant; + side_ptr_t(const struct side_type_struct) side_struct; + side_ptr_t(const struct side_type_variant) side_variant; /* Stack-copy enumeration types */ struct side_type_enum side_enum; @@ -493,14 +493,14 @@ struct side_variant_option { struct side_type_variant { const struct side_type selector; - const struct side_variant_option *options; + side_ptr_t(const struct side_variant_option) options; side_ptr_t(const struct side_attr) attr; uint32_t nr_options; uint32_t nr_attr; } SIDE_PACKED; struct side_event_field { - const char *field_name; + side_ptr_t(const char) field_name; struct side_type side_type; } SIDE_PACKED; @@ -873,7 +873,7 @@ struct side_event_description { #define _side_field(_name, _type) \ { \ - .field_name = _name, \ + .field_name = SIDE_PTR_INIT(_name), \ .side_type = _type, \ } @@ -990,7 +990,7 @@ struct side_event_description { .u = { \ .side_enum = { \ .mappings = SIDE_PTR_INIT(_mappings), \ - .elem_type = _elem_type, \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ }, \ }, \ } @@ -1003,7 +1003,7 @@ struct side_event_description { .u = { \ .side_enum_bitmap = { \ .mappings = SIDE_PTR_INIT(_mappings), \ - .elem_type = _elem_type, \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ }, \ }, \ } @@ -1014,7 +1014,7 @@ struct side_event_description { { \ .type = SIDE_TYPE_STRUCT, \ .u = { \ - .side_struct = _struct, \ + .side_struct = SIDE_PTR_INIT(_struct), \ }, \ } #define side_field_struct(_name, _struct) \ @@ -1022,7 +1022,7 @@ struct side_event_description { #define _side_type_struct_define(_fields, _attr) \ { \ - .fields = _fields, \ + .fields = SIDE_PTR_INIT(_fields), \ .attr = SIDE_PTR_INIT(_attr), \ .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ @@ -1039,7 +1039,7 @@ struct side_event_description { { \ .type = SIDE_TYPE_VARIANT, \ .u = { \ - .side_variant = _variant, \ + .side_variant = SIDE_PTR_INIT(_variant), \ }, \ } #define side_field_variant(_name, _variant) \ @@ -1048,7 +1048,7 @@ struct side_event_description { #define _side_type_variant_define(_selector, _options, _attr) \ { \ .selector = _selector, \ - .options = _options, \ + .options = SIDE_PTR_INIT(_options), \ .attr = SIDE_PTR_INIT(_attr), \ .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ @@ -1067,7 +1067,7 @@ struct side_event_description { .type = SIDE_TYPE_ARRAY, \ .u = { \ .side_array = { \ - .elem_type = _elem_type, \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .length = _length, \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -1082,7 +1082,7 @@ struct side_event_description { .type = SIDE_TYPE_VLA, \ .u = { \ .side_vla = { \ - .elem_type = _elem_type, \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ @@ -1096,7 +1096,7 @@ struct side_event_description { .type = SIDE_TYPE_VLA_VISITOR, \ .u = { \ .side_vla_visitor = { \ - .elem_type = SIDE_PARAM(_elem_type), \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ .visitor = _visitor, \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -1338,7 +1338,7 @@ struct side_event_description { .u = { \ .side_enum = { \ .mappings = SIDE_PTR_INIT(_mappings), \ - .elem_type = _elem_type, \ + .elem_type = SIDE_PTR_INIT(_elem_type), \ }, \ }, \ } @@ -1354,7 +1354,7 @@ struct side_event_description { .side_struct = { \ .offset = _offset, \ .access_mode = _access_mode, \ - .type = _struct_gather, \ + .type = SIDE_PTR_INIT(_struct_gather), \ .size = _size, \ }, \ }, \ @@ -1374,7 +1374,7 @@ struct side_event_description { .offset = _offset, \ .access_mode = _access_mode, \ .type = { \ - .elem_type = _elem_type_gather, \ + .elem_type = SIDE_PTR_INIT(_elem_type_gather), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .length = _length, \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ @@ -1394,11 +1394,11 @@ struct side_event_description { .side_gather = { \ .u = { \ .side_vla = { \ - .length_type = _length_type_gather, \ + .length_type = SIDE_PTR_INIT(_length_type_gather), \ .offset = _offset, \ .access_mode = _access_mode, \ .type = { \ - .elem_type = _elem_type_gather, \ + .elem_type = SIDE_PTR_INIT(_elem_type_gather), \ .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \ }, \ diff --git a/src/tracer.c b/src/tracer.c index 170c611..fe09d7b 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -472,7 +472,7 @@ static void tracer_print_enum(const struct side_type *type_desc, const struct side_arg *item) { const struct side_enum_mappings *mappings = side_ptr_get(type_desc->u.side_enum.mappings); - const struct side_type *elem_type = type_desc->u.side_enum.elem_type; + 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) { @@ -518,7 +518,7 @@ 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 = side_ptr_get(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_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; @@ -537,12 +537,12 @@ 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; + elem_type = side_ptr_get(enum_elem_type->u.side_array.elem_type); array_item = 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; + elem_type = side_ptr_get(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; break; @@ -1040,7 +1040,7 @@ 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); } @@ -1048,18 +1048,19 @@ 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_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", ":", side_ptr_get(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(" }"); } @@ -1067,7 +1068,7 @@ 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; @@ -1093,7 +1094,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); @@ -1120,7 +1121,7 @@ void tracer_print_array(const struct side_type *type_desc, const struct side_arg 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(" ]"); } @@ -1137,7 +1138,7 @@ void tracer_print_vla(const struct side_type *type_desc, const struct side_arg_v 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(" ]"); } @@ -1354,7 +1355,7 @@ static uint32_t tracer_print_gather_enum_type(const struct side_type_gather *type_gather, const void *_ptr) { const struct side_enum_mappings *mappings = side_ptr_get(type_gather->u.side_enum.mappings); - const struct side_type *enum_elem_type = type_gather->u.side_enum.elem_type; + 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; @@ -1385,7 +1386,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); } @@ -1394,16 +1395,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", ":", side_ptr_get(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); @@ -1424,7 +1426,9 @@ uint32_t tracer_print_gather_array(const struct side_type_gather *type_gather, c 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 (elem_type->type) { case SIDE_TYPE_GATHER_VLA: fprintf(stderr, "\n"); abort(); @@ -1432,7 +1436,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); @@ -1444,20 +1448,21 @@ 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 (length_type->type) { case SIDE_TYPE_GATHER_INTEGER: break; default: fprintf(stderr, "\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); @@ -1467,7 +1472,9 @@ uint32_t tracer_print_gather_vla(const struct side_type_gather *type_gather, con 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 (elem_type->type) { case SIDE_TYPE_GATHER_VLA: fprintf(stderr, "\n"); abort(); @@ -1475,7 +1482,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); @@ -1502,7 +1509,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 = {