enum side_error is actually used
[libside.git] / include / side / trace.h
index d941616bdae1488a5fe5b57bcd61b52e8b0a70eb..fc51ec617691c296046e716825ffc2f00742be8a 100644 (file)
 /*
  * SIDE stands for "Software Instrumentation Dynamically Enabled"
  *
- * This is an instrumentation API for Linux user-space, which exposes an
+ * This is an instrumentation ABI for Linux user-space, which exposes an
  * instrumentation type system and facilities allowing a kernel or
  * user-space tracer to consume user-space instrumentation.
  *
- * This instrumentation API exposes 3 type systems:
+ * This instrumentation ABI exposes 3 type systems:
  *
  * * Stack-copy type system: This is the core type system which can
  *   represent all supported types and into which all other type systems
  *   Those dynamic types can be either used as arguments to a variadic
  *   field list, or as on-stack instrumentation argument for a static
  *   type SIDE_TYPE_DYNAMIC place holder in the stack-copy type system.
+ *
+ * The extensibility scheme for the SIDE ABI is as follows:
+ *
+ * * Existing field types are never changed nor extended. Field types
+ *   can be added to the ABI by reserving a label within
+ *   enum side_type_label.
+ * * Existing attribute types are never changed nor extended. Attribute
+ *   types can be added to the ABI by reserving a label within
+ *   enum side_attr_type.
+ * * Each union part of the ABI has an explicit side defined by a
+ *   side_padding() member. Each structure and union have a static
+ *   assert validating its size.
+ *
+ * Handling of unknown types by the tracers:
+ *
+ * * A tracer may choose to support only a subset of the types supported
+ *   by libside. When encountering an unknown or unsupported type, the
+ *   tracer has the option to either disallow the entire event or skip
+ *   over the unknown type, both at event registration and when
+ *   receiving the side_call arguments.
+ *
+ * TODO: extend event description with new fields ?
  */
 
 //TODO: as those structures will be ABI, we need to either consider them
@@ -84,6 +106,8 @@ struct side_event_description;
 struct side_arg_dynamic_struct;
 struct side_events_register_handle;
 struct side_arg_variant;
+struct side_event_state;
+struct side_callback;
 
 enum side_type_label {
        /* Stack-copy basic types */
@@ -224,6 +248,12 @@ typedef enum side_visitor_status (*side_visitor_func)(
 typedef enum side_visitor_status (*side_dynamic_struct_visitor_func)(
                const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
                void *app_ctx);
+typedef enum side_visitor_status (*side_write_elem_func)(
+               const struct side_tracer_visitor_ctx *tracer_ctx,
+               const struct side_arg *elem);
+typedef enum side_visitor_status (*side_write_field_func)(
+               const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
+               const struct side_arg_dynamic_field *dynamic_field);
 
 union side_integer_value {
        uint8_t side_u8;
@@ -235,14 +265,18 @@ union side_integer_value {
        int32_t side_s32;
        int64_t side_s64;
        uintptr_t side_uptr;
+       side_padding(32);
 } SIDE_PACKED;
+side_check_size(union side_integer_value, 32);
 
 union side_bool_value {
        uint8_t side_bool8;
        uint16_t side_bool16;
        uint32_t side_bool32;
        uint64_t side_bool64;
+       side_padding(32);
 } SIDE_PACKED;
+side_check_size(union side_bool_value, 32);
 
 union side_float_value {
 #if __HAVE_FLOAT16
@@ -257,55 +291,65 @@ union side_float_value {
 #if __HAVE_FLOAT128
        _Float128 side_float_binary128;
 #endif
+       side_padding(32);
 } SIDE_PACKED;
+side_check_size(union side_float_value, 32);
 
 struct side_type_raw_string {
        side_ptr_t(const void) p;       /* pointer to string */
        uint8_t unit_size;              /* 1, 2, or 4 bytes */
-       uint8_t byte_order;             /* enum side_type_label_byte_order */
+       side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
 } SIDE_PACKED;
+side_check_size(struct side_type_raw_string, 18);
 
 struct side_attr_value {
-       uint32_t type;  /* enum side_attr_type */
+       side_enum_t(enum side_attr_type, uint32_t) type;
        union {
                uint8_t bool_value;
                struct side_type_raw_string string_value;
                union side_integer_value integer_value;
                union side_float_value float_value;
+               side_padding(32);
        } SIDE_PACKED u;
 };
+side_check_size(struct side_attr_value, 36);
 
 /* User attributes. */
 struct side_attr {
        const struct side_type_raw_string key;
        const struct side_attr_value value;
 } SIDE_PACKED;
+side_check_size(struct side_attr, 54);
 
 /* Type descriptions */
 struct side_type_null {
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_type_null, 20);
 
 struct side_type_bool {
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
        uint16_t bool_size;             /* bytes */
        uint16_t len_bits;              /* bits. 0 for (bool_size * CHAR_BITS) */
-       uint8_t byte_order;             /* enum side_type_label_byte_order */
+       side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
 } SIDE_PACKED;
+side_check_size(struct side_type_bool, 25);
 
 struct side_type_byte {
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_type_byte, 20);
 
 struct side_type_string {
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
        uint8_t unit_size;              /* 1, 2, or 4 bytes */
-       uint8_t byte_order;             /* enum side_type_label_byte_order */
+       side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
 } SIDE_PACKED;
+side_check_size(struct side_type_string, 22);
 
 struct side_type_integer {
        side_ptr_t(const struct side_attr) attr;
@@ -313,21 +357,24 @@ struct side_type_integer {
        uint16_t integer_size;          /* bytes */
        uint16_t len_bits;              /* bits. 0 for (integer_size * CHAR_BITS) */
        uint8_t signedness;             /* true/false */
-       uint8_t byte_order;             /* enum side_type_label_byte_order */
+       side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
 } SIDE_PACKED;
+side_check_size(struct side_type_integer, 26);
 
 struct side_type_float {
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
        uint16_t float_size;            /* bytes */
-       uint8_t byte_order;             /* enum side_type_label_byte_order */
+       side_enum_t(enum side_type_label_byte_order, uint8_t) byte_order;
 } SIDE_PACKED;
+side_check_size(struct side_type_float, 23);
 
 struct side_enum_mapping {
        int64_t range_begin;
        int64_t range_end;
        struct side_type_raw_string label;
 } SIDE_PACKED;
+side_check_size(struct side_enum_mapping, 16 + sizeof(struct side_type_raw_string));
 
 struct side_enum_mappings {
        side_ptr_t(const struct side_enum_mapping) mappings;
@@ -335,12 +382,14 @@ struct side_enum_mappings {
        uint32_t nr_mappings;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_enum_mappings, 40);
 
 struct side_enum_bitmap_mapping {
        uint64_t range_begin;
        uint64_t range_end;
        struct side_type_raw_string label;
 } SIDE_PACKED;
+side_check_size(struct side_enum_bitmap_mapping, 16 + sizeof(struct side_type_raw_string));
 
 struct side_enum_bitmap_mappings {
        side_ptr_t(const struct side_enum_bitmap_mapping) mappings;
@@ -348,6 +397,7 @@ struct side_enum_bitmap_mappings {
        uint32_t nr_mappings;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_enum_bitmap_mappings, 40);
 
 struct side_type_struct {
        side_ptr_t(const struct side_event_field) fields;
@@ -355,6 +405,7 @@ struct side_type_struct {
        uint32_t nr_fields;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_type_struct, 40);
 
 struct side_type_array {
        side_ptr_t(const struct side_type) elem_type;
@@ -362,87 +413,100 @@ struct side_type_array {
        uint32_t length;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_type_array, 40);
 
 struct side_type_vla {
        side_ptr_t(const struct side_type) elem_type;
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_type_vla, 36);
 
 struct side_type_vla_visitor {
        side_ptr_t(const struct side_type) elem_type;
-       side_visitor_func visitor;
+       side_func_ptr_t(side_visitor_func) visitor;
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_type_vla_visitor, 52);
 
 struct side_type_enum {
        side_ptr_t(const struct side_enum_mappings) mappings;
        side_ptr_t(const struct side_type) elem_type;
 } SIDE_PACKED;
+side_check_size(struct side_type_enum, 32);
 
 struct side_type_enum_bitmap {
        side_ptr_t(const struct side_enum_bitmap_mappings) mappings;
        side_ptr_t(const struct side_type) elem_type;
 } SIDE_PACKED;
+side_check_size(struct side_type_enum_bitmap, 32);
 
 struct side_type_gather_bool {
        uint64_t offset;        /* bytes */
+       uint16_t offset_bits;   /* bits */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
        struct side_type_bool type;
-       uint16_t offset_bits;   /* bits */
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_bool, 11 + sizeof(struct side_type_bool));
 
 struct side_type_gather_byte {
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
        struct side_type_byte type;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_byte, 9 + sizeof(struct side_type_byte));
 
 struct side_type_gather_integer {
        uint64_t offset;        /* bytes */
+       uint16_t offset_bits;   /* bits */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
        struct side_type_integer type;
-       uint16_t offset_bits;   /* bits */
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_integer, 11 + sizeof(struct side_type_integer));
 
 struct side_type_gather_float {
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
        struct side_type_float type;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_float, 9 + sizeof(struct side_type_float));
 
 struct side_type_gather_string {
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
        struct side_type_string type;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_string, 9 + sizeof(struct side_type_string));
 
 struct side_type_gather_enum {
        side_ptr_t(const struct side_enum_mappings) mappings;
        side_ptr_t(const struct side_type) elem_type;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_enum, 32);
 
 struct side_type_gather_struct {
+       side_ptr_t(const struct side_type_struct) type;
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
-       side_ptr_t(const struct side_type_struct) type;
        uint32_t size;          /* bytes */
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_struct, 29);
 
 struct side_type_gather_array {
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
        struct side_type_array type;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_array, 9 + sizeof(struct side_type_array));
 
 struct side_type_gather_vla {
        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 */
        struct side_type_vla type;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather_vla, 25 + sizeof(struct side_type_vla));
 
 struct side_type_gather {
        union {
@@ -455,11 +519,13 @@ struct side_type_gather {
                struct side_type_gather_array side_array;
                struct side_type_gather_vla side_vla;
                struct side_type_gather_struct side_struct;
+               side_padding(61);
        } SIDE_PACKED u;
 } SIDE_PACKED;
+side_check_size(struct side_type_gather, 61);
 
 struct side_type {
-       uint32_t type;  /* enum side_type_label */
+       side_enum_t(enum side_type_label, uint16_t) type;
        union {
                /* Stack-copy basic types */
                struct side_type_null side_null;
@@ -482,45 +548,37 @@ struct side_type {
 
                /* Gather types */
                struct side_type_gather side_gather;
+               side_padding(62);
        } SIDE_PACKED u;
 } SIDE_PACKED;
+side_check_size(struct side_type, 64);
 
 struct side_variant_option {
        int64_t range_begin;
        int64_t range_end;
        const struct side_type side_type;
 } SIDE_PACKED;
+side_check_size(struct side_variant_option, 16 + sizeof(const struct side_type));
 
 struct side_type_variant {
-       const struct side_type selector;
        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;
+       const struct side_type selector;
 } SIDE_PACKED;
+side_check_size(struct side_type_variant, 40 + sizeof(const struct side_type));
 
 struct side_event_field {
        side_ptr_t(const char) field_name;
        struct side_type side_type;
 } SIDE_PACKED;
+side_check_size(struct side_event_field, 16 + sizeof(struct side_type));
 
 enum side_event_flags {
        SIDE_EVENT_FLAG_VARIADIC = (1 << 0),
 };
 
-struct side_callback {
-       union {
-               void (*call)(const struct side_event_description *desc,
-                       const struct side_arg_vec *side_arg_vec,
-                       void *priv);
-               void (*call_variadic)(const struct side_event_description *desc,
-                       const struct side_arg_vec *side_arg_vec,
-                       const struct side_arg_dynamic_struct *var_struct,
-                       void *priv);
-       } SIDE_PACKED u;
-       void *priv;
-} SIDE_PACKED;
-
 union side_arg_static {
        /* Stack-copy basic types */
        union side_bool_value bool_value;
@@ -550,7 +608,9 @@ union side_arg_static {
                side_ptr_t(const void) ptr;
                side_ptr_t(const void) length_ptr;
        } SIDE_PACKED side_vla_gather;
+       side_padding(32);
 } SIDE_PACKED;
+side_check_size(union side_arg_static, 32);
 
 struct side_arg_dynamic_vla {
        side_ptr_t(const struct side_arg) sav;
@@ -558,6 +618,7 @@ struct side_arg_dynamic_vla {
        uint32_t len;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_arg_dynamic_vla, 40);
 
 struct side_arg_dynamic_struct {
        side_ptr_t(const struct side_arg_dynamic_field) fields;
@@ -565,20 +626,23 @@ struct side_arg_dynamic_struct {
        uint32_t len;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_arg_dynamic_struct, 40);
 
 struct side_dynamic_struct_visitor {
-       void *app_ctx;
-       side_dynamic_struct_visitor_func visitor;
+       side_func_ptr_t(side_dynamic_struct_visitor_func) visitor;
+       side_ptr_t(void) app_ctx;
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_dynamic_struct_visitor, 52);
 
 struct side_dynamic_vla_visitor {
-       void *app_ctx;
-       side_visitor_func visitor;
+       side_func_ptr_t(side_visitor_func) visitor;
+       side_ptr_t(void) app_ctx;
        side_ptr_t(const struct side_attr) attr;
        uint32_t nr_attr;
 } SIDE_PACKED;
+side_check_size(struct side_dynamic_vla_visitor, 52);
 
 union side_arg_dynamic {
        /* Dynamic basic types */
@@ -610,55 +674,38 @@ union side_arg_dynamic {
 
        struct side_dynamic_struct_visitor side_dynamic_struct_visitor;
        struct side_dynamic_vla_visitor side_dynamic_vla_visitor;
+
+       side_padding(58);
 } SIDE_PACKED;
+side_check_size(union side_arg_dynamic, 58);
 
 struct side_arg {
-       uint32_t type;  /* enum side_type_label */
+       side_enum_t(enum side_type_label, uint16_t) type;
        union {
                union side_arg_static side_static;
                union side_arg_dynamic side_dynamic;
+               side_padding(62);
        } SIDE_PACKED u;
 } SIDE_PACKED;
+side_check_size(struct side_arg, 64);
 
 struct side_arg_variant {
        struct side_arg selector;
        struct side_arg option;
 } SIDE_PACKED;
+side_check_size(struct side_arg_variant, 128);
 
 struct side_arg_vec {
        side_ptr_t(const struct side_arg) sav;
        uint32_t len;
 } SIDE_PACKED;
+side_check_size(struct side_arg_vec, 20);
 
 struct side_arg_dynamic_field {
        side_ptr_t(const char) field_name;
        const struct side_arg elem;
 } SIDE_PACKED;
-
-/* The visitor pattern is a double-dispatch visitor. */
-struct side_tracer_visitor_ctx {
-       enum side_visitor_status (*write_elem)(
-                       const struct side_tracer_visitor_ctx *tracer_ctx,
-                       const struct side_arg *elem);
-       void *priv;             /* Private tracer context. */
-} SIDE_PACKED;
-
-struct side_tracer_dynamic_struct_visitor_ctx {
-       enum side_visitor_status (*write_field)(
-                       const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx,
-                       const struct side_arg_dynamic_field *dynamic_field);
-       void *priv;             /* Private tracer context. */
-} SIDE_PACKED;
-
-/*
- * This structure is _not_ packed to allow atomic operations on its
- * fields.
- */
-struct side_event_state {
-       uintptr_t enabled;
-       const struct side_callback *callbacks;
-       uint32_t nr_callbacks;
-};
+side_check_size(struct side_arg_dynamic_field, 16 + sizeof(const struct side_arg));
 
 struct side_event_description {
        side_ptr_t(struct side_event_state) state;
@@ -668,11 +715,22 @@ struct side_event_description {
        side_ptr_t(const struct side_attr) attr;
        uint64_t flags;
        uint32_t version;
-       uint32_t loglevel;      /* enum side_loglevel */
+       side_enum_t(enum side_loglevel, uint32_t) loglevel;
        uint32_t nr_fields;
        uint32_t nr_attr;
+       uint32_t nr_callbacks;
 } SIDE_PACKED;
 
+/*
+ * This structure is _not_ packed to allow atomic operations on its
+ * fields.
+ */
+struct side_event_state {
+       uintptr_t enabled;
+       const struct side_callback *callbacks;
+       struct side_event_description *desc;
+};
+
 /* Event and type attributes */
 
 #define side_attr(_key, _value)        \
@@ -680,7 +738,7 @@ struct side_event_description {
                .key = { \
                        .p = SIDE_PTR_INIT(_key), \
                        .unit_size = sizeof(uint8_t), \
-                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                       .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                }, \
                .value = SIDE_PARAM(_value), \
        }
@@ -689,28 +747,28 @@ struct side_event_description {
        SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__)
 
 #define side_attr_null(_val)           { .type = SIDE_ATTR_TYPE_NULL }
-#define side_attr_bool(_val)           { .type = SIDE_ATTR_TYPE_BOOL, .u = { .bool_value = !!(_val) } }
-#define side_attr_u8(_val)             { .type = SIDE_ATTR_TYPE_U8, .u = { .integer_value = { .side_u8 = (_val) } } }
-#define side_attr_u16(_val)            { .type = SIDE_ATTR_TYPE_U16, .u = { .integer_value = { .side_u16 = (_val) } } }
-#define side_attr_u32(_val)            { .type = SIDE_ATTR_TYPE_U32, .u = { .integer_value = { .side_u32 = (_val) } } }
-#define side_attr_u64(_val)            { .type = SIDE_ATTR_TYPE_U64, .u = { .integer_value = { .side_u64 = (_val) } } }
-#define side_attr_s8(_val)             { .type = SIDE_ATTR_TYPE_S8, .u = { .integer_value = { .side_s8 = (_val) } } }
-#define side_attr_s16(_val)            { .type = SIDE_ATTR_TYPE_S16, .u = { .integer_value = { .side_s16 = (_val) } } }
-#define side_attr_s32(_val)            { .type = SIDE_ATTR_TYPE_S32, .u = { .integer_value = { .side_s32 = (_val) } } }
-#define side_attr_s64(_val)            { .type = SIDE_ATTR_TYPE_S64, .u = { .integer_value = { .side_s64 = (_val) } } }
-#define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .float_value = { .side_float_binary16 = (_val) } } }
-#define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .float_value = { .side_float_binary32 = (_val) } } }
-#define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .float_value = { .side_float_binary64 = (_val) } } }
-#define side_attr_float_binary128(_val)        { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .float_value = { .side_float_binary128 = (_val) } } }
+#define side_attr_bool(_val)           { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_BOOL), .u = { .bool_value = !!(_val) } }
+#define side_attr_u8(_val)             { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U8), .u = { .integer_value = { .side_u8 = (_val) } } }
+#define side_attr_u16(_val)            { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U16), .u = { .integer_value = { .side_u16 = (_val) } } }
+#define side_attr_u32(_val)            { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U32), .u = { .integer_value = { .side_u32 = (_val) } } }
+#define side_attr_u64(_val)            { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_U64), .u = { .integer_value = { .side_u64 = (_val) } } }
+#define side_attr_s8(_val)             { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S8), .u = { .integer_value = { .side_s8 = (_val) } } }
+#define side_attr_s16(_val)            { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S16), .u = { .integer_value = { .side_s16 = (_val) } } }
+#define side_attr_s32(_val)            { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S32), .u = { .integer_value = { .side_s32 = (_val) } } }
+#define side_attr_s64(_val)            { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_S64), .u = { .integer_value = { .side_s64 = (_val) } } }
+#define side_attr_float_binary16(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY16), .u = { .float_value = { .side_float_binary16 = (_val) } } }
+#define side_attr_float_binary32(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY32), .u = { .float_value = { .side_float_binary32 = (_val) } } }
+#define side_attr_float_binary64(_val) { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY64), .u = { .float_value = { .side_float_binary64 = (_val) } } }
+#define side_attr_float_binary128(_val)        { .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_FLOAT_BINARY128), .u = { .float_value = { .side_float_binary128 = (_val) } } }
 
 #define _side_attr_string(_val, _byte_order, _unit_size) \
        { \
-               .type = SIDE_ATTR_TYPE_STRING, \
+               .type = SIDE_ENUM_INIT(SIDE_ATTR_TYPE_STRING), \
                .u = { \
                        .string_value = { \
                                .p = SIDE_PTR_INIT(_val), \
                                .unit_size = _unit_size, \
-                               .byte_order = _byte_order, \
+                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                        }, \
                }, \
        }
@@ -739,7 +797,7 @@ struct side_event_description {
                .label = { \
                        .p = SIDE_PTR_INIT(_label), \
                        .unit_size = sizeof(uint8_t), \
-                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                       .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                }, \
        }
 
@@ -750,7 +808,7 @@ struct side_event_description {
                .label = { \
                        .p = SIDE_PTR_INIT(_label), \
                        .unit_size = sizeof(uint8_t), \
-                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                       .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                }, \
        }
 
@@ -772,7 +830,7 @@ struct side_event_description {
                .label = { \
                        .p = SIDE_PTR_INIT(_label), \
                        .unit_size = sizeof(uint8_t), \
-                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                       .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                }, \
        }
 
@@ -783,7 +841,7 @@ struct side_event_description {
                .label = { \
                        .p = SIDE_PTR_INIT(_label), \
                        .unit_size = sizeof(uint8_t), \
-                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                       .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                }, \
        }
 
@@ -791,7 +849,7 @@ struct side_event_description {
 
 #define side_type_null(_attr...) \
        { \
-               .type = SIDE_TYPE_NULL, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL), \
                .u = { \
                        .side_null = { \
                                .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
@@ -802,21 +860,21 @@ struct side_event_description {
 
 #define side_type_bool(_attr...) \
        { \
-               .type = SIDE_TYPE_BOOL, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), \
                .u = { \
                        .side_bool = { \
                                .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())), \
                                .bool_size = sizeof(uint8_t), \
                                .len_bits = 0, \
-                               .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                               .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                        }, \
                }, \
        }
 
 #define side_type_byte(_attr...) \
        { \
-               .type = SIDE_TYPE_BYTE, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), \
                .u = { \
                        .side_byte = { \
                                .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
@@ -827,25 +885,25 @@ struct side_event_description {
 
 #define _side_type_string(_type, _byte_order, _unit_size, _attr) \
        { \
-               .type = _type, \
+               .type = SIDE_ENUM_INIT(_type), \
                .u = { \
                        .side_string = { \
                                .attr = SIDE_PTR_INIT(_attr), \
                                .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
                                .unit_size = _unit_size, \
-                               .byte_order = _byte_order, \
+                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                        }, \
                }, \
        }
 
 #define side_type_dynamic() \
        { \
-               .type = SIDE_TYPE_DYNAMIC, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC), \
        }
 
 #define _side_type_integer(_type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
        { \
-               .type = _type, \
+               .type = SIDE_ENUM_INIT(_type), \
                .u = { \
                        .side_integer = { \
                                .attr = SIDE_PTR_INIT(_attr), \
@@ -853,20 +911,20 @@ struct side_event_description {
                                .integer_size = _integer_size, \
                                .len_bits = _len_bits, \
                                .signedness = _signedness, \
-                               .byte_order = _byte_order, \
+                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                        }, \
                }, \
        }
 
 #define _side_type_float(_type, _byte_order, _float_size, _attr) \
        { \
-               .type = _type, \
+               .type = SIDE_ENUM_INIT(_type), \
                .u = { \
                        .side_float = { \
                                .attr = SIDE_PTR_INIT(_attr), \
                                .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
                                .float_size = _float_size, \
-                               .byte_order = _byte_order, \
+                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                        }, \
                }, \
        }
@@ -986,7 +1044,7 @@ struct side_event_description {
 
 #define side_type_enum(_mappings, _elem_type) \
        { \
-               .type = SIDE_TYPE_ENUM, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM), \
                .u = { \
                        .side_enum = { \
                                .mappings = SIDE_PTR_INIT(_mappings), \
@@ -999,7 +1057,7 @@ struct side_event_description {
 
 #define side_type_enum_bitmap(_mappings, _elem_type) \
        { \
-               .type = SIDE_TYPE_ENUM_BITMAP, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_ENUM_BITMAP), \
                .u = { \
                        .side_enum_bitmap = { \
                                .mappings = SIDE_PTR_INIT(_mappings), \
@@ -1012,7 +1070,7 @@ struct side_event_description {
 
 #define side_type_struct(_struct) \
        { \
-               .type = SIDE_TYPE_STRUCT, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), \
                .u = { \
                        .side_struct = SIDE_PTR_INIT(_struct), \
                }, \
@@ -1037,7 +1095,7 @@ struct side_event_description {
 
 #define side_type_variant(_variant) \
        { \
-               .type = SIDE_TYPE_VARIANT, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \
                .u = { \
                        .side_variant = SIDE_PTR_INIT(_variant), \
                }, \
@@ -1064,7 +1122,7 @@ struct side_event_description {
 
 #define side_type_array(_elem_type, _length, _attr...) \
        { \
-               .type = SIDE_TYPE_ARRAY, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), \
                .u = { \
                        .side_array = { \
                                .elem_type = SIDE_PTR_INIT(_elem_type), \
@@ -1079,7 +1137,7 @@ struct side_event_description {
 
 #define side_type_vla(_elem_type, _attr...) \
        { \
-               .type = SIDE_TYPE_VLA, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), \
                .u = { \
                        .side_vla = { \
                                .elem_type = SIDE_PTR_INIT(_elem_type), \
@@ -1093,11 +1151,11 @@ struct side_event_description {
 
 #define side_type_vla_visitor(_elem_type, _visitor, _attr...) \
        { \
-               .type = SIDE_TYPE_VLA_VISITOR, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), \
                .u = { \
                        .side_vla_visitor = { \
                                .elem_type = SIDE_PTR_INIT(_elem_type), \
-                               .visitor = _visitor, \
+                               .visitor = SIDE_PTR_INIT(_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())), \
                        }, \
@@ -1110,7 +1168,7 @@ struct side_event_description {
 
 #define side_type_gather_byte(_offset, _access_mode, _attr...) \
        { \
-               .type = SIDE_TYPE_GATHER_BYTE, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1131,7 +1189,7 @@ struct side_event_description {
 
 #define _side_type_gather_bool(_byte_order, _offset, _bool_size, _offset_bits, _len_bits, _access_mode, _attr...) \
        { \
-               .type = SIDE_TYPE_GATHER_BOOL, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1143,7 +1201,7 @@ struct side_event_description {
                                                        .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
                                                        .bool_size = _bool_size, \
                                                        .len_bits = _len_bits, \
-                                                       .byte_order = _byte_order, \
+                                                       .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                                }, \
                                                .offset_bits = _offset_bits, \
                                        }, \
@@ -1168,7 +1226,7 @@ struct side_event_description {
 #define _side_type_gather_integer(_type, _signedness, _byte_order, _offset, \
                _integer_size, _offset_bits, _len_bits, _access_mode, _attr...) \
        { \
-               .type = _type, \
+               .type = SIDE_ENUM_INIT(_type), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1181,7 +1239,7 @@ struct side_event_description {
                                                        .integer_size = _integer_size, \
                                                        .len_bits = _len_bits, \
                                                        .signedness = _signedness, \
-                                                       .byte_order = _byte_order, \
+                                                       .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                                }, \
                                                .offset_bits = _offset_bits, \
                                        }, \
@@ -1246,7 +1304,7 @@ struct side_event_description {
 
 #define _side_type_gather_float(_byte_order, _offset, _float_size, _access_mode, _attr...) \
        { \
-               .type = SIDE_TYPE_GATHER_FLOAT, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1257,7 +1315,7 @@ struct side_event_description {
                                                        .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())), \
                                                        .float_size = _float_size, \
-                                                       .byte_order = _byte_order, \
+                                                       .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                                }, \
                                        }, \
                                }, \
@@ -1281,7 +1339,7 @@ struct side_event_description {
 
 #define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr...) \
        { \
-               .type = SIDE_TYPE_GATHER_STRING, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1292,7 +1350,7 @@ struct side_event_description {
                                                        .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())), \
                                                        .unit_size = _unit_size, \
-                                                       .byte_order = _byte_order, \
+                                                       .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                                }, \
                                        }, \
                                }, \
@@ -1334,7 +1392,7 @@ struct side_event_description {
 
 #define side_type_gather_enum(_mappings, _elem_type) \
        { \
-               .type = SIDE_TYPE_GATHER_ENUM, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ENUM), \
                .u = { \
                        .side_enum = { \
                                .mappings = SIDE_PTR_INIT(_mappings), \
@@ -1347,7 +1405,7 @@ struct side_event_description {
 
 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
        { \
-               .type = SIDE_TYPE_GATHER_STRUCT, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1366,7 +1424,7 @@ struct side_event_description {
 
 #define side_type_gather_array(_elem_type_gather, _length, _offset, _access_mode, _attr...) \
        { \
-               .type = SIDE_TYPE_GATHER_ARRAY, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1389,7 +1447,7 @@ struct side_event_description {
 
 #define side_type_gather_vla(_elem_type_gather, _offset, _access_mode, _length_type_gather, _attr...) \
        { \
-               .type = SIDE_TYPE_GATHER_VLA, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), \
                .u = { \
                        .side_gather = { \
                                .u = { \
@@ -1424,28 +1482,28 @@ struct side_event_description {
 
 /* Stack-copy field arguments */
 
-#define side_arg_null(_val)            { .type = SIDE_TYPE_NULL }
-#define side_arg_bool(_val)            { .type = SIDE_TYPE_BOOL, .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
-#define side_arg_byte(_val)            { .type = SIDE_TYPE_BYTE, .u = { .side_static = { .byte_value = (_val) } } }
-#define side_arg_string(_val)          { .type = SIDE_TYPE_STRING_UTF8, .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
-#define side_arg_string16(_val)                { .type = SIDE_TYPE_STRING_UTF16, .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
-#define side_arg_string32(_val)                { .type = SIDE_TYPE_STRING_UTF32, .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
-
-#define side_arg_u8(_val)              { .type = SIDE_TYPE_U8, .u = { .side_static = {  .integer_value = { .side_u8 = (_val) } } } }
-#define side_arg_u16(_val)             { .type = SIDE_TYPE_U16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
-#define side_arg_u32(_val)             { .type = SIDE_TYPE_U32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
-#define side_arg_u64(_val)             { .type = SIDE_TYPE_U64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
-#define side_arg_s8(_val)              { .type = SIDE_TYPE_S8, .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
-#define side_arg_s16(_val)             { .type = SIDE_TYPE_S16, .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
-#define side_arg_s32(_val)             { .type = SIDE_TYPE_S32, .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
-#define side_arg_s64(_val)             { .type = SIDE_TYPE_S64, .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
-#define side_arg_pointer(_val)         { .type = SIDE_TYPE_POINTER, .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
-#define side_arg_float_binary16(_val)  { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
-#define side_arg_float_binary32(_val)  { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
-#define side_arg_float_binary64(_val)  { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
-#define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
-
-#define side_arg_struct(_side_type)    { .type = SIDE_TYPE_STRUCT, .u = { .side_static = { .side_struct = SIDE_PTR_INIT(_side_type) } } }
+#define side_arg_null(_val)            { .type = SIDE_ENUM_INIT(SIDE_TYPE_NULL) }
+#define side_arg_bool(_val)            { .type = SIDE_ENUM_INIT(SIDE_TYPE_BOOL), .u = { .side_static = { .bool_value = { .side_bool8 = !!(_val) } } } }
+#define side_arg_byte(_val)            { .type = SIDE_ENUM_INIT(SIDE_TYPE_BYTE), .u = { .side_static = { .byte_value = (_val) } } }
+#define side_arg_string(_val)          { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF8), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
+#define side_arg_string16(_val)                { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF16), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
+#define side_arg_string32(_val)                { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRING_UTF32), .u = { .side_static = { .string_value = SIDE_PTR_INIT(_val) } } }
+
+#define side_arg_u8(_val)              { .type = SIDE_ENUM_INIT(SIDE_TYPE_U8), .u = { .side_static = {  .integer_value = { .side_u8 = (_val) } } } }
+#define side_arg_u16(_val)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_U16), .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
+#define side_arg_u32(_val)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_U32), .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
+#define side_arg_u64(_val)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_U64), .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
+#define side_arg_s8(_val)              { .type = SIDE_ENUM_INIT(SIDE_TYPE_S8), .u = { .side_static = { .integer_value = { .side_s8 = (_val) } } } }
+#define side_arg_s16(_val)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_S16), .u = { .side_static = { .integer_value = { .side_s16 = (_val) } } } }
+#define side_arg_s32(_val)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_S32), .u = { .side_static = { .integer_value = { .side_s32 = (_val) } } } }
+#define side_arg_s64(_val)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_S64), .u = { .side_static = { .integer_value = { .side_s64 = (_val) } } } }
+#define side_arg_pointer(_val)         { .type = SIDE_ENUM_INIT(SIDE_TYPE_POINTER), .u = { .side_static = { .integer_value = { .side_uptr = (uintptr_t) (_val) } } } }
+#define side_arg_float_binary16(_val)  { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY16), .u = { .side_static = { .float_value = { .side_float_binary16 = (_val) } } } }
+#define side_arg_float_binary32(_val)  { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY32), .u = { .side_static = { .float_value = { .side_float_binary32 = (_val) } } } }
+#define side_arg_float_binary64(_val)  { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY64), .u = { .side_static = { .float_value = { .side_float_binary64 = (_val) } } } }
+#define side_arg_float_binary128(_val) { .type = SIDE_ENUM_INIT(SIDE_TYPE_FLOAT_BINARY128), .u = { .side_static = { .float_value = { .side_float_binary128 = (_val) } } } }
+
+#define side_arg_struct(_side_type)    { .type = SIDE_ENUM_INIT(SIDE_TYPE_STRUCT), .u = { .side_static = { .side_struct = SIDE_PTR_INIT(_side_type) } } }
 
 #define side_arg_define_variant(_identifier, _selector_val, _option) \
        const struct side_arg_variant _identifier = { \
@@ -1454,7 +1512,7 @@ struct side_event_description {
        }
 #define side_arg_variant(_side_variant) \
        { \
-               .type = SIDE_TYPE_VARIANT, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_VARIANT), \
                .u = { \
                        .side_static = { \
                                .side_variant = SIDE_PTR_INIT(_side_variant), \
@@ -1462,27 +1520,27 @@ struct side_event_description {
                }, \
        }
 
-#define side_arg_array(_side_type)     { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = SIDE_PTR_INIT(_side_type) } } }
-#define side_arg_vla(_side_type)       { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = SIDE_PTR_INIT(_side_type) } } }
-#define side_arg_vla_visitor(_ctx)     { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
+#define side_arg_array(_side_type)     { .type = SIDE_ENUM_INIT(SIDE_TYPE_ARRAY), .u = { .side_static = { .side_array = SIDE_PTR_INIT(_side_type) } } }
+#define side_arg_vla(_side_type)       { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA), .u = { .side_static = { .side_vla = SIDE_PTR_INIT(_side_type) } } }
+#define side_arg_vla_visitor(_ctx)     { .type = SIDE_ENUM_INIT(SIDE_TYPE_VLA_VISITOR), .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
 
 /* Gather field arguments */
 
-#define side_arg_gather_bool(_ptr)             { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_byte(_ptr)             { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_pointer(_ptr)          { .type = SIDE_TYPE_GATHER_POINTER, .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_integer(_ptr)          { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_float(_ptr)            { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_string(_ptr)           { .type = SIDE_TYPE_GATHER_STRING, .u = { .side_static = { .side_string_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_struct(_ptr)           { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_array(_ptr)            { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
-#define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_TYPE_GATHER_VLA, .u = { .side_static = { .side_vla_gather = { .ptr = SIDE_PTR_INIT(_ptr), .length_ptr = SIDE_PTR_INIT(_length_ptr) } } } }
+#define side_arg_gather_bool(_ptr)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BOOL), .u = { .side_static = { .side_bool_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_byte(_ptr)             { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_BYTE), .u = { .side_static = { .side_byte_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_pointer(_ptr)          { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_POINTER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_integer(_ptr)          { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_INTEGER), .u = { .side_static = { .side_integer_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_float(_ptr)            { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_FLOAT), .u = { .side_static = { .side_float_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_string(_ptr)           { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRING), .u = { .side_static = { .side_string_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_struct(_ptr)           { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_STRUCT), .u = { .side_static = { .side_struct_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_array(_ptr)            { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_ARRAY), .u = { .side_static = { .side_array_gather_ptr = SIDE_PTR_INIT(_ptr) } } }
+#define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_ENUM_INIT(SIDE_TYPE_GATHER_VLA), .u = { .side_static = { .side_vla_gather = { .ptr = SIDE_PTR_INIT(_ptr), .length_ptr = SIDE_PTR_INIT(_length_ptr) } } } }
 
 /* Dynamic field arguments */
 
 #define side_arg_dynamic_null(_attr...) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_NULL, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_NULL), \
                .u = { \
                        .side_dynamic = { \
                                .side_null = { \
@@ -1495,7 +1553,7 @@ struct side_event_description {
 
 #define side_arg_dynamic_bool(_val, _attr...) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_BOOL, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BOOL), \
                .u = { \
                        .side_dynamic = { \
                                .side_bool = { \
@@ -1504,7 +1562,7 @@ struct side_event_description {
                                                .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
                                                .bool_size = sizeof(uint8_t), \
                                                .len_bits = 0, \
-                                               .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+                                               .byte_order = SIDE_ENUM_INIT(SIDE_TYPE_BYTE_ORDER_HOST), \
                                        }, \
                                        .value = { \
                                                .side_bool8 = !!(_val), \
@@ -1516,7 +1574,7 @@ struct side_event_description {
 
 #define side_arg_dynamic_byte(_val, _attr...) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_BYTE, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_BYTE), \
                .u = { \
                        .side_dynamic = { \
                                .side_byte = { \
@@ -1532,7 +1590,7 @@ struct side_event_description {
 
 #define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr...) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_STRING, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRING), \
                .u = { \
                        .side_dynamic = { \
                                .side_string = { \
@@ -1540,7 +1598,7 @@ struct side_event_description {
                                                .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())), \
                                                .unit_size = _unit_size, \
-                                               .byte_order = _byte_order, \
+                                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                        }, \
                                        .value = (uintptr_t) (_val), \
                                }, \
@@ -1564,7 +1622,7 @@ struct side_event_description {
 
 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr...) \
        { \
-               .type = _type, \
+               .type = SIDE_ENUM_INIT(_type), \
                .u = { \
                        .side_dynamic = { \
                                .side_integer = { \
@@ -1574,7 +1632,7 @@ struct side_event_description {
                                                .integer_size = _integer_size, \
                                                .len_bits = _len_bits, \
                                                .signedness = _signedness, \
-                                               .byte_order = _byte_order, \
+                                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                        }, \
                                        .value = { \
                                                _field = (_val), \
@@ -1609,7 +1667,7 @@ struct side_event_description {
 
 #define _side_arg_dynamic_float(_field, _val, _type, _byte_order, _float_size, _attr...) \
        { \
-               .type = _type, \
+               .type = SIDE_ENUM_INIT(_type), \
                .u = { \
                        .side_dynamic = { \
                                .side_float = { \
@@ -1617,7 +1675,7 @@ struct side_event_description {
                                                .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())), \
                                                .float_size = _float_size, \
-                                               .byte_order = _byte_order, \
+                                               .byte_order = SIDE_ENUM_INIT(_byte_order), \
                                        }, \
                                        .value = { \
                                                _field = (_val), \
@@ -1677,7 +1735,7 @@ struct side_event_description {
 
 #define side_arg_dynamic_vla(_vla) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_VLA, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA), \
                .u = { \
                        .side_dynamic = { \
                                .side_dynamic_vla = SIDE_PTR_INIT(_vla), \
@@ -1687,12 +1745,12 @@ struct side_event_description {
 
 #define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr...) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_VLA_VISITOR, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_VLA_VISITOR), \
                .u = { \
                        .side_dynamic = { \
                                .side_dynamic_vla_visitor = { \
-                                       .app_ctx = _ctx, \
-                                       .visitor = _dynamic_vla_visitor, \
+                                       .app_ctx = SIDE_PTR_INIT(_ctx), \
+                                       .visitor = SIDE_PTR_INIT(_dynamic_vla_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())), \
                                }, \
@@ -1702,7 +1760,7 @@ struct side_event_description {
 
 #define side_arg_dynamic_struct(_struct) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_STRUCT, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT), \
                .u = { \
                        .side_dynamic = { \
                                .side_dynamic_struct = SIDE_PTR_INIT(_struct), \
@@ -1712,12 +1770,12 @@ struct side_event_description {
 
 #define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr...) \
        { \
-               .type = SIDE_TYPE_DYNAMIC_STRUCT_VISITOR, \
+               .type = SIDE_ENUM_INIT(SIDE_TYPE_DYNAMIC_STRUCT_VISITOR), \
                .u = { \
                        .side_dynamic = { \
                                .side_dynamic_struct_visitor = { \
-                                       .app_ctx = _ctx, \
-                                       .visitor = _dynamic_struct_visitor, \
+                                       .app_ctx = SIDE_PTR_INIT(_ctx), \
+                                       .visitor = SIDE_PTR_INIT(_dynamic_struct_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())), \
                                }, \
@@ -1774,7 +1832,7 @@ struct side_event_description {
                        .sav = SIDE_PTR_INIT(side_sav), \
                        .len = SIDE_ARRAY_SIZE(side_sav), \
                }; \
-               side_call(&(_identifier), &side_arg_vec); \
+               side_call(&(side_event_state__##_identifier), &side_arg_vec); \
        }
 
 #define side_event(_identifier, _sav) \
@@ -1795,7 +1853,7 @@ struct side_event_description {
                        .len = SIDE_ARRAY_SIZE(side_fields), \
                        .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
                }; \
-               side_call_variadic(&(_identifier), &side_arg_vec, &var_struct); \
+               side_call_variadic(&(side_event_state__##_identifier), &side_arg_vec, &var_struct); \
        }
 
 #define side_event_variadic(_identifier, _sav, _var, _attr...) \
@@ -1803,11 +1861,13 @@ struct side_event_description {
                side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list()))
 
 #define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _flags, _attr...) \
+       _linkage struct side_event_description __attribute__((section("side_event_description"))) \
+                       _identifier; \
        _linkage struct side_event_state __attribute__((section("side_event_state"))) \
                        side_event_state__##_identifier = { \
                .enabled = 0, \
                .callbacks = &side_empty_callback, \
-               .nr_callbacks = 0, \
+               .desc = &(_identifier), \
        }; \
        _linkage struct side_event_description __attribute__((section("side_event_description"))) \
                        _identifier = { \
@@ -1818,9 +1878,10 @@ struct side_event_description {
                .attr = SIDE_PTR_INIT(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
                .flags = (_flags), \
                .version = 0, \
-               .loglevel = _loglevel, \
+               .loglevel = SIDE_ENUM_INIT(_loglevel), \
                .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \
                .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM_SELECT_ARG1(_, ##_attr, side_attr_list())), \
+               .nr_callbacks = 0, \
        }; \
        static const struct side_event_description *side_event_ptr__##_identifier \
                __attribute__((section("side_event_description_ptr"), used)) = &(_identifier);
@@ -1857,11 +1918,35 @@ struct side_event_description {
 extern "C" {
 #endif
 
+struct side_callback {
+       union {
+               void (*call)(const struct side_event_description *desc,
+                       const struct side_arg_vec *side_arg_vec,
+                       void *priv);
+               void (*call_variadic)(const struct side_event_description *desc,
+                       const struct side_arg_vec *side_arg_vec,
+                       const struct side_arg_dynamic_struct *var_struct,
+                       void *priv);
+       } SIDE_PACKED u;
+       void *priv;
+} SIDE_PACKED;
+
+/* The visitor pattern is a double-dispatch visitor. */
+struct side_tracer_visitor_ctx {
+       side_write_elem_func write_elem;
+       void *priv;             /* Private tracer context. */
+} SIDE_PACKED;
+
+struct side_tracer_dynamic_struct_visitor_ctx {
+       side_write_field_func write_field;
+       void *priv;             /* Private tracer context. */
+} SIDE_PACKED;
+
 extern const struct side_callback side_empty_callback;
 
-void side_call(const struct side_event_description *desc,
+void side_call(const struct side_event_state *state,
        const struct side_arg_vec *side_arg_vec);
-void side_call_variadic(const struct side_event_description *desc,
+void side_call_variadic(const struct side_event_state *state,
        const struct side_arg_vec *side_arg_vec,
        const struct side_arg_dynamic_struct *var_struct);
 
This page took 0.074062 seconds and 4 git commands to generate.