Implement variant type
[libside.git] / include / side / trace.h
index 9a9d942d0e72a5d8eb4ab7d79618394d160c07ad..e341047af5a14fcf9d8ec4194d779d8e4867edb5 100644 (file)
@@ -15,7 +15,7 @@
 #include <side/endian.h>
 
 /*
- * SIDE stands for "Static Instrumentation Dynamically Enabled"
+ * SIDE stands for "Software Instrumentation Dynamically Enabled"
  *
  * This is an instrumentation API for Linux user-space, which exposes an
  * instrumentation type system and facilities allowing a kernel or
@@ -82,6 +82,7 @@ struct side_tracer_dynamic_struct_visitor_ctx;
 struct side_event_description;
 struct side_arg_dynamic_struct;
 struct side_events_register_handle;
+struct side_arg_variant;
 
 enum side_type_label {
        /* Stack-copy basic types */
@@ -101,10 +102,13 @@ enum side_type_label {
        SIDE_TYPE_FLOAT_BINARY32,
        SIDE_TYPE_FLOAT_BINARY64,
        SIDE_TYPE_FLOAT_BINARY128,
-       SIDE_TYPE_STRING,
+       SIDE_TYPE_STRING_UTF8,
+       SIDE_TYPE_STRING_UTF16,
+       SIDE_TYPE_STRING_UTF32,
 
        /* Stack-copy compound types */
        SIDE_TYPE_STRUCT,
+       SIDE_TYPE_VARIANT,
        SIDE_TYPE_ARRAY,
        SIDE_TYPE_VLA,
        SIDE_TYPE_VLA_VISITOR,
@@ -122,12 +126,16 @@ enum side_type_label {
        SIDE_TYPE_GATHER_BYTE,
        SIDE_TYPE_GATHER_POINTER,
        SIDE_TYPE_GATHER_FLOAT,
+       SIDE_TYPE_GATHER_STRING,
 
        /* Gather compound types */
        SIDE_TYPE_GATHER_STRUCT,
        SIDE_TYPE_GATHER_ARRAY,
        SIDE_TYPE_GATHER_VLA,
 
+       /* Gather enumeration types */
+       SIDE_TYPE_GATHER_ENUM,
+
        /* Dynamic basic types */
        SIDE_TYPE_DYNAMIC_NULL,
        SIDE_TYPE_DYNAMIC_BOOL,
@@ -250,11 +258,17 @@ union side_float_value {
 #endif
 } SIDE_PACKED;
 
+struct side_type_raw_string {
+       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_PACKED;
+
 struct side_attr_value {
        uint32_t type;  /* enum side_attr_type */
        union {
                uint8_t bool_value;
-               uint64_t string_value;  /* const char * */
+               struct side_type_raw_string string_value;
                union side_integer_value integer_value;
                union side_float_value float_value;
        } SIDE_PACKED u;
@@ -262,7 +276,7 @@ struct side_attr_value {
 
 /* User attributes. */
 struct side_attr {
-       const char *key;
+       const struct side_type_raw_string key;
        const struct side_attr_value value;
 } SIDE_PACKED;
 
@@ -288,6 +302,8 @@ struct side_type_byte {
 struct side_type_string {
        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_PACKED;
 
 struct side_type_integer {
@@ -309,7 +325,7 @@ struct side_type_float {
 struct side_enum_mapping {
        int64_t range_begin;
        int64_t range_end;
-       const char *label;
+       struct side_type_raw_string label;
 } SIDE_PACKED;
 
 struct side_enum_mappings {
@@ -322,7 +338,7 @@ struct side_enum_mappings {
 struct side_enum_bitmap_mapping {
        uint64_t range_begin;
        uint64_t range_end;
-       const char *label;
+       struct side_type_raw_string label;
 } SIDE_PACKED;
 
 struct side_enum_bitmap_mappings {
@@ -395,6 +411,17 @@ struct side_type_gather_float {
        struct side_type_float type;
 } SIDE_PACKED;
 
+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;
+
+struct side_type_gather_enum {
+       const struct side_enum_mappings *mappings;
+       const struct side_type *elem_type;
+} SIDE_PACKED;
+
 struct side_type_gather_struct {
        uint64_t offset;        /* bytes */
        uint8_t access_mode;    /* enum side_type_gather_access_mode */
@@ -422,6 +449,8 @@ struct side_type_gather {
                struct side_type_gather_byte side_byte;
                struct side_type_gather_integer side_integer;
                struct side_type_gather_float side_float;
+               struct side_type_gather_string side_string;
+               struct side_type_gather_enum side_enum;
                struct side_type_gather_array side_array;
                struct side_type_gather_vla side_vla;
                struct side_type_gather_struct side_struct;
@@ -444,6 +473,7 @@ struct side_type {
                struct side_type_vla side_vla;
                struct side_type_vla_visitor side_vla_visitor;
                const struct side_type_struct *side_struct;
+               const struct side_type_variant *side_variant;
 
                /* Stack-copy enumeration types */
                struct side_type_enum side_enum;
@@ -454,6 +484,20 @@ struct side_type {
        } SIDE_PACKED u;
 } SIDE_PACKED;
 
+struct side_variant_option {
+       int64_t range_begin;
+       int64_t range_end;
+       const struct side_type side_type;
+} SIDE_PACKED;
+
+struct side_type_variant {
+       const struct side_type selector;
+       const struct side_variant_option *options;
+       const struct side_attr *attr;
+       uint32_t nr_options;
+       uint32_t nr_attr;
+} SIDE_PACKED;
+
 struct side_event_field {
        const char *field_name;
        struct side_type side_type;
@@ -480,28 +524,30 @@ struct side_arg_static {
        /* Stack-copy basic types */
        union side_bool_value bool_value;
        uint8_t byte_value;
-       uint64_t string_value;  /* const char * */
+       uint64_t string_value;  /* const {uint8_t, uint16_t, uint32_t} * */
        union side_integer_value integer_value;
        union side_float_value float_value;
 
        /* Stack-copy compound types */
        const struct side_arg_vec *side_struct;
+       const struct side_arg_variant *side_variant;
        const struct side_arg_vec *side_array;
        const struct side_arg_vec *side_vla;
        void *side_vla_app_visitor_ctx;
 
        /* Gather basic types */
-       void *side_bool_gather_ptr;
-       void *side_byte_gather_ptr;
-       void *side_integer_gather_ptr;
-       void *side_float_gather_ptr;
+       const void *side_bool_gather_ptr;
+       const void *side_byte_gather_ptr;
+       const void *side_integer_gather_ptr;
+       const void *side_float_gather_ptr;
+       const void *side_string_gather_ptr;
 
        /* Gather compound types */
-       void *side_array_gather_ptr;
-       void *side_struct_gather_ptr;
+       const void *side_array_gather_ptr;
+       const void *side_struct_gather_ptr;
        struct {
-               void *ptr;
-               void *length_ptr;
+               const void *ptr;
+               const void *length_ptr;
        } SIDE_PACKED side_vla_gather;
 } SIDE_PACKED;
 
@@ -566,13 +612,18 @@ struct side_arg_dynamic {
 } SIDE_PACKED;
 
 struct side_arg {
-       enum side_type_label type;
+       uint32_t type;  /* enum side_type_label */
        union {
                struct side_arg_static side_static;
                struct side_arg_dynamic side_dynamic;
        } SIDE_PACKED u;
 } SIDE_PACKED;
 
+struct side_arg_variant {
+       struct side_arg selector;
+       struct side_arg option;
+} SIDE_PACKED;
+
 struct side_arg_vec {
        const struct side_arg *sav;
        uint32_t len;
@@ -617,7 +668,11 @@ struct side_event_description {
 
 #define side_attr(_key, _value)        \
        { \
-               .key = _key, \
+               .key = { \
+                       .p = (_key), \
+                       .unit_size = sizeof(uint8_t), \
+                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+               }, \
                .value = SIDE_PARAM(_value), \
        }
 
@@ -638,7 +693,22 @@ struct side_event_description {
 #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_string(_val)         { .type = SIDE_ATTR_TYPE_STRING, .u = { .string_value = (uintptr_t) (_val) } }
+
+#define _side_attr_string(_val, _byte_order, _unit_size) \
+       { \
+               .type = SIDE_ATTR_TYPE_STRING, \
+               .u = { \
+                       .string_value = { \
+                               .p = (const void *) (_val), \
+                               .unit_size = _unit_size, \
+                               .byte_order = _byte_order, \
+                       }, \
+               }, \
+       }
+
+#define side_attr_string(_val)         _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t))
+#define side_attr_string16(_val)       _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t))
+#define side_attr_string32(_val)       _side_attr_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t))
 
 /* Stack-copy enumeration type definitions */
 
@@ -657,14 +727,22 @@ struct side_event_description {
        { \
                .range_begin = _begin, \
                .range_end = _end, \
-               .label = _label, \
+               .label = { \
+                       .p = (_label), \
+                       .unit_size = sizeof(uint8_t), \
+                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+               }, \
        }
 
 #define side_enum_mapping_value(_label, _value) \
        { \
                .range_begin = _value, \
                .range_end = _value, \
-               .label = _label, \
+               .label = { \
+                       .p = (_label), \
+                       .unit_size = sizeof(uint8_t), \
+                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+               }, \
        }
 
 #define side_define_enum_bitmap(_identifier, _mappings, _attr) \
@@ -682,14 +760,22 @@ struct side_event_description {
        { \
                .range_begin = _begin, \
                .range_end = _end, \
-               .label = _label, \
+               .label = { \
+                       .p = (_label), \
+                       .unit_size = sizeof(uint8_t), \
+                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+               }, \
        }
 
 #define side_enum_bitmap_mapping_value(_label, _value) \
        { \
                .range_begin = _value, \
                .range_end = _value, \
-               .label = _label, \
+               .label = { \
+                       .p = (_label), \
+                       .unit_size = sizeof(uint8_t), \
+                       .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \
+               }, \
        }
 
 /* Stack-copy field and type definitions */
@@ -730,13 +816,15 @@ struct side_event_description {
                }, \
        }
 
-#define side_type_string(_attr) \
+#define _side_type_string(_type, _byte_order, _unit_size, _attr) \
        { \
-               .type = SIDE_TYPE_STRING, \
+               .type = _type, \
                .u = { \
                        .side_string = { \
                                .attr = _attr, \
                                .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+                               .unit_size = _unit_size, \
+                               .byte_order = _byte_order, \
                        }, \
                }, \
        }
@@ -780,6 +868,16 @@ struct side_event_description {
                .side_type = _type, \
        }
 
+#define side_option_range(_range_begin, _range_end, _type) \
+       { \
+               .range_begin = _range_begin, \
+               .range_end = _range_end, \
+               .side_type = _type, \
+       }
+
+#define side_option(_value, _type) \
+       side_option_range(_value, _value, SIDE_PARAM(_type))
+
 /* Host endian */
 #define side_type_u8(_attr)                            _side_type_integer(SIDE_TYPE_U8, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), 0, SIDE_PARAM(_attr))
 #define side_type_u16(_attr)                           _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
@@ -794,6 +892,9 @@ struct side_event_description {
 #define side_type_float_binary32(_attr)                        _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float32), SIDE_PARAM(_attr))
 #define side_type_float_binary64(_attr)                        _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float64), SIDE_PARAM(_attr))
 #define side_type_float_binary128(_attr)               _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, sizeof(_Float128), SIDE_PARAM(_attr))
+#define side_type_string(_attr)                                _side_type_string(SIDE_TYPE_STRING_UTF8, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM(_attr))
+#define side_type_string16(_attr)                      _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM(_attr))
+#define side_type_string32(_attr)                      _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM(_attr))
 
 #define side_field_null(_name, _attr)                  _side_field(_name, side_type_null(SIDE_PARAM(_attr)))
 #define side_field_bool(_name, _attr)                  _side_field(_name, side_type_bool(SIDE_PARAM(_attr)))
@@ -812,6 +913,8 @@ struct side_event_description {
 #define side_field_float_binary64(_name, _attr)                _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
 #define side_field_float_binary128(_name, _attr)       _side_field(_name, side_type_float_binary128(SIDE_PARAM(_attr)))
 #define side_field_string(_name, _attr)                        _side_field(_name, side_type_string(SIDE_PARAM(_attr)))
+#define side_field_string16(_name, _attr)              _side_field(_name, side_type_string16(SIDE_PARAM(_attr)))
+#define side_field_string32(_name, _attr)              _side_field(_name, side_type_string32(SIDE_PARAM(_attr)))
 #define side_field_dynamic(_name)                      _side_field(_name, side_type_dynamic())
 
 /* Little endian */
@@ -826,6 +929,8 @@ struct side_event_description {
 #define side_type_float_binary32_le(_attr)             _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float32), SIDE_PARAM(_attr))
 #define side_type_float_binary64_le(_attr)             _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float64), SIDE_PARAM(_attr))
 #define side_type_float_binary128_le(_attr)            _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, sizeof(_Float128), SIDE_PARAM(_attr))
+#define side_type_string16_le(_attr)                   _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM(_attr))
+#define side_type_string32_le(_attr)                   _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM(_attr))
 
 #define side_field_u16_le(_name, _attr)                        _side_field(_name, side_type_u16_le(SIDE_PARAM(_attr)))
 #define side_field_u32_le(_name, _attr)                        _side_field(_name, side_type_u32_le(SIDE_PARAM(_attr)))
@@ -838,6 +943,8 @@ struct side_event_description {
 #define side_field_float_binary32_le(_name, _attr)     _side_field(_name, side_type_float_binary32_le(SIDE_PARAM(_attr)))
 #define side_field_float_binary64_le(_name, _attr)     _side_field(_name, side_type_float_binary64_le(SIDE_PARAM(_attr)))
 #define side_field_float_binary128_le(_name, _attr)    _side_field(_name, side_type_float_binary128_le(SIDE_PARAM(_attr)))
+#define side_field_string16_le(_name, _attr)           _side_field(_name, side_type_string16_le(SIDE_PARAM(_attr)))
+#define side_field_string32_le(_name, _attr)           _side_field(_name, side_type_string32_le(SIDE_PARAM(_attr)))
 
 /* Big endian */
 #define side_type_u16_be(_attr)                                _side_type_integer(SIDE_TYPE_U16, false, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), 0, SIDE_PARAM(_attr))
@@ -851,6 +958,8 @@ struct side_event_description {
 #define side_type_float_binary32_be(_attr)             _side_type_float(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float32), SIDE_PARAM(_attr))
 #define side_type_float_binary64_be(_attr)             _side_type_float(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float64), SIDE_PARAM(_attr))
 #define side_type_float_binary128_be(_attr)            _side_type_float(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, sizeof(_Float128), SIDE_PARAM(_attr))
+#define side_type_string16_be(_attr)                   _side_type_string(SIDE_TYPE_STRING_UTF16, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM(_attr))
+#define side_type_string32_be(_attr)                   _side_type_string(SIDE_TYPE_STRING_UTF32, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM(_attr))
 
 #define side_field_u16_be(_name, _attr)                        _side_field(_name, side_type_u16_be(SIDE_PARAM(_attr)))
 #define side_field_u32_be(_name, _attr)                        _side_field(_name, side_type_u32_be(SIDE_PARAM(_attr)))
@@ -863,6 +972,8 @@ struct side_event_description {
 #define side_field_float_binary32_be(_name, _attr)     _side_field(_name, side_type_float_binary32_be(SIDE_PARAM(_attr)))
 #define side_field_float_binary64_be(_name, _attr)     _side_field(_name, side_type_float_binary64_be(SIDE_PARAM(_attr)))
 #define side_field_float_binary128_be(_name, _attr)    _side_field(_name, side_type_float_binary128_be(SIDE_PARAM(_attr)))
+#define side_field_string16_be(_name, _attr)           _side_field(_name, side_type_string16_be(SIDE_PARAM(_attr)))
+#define side_field_string32_be(_name, _attr)           _side_field(_name, side_type_string32_be(SIDE_PARAM(_attr)))
 
 #define side_type_enum(_mappings, _elem_type) \
        { \
@@ -915,6 +1026,33 @@ struct side_event_description {
        SIDE_COMPOUND_LITERAL(const struct side_type_struct, \
                _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)))
 
+#define side_type_variant(_variant) \
+       { \
+               .type = SIDE_TYPE_VARIANT, \
+               .u = { \
+                       .side_variant = _variant, \
+               }, \
+       }
+#define side_field_variant(_name, _variant) \
+       _side_field(_name, side_type_variant(SIDE_PARAM(_variant)))
+
+#define _side_type_variant_define(_selector, _options, _attr) \
+       { \
+               .selector = _selector, \
+               .options = _options, \
+               .attr = _attr, \
+               .nr_options = SIDE_ARRAY_SIZE(SIDE_PARAM(_options)), \
+               .nr_attr  = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+       }
+
+#define side_define_variant(_identifier, _selector, _options, _attr) \
+       const struct side_type_variant _identifier = \
+               _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM(_attr))
+
+#define side_variant_literal(_selector, _options, _attr) \
+       SIDE_COMPOUND_LITERAL(const struct side_type_variant, \
+               _side_type_variant_define(SIDE_PARAM(_selector), SIDE_PARAM(_options), SIDE_PARAM(_attr)))
+
 #define side_type_array(_elem_type, _length, _attr) \
        { \
                .type = SIDE_TYPE_ARRAY, \
@@ -1132,6 +1270,72 @@ struct side_event_description {
 #define side_field_gather_float_be(_name, _offset, _float_size, _access_mode, _attr) \
        _side_field(_name, side_type_gather_float_be(_offset, _float_size, _access_mode, _attr))
 
+#define _side_type_gather_string(_offset, _byte_order, _unit_size, _access_mode, _attr) \
+       { \
+               .type = SIDE_TYPE_GATHER_STRING, \
+               .u = { \
+                       .side_gather = { \
+                               .u = { \
+                                       .side_string = { \
+                                               .offset = _offset, \
+                                               .access_mode = _access_mode, \
+                                               .type = { \
+                                                       .attr = _attr, \
+                                                       .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+                                                       .unit_size = _unit_size, \
+                                                       .byte_order = _byte_order, \
+                                               }, \
+                                       }, \
+                               }, \
+                       }, \
+               }, \
+       }
+#define side_type_gather_string(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), _access_mode, SIDE_PARAM(_attr))
+#define side_field_gather_string(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string(_offset, _access_mode, SIDE_PARAM(_attr)))
+
+#define side_type_gather_string16(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), _access_mode, SIDE_PARAM(_attr))
+#define side_type_gather_string16_le(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), _access_mode, SIDE_PARAM(_attr))
+#define side_type_gather_string16_be(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), _access_mode, SIDE_PARAM(_attr))
+
+#define side_field_gather_string16(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string16(_offset, _access_mode, SIDE_PARAM(_attr)))
+#define side_field_gather_string16_le(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string16_le(_offset, _access_mode, SIDE_PARAM(_attr)))
+#define side_field_gather_string16_be(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string16_be(_offset, _access_mode, SIDE_PARAM(_attr)))
+
+#define side_type_gather_string32(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), _access_mode, SIDE_PARAM(_attr))
+#define side_type_gather_string32_le(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), _access_mode, SIDE_PARAM(_attr))
+#define side_type_gather_string32_be(_offset, _access_mode, _attr) \
+       _side_type_gather_string(_offset, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), _access_mode, SIDE_PARAM(_attr))
+
+#define side_field_gather_string32(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string32(_offset, _access_mode, SIDE_PARAM(_attr)))
+#define side_field_gather_string32_le(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string32_le(_offset, _access_mode, SIDE_PARAM(_attr)))
+#define side_field_gather_string32_be(_name, _offset, _access_mode, _attr) \
+       _side_field(_name, side_type_gather_string32_be(_offset, _access_mode, SIDE_PARAM(_attr)))
+
+#define side_type_gather_enum(_mappings, _elem_type) \
+       { \
+               .type = SIDE_TYPE_GATHER_ENUM, \
+               .u = { \
+                       .side_enum = { \
+                               .mappings = _mappings, \
+                               .elem_type = _elem_type, \
+                       }, \
+               }, \
+       }
+#define side_field_gather_enum(_name, _mappings, _elem_type) \
+       _side_field(_name, side_type_gather_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type)))
+
 #define side_type_gather_struct(_struct_gather, _offset, _size, _access_mode) \
        { \
                .type = SIDE_TYPE_GATHER_STRUCT, \
@@ -1181,6 +1385,7 @@ struct side_event_description {
                        .side_gather = { \
                                .u = { \
                                        .side_vla = { \
+                                               .length_type = _length_type_gather, \
                                                .offset = _offset, \
                                                .access_mode = _access_mode, \
                                                .type = { \
@@ -1188,7 +1393,6 @@ struct side_event_description {
                                                        .attr = _attr, \
                                                        .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
                                                }, \
-                                               .length_type = _length_type_gather, \
                                        }, \
                                }, \
                        }, \
@@ -1206,12 +1410,17 @@ struct side_event_description {
 #define side_field_list(...) \
        SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__)
 
+#define side_option_list(...) \
+       SIDE_COMPOUND_LITERAL(const struct side_variant_option, __VA_ARGS__)
+
 /* 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_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, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
+#define side_arg_string(_val)          { .type = SIDE_TYPE_STRING_UTF8, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
+#define side_arg_string16(_val)                { .type = SIDE_TYPE_STRING_UTF16, .u = { .side_static = { .string_value = (uintptr_t) (_val) } } }
+#define side_arg_string32(_val)                { .type = SIDE_TYPE_STRING_UTF32, .u = { .side_static = { .string_value = (uintptr_t) (_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) } } } }
@@ -1222,18 +1431,28 @@ struct side_event_description {
 #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_enum_bitmap8(_val)    { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_static = { .integer_value = { .side_u8 = (_val) } } } }
-#define side_arg_enum_bitmap16(_val)   { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_static = { .integer_value = { .side_u16 = (_val) } } } }
-#define side_arg_enum_bitmap32(_val)   { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_static = { .integer_value = { .side_u32 = (_val) } } } }
-#define side_arg_enum_bitmap64(_val)   { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_static = { .integer_value = { .side_u64 = (_val) } } } }
-#define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
-#define side_arg_enum_bitmap_vla(_side_type)   { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
 #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_type) } } }
+
+#define side_arg_define_variant(_identifier, _selector_val, _option) \
+       const struct side_arg_variant _identifier = { \
+               .selector = _selector_val, \
+               .option = _option, \
+       }
+#define side_arg_variant(_side_variant) \
+       { \
+               .type = SIDE_TYPE_VARIANT, \
+               .u = { \
+                       .side_static = { \
+                               .side_variant = (_side_variant), \
+                       }, \
+               }, \
+       }
+
 #define side_arg_array(_side_type)     { .type = SIDE_TYPE_ARRAY, .u = { .side_static = { .side_array = (_side_type) } } }
 #define side_arg_vla(_side_type)       { .type = SIDE_TYPE_VLA, .u = { .side_static = { .side_vla = (_side_type) } } }
 #define side_arg_vla_visitor(_ctx)     { .type = SIDE_TYPE_VLA_VISITOR, .u = { .side_static = { .side_vla_app_visitor_ctx = (_ctx) } } }
@@ -1243,9 +1462,9 @@ struct side_event_description {
 #define side_arg_gather_bool(_ptr)             { .type = SIDE_TYPE_GATHER_BOOL, .u = { .side_static = { .side_bool_gather_ptr = (_ptr) } } }
 #define side_arg_gather_byte(_ptr)             { .type = SIDE_TYPE_GATHER_BYTE, .u = { .side_static = { .side_byte_gather_ptr = (_ptr) } } }
 #define side_arg_gather_pointer(_ptr)          { .type = SIDE_TYPE_GATHER_POINTER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
-#define side_arg_gather_unsigned_integer(_ptr) { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
-#define side_arg_gather_signed_integer(_ptr)   { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
+#define side_arg_gather_integer(_ptr)          { .type = SIDE_TYPE_GATHER_INTEGER, .u = { .side_static = { .side_integer_gather_ptr = (_ptr) } } }
 #define side_arg_gather_float(_ptr)            { .type = SIDE_TYPE_GATHER_FLOAT, .u = { .side_static = { .side_float_gather_ptr = (_ptr) } } }
+#define side_arg_gather_string(_ptr)           { .type = SIDE_TYPE_GATHER_STRING, .u = { .side_static = { .side_string_gather_ptr = (_ptr) } } }
 #define side_arg_gather_struct(_ptr)           { .type = SIDE_TYPE_GATHER_STRUCT, .u = { .side_static = { .side_struct_gather_ptr = (_ptr) } } }
 #define side_arg_gather_array(_ptr)            { .type = SIDE_TYPE_GATHER_ARRAY, .u = { .side_static = { .side_array_gather_ptr = (_ptr) } } }
 #define side_arg_gather_vla(_ptr, _length_ptr) { .type = SIDE_TYPE_GATHER_VLA, .u = { .side_static = { .side_vla_gather = { .ptr = (_ptr), .length_ptr = (_length_ptr) } } } }
@@ -1301,7 +1520,7 @@ struct side_event_description {
                        }, \
                }, \
        }
-#define side_arg_dynamic_string(_val, _attr) \
+#define _side_arg_dynamic_string(_val, _byte_order, _unit_size, _attr) \
        { \
                .type = SIDE_TYPE_DYNAMIC_STRING, \
                .u = { \
@@ -1310,12 +1529,28 @@ struct side_event_description {
                                        .type = { \
                                                .attr = _attr, \
                                                .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \
+                                               .unit_size = _unit_size, \
+                                               .byte_order = _byte_order, \
                                        }, \
                                        .value = (uintptr_t) (_val), \
                                }, \
                        }, \
                }, \
        }
+#define side_arg_dynamic_string(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint8_t), SIDE_PARAM(_attr))
+#define side_arg_dynamic_string16(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint16_t), SIDE_PARAM(_attr))
+#define side_arg_dynamic_string16_le(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint16_t), SIDE_PARAM(_attr))
+#define side_arg_dynamic_string16_be(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint16_t), SIDE_PARAM(_attr))
+#define side_arg_dynamic_string32(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_HOST, sizeof(uint32_t), SIDE_PARAM(_attr))
+#define side_arg_dynamic_string32_le(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_LE, sizeof(uint32_t), SIDE_PARAM(_attr))
+#define side_arg_dynamic_string32_be(_val, _attr) \
+       _side_arg_dynamic_string(_val, SIDE_TYPE_BYTE_ORDER_BE, sizeof(uint32_t), SIDE_PARAM(_attr))
 
 #define _side_arg_dynamic_integer(_field, _val, _type, _signedness, _byte_order, _integer_size, _len_bits, _attr) \
        { \
@@ -1605,6 +1840,10 @@ struct side_event_description {
        extern uintptr_t side_event_enable_##_identifier; \
        extern struct side_event_description _identifier
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 extern const struct side_callback side_empty_callback;
 
 void side_call(const struct side_event_description *desc,
@@ -1660,8 +1899,8 @@ void side_tracer_event_notification_unregister(struct side_tracer_handle *handle
  * Explicit hooks to initialize/finalize the side instrumentation
  * library. Those are also library constructor/destructor.
  */
-void side_init(void);
-void side_exit(void);
+void side_init(void) __attribute__((constructor));
+void side_exit(void) __attribute__((destructor));
 
 /*
  * The following constructors/destructors perform automatic registration
@@ -1709,4 +1948,8 @@ side_event_description_ptr_exit(void)
        side_events_handle = NULL;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _SIDE_TRACE_H */
This page took 0.030006 seconds and 4 git commands to generate.