From: Olivier Dion Date: Wed, 23 Oct 2024 13:16:50 +0000 (-0400) Subject: Make all container types pointers X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=572b2030e71e97cd14ebbd7f72bca29d0b964e00;p=libside.git Make all container types pointers Array and VLA were not pointers in `struct side_type' like other container types such as struct and variant. Make those pointers to ensure container types are all similar. API change (user-visible): This prevents defining array and VLA fields inline. That is, it is now necessary to define the array/VLA type before referencing it in a field. Change-Id: Ia3634a40514d827cb23ce242fb6bd05c7c583e34 Signed-off-by: Olivier Dion Signed-off-by: Mathieu Desnoyers --- diff --git a/include/side/abi/type-description.h b/include/side/abi/type-description.h index aa30485..d0d058e 100644 --- a/include/side/abi/type-description.h +++ b/include/side/abi/type-description.h @@ -378,8 +378,8 @@ struct side_type { struct side_type_float side_float; /* Stack-copy compound types */ - struct side_type_array side_array; - struct side_type_vla side_vla; + side_ptr_t(const struct side_type_array) side_array; + side_ptr_t(const struct side_type_vla) side_vla; side_ptr_t(const struct side_type_vla_visitor) side_vla_visitor; side_ptr_t(const struct side_type_struct) side_struct; side_ptr_t(const struct side_type_variant) side_variant; diff --git a/include/side/instrumentation-c-api.h b/include/side/instrumentation-c-api.h index 57f22ea..df33208 100644 --- a/include/side/instrumentation-c-api.h +++ b/include/side/instrumentation-c-api.h @@ -590,6 +590,7 @@ .side_struct = SIDE_PTR_INIT(_struct), \ }, \ } + #define side_field_struct(_name, _struct) \ _side_field(_name, side_type_struct(SIDE_PARAM(_struct))) @@ -653,35 +654,43 @@ enum { #define side_field_optional_literal(_name, _type) \ _side_field(_name, side_type_optional(SIDE_PARAM(_type))) -#define side_type_array(_elem_type, _length, _attr...) \ - { \ - .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \ - .u = { \ - .side_array = { \ - .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())), \ - }, \ - }, \ +#define side_type_array(_array) \ + { \ + .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \ + .u = { \ + .side_array = SIDE_PTR_INIT(_array) \ + } \ } -#define side_field_array(_name, _elem_type, _length, _attr...) \ - _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) -#define side_type_vla(_elem_type, _length_type, _attr...) \ - { \ - .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \ - .u = { \ - .side_vla = { \ - .elem_type = SIDE_PTR_INIT(_elem_type), \ - .length_type = SIDE_PTR_INIT(_length_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())), \ - }, \ - }, \ +#define side_field_array(_name, _array) \ + _side_field(_name, side_type_array(_array)) + +#define side_define_array(_identifier, _elem_type, _length, _attr...) \ + const struct side_type_array _identifier = { \ + .elem_type = SIDE_PTR_INIT(SIDE_PARAM(_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())), \ + } + +#define side_type_vla(_vla) \ + { \ + .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \ + .u = { \ + .side_vla = SIDE_PTR_INIT(_vla), \ + }, \ + } + +#define side_field_vla(_name, _vla) \ + _side_field(_name, side_type_vla(_vla)) + +#define side_define_vla(_identifier, _elem_type, _length_type, _attr...) \ + const struct side_type_vla _identifier = { \ + .elem_type = SIDE_PTR_INIT(SIDE_PARAM(_elem_type)), \ + .length_type = SIDE_PTR_INIT(SIDE_PARAM(_length_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())), \ } -#define side_field_vla(_name, _elem_type, _length_type, _attr...) \ - _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_length_type), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))) #define _side_type_vla_visitor_define(_elem_type, _length_type, _visitor, _attr...) \ { \ diff --git a/src/tracer.c b/src/tracer.c index ff24388..66ef574 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -1355,12 +1355,12 @@ static void tracer_print_enum_bitmap(const struct side_type *type_desc, nr_items = 1; break; case SIDE_TYPE_ARRAY: - elem_type = side_ptr_get(enum_elem_type->u.side_array.elem_type); + elem_type = side_ptr_get(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; + nr_items = side_ptr_get(type_desc->u.side_array)->length; break; case SIDE_TYPE_VLA: - elem_type = side_ptr_get(enum_elem_type->u.side_vla.elem_type); + elem_type = side_ptr_get(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; diff --git a/src/visit-arg-vec.c b/src/visit-arg-vec.c index bda94cc..7b54d9a 100644 --- a/src/visit-arg-vec.c +++ b/src/visit-arg-vec.c @@ -365,22 +365,22 @@ void type_visitor_array(const struct side_type_visitor *type_visitor, const stru 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) { + if (side_ptr_get(type_desc->u.side_array)->length != side_sav_len) { fprintf(stderr, "ERROR: length mismatch between description and arguments of array\n"); abort(); } if (type_visitor->before_array_type_func) - type_visitor->before_array_type_func(&type_desc->u.side_array, side_arg_vec, priv); + type_visitor->before_array_type_func(side_ptr_get(type_desc->u.side_array), side_arg_vec, priv); for (i = 0; i < side_sav_len; i++) { struct visit_context new_ctx = { .type = CONTEXT_ARRAY, .array_index = i, .parent = ctx }; - side_visit_elem(type_visitor, &new_ctx, side_ptr_get(type_desc->u.side_array.elem_type), &sav[i], priv); + side_visit_elem(type_visitor, &new_ctx, side_ptr_get(side_ptr_get(type_desc->u.side_array)->elem_type), &sav[i], priv); } if (type_visitor->after_array_type_func) - type_visitor->after_array_type_func(&type_desc->u.side_array, side_arg_vec, priv); + type_visitor->after_array_type_func(side_ptr_get(type_desc->u.side_array), side_arg_vec, priv); } static @@ -391,17 +391,17 @@ void type_visitor_vla(const struct side_type_visitor *type_visitor, const struct uint32_t i, side_sav_len = side_arg_vec->len; if (type_visitor->before_vla_type_func) - type_visitor->before_vla_type_func(&type_desc->u.side_vla, side_arg_vec, priv); + type_visitor->before_vla_type_func(side_ptr_get(type_desc->u.side_vla), side_arg_vec, priv); for (i = 0; i < side_sav_len; i++) { struct visit_context new_ctx = { .type = CONTEXT_ARRAY, .array_index = i, .parent = ctx }; - side_visit_elem(type_visitor, &new_ctx, side_ptr_get(type_desc->u.side_vla.elem_type), &sav[i], priv); + side_visit_elem(type_visitor, &new_ctx, side_ptr_get(side_ptr_get(type_desc->u.side_vla)->elem_type), &sav[i], priv); } if (type_visitor->after_vla_type_func) - type_visitor->after_vla_type_func(&type_desc->u.side_vla, side_arg_vec, priv); + type_visitor->after_vla_type_func(side_ptr_get(type_desc->u.side_vla), side_arg_vec, priv); } struct tracer_visitor_priv { diff --git a/src/visit-description.c b/src/visit-description.c index bbb6999..3c347f0 100644 --- a/src/visit-description.c +++ b/src/visit-description.c @@ -139,23 +139,23 @@ static void description_visitor_array(const struct side_description_visitor *description_visitor, const struct side_type *type_desc, void *priv) { if (description_visitor->before_array_type_func) - description_visitor->before_array_type_func(&type_desc->u.side_array, priv); - side_visit_elem(description_visitor, side_ptr_get(type_desc->u.side_array.elem_type), priv); + description_visitor->before_array_type_func(side_ptr_get(type_desc->u.side_array), priv); + side_visit_elem(description_visitor, side_ptr_get(side_ptr_get(type_desc->u.side_array)->elem_type), priv); if (description_visitor->after_array_type_func) - description_visitor->after_array_type_func(&type_desc->u.side_array, priv); + description_visitor->after_array_type_func(side_ptr_get(type_desc->u.side_array), priv); } static void description_visitor_vla(const struct side_description_visitor *description_visitor, const struct side_type *type_desc, void *priv) { if (description_visitor->before_vla_type_func) - description_visitor->before_vla_type_func(&type_desc->u.side_vla, priv); - side_visit_elem(description_visitor, side_ptr_get(type_desc->u.side_vla.length_type), priv); + description_visitor->before_vla_type_func(side_ptr_get(type_desc->u.side_vla), priv); + side_visit_elem(description_visitor, side_ptr_get(side_ptr_get(type_desc->u.side_vla)->length_type), priv); if (description_visitor->after_length_vla_type_func) - description_visitor->after_length_vla_type_func(&type_desc->u.side_vla, priv); - side_visit_elem(description_visitor, side_ptr_get(type_desc->u.side_vla.elem_type), priv); + description_visitor->after_length_vla_type_func(side_ptr_get(type_desc->u.side_vla), priv); + side_visit_elem(description_visitor, side_ptr_get(side_ptr_get(type_desc->u.side_vla)->elem_type), priv); if (description_visitor->after_element_vla_type_func) - description_visitor->after_element_vla_type_func(&type_desc->u.side_vla, priv); + description_visitor->after_element_vla_type_func(side_ptr_get(type_desc->u.side_vla), priv); } static diff --git a/tests/unit/test.c b/tests/unit/test.c index 90de62d..e93f7e6 100644 --- a/tests/unit/test.c +++ b/tests/unit/test.c @@ -115,9 +115,14 @@ void test_struct(void) } } +static side_define_array(my_array_u32_3, + side_elem(side_type_u32()), + 3 +); + side_static_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG, side_field_list( - side_field_array("arr", side_elem(side_type_u32()), 3), + side_field_array("arr", &my_array_u32_3), side_field_s64("v"), ) ); @@ -131,9 +136,14 @@ void test_array(void) } } +static side_define_vla(my_vla_u32, + side_elem(side_type_u32()), + side_elem(side_type_u32()) +); + side_static_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG, side_field_list( - side_field_vla("vla", side_elem(side_type_u32()), side_elem(side_type_u32())), + side_field_vla("vla", &my_vla_u32), side_field_s64("v"), ) ); @@ -1094,6 +1104,16 @@ static side_define_enum_bitmap(myenum_bitmap, ) ); +static side_define_array(my_array_u32_5, + side_elem(side_type_u32()), + 5 +); + +static side_define_vla(my_vla_u32_for_bitmap, + side_elem(side_type_u32()), + side_elem(side_type_u32()) +); + side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG, side_field_list( side_field_enum_bitmap("bit_0", &myenum_bitmap, side_elem(side_type_u32())), @@ -1106,9 +1126,9 @@ side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitma side_field_enum_bitmap("bits_1+63", &myenum_bitmap, side_elem(side_type_u64())), side_field_enum_bitmap("byte_bit_2", &myenum_bitmap, side_elem(side_type_byte())), side_field_enum_bitmap("bit_159", &myenum_bitmap, - side_elem(side_type_array(side_elem(side_type_u32()), 5))), + side_elem(side_type_array(&my_array_u32_5))), side_field_enum_bitmap("bit_159", &myenum_bitmap, - side_elem(side_type_vla(side_elem(side_type_u32()), side_elem(side_type_u32())))), + side_elem(side_type_vla(&my_vla_u32_for_bitmap))), side_field_enum_bitmap("bit_2_be", &myenum_bitmap, side_elem(side_type_u32_be())), side_field_enum_bitmap("bit_2_le", &myenum_bitmap, side_elem(side_type_u32_le())), ) @@ -1152,10 +1172,15 @@ void test_enum_bitmap(void) } } +static side_define_array(my_array_byte, + side_elem(side_type_byte()), + 3 +); + side_static_event_variadic(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG, side_field_list( side_field_byte("blobfield"), - side_field_array("arrayblob", side_elem(side_type_byte()), 3), + side_field_array("arrayblob", &my_array_byte), ) );