X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=include%2Fside%2Ftrace.h;h=7f6f04e9fb1aab4e5f68d46b10869b19aace4d73;hb=f5e650d7ed962c334c835acfb47668fdc5dadcc0;hp=baac5f4f24a88513b1ac0ea4844d96964cf02090;hpb=65010f43de12733d0af3f7c7d064904ed7f062b2;p=libside.git diff --git a/include/side/trace.h b/include/side/trace.h index baac5f4..7f6f04e 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -10,10 +10,16 @@ #include #include #include +#include #include +#include /* SIDE stands for "Static Instrumentation Dynamically Enabled" */ +//TODO: as those structures will be ABI, we need to either consider them +//fixed forever, or think of a scheme that would allow their binary +//representation to be extended if need be. + struct side_arg_vec; struct side_arg_vec_description; struct side_arg_dynamic_vec; @@ -23,10 +29,13 @@ struct side_event_field; struct side_tracer_visitor_ctx; struct side_tracer_dynamic_struct_visitor_ctx; struct side_tracer_dynamic_vla_visitor_ctx; +struct side_event_description; +struct side_arg_dynamic_event_struct; +struct side_events_register_handle; enum side_type { + /* Basic types */ SIDE_TYPE_BOOL, - SIDE_TYPE_U8, SIDE_TYPE_U16, SIDE_TYPE_U32, @@ -35,9 +44,15 @@ enum side_type { SIDE_TYPE_S16, SIDE_TYPE_S32, SIDE_TYPE_S64, - + SIDE_TYPE_BYTE, + SIDE_TYPE_POINTER, + SIDE_TYPE_FLOAT_BINARY16, + SIDE_TYPE_FLOAT_BINARY32, + SIDE_TYPE_FLOAT_BINARY64, + SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_STRING, + /* Compound types */ SIDE_TYPE_STRUCT, SIDE_TYPE_ARRAY, SIDE_TYPE_VLA, @@ -51,6 +66,8 @@ enum side_type { SIDE_TYPE_ARRAY_S16, SIDE_TYPE_ARRAY_S32, SIDE_TYPE_ARRAY_S64, + SIDE_TYPE_ARRAY_BYTE, + SIDE_TYPE_ARRAY_POINTER, SIDE_TYPE_VLA_U8, SIDE_TYPE_VLA_U16, @@ -60,15 +77,21 @@ enum side_type { SIDE_TYPE_VLA_S16, SIDE_TYPE_VLA_S32, SIDE_TYPE_VLA_S64, + SIDE_TYPE_VLA_BYTE, + SIDE_TYPE_VLA_POINTER, + /* Enumeration types */ + SIDE_TYPE_ENUM, + SIDE_TYPE_ENUM_BITMAP, + + /* Dynamic type */ SIDE_TYPE_DYNAMIC, }; enum side_dynamic_type { + /* Basic types */ SIDE_DYNAMIC_TYPE_NULL, - SIDE_DYNAMIC_TYPE_BOOL, - SIDE_DYNAMIC_TYPE_U8, SIDE_DYNAMIC_TYPE_U16, SIDE_DYNAMIC_TYPE_U32, @@ -77,16 +100,40 @@ enum side_dynamic_type { SIDE_DYNAMIC_TYPE_S16, SIDE_DYNAMIC_TYPE_S32, SIDE_DYNAMIC_TYPE_S64, - + SIDE_DYNAMIC_TYPE_BYTE, + SIDE_DYNAMIC_TYPE_POINTER, + SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, + SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, + SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, + SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, SIDE_DYNAMIC_TYPE_STRING, + /* Compound types */ SIDE_DYNAMIC_TYPE_STRUCT, SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, - SIDE_DYNAMIC_TYPE_VLA, SIDE_DYNAMIC_TYPE_VLA_VISITOR, }; +enum side_attr_type { + SIDE_ATTR_TYPE_NULL, + SIDE_ATTR_TYPE_BOOL, + SIDE_ATTR_TYPE_U8, + SIDE_ATTR_TYPE_U16, + SIDE_ATTR_TYPE_U32, + SIDE_ATTR_TYPE_U64, + SIDE_ATTR_TYPE_S8, + SIDE_ATTR_TYPE_S16, + SIDE_ATTR_TYPE_S32, + SIDE_ATTR_TYPE_S64, + SIDE_ATTR_TYPE_POINTER, + SIDE_ATTR_TYPE_FLOAT_BINARY16, + SIDE_ATTR_TYPE_FLOAT_BINARY32, + SIDE_ATTR_TYPE_FLOAT_BINARY64, + SIDE_ATTR_TYPE_FLOAT_BINARY128, + SIDE_ATTR_TYPE_STRING, +}; + enum side_loglevel { SIDE_LOGLEVEL_EMERG = 0, SIDE_LOGLEVEL_ALERT = 1, @@ -103,6 +150,32 @@ enum side_visitor_status { SIDE_VISITOR_STATUS_ERROR = -1, }; +enum side_error { + SIDE_ERROR_OK = 0, + SIDE_ERROR_INVAL = 1, + SIDE_ERROR_EXIST = 2, + SIDE_ERROR_NOMEM = 3, + SIDE_ERROR_NOENT = 4, + SIDE_ERROR_EXITING = 5, +}; + +enum side_type_byte_order { + SIDE_TYPE_BYTE_ORDER_LE = 0, + SIDE_TYPE_BYTE_ORDER_BE = 1, +}; + +#if (SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN) +# define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE +#else +# define SIDE_TYPE_BYTE_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE +#endif + +#if (SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN) +# define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_LE +#else +# define SIDE_TYPE_FLOAT_WORD_ORDER_HOST SIDE_TYPE_BYTE_ORDER_BE +#endif + typedef enum side_visitor_status (*side_visitor)( const struct side_tracer_visitor_ctx *tracer_ctx, void *app_ctx); @@ -113,31 +186,113 @@ typedef enum side_visitor_status (*side_dynamic_vla_visitor)( const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, void *app_ctx); +struct side_attr_value { + uint32_t type; /* enum side_attr_type */ + union { + uint8_t side_bool; + uint8_t side_u8; + uint16_t side_u16; + uint32_t side_u32; + uint64_t side_u64; + int8_t side_s8; + int16_t side_s16; + int32_t side_s32; + int64_t side_s64; + uintptr_t side_pointer; +#if __HAVE_FLOAT16 + _Float16 side_float_binary16; +#endif +#if __HAVE_FLOAT32 + _Float32 side_float_binary32; +#endif +#if __HAVE_FLOAT64 + _Float64 side_float_binary64; +#endif +#if __HAVE_FLOAT128 + _Float128 side_float_binary128; +#endif + const char *string; + } u; +}; + /* User attributes. */ struct side_attr { const char *key; - const char *value; + const struct side_attr_value value; +}; + +struct side_enum_mapping { + int64_t range_begin; + int64_t range_end; + const char *label; +}; + +struct side_enum_mappings { + const struct side_enum_mapping *mappings; + const struct side_attr *attr; + uint32_t nr_mappings; + uint32_t nr_attr; +}; + +struct side_enum_bitmap_mapping { + uint64_t range_begin; + uint64_t range_end; + const char *label; +}; + +struct side_enum_bitmap_mappings { + const struct side_enum_bitmap_mapping *mappings; + const struct side_attr *attr; + uint32_t nr_mappings; + uint32_t nr_attr; +}; + +struct side_type_struct { + uint32_t nr_fields; + uint32_t nr_attr; + const struct side_event_field *fields; + const struct side_attr *attr; }; struct side_type_description { uint32_t type; /* enum side_type */ - //TODO: we should add something like a list of user attributes (namespaced strings) union { + /* Basic types */ struct { - uint32_t nr_fields; - const struct side_event_field *fields; - } side_struct; + const struct side_attr *attr; + uint32_t nr_attr; + uint32_t byte_order; /* enum side_type_byte_order */ + } side_basic; + + /* Compound types */ struct { - uint32_t length; const struct side_type_description *elem_type; + const struct side_attr *attr; + uint32_t length; + uint32_t nr_attr; } side_array; struct { const struct side_type_description *elem_type; + const struct side_attr *attr; + uint32_t nr_attr; } side_vla; struct { const struct side_type_description *elem_type; side_visitor visitor; + const struct side_attr *attr; + uint32_t nr_attr; } side_vla_visitor; + const struct side_type_struct *side_struct; + + /* Enumeration types */ + struct { + const struct side_enum_mappings *mappings; + const struct side_type_description *elem_type; + } side_enum; + struct { + const struct side_enum_bitmap_mappings *mappings; + const struct side_type_description *elem_type; + } side_enum_bitmap; } u; }; @@ -150,71 +305,112 @@ 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_description *sav_desc, + void *priv); + void (*call_variadic)(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc, + const struct side_arg_dynamic_event_struct *var_struct, + void *priv); + } u; + void *priv; +}; + struct side_event_description { - uint32_t version; - uint32_t enabled; - uint32_t loglevel; /* enum side_loglevel */ - uint32_t nr_fields; - uint32_t nr_attr; - uint32_t _unused; - uint64_t flags; + uintptr_t *enabled; const char *provider_name; const char *event_name; const struct side_event_field *fields; const struct side_attr *attr; -}; - -struct side_arg_dynamic_vec_vla { - const struct side_arg_dynamic_vec *sav; - uint32_t len; + const struct side_callback *callbacks; + uint64_t flags; + uint32_t version; + uint32_t loglevel; /* enum side_loglevel */ + uint32_t nr_fields; + uint32_t nr_attr; + uint32_t nr_callbacks; }; struct side_arg_dynamic_vec { uint32_t dynamic_type; /* enum side_dynamic_type */ union { - uint8_t side_bool; - - uint8_t side_u8; - uint16_t side_u16; - uint32_t side_u32; - uint64_t side_u64; - int8_t side_s8; - int16_t side_s16; - int32_t side_s32; - int64_t side_s64; - - const char *string; - + /* Basic types */ + struct { + const struct side_attr *attr; + uint32_t nr_attr; + uint32_t byte_order; /* enum side_type_byte_order */ + union { + uint8_t side_bool; + uint8_t side_u8; + uint16_t side_u16; + uint32_t side_u32; + uint64_t side_u64; + int8_t side_s8; + int16_t side_s16; + int32_t side_s32; + int64_t side_s64; + uint8_t side_byte; + uintptr_t side_pointer; +#if __HAVE_FLOAT16 + _Float16 side_float_binary16; +#endif +#if __HAVE_FLOAT32 + _Float32 side_float_binary32; +#endif +#if __HAVE_FLOAT64 + _Float64 side_float_binary64; +#endif +#if __HAVE_FLOAT128 + _Float128 side_float_binary128; +#endif + const char *string; + } u; + } side_basic; + + /* Compound types */ const struct side_arg_dynamic_event_struct *side_dynamic_struct; struct { void *app_ctx; side_dynamic_struct_visitor visitor; + const struct side_attr *attr; + uint32_t nr_attr; } side_dynamic_struct_visitor; - const struct side_arg_dynamic_vec_vla *side_dynamic_vla; struct { void *app_ctx; side_dynamic_vla_visitor visitor; + const struct side_attr *attr; + uint32_t nr_attr; } side_dynamic_vla_visitor; } u; }; +struct side_arg_dynamic_vec_vla { + const struct side_arg_dynamic_vec *sav; + const struct side_attr *attr; + uint32_t len; + uint32_t nr_attr; +}; + struct side_arg_dynamic_event_field { const char *field_name; const struct side_arg_dynamic_vec elem; - //TODO: we should add something like a list of user attributes (namespaced strings) }; struct side_arg_dynamic_event_struct { const struct side_arg_dynamic_event_field *fields; + const struct side_attr *attr; uint32_t len; + uint32_t nr_attr; }; struct side_arg_vec { enum side_type type; union { + /* Basic types */ uint8_t side_bool; - uint8_t side_u8; uint16_t side_u16; uint32_t side_u32; @@ -223,19 +419,34 @@ struct side_arg_vec { int16_t side_s16; int32_t side_s32; int64_t side_s64; - + uint8_t side_byte; + uintptr_t side_pointer; +#if __HAVE_FLOAT16 + _Float16 side_float_binary16; +#endif +#if __HAVE_FLOAT32 + _Float32 side_float_binary32; +#endif +#if __HAVE_FLOAT64 + _Float64 side_float_binary64; +#endif +#if __HAVE_FLOAT128 + _Float128 side_float_binary128; +#endif const char *string; + + /* Compound types */ const struct side_arg_vec_description *side_struct; const struct side_arg_vec_description *side_array; const struct side_arg_vec_description *side_vla; void *side_vla_app_visitor_ctx; - void *side_array_fixint; struct { void *p; uint32_t length; } side_vla_fixint; + /* Dynamic type */ struct side_arg_dynamic_vec dynamic; } u; }; @@ -267,105 +478,267 @@ struct side_tracer_dynamic_vla_visitor_ctx { void *priv; /* Private tracer context. */ }; +/* Event and type attributes */ + #define side_attr(_key, _value) \ { \ .key = _key, \ - .value = _value, \ + .value = SIDE_PARAM(_value), \ } #define side_attr_list(...) \ SIDE_COMPOUND_LITERAL(const struct side_attr, __VA_ARGS__) -#define side_type_decl(_type) { .type = _type } +#define side_attr_null(_val) { .type = SIDE_ATTR_TYPE_NULL } +#define side_attr_bool(_val) { .type = SIDE_ATTR_TYPE_BOOL, .u = { .side_bool = !!(_val) } } +#define side_attr_u8(_val) { .type = SIDE_ATTR_TYPE_U8, .u = { .side_u8 = (_val) } } +#define side_attr_u16(_val) { .type = SIDE_ATTR_TYPE_U16, .u = { .side_u16 = (_val) } } +#define side_attr_u32(_val) { .type = SIDE_ATTR_TYPE_U32, .u = { .side_u32 = (_val) } } +#define side_attr_u64(_val) { .type = SIDE_ATTR_TYPE_U64, .u = { .side_u64 = (_val) } } +#define side_attr_s8(_val) { .type = SIDE_ATTR_TYPE_S8, .u = { .side_s8 = (_val) } } +#define side_attr_s16(_val) { .type = SIDE_ATTR_TYPE_S16, .u = { .side_s16 = (_val) } } +#define side_attr_s32(_val) { .type = SIDE_ATTR_TYPE_S32, .u = { .side_s32 = (_val) } } +#define side_attr_s64(_val) { .type = SIDE_ATTR_TYPE_S64, .u = { .side_s64 = (_val) } } +#define side_attr_pointer(_val) { .type = SIDE_ATTR_TYPE_POINTER, .u = { .side_pointer = (uintptr_t) (_val) } } +#define side_attr_float_binary16(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } } +#define side_attr_float_binary32(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } } +#define side_attr_float_binary64(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } } +#define side_attr_float_binary128(_val) { .type = SIDE_ATTR_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } } +#define side_attr_string(_val) { .type = SIDE_ATTR_TYPE_STRING, .u = { .string = (_val) } } + +/* Static field definition */ + +#define _side_type_basic(_type, _byte_order, _attr) \ + { \ + .type = _type, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + }, \ + }, \ + } -#define side_field(_name, _type) \ +#define _side_field(_name, _type) \ { \ .field_name = _name, \ - .side_type = side_type_decl(_type), \ + .side_type = _type, \ } -#define side_type_struct_decl(_fields) \ +/* Host endian */ +#define side_type_bool(_attr) _side_type_basic(SIDE_TYPE_BOOL, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_u8(_attr) _side_type_basic(SIDE_TYPE_U8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_u16(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_u32(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_u64(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_s8(_attr) _side_type_basic(SIDE_TYPE_S8, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_s16(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_s32(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_s64(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_byte(_attr) _side_type_basic(SIDE_TYPE_BYTE, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_pointer(_attr) _side_type_basic(SIDE_TYPE_POINTER, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_float_binary16(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_float_binary32(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_float_binary64(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_float_binary128(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_string(_attr) _side_type_basic(SIDE_TYPE_STRING, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_type_dynamic(_attr) _side_type_basic(SIDE_TYPE_DYNAMIC, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) + +#define side_field_bool(_name, _attr) _side_field(_name, side_type_bool(SIDE_PARAM(_attr))) +#define side_field_u8(_name, _attr) _side_field(_name, side_type_u8(SIDE_PARAM(_attr))) +#define side_field_u16(_name, _attr) _side_field(_name, side_type_u16(SIDE_PARAM(_attr))) +#define side_field_u32(_name, _attr) _side_field(_name, side_type_u32(SIDE_PARAM(_attr))) +#define side_field_u64(_name, _attr) _side_field(_name, side_type_u64(SIDE_PARAM(_attr))) +#define side_field_s8(_name, _attr) _side_field(_name, side_type_s8(SIDE_PARAM(_attr))) +#define side_field_s16(_name, _attr) _side_field(_name, side_type_s16(SIDE_PARAM(_attr))) +#define side_field_s32(_name, _attr) _side_field(_name, side_type_s32(SIDE_PARAM(_attr))) +#define side_field_s64(_name, _attr) _side_field(_name, side_type_s64(SIDE_PARAM(_attr))) +#define side_field_byte(_name, _attr) _side_field(_name, side_type_byte(SIDE_PARAM(_attr))) +#define side_field_pointer(_name, _attr) _side_field(_name, side_type_pointer(SIDE_PARAM(_attr))) +#define side_field_float_binary16(_name, _attr) _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr))) +#define side_field_float_binary32(_name, _attr) _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr))) +#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_dynamic(_name, _attr) _side_field(_name, side_type_dynamic(SIDE_PARAM(_attr))) + +/* Little endian */ +#define side_type_u16_le(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_u32_le(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_u64_le(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_s16_le(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_s32_le(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_s64_le(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_pointer_le(_attr) _side_type_basic(SIDE_TYPE_POINTER, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_float_binary16_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_float_binary32_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_float_binary64_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_type_float_binary128_le(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_LE, 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))) +#define side_field_u64_le(_name, _attr) _side_field(_name, side_type_u64_le(SIDE_PARAM(_attr))) +#define side_field_s16_le(_name, _attr) _side_field(_name, side_type_s16_le(SIDE_PARAM(_attr))) +#define side_field_s32_le(_name, _attr) _side_field(_name, side_type_s32_le(SIDE_PARAM(_attr))) +#define side_field_s64_le(_name, _attr) _side_field(_name, side_type_s64_le(SIDE_PARAM(_attr))) +#define side_field_pointer_le(_name, _attr) _side_field(_name, side_type_pointer_le(SIDE_PARAM(_attr))) +#define side_field_float_binary16_le(_name, _attr) _side_field(_name, side_type_float_binary16_le(SIDE_PARAM(_attr))) +#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))) + +/* Big endian */ +#define side_type_u16_be(_attr) _side_type_basic(SIDE_TYPE_U16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_u32_be(_attr) _side_type_basic(SIDE_TYPE_U32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_u64_be(_attr) _side_type_basic(SIDE_TYPE_U64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_s16_be(_attr) _side_type_basic(SIDE_TYPE_S16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_s32_be(_attr) _side_type_basic(SIDE_TYPE_S32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_s64_be(_attr) _side_type_basic(SIDE_TYPE_S64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_pointer_be(_attr) _side_type_basic(SIDE_TYPE_POINTER, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_float_binary16_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY16, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_float_binary32_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY32, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_float_binary64_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY64, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_type_float_binary128_be(_attr) _side_type_basic(SIDE_TYPE_FLOAT_BINARY128, SIDE_TYPE_BYTE_ORDER_BE, 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))) +#define side_field_u64_be(_name, _attr) _side_field(_name, side_type_u64_be(SIDE_PARAM(_attr))) +#define side_field_s16_be(_name, _attr) _side_field(_name, side_type_s16_be(SIDE_PARAM(_attr))) +#define side_field_s32_be(_name, _attr) _side_field(_name, side_type_s32_be(SIDE_PARAM(_attr))) +#define side_field_s64_be(_name, _attr) _side_field(_name, side_type_s64_be(SIDE_PARAM(_attr))) +#define side_field_pointer_be(_name, _attr) _side_field(_name, side_type_pointer_be(SIDE_PARAM(_attr))) +#define side_field_float_binary16_be(_name, _attr) _side_field(_name, side_type_float_binary16_be(SIDE_PARAM(_attr))) +#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_type_enum(_mappings, _elem_type) \ { \ - .type = SIDE_TYPE_STRUCT, \ + .type = SIDE_TYPE_ENUM, \ .u = { \ - .side_struct = { \ - .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ - .fields = _fields, \ + .side_enum = { \ + .mappings = _mappings, \ + .elem_type = _elem_type, \ }, \ }, \ } -#define side_field_struct(_name, _fields) \ +#define side_field_enum(_name, _mappings, _elem_type) \ + _side_field(_name, side_type_enum(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) + +#define side_type_enum_bitmap(_mappings, _elem_type) \ { \ - .field_name = _name, \ - .side_type = side_type_struct_decl(SIDE_PARAM(_fields)), \ + .type = SIDE_TYPE_ENUM_BITMAP, \ + .u = { \ + .side_enum_bitmap = { \ + .mappings = _mappings, \ + .elem_type = _elem_type, \ + }, \ + }, \ + } +#define side_field_enum_bitmap(_name, _mappings, _elem_type) \ + _side_field(_name, side_type_enum_bitmap(SIDE_PARAM(_mappings), SIDE_PARAM(_elem_type))) + +#define side_type_struct(_struct) \ + { \ + .type = SIDE_TYPE_STRUCT, \ + .u = { \ + .side_struct = _struct, \ + }, \ } +#define side_field_struct(_name, _struct) \ + _side_field(_name, side_type_struct(SIDE_PARAM(_struct))) -#define side_type_array_decl(_elem_type, _length) \ +#define _side_type_struct_define(_fields, _attr) \ + { \ + .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .fields = _fields, \ + .attr = _attr, \ + } + +#define side_define_struct(_identifier, _fields, _attr) \ + const struct side_type_struct _identifier = _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr)) + +#define side_struct_literal(_fields, _attr) \ + SIDE_COMPOUND_LITERAL(const struct side_type_struct, \ + _side_type_struct_define(SIDE_PARAM(_fields), SIDE_PARAM(_attr))) + +#define side_type_array(_elem_type, _length, _attr) \ { \ .type = SIDE_TYPE_ARRAY, \ .u = { \ .side_array = { \ - .length = _length, \ .elem_type = _elem_type, \ + .attr = _attr, \ + .length = _length, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ }, \ }, \ } -#define side_field_array(_name, _elem_type, _length) \ - { \ - .field_name = _name, \ - .side_type = side_type_array_decl(_elem_type, _length), \ - } +#define side_field_array(_name, _elem_type, _length, _attr) \ + _side_field(_name, side_type_array(SIDE_PARAM(_elem_type), _length, SIDE_PARAM(_attr))) -#define side_type_vla_decl(_elem_type) \ +#define side_type_vla(_elem_type, _attr) \ { \ .type = SIDE_TYPE_VLA, \ .u = { \ .side_vla = { \ .elem_type = _elem_type, \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ }, \ }, \ } -#define side_field_vla(_name, _elem_type) \ - { \ - .field_name = _name, \ - .side_type = side_type_vla_decl(_elem_type), \ - } +#define side_field_vla(_name, _elem_type, _attr) \ + _side_field(_name, side_type_vla(SIDE_PARAM(_elem_type), SIDE_PARAM(_attr))) -#define side_type_vla_visitor_decl(_elem_type, _visitor) \ +#define side_type_vla_visitor(_elem_type, _visitor, _attr) \ { \ .type = SIDE_TYPE_VLA_VISITOR, \ .u = { \ .side_vla_visitor = { \ .elem_type = SIDE_PARAM(_elem_type), \ .visitor = _visitor, \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ }, \ }, \ } -#define side_field_vla_visitor(_name, _elem_type, _visitor) \ - { \ - .field_name = _name, \ - .side_type = side_type_vla_visitor_decl(SIDE_PARAM(_elem_type), _visitor), \ - } +#define side_field_vla_visitor(_name, _elem_type, _visitor, _attr) \ + _side_field(_name, side_type_vla_visitor(SIDE_PARAM(_elem_type), _visitor, SIDE_PARAM(_attr))) #define side_elem(...) \ SIDE_COMPOUND_LITERAL(const struct side_type_description, __VA_ARGS__) -#define side_elem_type(...) \ - side_elem(side_type_decl(__VA_ARGS__)) - #define side_field_list(...) \ SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) -#define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } } -#define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } } -#define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } } -#define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } } -#define side_arg_u64(val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (val) } } -#define side_arg_s8(val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (val) } } -#define side_arg_s16(val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } } -#define side_arg_s32(val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } } -#define side_arg_s64(val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } } -#define side_arg_string(val) { .type = SIDE_TYPE_STRING, .u = { .string = (val) } } +/* Static field arguments */ + +#define side_arg_bool(_val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(_val) } } +#define side_arg_u8(_val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (_val) } } +#define side_arg_u16(_val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (_val) } } +#define side_arg_u32(_val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (_val) } } +#define side_arg_u64(_val) { .type = SIDE_TYPE_U64, .u = { .side_u64 = (_val) } } +#define side_arg_s8(_val) { .type = SIDE_TYPE_S8, .u = { .side_s8 = (_val) } } +#define side_arg_s16(_val) { .type = SIDE_TYPE_S16, .u = { .side_s16 = (_val) } } +#define side_arg_s32(_val) { .type = SIDE_TYPE_S32, .u = { .side_s32 = (_val) } } +#define side_arg_s64(_val) { .type = SIDE_TYPE_S64, .u = { .side_s64 = (_val) } } +#define side_arg_byte(_val) { .type = SIDE_TYPE_BYTE, .u = { .side_byte = (_val) } } +#define side_arg_pointer(_val) { .type = SIDE_TYPE_POINTER, .u = { .side_pointer = (uintptr_t) (_val) } } +#define side_arg_enum_bitmap8(_val) { .type = SIDE_TYPE_ENUM_BITMAP8, .u = { .side_u8 = (_val) } } +#define side_arg_enum_bitmap16(_val) { .type = SIDE_TYPE_ENUM_BITMAP16, .u = { .side_u16 = (_val) } } +#define side_arg_enum_bitmap32(_val) { .type = SIDE_TYPE_ENUM_BITMAP32, .u = { .side_u32 = (_val) } } +#define side_arg_enum_bitmap64(_val) { .type = SIDE_TYPE_ENUM_BITMAP64, .u = { .side_u64 = (_val) } } +#define side_arg_enum_bitmap_array(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_ARRAY, .u = { .side_array = (_side_type) } } +#define side_arg_enum_bitmap_vla(_side_type) { .type = SIDE_TYPE_ENUM_BITMAP_VLA, .u = { .side_vla = (_side_type) } } +#define side_arg_float_binary16(_val) { .type = SIDE_TYPE_FLOAT_BINARY16, .u = { .side_float_binary16 = (_val) } } +#define side_arg_float_binary32(_val) { .type = SIDE_TYPE_FLOAT_BINARY32, .u = { .side_float_binary32 = (_val) } } +#define side_arg_float_binary64(_val) { .type = SIDE_TYPE_FLOAT_BINARY64, .u = { .side_float_binary64 = (_val) } } +#define side_arg_float_binary128(_val) { .type = SIDE_TYPE_FLOAT_BINARY128, .u = { .side_float_binary128 = (_val) } } + +#define side_arg_string(_val) { .type = SIDE_TYPE_STRING, .u = { .string = (_val) } } #define side_arg_struct(_side_type) { .type = SIDE_TYPE_STRUCT, .u = { .side_struct = (_side_type) } } #define side_arg_array(_side_type) { .type = SIDE_TYPE_ARRAY, .u = { .side_array = (_side_type) } } #define side_arg_vla(_side_type) { .type = SIDE_TYPE_VLA, .u = { .side_vla = (_side_type) } } @@ -379,6 +752,8 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_array_s16(_ptr) { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint = (_ptr) } } #define side_arg_array_s32(_ptr) { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } } #define side_arg_array_s64(_ptr) { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } } +#define side_arg_array_byte(_ptr) { .type = SIDE_TYPE_ARRAY_BYTE, .u = { .side_array_fixint = (_ptr) } } +#define side_arg_array_pointer(_ptr) { .type = SIDE_TYPE_ARRAY_POINTER, .u = { .side_array_fixint = (_ptr) } } #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } #define side_arg_vla_u16(_ptr, _length) { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } @@ -388,64 +763,356 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_vla_s16(_ptr, _length) { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } #define side_arg_vla_s32(_ptr, _length) { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } #define side_arg_vla_s64(_ptr, _length) { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } +#define side_arg_vla_byte(_ptr, _length) { .type = SIDE_TYPE_VLA_BYTE, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } +#define side_arg_vla_pointer(_ptr, _length) { .type = SIDE_TYPE_VLA_POINTER, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } } -#define side_arg_dynamic(dynamic_arg_type) \ +#define side_arg_dynamic(_dynamic_arg_type) \ { \ .type = SIDE_TYPE_DYNAMIC, \ .u = { \ - .dynamic = dynamic_arg_type, \ + .dynamic = _dynamic_arg_type, \ + }, \ + } + +/* Dynamic field arguments */ + +#define side_arg_dynamic_null(_attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_NULL, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + }, \ }, \ } -#define side_arg_dynamic_null(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_NULL } +#define side_arg_dynamic_bool(_val, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + .u = { \ + .side_bool = !!(_val), \ + }, \ + }, \ + }, \ + } + +#define side_arg_dynamic_u8(_val, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_U8, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + .u = { \ + .side_u8 = (_val), \ + }, \ + }, \ + }, \ + } +#define side_arg_dynamic_s8(_val, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_S8, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + .u = { \ + .side_s8 = (_val), \ + }, \ + }, \ + }, \ + } +#define side_arg_dynamic_byte(_val, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_BYTE, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + .u = { \ + .side_byte = (_val), \ + }, \ + }, \ + }, \ + } +#define side_arg_dynamic_string(_val, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = SIDE_TYPE_BYTE_ORDER_HOST, \ + .u = { \ + .string = (_val), \ + }, \ + }, \ + }, \ + } -#define side_arg_dynamic_bool(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, .u = { .side_bool = !!(val) } } -#define side_arg_dynamic_u8(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U8, .u = { .side_u8 = (val) } } -#define side_arg_dynamic_u16(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U16, .u = { .side_u16 = (val) } } -#define side_arg_dynamic_u32(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U32, .u = { .side_u32 = (val) } } -#define side_arg_dynamic_u64(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U64, .u = { .side_u64 = (val) } } -#define side_arg_dynamic_s8(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S8, .u = { .side_s8 = (val) } } -#define side_arg_dynamic_s16(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S16, .u = { .side_s16 = (val) } } -#define side_arg_dynamic_s32(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S32, .u = { .side_s32 = (val) } } -#define side_arg_dynamic_s64(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_S64, .u = { .side_s64 = (val) } } -#define side_arg_dynamic_string(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_STRING, .u = { .string = (val) } } +#define _side_arg_dynamic_u16(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_U16, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_u16 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_u32(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_U32, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_u32 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_u64(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_U64, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_u64 = (_val), \ + }, \ + }, \ + }, \ + } -#define side_arg_dynamic_vla(_vla) { .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, .u = { .side_dynamic_vla = (_vla) } } -#define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx) \ +#define _side_arg_dynamic_s16(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_S16, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_s16 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_s32(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_S32, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_s32 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_s64(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_S64, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_s64 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_pointer(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_POINTER, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_pointer = (uintptr_t) (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_float_binary16(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY16, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_float_binary16 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_float_binary32(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY32, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_float_binary32 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_float_binary64(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY64, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_float_binary64 = (_val), \ + }, \ + }, \ + }, \ + } +#define _side_arg_dynamic_float_binary128(_val, _byte_order, _attr) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_FLOAT_BINARY128, \ + .u = { \ + .side_basic = { \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .byte_order = _byte_order, \ + .u = { \ + .side_float_binary128 = (_val), \ + }, \ + }, \ + }, \ + } + +/* Host endian */ +#define side_arg_dynamic_u16(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u32(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u64(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s16(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s32(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s64(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_pointer(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary16(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary32(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary64(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary128(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_FLOAT_WORD_ORDER_HOST, SIDE_PARAM(_attr)) + +/* Little endian */ +#define side_arg_dynamic_u16_le(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u32_le(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u64_le(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s16_le(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s32_le(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s64_le(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_pointer_le(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary16_le(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary32_le(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary64_le(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary128_le(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_LE, SIDE_PARAM(_attr)) + +/* Big endian */ +#define side_arg_dynamic_u16_be(_val, _attr) _side_arg_dynamic_u16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u32_be(_val, _attr) _side_arg_dynamic_u32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_u64_be(_val, _attr) _side_arg_dynamic_u64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s16_be(_val, _attr) _side_arg_dynamic_s16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s32_be(_val, _attr) _side_arg_dynamic_s32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_s64_be(_val, _attr) _side_arg_dynamic_s64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_pointer_be(_val, _attr) _side_arg_dynamic_pointer(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary16_be(_val, _attr) _side_arg_dynamic_float_binary16(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary32_be(_val, _attr) _side_arg_dynamic_float_binary32(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary64_be(_val, _attr) _side_arg_dynamic_float_binary64(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) +#define side_arg_dynamic_float_binary128_be(_val, _attr) _side_arg_dynamic_float_binary128(_val, SIDE_TYPE_BYTE_ORDER_BE, SIDE_PARAM(_attr)) + +#define side_arg_dynamic_vla(_vla) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_VLA, \ + .u = { \ + .side_dynamic_vla = (_vla), \ + }, \ + } + +#define side_arg_dynamic_vla_visitor(_dynamic_vla_visitor, _ctx, _attr) \ { \ .dynamic_type = SIDE_DYNAMIC_TYPE_VLA_VISITOR, \ .u = { \ .side_dynamic_vla_visitor = { \ .app_ctx = _ctx, \ .visitor = _dynamic_vla_visitor, \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ }, \ }, \ } -#define side_arg_dynamic_struct(_struct) { .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, .u = { .side_dynamic_struct = (_struct) } } -#define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx) \ +#define side_arg_dynamic_struct(_struct) \ + { \ + .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT, \ + .u = { \ + .side_dynamic_struct = (_struct), \ + }, \ + } + +#define side_arg_dynamic_struct_visitor(_dynamic_struct_visitor, _ctx, _attr) \ { \ .dynamic_type = SIDE_DYNAMIC_TYPE_STRUCT_VISITOR, \ .u = { \ .side_dynamic_struct_visitor = { \ .app_ctx = _ctx, \ .visitor = _dynamic_struct_visitor, \ + .attr = _attr, \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ }, \ }, \ } -#define side_arg_dynamic_define_vec(_identifier, _sav) \ +#define side_arg_dynamic_define_vec(_identifier, _sav, _attr) \ const struct side_arg_dynamic_vec _identifier##_vec[] = { _sav }; \ const struct side_arg_dynamic_vec_vla _identifier = { \ .sav = _identifier##_vec, \ + .attr = _attr, \ .len = SIDE_ARRAY_SIZE(_identifier##_vec), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ } -#define side_arg_dynamic_define_struct(_identifier, _struct_fields) \ +#define side_arg_dynamic_define_struct(_identifier, _struct_fields, _attr) \ const struct side_arg_dynamic_event_field _identifier##_fields[] = { _struct_fields }; \ const struct side_arg_dynamic_event_struct _identifier = { \ .fields = _identifier##_fields, \ + .attr = _attr, \ .len = SIDE_ARRAY_SIZE(_identifier##_fields), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ } #define side_arg_define_vec(_identifier, _sav) \ @@ -463,23 +1130,75 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_list(...) __VA_ARGS__ -#define side_event_cond(desc) if (side_unlikely((desc)->enabled)) +#define side_define_enum(_identifier, _mappings, _attr) \ + const struct side_enum_mappings _identifier = { \ + .mappings = _mappings, \ + .attr = _attr, \ + .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + } + +#define side_enum_mapping_list(...) \ + SIDE_COMPOUND_LITERAL(const struct side_enum_mapping, __VA_ARGS__) + +#define side_enum_mapping_range(_label, _begin, _end) \ + { \ + .range_begin = _begin, \ + .range_end = _end, \ + .label = _label, \ + } + +#define side_enum_mapping_value(_label, _value) \ + { \ + .range_begin = _value, \ + .range_end = _value, \ + .label = _label, \ + } + +#define side_define_enum_bitmap(_identifier, _mappings, _attr) \ + const struct side_enum_bitmap_mappings _identifier = { \ + .mappings = _mappings, \ + .attr = _attr, \ + .nr_mappings = SIDE_ARRAY_SIZE(SIDE_PARAM(_mappings)), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + } + +#define side_enum_bitmap_mapping_list(...) \ + SIDE_COMPOUND_LITERAL(const struct side_enum_bitmap_mapping, __VA_ARGS__) + +#define side_enum_bitmap_mapping_range(_label, _begin, _end) \ + { \ + .range_begin = _begin, \ + .range_end = _end, \ + .label = _label, \ + } -#define side_event_call(desc, _sav) \ +#define side_enum_bitmap_mapping_value(_label, _value) \ + { \ + .range_begin = _value, \ + .range_end = _value, \ + .label = _label, \ + } + +#define side_event_cond(_identifier) \ + if (side_unlikely(__atomic_load_n(&side_event_enable__##_identifier, \ + __ATOMIC_RELAXED))) + +#define side_event_call(_identifier, _sav) \ { \ const struct side_arg_vec side_sav[] = { _sav }; \ const struct side_arg_vec_description sav_desc = { \ .sav = side_sav, \ .len = SIDE_ARRAY_SIZE(side_sav), \ }; \ - tracer_call(desc, &sav_desc); \ + side_call(&(_identifier), &sav_desc); \ } -#define side_event(desc, sav) \ - side_event_cond(desc) \ - side_event_call(desc, SIDE_PARAM(sav)) +#define side_event(_identifier, _sav) \ + side_event_cond(_identifier) \ + side_event_call(_identifier, SIDE_PARAM(_sav)) -#define side_event_call_variadic(desc, _sav, _var_fields) \ +#define side_event_call_variadic(_identifier, _sav, _var_fields, _attr) \ { \ const struct side_arg_vec side_sav[] = { _sav }; \ const struct side_arg_vec_description sav_desc = { \ @@ -489,38 +1208,152 @@ struct side_tracer_dynamic_vla_visitor_ctx { const struct side_arg_dynamic_event_field side_fields[] = { _var_fields }; \ const struct side_arg_dynamic_event_struct var_struct = { \ .fields = side_fields, \ + .attr = _attr, \ .len = SIDE_ARRAY_SIZE(side_fields), \ + .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ }; \ - tracer_call_variadic(desc, &sav_desc, &var_struct); \ + side_call_variadic(&(_identifier), &sav_desc, &var_struct); \ } -#define side_event_variadic(desc, sav, var) \ - side_event_cond(desc) \ - side_event_call_variadic(desc, SIDE_PARAM(sav), SIDE_PARAM(var)) +#define side_event_variadic(_identifier, _sav, _var, _attr) \ + side_event_cond(_identifier) \ + side_event_call_variadic(_identifier, SIDE_PARAM(_sav), SIDE_PARAM(_var), SIDE_PARAM(_attr)) -#define _side_define_event(_identifier, _provider, _event, _loglevel, _attr, _fields, _flags) \ - struct side_event_description _identifier = { \ +#define _side_define_event(_linkage, _identifier, _provider, _event, _loglevel, _fields, _attr, _flags) \ + _linkage uintptr_t side_event_enable__##_identifier __attribute__((section("side_event_enable"))); \ + _linkage struct side_event_description __attribute__((section("side_event_description"))) \ + _identifier = { \ .version = 0, \ - .enabled = 0, \ + .enabled = &(side_event_enable__##_identifier), \ .loglevel = _loglevel, \ .nr_fields = SIDE_ARRAY_SIZE(SIDE_PARAM(_fields)), \ .nr_attr = SIDE_ARRAY_SIZE(SIDE_PARAM(_attr)), \ + .nr_callbacks = 0, \ .flags = (_flags), \ .provider_name = _provider, \ .event_name = _event, \ .fields = _fields, \ .attr = _attr, \ - } + .callbacks = &side_empty_callback, \ + }; \ + static const struct side_event_description *side_event_ptr__##_identifier \ + __attribute__((section("side_event_description_ptr"), used)) = &(_identifier); + +#define side_static_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ + _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ + SIDE_PARAM(_attr), 0) + +#define side_static_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ + _side_define_event(static, _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ + SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) -#define side_define_event(_identifier, _provider, _event, _loglevel, _attr, _fields) \ - _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_attr), \ - SIDE_PARAM(_fields), 0) +#define side_hidden_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ + _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ + SIDE_PARAM(_attr), 0) -#define side_define_event_variadic(_identifier, _provider, _event, _loglevel, _attr, _fields) \ - _side_define_event(_identifier, _provider, _event, _loglevel, SIDE_PARAM(_attr), \ - SIDE_PARAM(_fields), SIDE_EVENT_FLAG_VARIADIC) +#define side_hidden_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ + _side_define_event(__attribute__((visibility("hidden"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ + SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) + +#define side_export_event(_identifier, _provider, _event, _loglevel, _fields, _attr) \ + _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ + SIDE_PARAM(_attr), 0) + +#define side_export_event_variadic(_identifier, _provider, _event, _loglevel, _fields, _attr) \ + _side_define_event(__attribute__((visibility("default"))), _identifier, _provider, _event, _loglevel, SIDE_PARAM(_fields), \ + SIDE_PARAM(_attr), SIDE_EVENT_FLAG_VARIADIC) #define side_declare_event(_identifier) \ - struct side_event_description _identifier + extern uintptr_t side_event_enable_##_identifier; \ + extern struct side_event_description _identifier + +extern const struct side_callback side_empty_callback; + +void side_call(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc); +void side_call_variadic(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc, + const struct side_arg_dynamic_event_struct *var_struct); + +int side_tracer_callback_register(struct side_event_description *desc, + void (*call)(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc, + void *priv), + void *priv); +int side_tracer_callback_variadic_register(struct side_event_description *desc, + void (*call_variadic)(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc, + const struct side_arg_dynamic_event_struct *var_struct, + void *priv), + void *priv); +int side_tracer_callback_unregister(struct side_event_description *desc, + void (*call)(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc, + void *priv), + void *priv); +int side_tracer_callback_variadic_unregister(struct side_event_description *desc, + void (*call_variadic)(const struct side_event_description *desc, + const struct side_arg_vec_description *sav_desc, + const struct side_arg_dynamic_event_struct *var_struct, + void *priv), + void *priv); + +struct side_events_register_handle *side_events_register(struct side_event_description **events, uint32_t nr_events); +void side_events_unregister(struct side_events_register_handle *handle); + +enum side_tracer_notification { + SIDE_TRACER_NOTIFICATION_INSERT_EVENTS, + SIDE_TRACER_NOTIFICATION_REMOVE_EVENTS, +}; + +/* Callback is invoked with side library internal lock held. */ +struct side_tracer_handle *side_tracer_event_notification_register( + void (*cb)(enum side_tracer_notification notif, + struct side_event_description **events, uint32_t nr_events, void *priv), + void *priv); +void side_tracer_event_notification_unregister(struct side_tracer_handle *handle); + +void side_init(void); +void side_exit(void); + +/* + * These weak symbols, the constructor, and destructor take care of + * registering only _one_ instance of the side instrumentation per + * shared-ojbect (or for the whole main program). + */ +extern struct side_event_description * __start_side_event_description_ptr[] + __attribute__((weak, visibility("hidden"))); +extern struct side_event_description * __stop_side_event_description_ptr[] + __attribute__((weak, visibility("hidden"))); +int side_event_description_ptr_registered + __attribute__((weak, visibility("hidden"))); +struct side_events_register_handle *side_events_handle + __attribute__((weak, visibility("hidden"))); + +static void +side_event_description_ptr_init(void) + __attribute__((no_instrument_function)) + __attribute__((constructor)); +static void +side_event_description_ptr_init(void) +{ + if (side_event_description_ptr_registered++) + return; + side_events_handle = side_events_register(__start_side_event_description_ptr, + __stop_side_event_description_ptr - __start_side_event_description_ptr); +} + +static void +side_event_description_ptr_exit(void) + __attribute__((no_instrument_function)) + __attribute__((destructor)); +static void +side_event_description_ptr_exit(void) +{ + if (--side_event_description_ptr_registered) + return; + side_events_unregister(side_events_handle); + side_events_handle = NULL; +} #endif /* _SIDE_TRACE_H */