Implement gather byte
[libside.git] / src / test.c
index 582203993b32233a45595ada6163b36d7d80e2ac..13419ad44f0c8f0f1e05f5c7cfcc0613464a6155 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdbool.h>
+#include <stddef.h>
 
 #include <side/trace.h>
 #include "tracer.h"
@@ -19,8 +20,9 @@ side_static_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBU
                side_field_u32("abc", side_attr_list()),
                side_field_s64("def", side_attr_list()),
                side_field_pointer("ptr", side_attr_list()),
-               side_field_dynamic("dynamic", side_attr_list()),
-               side_field_dynamic("dynamic_pointer", side_attr_list()),
+               side_field_dynamic("dynamic"),
+               side_field_dynamic("dynamic_pointer"),
+               side_field_null("null", side_attr_list()),
        ),
        side_attr_list()
 );
@@ -36,8 +38,9 @@ void test_fields(void)
                        side_arg_u32(uw),
                        side_arg_s64(sdw),
                        side_arg_pointer((void *) 0x1),
-                       side_arg_dynamic(side_arg_dynamic_string("zzz", side_attr_list())),
-                       side_arg_dynamic(side_arg_dynamic_pointer((void *) 0x1, side_attr_list())),
+                       side_arg_dynamic_string("zzz", side_attr_list()),
+                       side_arg_dynamic_pointer((void *) 0x1, side_attr_list()),
+                       side_arg_null(),
                )
        );
 }
@@ -168,7 +171,7 @@ enum side_visitor_status test_visitor(const struct side_tracer_visitor_ctx *trac
        uint32_t length = ctx->length, i;
 
        for (i = 0; i < length; i++) {
-               const struct side_arg_vec elem = side_arg_u32(ctx->ptr[i]);
+               const struct side_arg elem = side_arg_u32(ctx->ptr[i]);
 
                if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
                        return SIDE_VISITOR_STATUS_ERROR;
@@ -212,7 +215,7 @@ enum side_visitor_status test_inner_visitor(const struct side_tracer_visitor_ctx
        uint32_t length = ctx->length, i;
 
        for (i = 0; i < length; i++) {
-               const struct side_arg_vec elem = side_arg_u32(ctx->ptr[i]);
+               const struct side_arg elem = side_arg_u32(ctx->ptr[i]);
 
                if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
                        return SIDE_VISITOR_STATUS_ERROR;
@@ -236,7 +239,7 @@ enum side_visitor_status test_outer_visitor(const struct side_tracer_visitor_ctx
                        .ptr = ctx->ptr[i],
                        .length = 2,
                };
-               const struct side_arg_vec elem = side_arg_vla_visitor(&inner_ctx);
+               const struct side_arg elem = side_arg_vla_visitor(&inner_ctx);
                if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
                        return SIDE_VISITOR_STATUS_ERROR;
        }
@@ -312,7 +315,7 @@ void test_vla_fixint(void)
 side_static_event(my_provider_event_dynamic_basic,
        "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -321,13 +324,13 @@ static
 void test_dynamic_basic_type(void)
 {
        side_event(my_provider_event_dynamic_basic,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_s16(-33, side_attr_list()))));
+               side_arg_list(side_arg_dynamic_s16(-33, side_attr_list())));
 }
 
 side_static_event(my_provider_event_dynamic_vla,
        "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -344,13 +347,13 @@ void test_dynamic_vla(void)
                side_attr_list()
        );
        side_event(my_provider_event_dynamic_vla,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla))));
+               side_arg_list(side_arg_dynamic_vla(&myvla)));
 }
 
 side_static_event(my_provider_event_dynamic_null,
        "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -359,13 +362,13 @@ static
 void test_dynamic_null(void)
 {
        side_event(my_provider_event_dynamic_null,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_null(side_attr_list()))));
+               side_arg_list(side_arg_dynamic_null(side_attr_list())));
 }
 
 side_static_event(my_provider_event_dynamic_struct,
        "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -383,13 +386,13 @@ void test_dynamic_struct(void)
        );
 
        side_event(my_provider_event_dynamic_struct,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct))));
+               side_arg_list(side_arg_dynamic_struct(&mystruct)));
 }
 
 side_static_event(my_provider_event_dynamic_nested_struct,
        "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -419,13 +422,13 @@ void test_dynamic_nested_struct(void)
                side_attr_list()
        );
        side_event(my_provider_event_dynamic_nested_struct,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct))));
+               side_arg_list(side_arg_dynamic_struct(&mystruct)));
 }
 
 side_static_event(my_provider_event_dynamic_vla_struct,
        "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -450,13 +453,13 @@ void test_dynamic_vla_struct(void)
                side_attr_list()
        );
        side_event(my_provider_event_dynamic_vla_struct,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla))));
+               side_arg_list(side_arg_dynamic_vla(&myvla)));
 }
 
 side_static_event(my_provider_event_dynamic_struct_vla,
        "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -488,13 +491,13 @@ void test_dynamic_struct_vla(void)
                side_attr_list()
        );
        side_event(my_provider_event_dynamic_struct_vla,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct))));
+               side_arg_list(side_arg_dynamic_struct(&mystruct)));
 }
 
 side_static_event(my_provider_event_dynamic_nested_vla,
        "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -526,7 +529,7 @@ void test_dynamic_nested_vla(void)
                side_attr_list()
        );
        side_event(my_provider_event_dynamic_nested_vla,
-               side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla))));
+               side_arg_list(side_arg_dynamic_vla(&myvla)));
 }
 
 side_static_event_variadic(my_provider_event_variadic,
@@ -634,7 +637,7 @@ void test_dynamic_bool(void)
 side_static_event(my_provider_event_dynamic_vla_visitor,
        "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -645,24 +648,13 @@ struct app_dynamic_vla_visitor_ctx {
 };
 
 static
-enum side_visitor_status test_dynamic_vla_visitor(const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, void *_ctx)
+enum side_visitor_status test_dynamic_vla_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
 {
        struct app_dynamic_vla_visitor_ctx *ctx = (struct app_dynamic_vla_visitor_ctx *) _ctx;
        uint32_t length = ctx->length, i;
 
        for (i = 0; i < length; i++) {
-               const struct side_arg_dynamic_vec elem = {
-                       .dynamic_type = SIDE_DYNAMIC_TYPE_U32,
-                       .u = {
-                               .side_basic = {
-                                       .attr = NULL,
-                                       .nr_attr = 0,
-                                       .u = {
-                                               .side_u32 = ctx->ptr[i],
-                                       },
-                               },
-                       },
-               };
+               const struct side_arg elem = side_arg_dynamic_u32(ctx->ptr[i], side_attr_list());
                if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
                        return SIDE_VISITOR_STATUS_ERROR;
        }
@@ -681,9 +673,7 @@ void test_dynamic_vla_with_visitor(void)
                };
                side_event_call(my_provider_event_dynamic_vla_visitor,
                        side_arg_list(
-                               side_arg_dynamic(
-                                       side_arg_dynamic_vla_visitor(test_dynamic_vla_visitor, &ctx, side_attr_list())
-                               )
+                               side_arg_dynamic_vla_visitor(test_dynamic_vla_visitor, &ctx, side_attr_list())
                        )
                );
        }
@@ -692,7 +682,7 @@ void test_dynamic_vla_with_visitor(void)
 side_static_event(my_provider_event_dynamic_struct_visitor,
        "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
        side_field_list(
-               side_field_dynamic("dynamic", side_attr_list()),
+               side_field_dynamic("dynamic"),
        ),
        side_attr_list()
 );
@@ -714,20 +704,9 @@ enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dy
        uint32_t length = ctx->length, i;
 
        for (i = 0; i < length; i++) {
-               struct side_arg_dynamic_event_field dynamic_field = {
+               struct side_arg_dynamic_field dynamic_field = {
                        .field_name = ctx->ptr[i].name,
-                       .elem = {
-                               .dynamic_type = SIDE_DYNAMIC_TYPE_U32,
-                               .u = {
-                                       .side_basic = {
-                                               .nr_attr = 0,
-                                               .attr = NULL,
-                                               .u = {
-                                                       .side_u32 = ctx->ptr[i].value,
-                                               },
-                                       },
-                               },
-                       },
+                       .elem = side_arg_dynamic_u32(ctx->ptr[i].value, side_attr_list()),
                };
                if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK)
                        return SIDE_VISITOR_STATUS_ERROR;
@@ -752,9 +731,7 @@ void test_dynamic_struct_with_visitor(void)
                };
                side_event_call(my_provider_event_dynamic_struct_visitor,
                        side_arg_list(
-                               side_arg_dynamic(
-                                       side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor, &ctx, side_attr_list())
-                               )
+                               side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor, &ctx, side_attr_list())
                        )
                );
        }
@@ -1222,23 +1199,23 @@ void test_enum_bitmap(void)
                );
                side_event_call(my_provider_event_enum_bitmap,
                        side_arg_list(
-                               side_arg_u32(1 << 0),
-                               side_arg_u32(1 << 1),
-                               side_arg_u8(1 << 2),
-                               side_arg_u8(1 << 3),
-                               side_arg_u32(1 << 30),
-                               side_arg_u32(1 << 31),
+                               side_arg_u32(1U << 0),
+                               side_arg_u32(1U << 1),
+                               side_arg_u8(1U << 2),
+                               side_arg_u8(1U << 3),
+                               side_arg_u32(1U << 30),
+                               side_arg_u32(1U << 31),
                                side_arg_u64(1ULL << 63),
                                side_arg_u64((1ULL << 1) | (1ULL << 63)),
-                               side_arg_byte(1 << 2),
+                               side_arg_byte(1U << 2),
                                side_arg_array(&myarray),
                                side_arg_vla(&myarray),
 #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
-                               side_arg_u32(side_bswap_32(1 << 2)),
-                               side_arg_u32(1 << 2),
+                               side_arg_u32(side_bswap_32(1U << 2)),
+                               side_arg_u32(1U << 2),
 #else
                                side_arg_u32(0x06000000),
-                               side_arg_u32(side_bswap_32(1 << 2)),
+                               side_arg_u32(side_bswap_32(1U << 2)),
 #endif
                        )
                );
@@ -1483,6 +1460,547 @@ void test_base(void)
        );
 }
 
+struct test {
+       uint32_t a;
+       uint64_t b;
+       uint8_t c;
+       int32_t d;
+       uint16_t e;
+       int8_t f;
+       int16_t g;
+       int32_t h;
+       int64_t i;
+       int64_t j;
+       int64_t k;
+       uint64_t test;
+};
+
+static side_define_struct(mystructgatherdef,
+       side_field_list(
+               side_field_gather_unsigned_integer("a", offsetof(struct test, a),
+                       side_struct_field_sizeof_bit(struct test, a), 0,
+                       side_struct_field_sizeof_bit(struct test, a), SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+               side_field_gather_signed_integer("d", offsetof(struct test, d),
+                       side_struct_field_sizeof_bit(struct test, d), 0,
+                       side_struct_field_sizeof_bit(struct test, d), SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+               side_field_gather_unsigned_integer("e", offsetof(struct test, e),
+                       side_struct_field_sizeof_bit(struct test, e), 8, 4,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
+               side_field_gather_signed_integer("f", offsetof(struct test, f),
+                       side_struct_field_sizeof_bit(struct test, f), 1, 4,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+               side_field_gather_signed_integer("g", offsetof(struct test, g),
+                       side_struct_field_sizeof_bit(struct test, g), 11, 4,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+               side_field_gather_signed_integer("h", offsetof(struct test, h),
+                       side_struct_field_sizeof_bit(struct test, h), 1, 31,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+               side_field_gather_signed_integer("i", offsetof(struct test, i),
+                       side_struct_field_sizeof_bit(struct test, i), 33, 20,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+               side_field_gather_signed_integer("j", offsetof(struct test, j),
+                       side_struct_field_sizeof_bit(struct test, j), 63, 1,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+               side_field_gather_signed_integer("k", offsetof(struct test, k), 
+                       side_struct_field_sizeof_bit(struct test, k), 1, 63,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+               side_field_gather_unsigned_integer_le("test", offsetof(struct test, test),
+                       side_struct_field_sizeof_bit(struct test, test), 0, 64,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
+               side_field_gather_unsigned_integer_le("test_le", offsetof(struct test, test),
+                       side_struct_field_sizeof_bit(struct test, test), 0, 64,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
+               side_field_gather_unsigned_integer_be("test_be", offsetof(struct test, test),
+                       side_struct_field_sizeof_bit(struct test, test), 0, 64,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_structgather, "myprovider", "myeventstructgather", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("structgather", &mystructgatherdef, 0, sizeof(struct test),
+                               SIDE_TYPE_GATHER_ACCESS_POINTER),
+               side_field_gather_signed_integer("intgather", 0, 32, 0, 32, SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
+#if __HAVE_FLOAT32
+               side_field_gather_float("f32", 0, 32, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+#endif
+       ),
+       side_attr_list()
+);
+
+static
+void test_struct_gather(void)
+{
+       side_event_cond(my_provider_event_structgather) {
+               struct test mystruct = {
+                       .a = 55,
+                       .b = 123,
+                       .c = 2,
+                       .d = -55,
+                       .e = 0xABCD,
+                       .f = -1,
+                       .g = -1,
+                       .h = -1,
+                       .i = -1,
+                       .j = -1,
+                       .k = -1,
+                       .test = 0xFF,
+               };
+               int32_t val = -66;
+#if __HAVE_FLOAT32
+               _Float32 f32 = 1.1;
+#endif
+               side_event_call(my_provider_event_structgather,
+                       side_arg_list(
+                               side_arg_gather_struct(&mystruct),
+                               side_arg_gather_signed_integer(&val),
+#if __HAVE_FLOAT32
+                               side_arg_gather_float(&f32),
+#endif
+                       )
+               );
+       }
+}
+
+struct testnest2 {
+       uint8_t c;
+};
+
+struct testnest1 {
+       uint64_t b;
+       struct testnest2 *nest;
+};
+
+struct testnest0 {
+       uint32_t a;
+       struct testnest1 *nest;
+};
+
+static side_define_struct(mystructgathernest2,
+       side_field_list(
+               side_field_gather_unsigned_integer("c", offsetof(struct testnest2, c),
+                       side_struct_field_sizeof_bit(struct testnest2, c), 0,
+                       side_struct_field_sizeof_bit(struct testnest2, c), SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+       ),
+       side_attr_list()
+);
+
+static side_define_struct(mystructgathernest1,
+       side_field_list(
+               side_field_gather_unsigned_integer("b", offsetof(struct testnest1, b),
+                       side_struct_field_sizeof_bit(struct testnest1, b), 0,
+                       side_struct_field_sizeof_bit(struct testnest1, b), SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+               side_field_gather_struct("nest2", &mystructgathernest2,
+                       offsetof(struct testnest1, nest), sizeof(struct testnest2),
+                       SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+static side_define_struct(mystructgathernest0,
+       side_field_list(
+               side_field_gather_unsigned_integer("a", offsetof(struct testnest0, a),
+                       side_struct_field_sizeof_bit(struct testnest0, a), 0,
+                       side_struct_field_sizeof_bit(struct testnest0, a), SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+               side_field_gather_struct("nest1", &mystructgathernest1,
+                       offsetof(struct testnest0, nest), sizeof(struct testnest1),
+                       SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_structgather_nest,
+       "myprovider", "myeventstructgathernest", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("nest0", &mystructgathernest0, 0,
+                       sizeof(struct testnest0), SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+static
+void test_struct_gather_nest_ptr(void)
+{
+       side_event_cond(my_provider_event_structgather_nest) {
+               struct testnest2 mystruct2 = {
+                       .c = 77,
+               };
+               struct testnest1 mystruct1 = {
+                       .b = 66,
+                       .nest = &mystruct2,
+               };
+               struct testnest0 mystruct = {
+                       .a = 55,
+                       .nest = &mystruct1,
+               };
+               side_event_call(my_provider_event_structgather_nest,
+                       side_arg_list(
+                               side_arg_gather_struct(&mystruct),
+                       )
+               );
+       }
+}
+
+struct testfloat {
+#if __HAVE_FLOAT16
+       _Float16 f16;
+#endif
+#if __HAVE_FLOAT32
+       _Float32 f32;
+#endif
+#if __HAVE_FLOAT64
+       _Float64 f64;
+#endif
+#if __HAVE_FLOAT128
+       _Float128 f128;
+#endif
+};
+
+static side_define_struct(mystructgatherfloat,
+       side_field_list(
+#if __HAVE_FLOAT16
+               side_field_gather_float("f16", offsetof(struct testfloat, f16), 16,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list()),
+#endif
+#if __HAVE_FLOAT32
+               side_field_gather_float("f32", offsetof(struct testfloat, f32), 32,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list()),
+#endif
+#if __HAVE_FLOAT64
+               side_field_gather_float("f64", offsetof(struct testfloat, f64), 64,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list()),
+#endif
+#if __HAVE_FLOAT128
+               side_field_gather_float("f128", offsetof(struct testfloat, f128), 128,
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list()),
+#endif
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_structgatherfloat,
+       "myprovider", "myeventstructgatherfloat", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("structgatherfloat", &mystructgatherfloat, 0,
+                       sizeof(struct testfloat), SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+static
+void test_struct_gather_float(void)
+{
+       side_event_cond(my_provider_event_structgatherfloat) {
+               struct testfloat mystruct = {
+#if __HAVE_FLOAT16
+                       .f16 = 1.1,
+#endif
+#if __HAVE_FLOAT32
+                       .f32 = 2.2,
+#endif
+#if __HAVE_FLOAT64
+                       .f64 = 3.3,
+#endif
+#if __HAVE_FLOAT128
+                       .f128 = 4.4,
+#endif
+               };
+               side_event_call(my_provider_event_structgatherfloat,
+                       side_arg_list(
+                               side_arg_gather_struct(&mystruct),
+                       )
+               );
+       }
+}
+
+uint32_t mygatherarray[] = { 1, 2, 3, 4, 5 };
+
+uint16_t mygatherarray2[] = { 6, 7, 8, 9 };
+
+struct testarray {
+       int a;
+       uint32_t *ptr;
+};
+
+static side_define_struct(mystructgatherarray,
+       side_field_list(
+               side_field_gather_array("array",
+                       side_elem(side_type_gather_unsigned_integer(0, 32, 0, 32, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       SIDE_ARRAY_SIZE(mygatherarray),
+                       offsetof(struct testarray, ptr),
+                       SIDE_TYPE_GATHER_ACCESS_POINTER,
+                       side_attr_list()),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_structgatherarray,
+       "myprovider", "myeventstructgatherarray", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("structgatherarray", &mystructgatherarray, 0,
+                               sizeof(struct testarray), SIDE_TYPE_GATHER_ACCESS_POINTER),
+               side_field_gather_array("array2",
+                       side_elem(side_type_gather_unsigned_integer(0, 16, 0, 16, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       SIDE_ARRAY_SIZE(mygatherarray2), 0,
+                       SIDE_TYPE_GATHER_ACCESS_POINTER,
+                       side_attr_list()
+               ),
+       ),
+       side_attr_list()
+);
+
+static
+void test_array_gather(void)
+{
+       side_event_cond(my_provider_event_structgatherarray) {
+               struct testarray mystruct = {
+                       .a = 55,
+                       .ptr = mygatherarray,
+               };
+               side_event_call(my_provider_event_structgatherarray,
+                       side_arg_list(
+                               side_arg_gather_struct(&mystruct),
+                               side_arg_gather_array(&mygatherarray2),
+                       )
+               );
+       }
+}
+
+#define TESTSGNESTARRAY_LEN 4
+struct testgatherstructnest1 {
+       int b;
+       int c[TESTSGNESTARRAY_LEN];
+};
+
+struct testgatherstructnest0 {
+       struct testgatherstructnest1 nest;
+       struct testgatherstructnest1 nestarray[2];
+       int a;
+};
+
+
+static side_define_struct(mystructgatherstructnest1,
+       side_field_list(
+               side_field_gather_signed_integer("b", offsetof(struct testgatherstructnest1, b),
+                       side_struct_field_sizeof_bit(struct testgatherstructnest1, b), 0,
+                       side_struct_field_sizeof_bit(struct testgatherstructnest1, b),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+               side_field_gather_array("c",
+                       side_elem(
+                               side_type_gather_signed_integer(0, 32, 0, 32, 
+                                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+                       ),
+                       TESTSGNESTARRAY_LEN,
+                       offsetof(struct testgatherstructnest1, c),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list()),
+       ),
+       side_attr_list()
+);
+
+static side_define_struct(mystructgatherstructnest0,
+       side_field_list(
+               side_field_gather_signed_integer("a", offsetof(struct testgatherstructnest0, a),
+                       side_struct_field_sizeof_bit(struct testgatherstructnest0, a), 0,
+                       side_struct_field_sizeof_bit(struct testgatherstructnest0, a),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()),
+               side_field_gather_struct("structnest0", &mystructgatherstructnest1,
+                       offsetof(struct testgatherstructnest0, nest),
+                       sizeof(struct testgatherstructnest1),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS),
+               side_field_gather_array("nestarray",
+                       side_elem(
+                               side_type_gather_struct(&mystructgatherstructnest1,
+                                       0,
+                                       sizeof(struct testgatherstructnest1),
+                                       SIDE_TYPE_GATHER_ACCESS_ADDRESS),
+                       ),
+                       2,
+                       offsetof(struct testgatherstructnest0, nestarray),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_attr_list()),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_gatherstructnest,
+       "myprovider", "myeventgatherstructnest", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("structgather", &mystructgatherstructnest0, 0,
+                               sizeof(struct testgatherstructnest0), SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+static
+void test_gather_structnest(void)
+{
+       side_event_cond(my_provider_event_gatherstructnest) {
+               struct testgatherstructnest0 mystruct = {
+                       .nest = {
+                               .b = 66,
+                               .c = { 0, 1, 2, 3 },
+                       },
+                       .nestarray = {
+                               [0] = {
+                                       .b = 77,
+                                       .c = { 11, 12, 13, 14 },
+                               },
+                               [1] = {
+                                       .b = 88,
+                                       .c = { 15, 16, 17, 18 },
+                               },
+                       },
+                       .a = 55,
+               };
+               side_event_call(my_provider_event_gatherstructnest,
+                       side_arg_list(
+                               side_arg_gather_struct(&mystruct),
+                       )
+               );
+       }
+}
+
+uint32_t gathervla[] = { 1, 2, 3, 4 };
+
+struct testgathervla {
+       int a;
+       uint16_t len;
+       uint32_t *p;
+};
+
+static side_define_struct(mystructgathervla,
+       side_field_list(
+               side_field_gather_signed_integer("a", offsetof(struct testgathervla, a),
+                       side_struct_field_sizeof_bit(struct testgathervla, a), 0,
+                       side_struct_field_sizeof_bit(struct testgathervla, a),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list()
+               ),
+               side_field_gather_vla("nestvla",
+                       side_elem(side_type_gather_unsigned_integer(0, 32, 0, 32, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       offsetof(struct testgathervla, p),
+                       SIDE_TYPE_GATHER_ACCESS_POINTER,
+                       side_length(side_type_gather_unsigned_integer(offsetof(struct testgathervla, len),
+                                       16, 0, 16, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       side_attr_list()
+               ),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_gathervla,
+       "myprovider", "myeventgathervla", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("structgathervla", &mystructgathervla, 0,
+                               sizeof(struct testgathervla), SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+static
+void test_gather_vla(void)
+{
+       side_event_cond(my_provider_event_gathervla) {
+               struct testgathervla mystruct = {
+                       .a = 55,
+                       .len = SIDE_ARRAY_SIZE(gathervla),
+                       .p = gathervla,
+               };
+               side_event_call(my_provider_event_gathervla,
+                       side_arg_list(
+                               side_arg_gather_struct(&mystruct),
+                       )
+               );
+       }
+}
+
+struct testgathervlaflex {
+       uint8_t len;
+       uint32_t otherfield;
+       uint64_t array[];
+};
+
+static side_define_struct(mystructgathervlaflex,
+       side_field_list(
+               side_field_gather_vla("vlaflex",
+                       side_elem(side_type_gather_unsigned_integer(0, 64, 0, 64, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       offsetof(struct testgathervlaflex, array),
+                       SIDE_TYPE_GATHER_ACCESS_ADDRESS,
+                       side_length(side_type_gather_unsigned_integer(offsetof(struct testgathervlaflex, len),
+                                       8, 0, 8, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       side_attr_list()
+               ),
+       ),
+       side_attr_list()
+);
+
+side_static_event(my_provider_event_gathervlaflex,
+       "myprovider", "myeventgathervlaflex", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_struct("structgathervlaflex", &mystructgathervlaflex, 0,
+                               sizeof(struct testgathervlaflex), SIDE_TYPE_GATHER_ACCESS_POINTER),
+       ),
+       side_attr_list()
+);
+
+#define VLAFLEXLEN     6
+static
+void test_gather_vla_flex(void)
+{
+       side_event_cond(my_provider_event_gathervlaflex) {
+               struct testgathervlaflex *mystruct = malloc(sizeof(*mystruct) + VLAFLEXLEN + sizeof(uint64_t));
+
+               mystruct->len = VLAFLEXLEN;
+               mystruct->otherfield = 0;
+               mystruct->array[0] = 1;
+               mystruct->array[1] = 2;
+               mystruct->array[2] = 3;
+               mystruct->array[3] = 4;
+               mystruct->array[4] = 5;
+               mystruct->array[5] = 6;
+               side_event_call(my_provider_event_gathervlaflex,
+                       side_arg_list(
+                               side_arg_gather_struct(mystruct),
+                       )
+               );
+               free(mystruct);
+       }
+}
+
+side_static_event(my_provider_event_gatherbyte,
+       "myprovider", "myeventgatherbyte", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_gather_byte("byte", 0, SIDE_TYPE_GATHER_ACCESS_POINTER, side_attr_list()),
+               side_field_gather_array("array",
+                       side_elem(side_type_gather_byte(0, SIDE_TYPE_GATHER_ACCESS_ADDRESS, side_attr_list())),
+                       3, 0, SIDE_TYPE_GATHER_ACCESS_POINTER, side_attr_list()
+               ),
+       ),
+       side_attr_list()
+);
+
+static
+void test_gather_byte(void)
+{
+       side_event_cond(my_provider_event_structgatherarray) {
+               uint8_t v = 0x44;
+               uint8_t array[3] = { 0x1, 0x2, 0x3 };
+
+               side_event_call(my_provider_event_gatherbyte,
+                       side_arg_list(
+                               side_arg_gather_byte(&v),
+                               side_arg_gather_array(array),
+                       )
+               );
+       }
+}
+
 int main()
 {
        test_fields();
@@ -1523,5 +2041,13 @@ int main()
        test_fmt_string();
        test_endian();
        test_base();
+       test_struct_gather();
+       test_struct_gather_nest_ptr();
+       test_struct_gather_float();
+       test_array_gather();
+       test_gather_structnest();
+       test_gather_vla();
+       test_gather_vla_flex();
+       test_gather_byte();
        return 0;
 }
This page took 0.033797 seconds and 4 git commands to generate.