From a084756d092167324ee09d3f819cc45407b58233 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 16 Mar 2021 22:41:20 -0400 Subject: [PATCH] Refactoring: UST types public interfaces - Properly namespace public type interfaces with lttng_ust_ prefix, - Move from union to parent embedding into children for inheritance. - Introduce struct lttng_ust_type_common, which is fixed-size, to contain the type selector. Used as parent for each sub-type. - Use compound literals on tracepoint probe definition rather than nesting into event field structure to allow each type to be extended with a struct_size scheme. - The parent field is required to be the first field of each sub-type, allowing cast between parent and children types. - Remove const-ness from various probe provider visible types to facilitate re-use of the code for eventual dynamically allocated structures. - Remove "field_name" field from lttng_ust_ctx_field. Instead, dynamically allocate field names for each context. - Introduce get_type_max_align() in lttng-context.c now used by lttng_context_update(). It performs a recursive traversal of the nested types rather than erroring out on recursive cases. - Move "encoding" from integer type to array and sequences types. Signed-off-by: Mathieu Desnoyers Change-Id: If99a2689f042b7e642b373e4646e9f85c009a47d --- include/lttng/ust-events.h | 200 +++++++++++---------- include/lttng/ust-tracepoint-event.h | 99 +++++----- include/ust-comm.h | 4 +- include/ust-context-provider.h | 1 - include/ust-dynamic-type.h | 6 +- liblttng-ust-comm/lttng-ust-comm.c | 142 ++++++++------- liblttng-ust/event-notifier-notification.c | 26 +-- liblttng-ust/lttng-bytecode-interpreter.c | 42 ++--- liblttng-ust/lttng-bytecode-specialize.c | 80 ++++----- liblttng-ust/lttng-bytecode.c | 50 +++--- liblttng-ust/lttng-bytecode.h | 8 +- liblttng-ust/lttng-context-cgroup-ns.c | 41 +++-- liblttng-ust/lttng-context-cpu-id.c | 39 ++-- liblttng-ust/lttng-context-ip.c | 39 ++-- liblttng-ust/lttng-context-ipc-ns.c | 41 +++-- liblttng-ust/lttng-context-mnt-ns.c | 41 +++-- liblttng-ust/lttng-context-net-ns.c | 41 +++-- liblttng-ust/lttng-context-perf-counters.c | 22 +-- liblttng-ust/lttng-context-pid-ns.c | 41 +++-- liblttng-ust/lttng-context-procname.c | 36 ++-- liblttng-ust/lttng-context-provider.c | 17 +- liblttng-ust/lttng-context-pthread-id.c | 39 ++-- liblttng-ust/lttng-context-time-ns.c | 41 +++-- liblttng-ust/lttng-context-user-ns.c | 41 +++-- liblttng-ust/lttng-context-uts-ns.c | 41 +++-- liblttng-ust/lttng-context-vegid.c | 41 +++-- liblttng-ust/lttng-context-veuid.c | 41 +++-- liblttng-ust/lttng-context-vgid.c | 41 +++-- liblttng-ust/lttng-context-vpid.c | 39 ++-- liblttng-ust/lttng-context-vsgid.c | 41 +++-- liblttng-ust/lttng-context-vsuid.c | 41 +++-- liblttng-ust/lttng-context-vtid.c | 39 ++-- liblttng-ust/lttng-context-vuid.c | 41 +++-- liblttng-ust/lttng-context.c | 105 +++++------ liblttng-ust/lttng-events.c | 60 +++---- liblttng-ust/lttng-probes.c | 20 +-- liblttng-ust/lttng-ust-abi.c | 2 +- liblttng-ust/lttng-ust-dynamic-type.c | 72 ++++---- liblttng-ust/ust-core.c | 2 +- liblttng-ust/ust-events-internal.h | 163 ++++++++++++++++- 40 files changed, 1193 insertions(+), 733 deletions(-) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 5025b187..946abe4b 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -47,30 +47,28 @@ struct lttng_ust_event_field; /* * Data structures used by tracepoint event declarations, and by the - * tracer. Those structures have padding for future extension. + * tracer. */ /* Type description */ -/* Update the astract_types name table in lttng-types.c along with this enum */ -enum lttng_abstract_types { - atype_integer, - atype_string, - atype_float, - atype_dynamic, - atype_enum_nestable, - atype_array_nestable, - atype_sequence_nestable, - atype_struct_nestable, - NR_ABSTRACT_TYPES, +enum lttng_ust_type { + lttng_ust_type_integer, + lttng_ust_type_string, + lttng_ust_type_float, + lttng_ust_type_dynamic, + lttng_ust_type_enum, + lttng_ust_type_array, + lttng_ust_type_sequence, + lttng_ust_type_struct, + NR_LTTNG_UST_TYPE, }; -/* Update the string_encodings name table in lttng-types.c along with this enum */ -enum lttng_string_encodings { - lttng_encode_none = 0, - lttng_encode_UTF8 = 1, - lttng_encode_ASCII = 2, - NR_STRING_ENCODINGS, +enum lttng_ust_string_encoding { + lttng_ust_string_encoding_none = 0, + lttng_ust_string_encoding_UTF8 = 1, + lttng_ust_string_encoding_ASCII = 2, + NR_LTTNG_UST_STRING_ENCODING, }; struct lttng_enum_value { @@ -104,30 +102,44 @@ struct lttng_ust_enum_entry { /* End of base ABI. Fields below should be used after checking struct_size. */ }; -#define __type_integer(_type, _byte_order, _base, _encoding) \ - { \ - .atype = atype_integer, \ - .u = { \ - .integer = { \ - .size = sizeof(_type) * CHAR_BIT, \ - .alignment = lttng_alignof(_type) * CHAR_BIT, \ - .signedness = lttng_is_signed_type(_type), \ - .reverse_byte_order = _byte_order != BYTE_ORDER, \ - .base = _base, \ - .encoding = lttng_encode_##_encoding, \ - } \ - }, \ - } \ - -#define LTTNG_UST_INTEGER_TYPE_PADDING 24 -struct lttng_integer_type { +/* + * struct lttng_ust_type_common is fixed-size. Its children inherits + * from it by embedding struct lttng_ust_type_common as its first field. + */ +struct lttng_ust_type_common { + enum lttng_ust_type type; +}; + +struct lttng_ust_type_integer { + struct lttng_ust_type_common parent; + uint32_t struct_size; unsigned int size; /* in bits */ unsigned short alignment; /* in bits */ unsigned int signedness:1; unsigned int reverse_byte_order:1; unsigned int base; /* 2, 8, 10, 16, for pretty print */ - enum lttng_string_encodings encoding; - char padding[LTTNG_UST_INTEGER_TYPE_PADDING]; +}; + +#define lttng_ust_type_integer_define(_type, _byte_order, _base) \ + ((struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_integer, { \ + .parent = { \ + .type = lttng_ust_type_integer, \ + }, \ + .struct_size = sizeof(struct lttng_ust_type_integer), \ + .size = sizeof(_type) * CHAR_BIT, \ + .alignment = lttng_alignof(_type) * CHAR_BIT, \ + .signedness = lttng_is_signed_type(_type), \ + .reverse_byte_order = _byte_order != BYTE_ORDER, \ + .base = _base, \ + })) + +struct lttng_ust_type_float { + struct lttng_ust_type_common parent; + uint32_t struct_size; + unsigned int exp_dig; /* exponent digits, in bits */ + unsigned int mant_dig; /* mantissa digits, in bits */ + unsigned short alignment; /* in bits */ + unsigned int reverse_byte_order:1; }; /* @@ -139,61 +151,57 @@ struct lttng_integer_type { : (sizeof(_type) == sizeof(double) ? DBL_MANT_DIG \ : 0)) -#define __type_float(_type) \ - { \ - .atype = atype_float, \ - .u = { \ - ._float = { \ - .exp_dig = sizeof(_type) * CHAR_BIT \ - - _float_mant_dig(_type), \ - .mant_dig = _float_mant_dig(_type), \ - .alignment = lttng_alignof(_type) * CHAR_BIT, \ - .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \ - } \ - } \ - } \ - -#define LTTNG_UST_FLOAT_TYPE_PADDING 24 -struct lttng_float_type { - unsigned int exp_dig; /* exponent digits, in bits */ - unsigned int mant_dig; /* mantissa digits, in bits */ - unsigned short alignment; /* in bits */ - unsigned int reverse_byte_order:1; - char padding[LTTNG_UST_FLOAT_TYPE_PADDING]; +#define lttng_ust_type_float_define(_type) \ + ((struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_float, { \ + .parent = { \ + .type = lttng_ust_type_float, \ + }, \ + .struct_size = sizeof(struct lttng_ust_type_float), \ + .exp_dig = sizeof(_type) * CHAR_BIT \ + - _float_mant_dig(_type), \ + .mant_dig = _float_mant_dig(_type), \ + .alignment = lttng_alignof(_type) * CHAR_BIT, \ + .reverse_byte_order = BYTE_ORDER != FLOAT_WORD_ORDER, \ + })) + + +struct lttng_ust_type_string { + struct lttng_ust_type_common parent; + uint32_t struct_size; + enum lttng_ust_string_encoding encoding; }; -#define LTTNG_UST_TYPE_PADDING 128 -struct lttng_type { - enum lttng_abstract_types atype; - union { - /* provider ABI 2.0 */ - struct lttng_integer_type integer; - struct lttng_float_type _float; - struct { - enum lttng_string_encodings encoding; - } string; - struct { - const struct lttng_ust_enum_desc *desc; /* Enumeration mapping */ - struct lttng_type *container_type; - } enum_nestable; - struct { - const struct lttng_type *elem_type; - unsigned int length; /* Num. elems. */ - unsigned int alignment; - } array_nestable; - struct { - const char *length_name; /* Length field name. */ - const struct lttng_type *elem_type; - unsigned int alignment; /* Alignment before elements. */ - } sequence_nestable; - struct { - unsigned int nr_fields; - const struct lttng_ust_event_field **fields; /* Array of pointers to fields. */ - unsigned int alignment; - } struct_nestable; - - char padding[LTTNG_UST_TYPE_PADDING]; - } u; +struct lttng_ust_type_enum { + struct lttng_ust_type_common parent; + uint32_t struct_size; + struct lttng_ust_enum_desc *desc; /* Enumeration mapping */ + struct lttng_ust_type_common *container_type; +}; + +struct lttng_ust_type_array { + struct lttng_ust_type_common parent; + uint32_t struct_size; + struct lttng_ust_type_common *elem_type; + unsigned int length; /* Num. elems. */ + unsigned int alignment; + enum lttng_ust_string_encoding encoding; +}; + +struct lttng_ust_type_sequence { + struct lttng_ust_type_common parent; + uint32_t struct_size; + const char *length_name; /* Length field name. */ + struct lttng_ust_type_common *elem_type; + unsigned int alignment; /* Alignment before elements. */ + enum lttng_ust_string_encoding encoding; +}; + +struct lttng_ust_type_struct { + struct lttng_ust_type_common parent; + uint32_t struct_size; + unsigned int nr_fields; + struct lttng_ust_event_field **fields; /* Array of pointers to fields. */ + unsigned int alignment; }; /* @@ -212,7 +220,7 @@ struct lttng_ust_enum_desc { uint32_t struct_size; const char *name; - const struct lttng_ust_enum_entry **entries; + struct lttng_ust_enum_entry **entries; unsigned int nr_entries; /* End of base ABI. Fields below should be used after checking struct_size. */ @@ -234,7 +242,7 @@ struct lttng_ust_event_field { uint32_t struct_size; const char *name; - struct lttng_type type; + struct lttng_ust_type_common *type; unsigned int nowrite:1, /* do not write into trace */ nofilter:1; /* do not consider for filter */ @@ -256,8 +264,8 @@ struct lttng_ust_event_desc { const char *name; void (*probe_callback)(void); - const struct lttng_event_ctx *ctx; /* context */ - const struct lttng_ust_event_field **fields; /* event payload */ + struct lttng_event_ctx *ctx; /* context */ + struct lttng_ust_event_field **fields; /* event payload */ unsigned int nr_fields; const int **loglevel; const char *signature; /* Argument types/names received */ @@ -279,7 +287,7 @@ struct lttng_ust_probe_desc { uint32_t struct_size; /* Size of this structure. */ const char *provider; - const struct lttng_ust_event_desc **event_desc; + struct lttng_ust_event_desc **event_desc; unsigned int nr_events; struct cds_list_head head; /* chain registered probes */ struct cds_list_head lazy_init_head; @@ -484,7 +492,7 @@ struct lttng_channel { struct lttng_ust_session *session; int objd; /* Object associated to channel */ struct cds_list_head node; /* Channel list in session */ - const struct lttng_ust_channel_ops *ops; + struct lttng_ust_channel_ops *ops; int header_type; /* 0: unset, 1: compact, 2: large */ struct lttng_ust_shm_handle *handle; /* shared-memory handle */ diff --git a/include/lttng/ust-tracepoint-event.h b/include/lttng/ust-tracepoint-event.h index c4e4f1ed..5d84e0b2 100644 --- a/include/lttng/ust-tracepoint-event.h +++ b/include/lttng/ust-tracepoint-event.h @@ -203,7 +203,7 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args) #undef TRACEPOINT_ENUM #define TRACEPOINT_ENUM(_provider, _name, _values) \ - const struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \ + struct lttng_ust_enum_entry *__enum_values__##_provider##_##_name[] = { \ _values \ ctf_enum_value("", 0) /* Dummy, 0-len array forbidden by C99. */ \ }; @@ -254,20 +254,20 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args) #undef _ctf_integer_ext #define _ctf_integer_ext(_type, _item, _src, _byte_order, _base, _nowrite) \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = #_item, \ - .type = __type_integer(_type, _byte_order, _base, none), \ + .type = lttng_ust_type_integer_define(_type, _byte_order, _base), \ .nowrite = _nowrite, \ .nofilter = 0, \ }), #undef _ctf_float #define _ctf_float(_type, _item, _src, _nowrite) \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = #_item, \ - .type = __type_float(_type), \ + .type = lttng_ust_type_float_define(_type), \ .nowrite = _nowrite, \ .nofilter = 0, \ }), @@ -276,20 +276,19 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args) #define _ctf_array_encoded(_type, _item, _src, _byte_order, \ _length, _encoding, _nowrite, \ _elem_type_base) \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = #_item, \ - .type = { \ - .atype = atype_array_nestable, \ - .u = { \ - .array_nestable = { \ - .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ - __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \ - .length = _length, \ - .alignment = 0, \ - } \ - } \ - }, \ + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_array, { \ + .parent = { \ + .type = lttng_ust_type_array, \ + }, \ + .struct_size = sizeof(struct lttng_ust_type_array), \ + .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ + .length = _length, \ + .alignment = 0, \ + .encoding = lttng_ust_string_encoding_##_encoding, \ + }), \ .nowrite = _nowrite, \ .nofilter = 0, \ }), @@ -298,61 +297,59 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args) #define _ctf_sequence_encoded(_type, _item, _src, _byte_order, \ _length_type, _src_length, _encoding, _nowrite, \ _elem_type_base) \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = "_" #_item "_length", \ - .type = __type_integer(_length_type, BYTE_ORDER, 10, none), \ + .type = lttng_ust_type_integer_define(_length_type, BYTE_ORDER, 10), \ .nowrite = _nowrite, \ .nofilter = 1, \ }), \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = #_item, \ - .type = { \ - .atype = atype_sequence_nestable, \ - .u = { \ - .sequence_nestable = { \ - .length_name = "_" #_item "_length", \ - .elem_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ - __type_integer(_type, _byte_order, _elem_type_base, _encoding)), \ - .alignment = 0, \ - }, \ + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_sequence, { \ + .parent = { \ + .type = lttng_ust_type_sequence, \ }, \ - }, \ + .struct_size = sizeof(struct lttng_ust_type_sequence), \ + .length_name = "_" #_item "_length", \ + .elem_type = lttng_ust_type_integer_define(_type, _byte_order, _elem_type_base), \ + .alignment = 0, \ + .encoding = lttng_ust_string_encoding_##_encoding, \ + }), \ .nowrite = _nowrite, \ .nofilter = 0, \ }), #undef _ctf_string #define _ctf_string(_item, _src, _nowrite) \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = #_item, \ - .type = { \ - .atype = atype_string, \ - .u = { \ - .string = { .encoding = lttng_encode_UTF8 } \ + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { \ + .parent = { \ + .type = lttng_ust_type_string, \ }, \ - }, \ + .struct_size = sizeof(struct lttng_ust_type_string), \ + .encoding = lttng_ust_string_encoding_UTF8, \ + }), \ .nowrite = _nowrite, \ .nofilter = 0, \ }), #undef _ctf_enum #define _ctf_enum(_provider, _name, _type, _item, _src, _nowrite) \ - __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ + __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { \ .struct_size = sizeof(struct lttng_ust_event_field), \ .name = #_item, \ - .type = { \ - .atype = atype_enum_nestable, \ - .u = { \ - .enum_nestable = { \ - .desc = &__enum_##_provider##_##_name, \ - .container_type = __LTTNG_COMPOUND_LITERAL(struct lttng_type, \ - __type_integer(_type, BYTE_ORDER, 10, none)), \ - }, \ + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { \ + .parent = { \ + .type = lttng_ust_type_enum, \ }, \ - }, \ + .struct_size = sizeof(struct lttng_ust_type_enum), \ + .desc = &__enum_##_provider##_##_name, \ + .container_type = lttng_ust_type_integer_define(_type, BYTE_ORDER, 10), \ + }), \ .nowrite = _nowrite, \ .nofilter = 0, \ }), @@ -362,15 +359,15 @@ void __event_template_proto___##_provider##___##_name(_TP_ARGS_DATA_PROTO(_args) #undef _TRACEPOINT_EVENT_CLASS #define _TRACEPOINT_EVENT_CLASS(_provider, _name, _args, _fields) \ - static const struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \ + static struct lttng_ust_event_field *__event_fields___##_provider##___##_name[] = { \ _fields \ ctf_integer(int, dummy, 0) /* Dummy, C99 forbids 0-len array. */ \ }; #undef TRACEPOINT_ENUM #define TRACEPOINT_ENUM(_provider, _name, _values) \ - static const struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \ - .struct_size = sizeof(struct lttng_ust_enum_desc), \ + static struct lttng_ust_enum_desc __enum_##_provider##_##_name = { \ + .struct_size = sizeof(struct lttng_ust_enum_desc), \ .name = #_provider "_" #_name, \ .entries = __enum_values__##_provider##_##_name, \ .nr_entries = _TP_ARRAY_SIZE(__enum_values__##_provider##_##_name) - 1, \ @@ -992,7 +989,7 @@ static const int * \ static const char * \ __ref_model_emf_uri___##_provider##___##_name \ __attribute__((weakref ("_model_emf_uri___" #_provider "___" #_name)));\ -static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \ +static struct lttng_ust_event_desc __event_desc___##_provider##_##_name = { \ .struct_size = sizeof(struct lttng_ust_event_desc), \ .name = #_provider ":" #_name, \ .probe_callback = (void (*)(void)) &__event_probe__##_provider##___##_template, \ @@ -1019,7 +1016,7 @@ static const struct lttng_ust_event_desc __event_desc___##_provider##_##_name = #define _TRACEPOINT_EVENT_INSTANCE(_provider, _template, _name, _args) \ &__event_desc___##_provider##_##_name, -static const struct lttng_ust_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { +static struct lttng_ust_event_desc *_TP_COMBINE_TOKENS(__event_desc___, TRACEPOINT_PROVIDER)[] = { #include TRACEPOINT_INCLUDE NULL, /* Dummy, C99 forbids 0-len array. */ }; diff --git a/include/ust-comm.h b/include/ust-comm.h index da4adc2f..39496921 100644 --- a/include/ust-comm.h +++ b/include/ust-comm.h @@ -292,7 +292,7 @@ int ustcomm_register_event(int sock, int loglevel, const char *signature, /* event signature (input) */ size_t nr_fields, /* fields */ - const struct lttng_ust_event_field **fields, + struct lttng_ust_event_field **fields, const char *model_emf_uri, uint32_t *id); /* event id (output) */ @@ -305,7 +305,7 @@ int ustcomm_register_enum(int sock, int session_objd, /* session descriptor */ const char *enum_name, /* enum name (input) */ size_t nr_entries, /* entries */ - const struct lttng_ust_enum_entry **entries, + struct lttng_ust_enum_entry **entries, uint64_t *id); /* enum id (output) */ /* diff --git a/include/ust-context-provider.h b/include/ust-context-provider.h index e62950e1..637bc0c2 100644 --- a/include/ust-context-provider.h +++ b/include/ust-context-provider.h @@ -61,7 +61,6 @@ struct lttng_ust_ctx_field { void (*get_value)(struct lttng_ust_ctx_field *field, struct lttng_ust_ctx_value *value); void (*destroy)(struct lttng_ust_ctx_field *field); - char *field_name; /* Has ownership, dynamically allocated. */ /* End of base ABI. Fields below should be used after checking struct_size. */ }; diff --git a/include/ust-dynamic-type.h b/include/ust-dynamic-type.h index cb628ad8..80a80d09 100644 --- a/include/ust-dynamic-type.h +++ b/include/ust-dynamic-type.h @@ -27,12 +27,12 @@ enum lttng_ust_dynamic_type { __attribute__((visibility("hidden"))) int lttng_ust_dynamic_type_choices(size_t *nr_choices, - const struct lttng_ust_event_field ***choices); + struct lttng_ust_event_field ***choices); __attribute__((visibility("hidden"))) -const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value); +struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value); __attribute__((visibility("hidden"))) -const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void); +struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void); #endif /* _LTTNG_UST_DYNAMIC_TYPE_H */ diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index e02aaeb6..8e17e417 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -37,16 +37,16 @@ static ssize_t count_fields_recursive(size_t nr_fields, - const struct lttng_ust_event_field **lttng_fields); + struct lttng_ust_event_field **lttng_fields); static int serialize_one_field(struct lttng_ust_session *session, struct ustctl_field *fields, size_t *iter_output, - const struct lttng_ust_event_field *lf); + struct lttng_ust_event_field *lf); static int serialize_fields(struct lttng_ust_session *session, struct ustctl_field *ustctl_fields, size_t *iter_output, size_t nr_lttng_fields, - const struct lttng_ust_event_field **lttng_fields); + struct lttng_ust_event_field **lttng_fields); /* * Human readable error message. @@ -865,26 +865,26 @@ int ustcomm_send_reg_msg(int sock, } static -ssize_t count_one_type(const struct lttng_type *lt) +ssize_t count_one_type(struct lttng_ust_type_common *lt) { - switch (lt->atype) { - case atype_integer: - case atype_float: - case atype_string: + switch (lt->type) { + case lttng_ust_type_integer: + case lttng_ust_type_float: + case lttng_ust_type_string: return 1; - case atype_enum_nestable: - return count_one_type(lt->u.enum_nestable.container_type) + 1; - case atype_array_nestable: - return count_one_type(lt->u.array_nestable.elem_type) + 1; - case atype_sequence_nestable: - return count_one_type(lt->u.sequence_nestable.elem_type) + 1; - case atype_struct_nestable: - return count_fields_recursive(lt->u.struct_nestable.nr_fields, - lt->u.struct_nestable.fields) + 1; - - case atype_dynamic: + case lttng_ust_type_enum: + return count_one_type(lttng_ust_get_type_enum(lt)->container_type) + 1; + case lttng_ust_type_array: + return count_one_type(lttng_ust_get_type_array(lt)->elem_type) + 1; + case lttng_ust_type_sequence: + return count_one_type(lttng_ust_get_type_sequence(lt)->elem_type) + 1; + case lttng_ust_type_struct: + return count_fields_recursive(lttng_ust_get_type_struct(lt)->nr_fields, + lttng_ust_get_type_struct(lt)->fields) + 1; + + case lttng_ust_type_dynamic: { - const struct lttng_ust_event_field **choices; + struct lttng_ust_event_field **choices; size_t nr_choices; int ret; @@ -907,7 +907,7 @@ ssize_t count_one_type(const struct lttng_type *lt) static ssize_t count_fields_recursive(size_t nr_fields, - const struct lttng_ust_event_field **lttng_fields) + struct lttng_ust_event_field **lttng_fields) { int i; ssize_t ret, count = 0; @@ -919,7 +919,7 @@ ssize_t count_fields_recursive(size_t nr_fields, /* skip 'nowrite' fields */ if (lf->nowrite) continue; - ret = count_one_type(&lf->type); + ret = count_one_type(lf->type); if (ret < 0) return ret; /* error */ count += ret; @@ -941,7 +941,7 @@ ssize_t count_ctx_fields_recursive(size_t nr_fields, /* skip 'nowrite' fields */ if (lf->nowrite) continue; - ret = count_one_type(&lf->type); + ret = count_one_type(lf->type); if (ret < 0) return ret; /* error */ count += ret; @@ -951,16 +951,16 @@ ssize_t count_ctx_fields_recursive(size_t nr_fields, static int serialize_string_encoding(int32_t *ue, - enum lttng_string_encodings le) + enum lttng_ust_string_encoding le) { switch (le) { - case lttng_encode_none: + case lttng_ust_string_encoding_none: *ue = ustctl_encode_none; break; - case lttng_encode_UTF8: + case lttng_ust_string_encoding_UTF8: *ue = ustctl_encode_UTF8; break; - case lttng_encode_ASCII: + case lttng_ust_string_encoding_ASCII: *ue = ustctl_encode_ASCII; break; default: @@ -971,7 +971,8 @@ int serialize_string_encoding(int32_t *ue, static int serialize_integer_type(struct ustctl_integer_type *uit, - const struct lttng_integer_type *lit) + const struct lttng_ust_type_integer *lit, + enum lttng_ust_string_encoding lencoding) { int32_t encoding; @@ -979,7 +980,7 @@ int serialize_integer_type(struct ustctl_integer_type *uit, uit->signedness = lit->signedness; uit->reverse_byte_order = lit->reverse_byte_order; uit->base = lit->base; - if (serialize_string_encoding(&encoding, lit->encoding)) + if (serialize_string_encoding(&encoding, lencoding)) return -EINVAL; uit->encoding = encoding; uit->alignment = lit->alignment; @@ -991,10 +992,10 @@ int serialize_dynamic_type(struct lttng_ust_session *session, struct ustctl_field *fields, size_t *iter_output, const char *field_name) { - const struct lttng_ust_event_field **choices; + struct lttng_ust_event_field **choices; char tag_field_name[LTTNG_UST_ABI_SYM_NAME_LEN]; - const struct lttng_type *tag_type; - const struct lttng_ust_event_field *tag_field_generic; + struct lttng_ust_type_common *tag_type; + struct lttng_ust_event_field *tag_field_generic; struct lttng_ust_event_field tag_field = { .name = tag_field_name, .nowrite = 0, @@ -1004,7 +1005,7 @@ int serialize_dynamic_type(struct lttng_ust_session *session, int ret; tag_field_generic = lttng_ust_dynamic_type_tag_field(); - tag_type = &tag_field_generic->type; + tag_type = tag_field_generic->type; /* Serialize enum field. */ strncpy(tag_field_name, field_name, LTTNG_UST_ABI_SYM_NAME_LEN); @@ -1012,7 +1013,7 @@ int serialize_dynamic_type(struct lttng_ust_session *session, strncat(tag_field_name, "_tag", LTTNG_UST_ABI_SYM_NAME_LEN - strlen(tag_field_name) - 1); - tag_field.type = *tag_type; + tag_field.type = tag_type; ret = serialize_one_field(session, fields, iter_output, &tag_field); if (ret) @@ -1048,7 +1049,8 @@ int serialize_dynamic_type(struct lttng_ust_session *session, static int serialize_one_type(struct lttng_ust_session *session, struct ustctl_field *fields, size_t *iter_output, - const char *field_name, const struct lttng_type *lt) + const char *field_name, struct lttng_ust_type_common *lt, + enum lttng_ust_string_encoding parent_encoding) { int ret; @@ -1057,8 +1059,8 @@ int serialize_one_type(struct lttng_ust_session *session, * entry with 0-length name. */ - switch (lt->atype) { - case atype_integer: + switch (lt->type) { + case lttng_ust_type_integer: { struct ustctl_field *uf = &fields[*iter_output]; struct ustctl_type *ut = &uf->type; @@ -1069,19 +1071,20 @@ int serialize_one_type(struct lttng_ust_session *session, } else { uf->name[0] = '\0'; } - ret = serialize_integer_type(&ut->u.integer, <->u.integer); + ret = serialize_integer_type(&ut->u.integer, lttng_ust_get_type_integer(lt), + parent_encoding); if (ret) return ret; ut->atype = ustctl_atype_integer; (*iter_output)++; break; } - case atype_float: + case lttng_ust_type_float: { struct ustctl_field *uf = &fields[*iter_output]; struct ustctl_type *ut = &uf->type; struct ustctl_float_type *uft; - const struct lttng_float_type *lft; + struct lttng_ust_type_float *lft; if (field_name) { strncpy(uf->name, field_name, LTTNG_UST_ABI_SYM_NAME_LEN); @@ -1090,7 +1093,7 @@ int serialize_one_type(struct lttng_ust_session *session, uf->name[0] = '\0'; } uft = &ut->u._float; - lft = <->u._float; + lft = lttng_ust_get_type_float(lt); uft->exp_dig = lft->exp_dig; uft->mant_dig = lft->mant_dig; uft->alignment = lft->alignment; @@ -1099,7 +1102,7 @@ int serialize_one_type(struct lttng_ust_session *session, (*iter_output)++; break; } - case atype_string: + case lttng_ust_type_string: { struct ustctl_field *uf = &fields[*iter_output]; struct ustctl_type *ut = &uf->type; @@ -1111,7 +1114,7 @@ int serialize_one_type(struct lttng_ust_session *session, } else { uf->name[0] = '\0'; } - ret = serialize_string_encoding(&encoding, lt->u.string.encoding); + ret = serialize_string_encoding(&encoding, lttng_ust_get_type_string(lt)->encoding); if (ret) return ret; ut->u.string.encoding = encoding; @@ -1119,7 +1122,7 @@ int serialize_one_type(struct lttng_ust_session *session, (*iter_output)++; break; } - case atype_array_nestable: + case lttng_ust_type_array: { struct ustctl_field *uf = &fields[*iter_output]; struct ustctl_type *ut = &uf->type; @@ -1131,17 +1134,18 @@ int serialize_one_type(struct lttng_ust_session *session, uf->name[0] = '\0'; } ut->atype = ustctl_atype_array_nestable; - ut->u.array_nestable.length = lt->u.array_nestable.length; - ut->u.array_nestable.alignment = lt->u.array_nestable.alignment; + ut->u.array_nestable.length = lttng_ust_get_type_array(lt)->length; + ut->u.array_nestable.alignment = lttng_ust_get_type_array(lt)->alignment; (*iter_output)++; ret = serialize_one_type(session, fields, iter_output, NULL, - lt->u.array_nestable.elem_type); + lttng_ust_get_type_array(lt)->elem_type, + lttng_ust_get_type_array(lt)->encoding); if (ret) return -EINVAL; break; } - case atype_sequence_nestable: + case lttng_ust_type_sequence: { struct ustctl_field *uf = &fields[*iter_output]; struct ustctl_type *ut = &uf->type; @@ -1154,19 +1158,20 @@ int serialize_one_type(struct lttng_ust_session *session, } ut->atype = ustctl_atype_sequence_nestable; strncpy(ut->u.sequence_nestable.length_name, - lt->u.sequence_nestable.length_name, + lttng_ust_get_type_sequence(lt)->length_name, LTTNG_UST_ABI_SYM_NAME_LEN); ut->u.sequence_nestable.length_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; - ut->u.sequence_nestable.alignment = lt->u.sequence_nestable.alignment; + ut->u.sequence_nestable.alignment = lttng_ust_get_type_sequence(lt)->alignment; (*iter_output)++; ret = serialize_one_type(session, fields, iter_output, NULL, - lt->u.sequence_nestable.elem_type); + lttng_ust_get_type_sequence(lt)->elem_type, + lttng_ust_get_type_sequence(lt)->encoding); if (ret) return -EINVAL; break; } - case atype_dynamic: + case lttng_ust_type_dynamic: { ret = serialize_dynamic_type(session, fields, iter_output, field_name); @@ -1174,7 +1179,7 @@ int serialize_one_type(struct lttng_ust_session *session, return -EINVAL; break; } - case atype_struct_nestable: + case lttng_ust_type_struct: { struct ustctl_field *uf = &fields[*iter_output]; @@ -1185,18 +1190,18 @@ int serialize_one_type(struct lttng_ust_session *session, uf->name[0] = '\0'; } uf->type.atype = ustctl_atype_struct_nestable; - uf->type.u.struct_nestable.nr_fields = lt->u.struct_nestable.nr_fields; - uf->type.u.struct_nestable.alignment = lt->u.struct_nestable.alignment; + uf->type.u.struct_nestable.nr_fields = lttng_ust_get_type_struct(lt)->nr_fields; + uf->type.u.struct_nestable.alignment = lttng_ust_get_type_struct(lt)->alignment; (*iter_output)++; ret = serialize_fields(session, fields, iter_output, - lt->u.struct_nestable.nr_fields, - lt->u.struct_nestable.fields); + lttng_ust_get_type_struct(lt)->nr_fields, + lttng_ust_get_type_struct(lt)->fields); if (ret) return -EINVAL; break; } - case atype_enum_nestable: + case lttng_ust_type_enum: { struct ustctl_field *uf = &fields[*iter_output]; struct ustctl_type *ut = &uf->type; @@ -1207,20 +1212,21 @@ int serialize_one_type(struct lttng_ust_session *session, } else { uf->name[0] = '\0'; } - strncpy(ut->u.enum_nestable.name, lt->u.enum_nestable.desc->name, + strncpy(ut->u.enum_nestable.name, lttng_ust_get_type_enum(lt)->desc->name, LTTNG_UST_ABI_SYM_NAME_LEN); ut->u.enum_nestable.name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; ut->atype = ustctl_atype_enum_nestable; (*iter_output)++; ret = serialize_one_type(session, fields, iter_output, NULL, - lt->u.enum_nestable.container_type); + lttng_ust_get_type_enum(lt)->container_type, + lttng_ust_string_encoding_none); if (ret) return -EINVAL; if (session) { const struct lttng_enum *_enum; - _enum = lttng_ust_enum_get_from_desc(session, lt->u.enum_nestable.desc); + _enum = lttng_ust_enum_get_from_desc(session, lttng_ust_get_type_enum(lt)->desc); if (!_enum) return -EINVAL; ut->u.enum_nestable.id = _enum->id; @@ -1238,20 +1244,20 @@ int serialize_one_type(struct lttng_ust_session *session, static int serialize_one_field(struct lttng_ust_session *session, struct ustctl_field *fields, size_t *iter_output, - const struct lttng_ust_event_field *lf) + struct lttng_ust_event_field *lf) { /* skip 'nowrite' fields */ if (lf->nowrite) return 0; - return serialize_one_type(session, fields, iter_output, lf->name, &lf->type); + return serialize_one_type(session, fields, iter_output, lf->name, lf->type, lttng_ust_string_encoding_none); } static int serialize_fields(struct lttng_ust_session *session, struct ustctl_field *ustctl_fields, size_t *iter_output, size_t nr_lttng_fields, - const struct lttng_ust_event_field **lttng_fields) + struct lttng_ust_event_field **lttng_fields) { int ret; size_t i; @@ -1270,7 +1276,7 @@ int alloc_serialize_fields(struct lttng_ust_session *session, size_t *_nr_write_fields, struct ustctl_field **ustctl_fields, size_t nr_fields, - const struct lttng_ust_event_field **lttng_fields) + struct lttng_ust_event_field **lttng_fields) { struct ustctl_field *fields; int ret; @@ -1303,7 +1309,7 @@ error_type: static int serialize_entries(struct ustctl_enum_entry **_entries, size_t nr_entries, - const struct lttng_ust_enum_entry **lttng_entries) + struct lttng_ust_enum_entry **lttng_entries) { struct ustctl_enum_entry *entries; int i; @@ -1384,7 +1390,7 @@ int ustcomm_register_event(int sock, int loglevel, const char *signature, /* event signature (input) */ size_t nr_fields, /* fields */ - const struct lttng_ust_event_field **lttng_fields, + struct lttng_ust_event_field **lttng_fields, const char *model_emf_uri, uint32_t *id) /* event id (output) */ { @@ -1523,7 +1529,7 @@ int ustcomm_register_enum(int sock, int session_objd, /* session descriptor */ const char *enum_name, /* enum name (input) */ size_t nr_entries, /* entries */ - const struct lttng_ust_enum_entry **lttng_entries, + struct lttng_ust_enum_entry **lttng_entries, uint64_t *id) { ssize_t len; diff --git a/liblttng-ust/event-notifier-notification.c b/liblttng-ust/event-notifier-notification.c index eb3c0bce..199e615b 100644 --- a/liblttng-ust/event-notifier-notification.c +++ b/liblttng-ust/event-notifier-notification.c @@ -60,11 +60,11 @@ void capture_enum(struct lttng_msgpack_writer *writer, static int64_t capture_sequence_element_signed(uint8_t *ptr, - const struct lttng_integer_type *type) + struct lttng_ust_type_integer *integer_type) { int64_t value; - unsigned int size = type->size; - bool byte_order_reversed = type->reverse_byte_order; + unsigned int size = integer_type->size; + bool byte_order_reversed = integer_type->reverse_byte_order; switch (size) { case 8: @@ -109,11 +109,11 @@ int64_t capture_sequence_element_signed(uint8_t *ptr, static uint64_t capture_sequence_element_unsigned(uint8_t *ptr, - const struct lttng_integer_type *type) + struct lttng_ust_type_integer *integer_type) { uint64_t value; - unsigned int size = type->size; - bool byte_order_reversed = type->reverse_byte_order; + unsigned int size = integer_type->size; + bool byte_order_reversed = integer_type->reverse_byte_order; switch (size) { case 8: @@ -160,8 +160,8 @@ static void capture_sequence(struct lttng_msgpack_writer *writer, struct lttng_interpreter_output *output) { - const struct lttng_integer_type *integer_type; - const struct lttng_type *nested_type; + struct lttng_ust_type_integer *integer_type; + struct lttng_ust_type_common *nested_type; uint8_t *ptr; bool signedness; int i; @@ -170,13 +170,13 @@ void capture_sequence(struct lttng_msgpack_writer *writer, ptr = (uint8_t *) output->u.sequence.ptr; nested_type = output->u.sequence.nested_type; - switch (nested_type->atype) { - case atype_integer: - integer_type = &nested_type->u.integer; + switch (nested_type->type) { + case lttng_ust_type_integer: + integer_type = lttng_ust_get_type_integer(nested_type); break; - case atype_enum_nestable: + case lttng_ust_type_enum: /* Treat enumeration as an integer. */ - integer_type = &nested_type->u.enum_nestable.container_type->u.integer; + integer_type = lttng_ust_get_type_integer(lttng_ust_get_type_enum(nested_type)->container_type); break; default: /* Capture of array of non-integer are not supported. */ diff --git a/liblttng-ust/lttng-bytecode-interpreter.c b/liblttng-ust/lttng-bytecode-interpreter.c index 947da3ee..765955fd 100644 --- a/liblttng-ust/lttng-bytecode-interpreter.c +++ b/liblttng-ust/lttng-bytecode-interpreter.c @@ -231,10 +231,10 @@ static int context_get_index(struct lttng_ust_ctx *ctx, ptr->type = LOAD_OBJECT; ptr->field = field; - switch (field->type.atype) { - case atype_integer: + switch (field->type->type) { + case lttng_ust_type_integer: ctx_field->get_value(ctx_field, &v); - if (field->type.u.integer.signedness) { + if (lttng_ust_get_type_integer(field->type)->signedness) { ptr->object_type = OBJECT_TYPE_S64; ptr->u.s64 = v.u.s64; ptr->ptr = &ptr->u.s64; @@ -244,11 +244,11 @@ static int context_get_index(struct lttng_ust_ctx *ctx, ptr->ptr = &ptr->u.u64; } break; - case atype_enum_nestable: + case lttng_ust_type_enum: { - const struct lttng_integer_type *itype; + const struct lttng_ust_type_integer *itype; - itype = &field->type.u.enum_nestable.container_type->u.integer; + itype = lttng_ust_get_type_integer(lttng_ust_get_type_enum(field->type)->container_type); ctx_field->get_value(ctx_field, &v); if (itype->signedness) { ptr->object_type = OBJECT_TYPE_SIGNED_ENUM; @@ -261,12 +261,12 @@ static int context_get_index(struct lttng_ust_ctx *ctx, } break; } - case atype_array_nestable: - if (field->type.u.array_nestable.elem_type->atype != atype_integer) { + case lttng_ust_type_array: + if (lttng_ust_get_type_array(field->type)->elem_type->type != lttng_ust_type_integer) { ERR("Array nesting only supports integer types."); return -EINVAL; } - if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) { + if (lttng_ust_get_type_array(field->type)->encoding == lttng_ust_string_encoding_none) { ERR("Only string arrays are supported for contexts."); return -EINVAL; } @@ -274,12 +274,12 @@ static int context_get_index(struct lttng_ust_ctx *ctx, ctx_field->get_value(ctx_field, &v); ptr->ptr = v.u.str; break; - case atype_sequence_nestable: - if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) { + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(field->type)->elem_type->type != lttng_ust_type_integer) { ERR("Sequence nesting only supports integer types."); return -EINVAL; } - if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) { + if (lttng_ust_get_type_sequence(field->type)->encoding == lttng_ust_string_encoding_none) { ERR("Only string sequences are supported for contexts."); return -EINVAL; } @@ -287,18 +287,18 @@ static int context_get_index(struct lttng_ust_ctx *ctx, ctx_field->get_value(ctx_field, &v); ptr->ptr = v.u.str; break; - case atype_string: + case lttng_ust_type_string: ptr->object_type = OBJECT_TYPE_STRING; ctx_field->get_value(ctx_field, &v); ptr->ptr = v.u.str; break; - case atype_float: + case lttng_ust_type_float: ptr->object_type = OBJECT_TYPE_DOUBLE; ctx_field->get_value(ctx_field, &v); ptr->u.d = v.u.d; ptr->ptr = &ptr->u.d; break; - case atype_dynamic: + case lttng_ust_type_dynamic: ctx_field->get_value(ctx_field, &v); switch (v.sel) { case LTTNG_UST_DYNAMIC_TYPE_NONE: @@ -339,7 +339,7 @@ static int context_get_index(struct lttng_ust_ctx *ctx, } break; default: - ERR("Unknown type: %d", (int) field->type.atype); + ERR("Unknown type: %d", (int) field->type->type); return -EINVAL; } return 0; @@ -367,7 +367,7 @@ static int dynamic_get_index(struct lttng_ust_ctx *ctx, stack_top->u.ptr.ptr = ptr; stack_top->u.ptr.object_type = gid->elem.type; stack_top->u.ptr.rev_bo = gid->elem.rev_bo; - assert(stack_top->u.ptr.field->type.atype == atype_array_nestable); + assert(stack_top->u.ptr.field->type->type == lttng_ust_type_array); stack_top->u.ptr.field = NULL; break; } @@ -386,7 +386,7 @@ static int dynamic_get_index(struct lttng_ust_ctx *ctx, stack_top->u.ptr.ptr = ptr; stack_top->u.ptr.object_type = gid->elem.type; stack_top->u.ptr.rev_bo = gid->elem.rev_bo; - assert(stack_top->u.ptr.field->type.atype == atype_sequence_nestable); + assert(stack_top->u.ptr.field->type->type == lttng_ust_type_sequence); stack_top->u.ptr.field = NULL; break; } @@ -664,14 +664,14 @@ again: output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE; output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long)); output->u.sequence.nr_elem = *(unsigned long *) ax->u.ptr.ptr; - output->u.sequence.nested_type = ax->u.ptr.field->type.u.sequence_nestable.elem_type; + output->u.sequence.nested_type = lttng_ust_get_type_sequence(ax->u.ptr.field->type)->elem_type; break; case OBJECT_TYPE_ARRAY: /* Skip count (unsigned long) */ output->type = LTTNG_INTERPRETER_TYPE_SEQUENCE; output->u.sequence.ptr = *(const char **) (ax->u.ptr.ptr + sizeof(unsigned long)); - output->u.sequence.nr_elem = ax->u.ptr.field->type.u.array_nestable.length; - output->u.sequence.nested_type = ax->u.ptr.field->type.u.array_nestable.elem_type; + output->u.sequence.nr_elem = lttng_ust_get_type_array(ax->u.ptr.field->type)->length; + output->u.sequence.nested_type = lttng_ust_get_type_array(ax->u.ptr.field->type)->elem_type; break; case OBJECT_TYPE_SIGNED_ENUM: ret = dynamic_load_field(ax); diff --git a/liblttng-ust/lttng-bytecode-specialize.c b/liblttng-ust/lttng-bytecode-specialize.c index c546c8d6..cb7480b3 100644 --- a/liblttng-ust/lttng-bytecode-specialize.c +++ b/liblttng-ust/lttng-bytecode-specialize.c @@ -253,20 +253,20 @@ static int specialize_get_index(struct bytecode_runtime *runtime, switch (stack_top->load.object_type) { case OBJECT_TYPE_ARRAY: { - const struct lttng_integer_type *integer_type; - const struct lttng_ust_event_field *field; + struct lttng_ust_type_integer *integer_type; + struct lttng_ust_event_field *field; uint32_t elem_len, num_elems; int signedness; field = stack_top->load.field; - switch (field->type.atype) { - case atype_array_nestable: - if (field->type.u.array_nestable.elem_type->atype != atype_integer) { + switch (field->type->type) { + case lttng_ust_type_array: + if (lttng_ust_get_type_array(field->type)->elem_type->type != lttng_ust_type_integer) { ret = -EINVAL; goto end; } - integer_type = &field->type.u.array_nestable.elem_type->u.integer; - num_elems = field->type.u.array_nestable.length; + integer_type = lttng_ust_get_type_integer(lttng_ust_get_type_array(field->type)->elem_type); + num_elems = lttng_ust_get_type_array(field->type)->length; break; default: ret = -EINVAL; @@ -293,19 +293,19 @@ static int specialize_get_index(struct bytecode_runtime *runtime, } case OBJECT_TYPE_SEQUENCE: { - const struct lttng_integer_type *integer_type; - const struct lttng_ust_event_field *field; + struct lttng_ust_type_integer *integer_type; + struct lttng_ust_event_field *field; uint32_t elem_len; int signedness; field = stack_top->load.field; - switch (field->type.atype) { - case atype_sequence_nestable: - if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) { + switch (field->type->type) { + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(field->type)->elem_type->type != lttng_ust_type_integer) { ret = -EINVAL; goto end; } - integer_type = &field->type.u.sequence_nestable.elem_type->u.integer; + integer_type = lttng_ust_get_type_integer(lttng_ust_get_type_sequence(field->type)->elem_type); break; default: ret = -EINVAL; @@ -378,24 +378,24 @@ static int specialize_context_lookup_name(struct lttng_ust_ctx *ctx, return lttng_get_context_index(ctx, name); } -static int specialize_load_object(const struct lttng_ust_event_field *field, +static int specialize_load_object(struct lttng_ust_event_field *field, struct vstack_load *load, bool is_context) { load->type = LOAD_OBJECT; - switch (field->type.atype) { - case atype_integer: - if (field->type.u.integer.signedness) + switch (field->type->type) { + case lttng_ust_type_integer: + if (lttng_ust_get_type_integer(field->type)->signedness) load->object_type = OBJECT_TYPE_S64; else load->object_type = OBJECT_TYPE_U64; load->rev_bo = false; break; - case atype_enum_nestable: + case lttng_ust_type_enum: { - const struct lttng_integer_type *itype; + struct lttng_ust_type_integer *itype; - itype = &field->type.u.enum_nestable.container_type->u.integer; + itype = lttng_ust_get_type_integer(lttng_ust_get_type_enum(field->type)->container_type); if (itype->signedness) load->object_type = OBJECT_TYPE_SIGNED_ENUM; else @@ -403,15 +403,15 @@ static int specialize_load_object(const struct lttng_ust_event_field *field, load->rev_bo = false; break; } - case atype_array_nestable: - if (field->type.u.array_nestable.elem_type->atype != atype_integer) { + case lttng_ust_type_array: + if (lttng_ust_get_type_array(field->type)->elem_type->type != lttng_ust_type_integer) { ERR("Array nesting only supports integer types."); return -EINVAL; } if (is_context) { load->object_type = OBJECT_TYPE_STRING; } else { - if (field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) { + if (lttng_ust_get_type_array(field->type)->encoding == lttng_ust_string_encoding_none) { load->object_type = OBJECT_TYPE_ARRAY; load->field = field; } else { @@ -419,15 +419,15 @@ static int specialize_load_object(const struct lttng_ust_event_field *field, } } break; - case atype_sequence_nestable: - if (field->type.u.sequence_nestable.elem_type->atype != atype_integer) { + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(field->type)->elem_type->type != lttng_ust_type_integer) { ERR("Sequence nesting only supports integer types."); return -EINVAL; } if (is_context) { load->object_type = OBJECT_TYPE_STRING; } else { - if (field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) { + if (lttng_ust_get_type_sequence(field->type)->encoding == lttng_ust_string_encoding_none) { load->object_type = OBJECT_TYPE_SEQUENCE; load->field = field; } else { @@ -436,17 +436,17 @@ static int specialize_load_object(const struct lttng_ust_event_field *field, } break; - case atype_string: + case lttng_ust_type_string: load->object_type = OBJECT_TYPE_STRING; break; - case atype_float: + case lttng_ust_type_float: load->object_type = OBJECT_TYPE_DOUBLE; break; - case atype_dynamic: + case lttng_ust_type_dynamic: load->object_type = OBJECT_TYPE_DYNAMIC; break; default: - ERR("Unknown type: %d", (int) field->type.atype); + ERR("Unknown type: %d", (int) field->type->type); return -EINVAL; } return 0; @@ -547,7 +547,7 @@ end: return ret; } -static int specialize_payload_lookup(const struct lttng_ust_event_desc *event_desc, +static int specialize_payload_lookup(struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *runtime, struct load_op *insn, struct vstack_load *load) @@ -557,7 +557,7 @@ static int specialize_payload_lookup(const struct lttng_ust_event_desc *event_de unsigned int i, nr_fields; bool found = false; uint32_t field_offset = 0; - const struct lttng_ust_event_field *field; + struct lttng_ust_event_field *field; int ret; struct bytecode_get_index_data gid; ssize_t data_offset; @@ -575,20 +575,20 @@ static int specialize_payload_lookup(const struct lttng_ust_event_desc *event_de break; } /* compute field offset on stack */ - switch (field->type.atype) { - case atype_integer: - case atype_enum_nestable: + switch (field->type->type) { + case lttng_ust_type_integer: + case lttng_ust_type_enum: field_offset += sizeof(int64_t); break; - case atype_array_nestable: - case atype_sequence_nestable: + case lttng_ust_type_array: + case lttng_ust_type_sequence: field_offset += sizeof(unsigned long); field_offset += sizeof(void *); break; - case atype_string: + case lttng_ust_type_string: field_offset += sizeof(void *); break; - case atype_float: + case lttng_ust_type_float: field_offset += sizeof(double); break; default: @@ -624,7 +624,7 @@ end: return ret; } -int lttng_bytecode_specialize(const struct lttng_ust_event_desc *event_desc, +int lttng_bytecode_specialize(struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *bytecode) { void *pc, *next_pc, *start_pc; diff --git a/liblttng-ust/lttng-bytecode.c b/liblttng-ust/lttng-bytecode.c index f9ebc476..d75600ba 100644 --- a/liblttng-ust/lttng-bytecode.c +++ b/liblttng-ust/lttng-bytecode.c @@ -179,7 +179,7 @@ int apply_field_reloc(const struct lttng_ust_event_desc *event_desc, const char *field_name, enum bytecode_op bytecode_op) { - const struct lttng_ust_event_field **fields, *field = NULL; + struct lttng_ust_event_field **fields, *field = NULL; unsigned int nr_fields, i; struct load_op *op; uint32_t field_offset = 0; @@ -202,20 +202,20 @@ int apply_field_reloc(const struct lttng_ust_event_desc *event_desc, break; } /* compute field offset */ - switch (fields[i]->type.atype) { - case atype_integer: - case atype_enum_nestable: + switch (fields[i]->type->type) { + case lttng_ust_type_integer: + case lttng_ust_type_enum: field_offset += sizeof(int64_t); break; - case atype_array_nestable: - case atype_sequence_nestable: + case lttng_ust_type_array: + case lttng_ust_type_sequence: field_offset += sizeof(unsigned long); field_offset += sizeof(void *); break; - case atype_string: + case lttng_ust_type_string: field_offset += sizeof(void *); break; - case atype_float: + case lttng_ust_type_float: field_offset += sizeof(double); break; default: @@ -238,19 +238,19 @@ int apply_field_reloc(const struct lttng_ust_event_desc *event_desc, struct field_ref *field_ref; field_ref = (struct field_ref *) op->data; - switch (field->type.atype) { - case atype_integer: - case atype_enum_nestable: + switch (field->type->type) { + case lttng_ust_type_integer: + case lttng_ust_type_enum: op->op = BYTECODE_OP_LOAD_FIELD_REF_S64; break; - case atype_array_nestable: - case atype_sequence_nestable: + case lttng_ust_type_array: + case lttng_ust_type_sequence: op->op = BYTECODE_OP_LOAD_FIELD_REF_SEQUENCE; break; - case atype_string: + case lttng_ust_type_string: op->op = BYTECODE_OP_LOAD_FIELD_REF_STRING; break; - case atype_float: + case lttng_ust_type_float: op->op = BYTECODE_OP_LOAD_FIELD_REF_DOUBLE; break; default: @@ -311,21 +311,21 @@ int apply_context_reloc(struct bytecode_runtime *runtime, struct field_ref *field_ref; field_ref = (struct field_ref *) op->data; - switch (ctx_field->event_field->type.atype) { - case atype_integer: - case atype_enum_nestable: + switch (ctx_field->event_field->type->type) { + case lttng_ust_type_integer: + case lttng_ust_type_enum: op->op = BYTECODE_OP_GET_CONTEXT_REF_S64; break; /* Sequence and array supported as string */ - case atype_string: - case atype_array_nestable: - case atype_sequence_nestable: + case lttng_ust_type_string: + case lttng_ust_type_array: + case lttng_ust_type_sequence: op->op = BYTECODE_OP_GET_CONTEXT_REF_STRING; break; - case atype_float: + case lttng_ust_type_float: op->op = BYTECODE_OP_GET_CONTEXT_REF_DOUBLE; break; - case atype_dynamic: + case lttng_ust_type_dynamic: op->op = BYTECODE_OP_GET_CONTEXT_REF; break; default: @@ -396,7 +396,7 @@ int bytecode_is_linked(struct lttng_ust_bytecode_node *bytecode, * bytecode runtime. */ static -int link_bytecode(const struct lttng_ust_event_desc *event_desc, +int link_bytecode(struct lttng_ust_event_desc *event_desc, struct lttng_ust_ctx **ctx, struct lttng_ust_bytecode_node *bytecode, struct cds_list_head *bytecode_runtime_head, @@ -529,7 +529,7 @@ void lttng_bytecode_capture_sync_state(struct lttng_ust_bytecode_runtime *runtim * This function is called after we confirmed that name enabler and the * instance are name matching (or glob pattern matching). */ -void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc, +void lttng_enabler_link_bytecode(struct lttng_ust_event_desc *event_desc, struct lttng_ust_ctx **ctx, struct cds_list_head *instance_bytecode_head, struct cds_list_head *enabler_bytecode_head) diff --git a/liblttng-ust/lttng-bytecode.h b/liblttng-ust/lttng-bytecode.h index 180dfbda..04dd2520 100644 --- a/liblttng-ust/lttng-bytecode.h +++ b/liblttng-ust/lttng-bytecode.h @@ -119,7 +119,7 @@ struct bytecode_get_index_data { * interpreter needs to find it from the event fields and types to * support variants. */ - const struct lttng_ust_event_field *field; + struct lttng_ust_event_field *field; struct { size_t len; enum object_type type; @@ -131,7 +131,7 @@ struct bytecode_get_index_data { struct vstack_load { enum load_type type; enum object_type object_type; - const struct lttng_ust_event_field *field; + struct lttng_ust_event_field *field; bool rev_bo; /* reverse byte order */ }; @@ -309,7 +309,7 @@ struct lttng_interpreter_output { size_t nr_elem; /* Inner type. */ - const struct lttng_type *nested_type; + struct lttng_ust_type_common *nested_type; } sequence; } u; }; @@ -327,7 +327,7 @@ __attribute__((visibility("hidden"))) int lttng_bytecode_validate(struct bytecode_runtime *bytecode); __attribute__((visibility("hidden"))) -int lttng_bytecode_specialize(const struct lttng_ust_event_desc *event_desc, +int lttng_bytecode_specialize(struct lttng_ust_event_desc *event_desc, struct bytecode_runtime *bytecode); __attribute__((visibility("hidden"))) diff --git a/liblttng-ust/lttng-context-cgroup-ns.c b/liblttng-ust/lttng-context-cgroup-ns.c index 2ba495b3..a6741fb1 100644 --- a/liblttng-ust/lttng-context-cgroup-ns.c +++ b/liblttng-ust/lttng-context-cgroup-ns.c @@ -121,27 +121,42 @@ void cgroup_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_cgroup_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "cgroup_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("cgroup_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "cgroup_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = cgroup_ns_get_size; field->record = cgroup_ns_record; field->get_value = cgroup_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-cpu-id.c b/liblttng-ust/lttng-context-cpu-id.c index 1221bf6c..cdcfe1a1 100644 --- a/liblttng-ust/lttng-context-cpu-id.c +++ b/liblttng-ust/lttng-context-cpu-id.c @@ -55,25 +55,40 @@ void cpu_id_get_value(struct lttng_ust_ctx_field *field, int lttng_add_cpu_id_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *type; + int ret; - field = lttng_append_context(ctx); - if (!field) + type = lttng_ust_create_type_integer(sizeof(int) * CHAR_BIT, + lttng_alignof(int) * CHAR_BIT, + lttng_is_signed_type(int), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "cpu_id")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; } - field->event_field->name = "cpu_id"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(int) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(int); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->name = strdup("cpu_id"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; + } + field->event_field->type = type; field->get_size = cpu_id_get_size; field->record = cpu_id_record; field->get_value = cpu_id_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-ip.c b/liblttng-ust/lttng-context-ip.c index 20c6fef3..4b32dc39 100644 --- a/liblttng-ust/lttng-context-ip.c +++ b/liblttng-ust/lttng-context-ip.c @@ -41,24 +41,39 @@ void ip_record(struct lttng_ust_ctx_field *field, int lttng_add_ip_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *type; + int ret; - field = lttng_append_context(ctx); - if (!field) + type = lttng_ust_create_type_integer(sizeof(void *) * CHAR_BIT, + lttng_alignof(void *) * CHAR_BIT, + lttng_is_signed_type(void *), + BYTE_ORDER, 16); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "ip")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; } - field->event_field->name = "ip"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(void *) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(void *) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(void *); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 16; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->name = strdup("ip"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; + } + field->event_field->type = type; field->get_size = ip_get_size; field->record = ip_record; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-ipc-ns.c b/liblttng-ust/lttng-context-ipc-ns.c index a9d2024d..d0c4ecd6 100644 --- a/liblttng-ust/lttng-context-ipc-ns.c +++ b/liblttng-ust/lttng-context-ipc-ns.c @@ -120,27 +120,42 @@ void ipc_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_ipc_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "ipc_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("ipc_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "ipc_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = ipc_ns_get_size; field->record = ipc_ns_record; field->get_value = ipc_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-mnt-ns.c b/liblttng-ust/lttng-context-mnt-ns.c index 930bd618..3535aacb 100644 --- a/liblttng-ust/lttng-context-mnt-ns.c +++ b/liblttng-ust/lttng-context-mnt-ns.c @@ -103,25 +103,40 @@ void mnt_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_mnt_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "mnt_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("mnt_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "mnt_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = mnt_ns_get_size; field->record = mnt_ns_record; field->get_value = mnt_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-net-ns.c b/liblttng-ust/lttng-context-net-ns.c index c7022b54..415c8ac3 100644 --- a/liblttng-ust/lttng-context-net-ns.c +++ b/liblttng-ust/lttng-context-net-ns.c @@ -120,27 +120,42 @@ void net_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_net_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "net_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("net_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "net_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = net_ns_get_size; field->record = net_ns_record; field->get_value = net_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-perf-counters.c b/liblttng-ust/lttng-context-perf-counters.c index fa283324..725f4cf1 100644 --- a/liblttng-ust/lttng-context-perf-counters.c +++ b/liblttng-ust/lttng-context-perf-counters.c @@ -529,6 +529,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *ust_type; struct lttng_perf_counter_field *perf_field; char *name_alloc; int ret; @@ -543,6 +544,14 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, ret = -ENOMEM; goto perf_field_alloc_error; } + ust_type = lttng_ust_create_type_integer(sizeof(uint64_t) * CHAR_BIT, + lttng_alignof(uint64_t) * CHAR_BIT, + lttng_is_signed_type(uint64_t), + BYTE_ORDER, 10); + if (!type) { + ret = -ENOMEM; + goto type_alloc_error; + } field = lttng_append_context(ctx); if (!field) { ret = -ENOMEM; @@ -556,16 +565,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, field->destroy = lttng_destroy_perf_counter_field; field->event_field->name = name_alloc; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = - sizeof(uint64_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = - lttng_alignof(uint64_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = - lttng_is_signed_type(uint64_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = ust_type; field->get_size = perf_counter_get_size; field->record = perf_counter_record; field->get_value = perf_counter_get_value; @@ -597,6 +597,8 @@ setup_error: find_error: lttng_remove_context_field(ctx, field); append_context_error: + lttng_ust_destroy_type(ust_type); +type_alloc_error: free(perf_field); perf_field_alloc_error: free(name_alloc); diff --git a/liblttng-ust/lttng-context-pid-ns.c b/liblttng-ust/lttng-context-pid-ns.c index 4ab4246c..d5c731c8 100644 --- a/liblttng-ust/lttng-context-pid-ns.c +++ b/liblttng-ust/lttng-context-pid-ns.c @@ -106,25 +106,40 @@ void pid_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_pid_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "pid_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("pid_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "pid_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = pid_ns_get_size; field->record = pid_ns_record; field->get_value = pid_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index 9e24cb06..5e3f9f8a 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -88,30 +88,42 @@ void procname_get_value(struct lttng_ust_ctx_field *field, value->u.str = wrapper_getprocname(); } -static const struct lttng_type procname_array_elem_type = - __type_integer(char, BYTE_ORDER, 10, UTF8); - int lttng_add_procname_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *type; + int ret; - field = lttng_append_context(ctx); - if (!field) + type = lttng_ust_create_type_array_text(LTTNG_UST_ABI_PROCNAME_LEN); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "procname")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("procname"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "procname"; - field->event_field->type.atype = atype_array_nestable; - field->event_field->type.u.array_nestable.elem_type = - &procname_array_elem_type; - field->event_field->type.u.array_nestable.length = LTTNG_UST_ABI_PROCNAME_LEN; + field->event_field->type = type; field->get_size = procname_get_size; field->record = procname_record; field->get_value = procname_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-provider.c b/liblttng-ust/lttng-context-provider.c index fe67c2ee..c3f50e80 100644 --- a/liblttng-ust/lttng-context-provider.c +++ b/liblttng-ust/lttng-context-provider.c @@ -139,13 +139,17 @@ int lttng_ust_add_app_context_to_ctx_rcu(const char *name, ret = -ENOMEM; goto error_event_field_alloc; } - new_field->field_name = strdup(name); - if (!new_field->field_name) { + new_field->event_field->name = strdup(name); + if (!new_field->event_field->name) { ret = -ENOMEM; goto error_field_name_alloc; } - new_field->event_field->name = new_field->field_name; - new_field->event_field->type.atype = atype_dynamic; + new_field->event_field->type = zmalloc(sizeof(struct lttng_ust_type_common)); + if (!new_field->event_field->type) { + ret = -ENOMEM; + goto error_field_type_alloc; + } + new_field->event_field->type->type = lttng_ust_type_dynamic; /* * If provider is not found, we add the context anyway, but * it will provide a dummy context. @@ -167,13 +171,16 @@ int lttng_ust_add_app_context_to_ctx_rcu(const char *name, */ ret = lttng_context_add_rcu(ctx, new_field); if (ret) { - free(new_field->field_name); + free(new_field->event_field->type); + free((char *) new_field->event_field->name); free(new_field->event_field); free(new_field); return ret; } return 0; +error_field_type_alloc: + free((char *) new_field->event_field->name); error_field_name_alloc: free(new_field->event_field); error_event_field_alloc: diff --git a/liblttng-ust/lttng-context-pthread-id.c b/liblttng-ust/lttng-context-pthread-id.c index 162b2cf4..d113f595 100644 --- a/liblttng-ust/lttng-context-pthread-id.c +++ b/liblttng-ust/lttng-context-pthread-id.c @@ -47,25 +47,40 @@ void pthread_id_get_value(struct lttng_ust_ctx_field *field, int lttng_add_pthread_id_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *type; + int ret; - field = lttng_append_context(ctx); - if (!field) + type = lttng_ust_create_type_integer(sizeof(unsigned long) * CHAR_BIT, + lttng_alignof(unsigned long) * CHAR_BIT, + lttng_is_signed_type(unsigned long), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "pthread_id")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; } - field->event_field->name = "pthread_id"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(unsigned long) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(unsigned long) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(unsigned long); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->name = strdup("pthread_id"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; + } + field->event_field->type = type; field->get_size = pthread_id_get_size; field->record = pthread_id_record; field->get_value = pthread_id_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-time-ns.c b/liblttng-ust/lttng-context-time-ns.c index 8edc1fae..dda556c6 100644 --- a/liblttng-ust/lttng-context-time-ns.c +++ b/liblttng-ust/lttng-context-time-ns.c @@ -119,27 +119,42 @@ void time_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_time_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "time_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("time_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "time_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = time_ns_get_size; field->record = time_ns_record; field->get_value = time_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-user-ns.c b/liblttng-ust/lttng-context-user-ns.c index fccf70f2..925b77b6 100644 --- a/liblttng-ust/lttng-context-user-ns.c +++ b/liblttng-ust/lttng-context-user-ns.c @@ -103,25 +103,40 @@ void user_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_user_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "user_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("user_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "user_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = user_ns_get_size; field->record = user_ns_record; field->get_value = user_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-uts-ns.c b/liblttng-ust/lttng-context-uts-ns.c index af8aad46..55a22899 100644 --- a/liblttng-ust/lttng-context-uts-ns.c +++ b/liblttng-ust/lttng-context-uts-ns.c @@ -121,27 +121,42 @@ void uts_ns_get_value(struct lttng_ust_ctx_field *field, int lttng_add_uts_ns_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(ino_t) * CHAR_BIT, + lttng_alignof(ino_t) * CHAR_BIT, + lttng_is_signed_type(ino_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "uts_ns")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("uts_ns"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "uts_ns"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(ino_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(ino_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = uts_ns_get_size; field->record = uts_ns_record; field->get_value = uts_ns_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-vegid.c b/liblttng-ust/lttng-context-vegid.c index a7bac4e2..d1a21a6e 100644 --- a/liblttng-ust/lttng-context-vegid.c +++ b/liblttng-ust/lttng-context-vegid.c @@ -92,25 +92,40 @@ void vegid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vegid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(gid_t) * CHAR_BIT, + lttng_alignof(gid_t) * CHAR_BIT, + lttng_is_signed_type(gid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vegid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("vegid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "vegid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = vegid_get_size; field->record = vegid_record; field->get_value = vegid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-veuid.c b/liblttng-ust/lttng-context-veuid.c index e2174503..159eb420 100644 --- a/liblttng-ust/lttng-context-veuid.c +++ b/liblttng-ust/lttng-context-veuid.c @@ -92,25 +92,40 @@ void veuid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_veuid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(uid_t) * CHAR_BIT, + lttng_alignof(uid_t) * CHAR_BIT, + lttng_is_signed_type(uid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "veuid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("veuid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "veuid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = veuid_get_size; field->record = veuid_record; field->get_value = veuid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-vgid.c b/liblttng-ust/lttng-context-vgid.c index 7bc12544..5bfcd22e 100644 --- a/liblttng-ust/lttng-context-vgid.c +++ b/liblttng-ust/lttng-context-vgid.c @@ -92,25 +92,40 @@ void vgid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vgid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(gid_t) * CHAR_BIT, + lttng_alignof(gid_t) * CHAR_BIT, + lttng_is_signed_type(gid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vgid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("vgid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "vgid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = vgid_get_size; field->record = vgid_record; field->get_value = vgid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-vpid.c b/liblttng-ust/lttng-context-vpid.c index ddcfb8ad..78e1f0ce 100644 --- a/liblttng-ust/lttng-context-vpid.c +++ b/liblttng-ust/lttng-context-vpid.c @@ -75,25 +75,40 @@ void vpid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vpid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *type; + int ret; - field = lttng_append_context(ctx); - if (!field) + type = lttng_ust_create_type_integer(sizeof(pid_t) * CHAR_BIT, + lttng_alignof(pid_t) * CHAR_BIT, + lttng_is_signed_type(pid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vpid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; } - field->event_field->name = "vpid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->name = strdup("vpid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; + } + field->event_field->type = type; field->get_size = vpid_get_size; field->record = vpid_record; field->get_value = vpid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-vsgid.c b/liblttng-ust/lttng-context-vsgid.c index 0d7b0426..16a68a5c 100644 --- a/liblttng-ust/lttng-context-vsgid.c +++ b/liblttng-ust/lttng-context-vsgid.c @@ -96,25 +96,40 @@ void vsgid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vsgid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(gid_t) * CHAR_BIT, + lttng_alignof(gid_t) * CHAR_BIT, + lttng_is_signed_type(gid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vsgid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("vsgid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "vsgid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(gid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(gid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(gid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = vsgid_get_size; field->record = vsgid_record; field->get_value = vsgid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-vsuid.c b/liblttng-ust/lttng-context-vsuid.c index 0428292a..c7d08151 100644 --- a/liblttng-ust/lttng-context-vsuid.c +++ b/liblttng-ust/lttng-context-vsuid.c @@ -96,25 +96,40 @@ void vsuid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vsuid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(uid_t) * CHAR_BIT, + lttng_alignof(uid_t) * CHAR_BIT, + lttng_is_signed_type(uid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vsuid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("vsuid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "vsuid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = vsuid_get_size; field->record = vsuid_record; field->get_value = vsuid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context-vtid.c b/liblttng-ust/lttng-context-vtid.c index 9b91e57c..432b8b0d 100644 --- a/liblttng-ust/lttng-context-vtid.c +++ b/liblttng-ust/lttng-context-vtid.c @@ -79,27 +79,42 @@ void vtid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vtid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; + struct lttng_ust_type_common *type; + int ret; - field = lttng_append_context(ctx); - if (!field) + type = lttng_ust_create_type_integer(sizeof(pid_t) * CHAR_BIT, + lttng_alignof(pid_t) * CHAR_BIT, + lttng_is_signed_type(pid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vtid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; } - field->event_field->name = "vtid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(pid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(pid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->name = strdup("vtid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; + } + field->event_field->type = type; field->get_size = vtid_get_size; field->record = vtid_record; field->get_value = vtid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } /* diff --git a/liblttng-ust/lttng-context-vuid.c b/liblttng-ust/lttng-context-vuid.c index 754218d2..e6f57e71 100644 --- a/liblttng-ust/lttng-context-vuid.c +++ b/liblttng-ust/lttng-context-vuid.c @@ -92,25 +92,40 @@ void vuid_get_value(struct lttng_ust_ctx_field *field, int lttng_add_vuid_to_ctx(struct lttng_ust_ctx **ctx) { struct lttng_ust_ctx_field *field; - - field = lttng_append_context(ctx); - if (!field) + struct lttng_ust_type_common *type; + int ret; + + type = lttng_ust_create_type_integer(sizeof(uid_t) * CHAR_BIT, + lttng_alignof(uid_t) * CHAR_BIT, + lttng_is_signed_type(uid_t), + BYTE_ORDER, 10); + if (!type) return -ENOMEM; + field = lttng_append_context(ctx); + if (!field) { + ret = -ENOMEM; + goto error_context; + } if (lttng_find_context(*ctx, "vuid")) { - lttng_remove_context_field(ctx, field); - return -EEXIST; + ret = -EEXIST; + goto error_find_context; + } + field->event_field->name = strdup("vuid"); + if (!field->event_field->name) { + ret = -ENOMEM; + goto error_name; } - field->event_field->name = "vuid"; - field->event_field->type.atype = atype_integer; - field->event_field->type.u.integer.size = sizeof(uid_t) * CHAR_BIT; - field->event_field->type.u.integer.alignment = lttng_alignof(uid_t) * CHAR_BIT; - field->event_field->type.u.integer.signedness = lttng_is_signed_type(uid_t); - field->event_field->type.u.integer.reverse_byte_order = 0; - field->event_field->type.u.integer.base = 10; - field->event_field->type.u.integer.encoding = lttng_encode_none; + field->event_field->type = type; field->get_size = vuid_get_size; field->record = vuid_record; field->get_value = vuid_get_value; lttng_context_update(*ctx); return 0; + +error_name: +error_find_context: + lttng_remove_context_field(ctx, field); +error_context: + lttng_ust_destroy_type(type); + return ret; } diff --git a/liblttng-ust/lttng-context.c b/liblttng-ust/lttng-context.c index 8ed9bbd4..e97b688a 100644 --- a/liblttng-ust/lttng-context.c +++ b/liblttng-ust/lttng-context.c @@ -189,6 +189,42 @@ int lttng_context_add_rcu(struct lttng_ust_ctx **ctx_p, return 0; } +static size_t get_type_max_align(struct lttng_ust_type_common *type) +{ + switch (type->type) { + case lttng_ust_type_integer: + return lttng_ust_get_type_integer(type)->alignment; + case lttng_ust_type_string: + return CHAR_BIT; + case lttng_ust_type_dynamic: + return 0; + case lttng_ust_type_enum: + return get_type_max_align(lttng_ust_get_type_enum(type)->container_type); + case lttng_ust_type_array: + return max_t(size_t, get_type_max_align(lttng_ust_get_type_array(type)->elem_type), + lttng_ust_get_type_array(type)->alignment); + case lttng_ust_type_sequence: + return max_t(size_t, get_type_max_align(lttng_ust_get_type_sequence(type)->elem_type), + lttng_ust_get_type_sequence(type)->alignment); + case lttng_ust_type_struct: + { + unsigned int i; + size_t field_align = 0; + struct lttng_ust_type_struct *struct_type = lttng_ust_get_type_struct(type); + + for (i = 0; i < struct_type->nr_fields; i++) { + field_align = max_t(size_t, + get_type_max_align(struct_type->fields[i]->type), + field_align); + } + return field_align; + } + default: + WARN_ON_ONCE(1); + return 0; + } +} + /* * lttng_context_update() should be called at least once between context * modification and trace start. @@ -199,68 +235,9 @@ void lttng_context_update(struct lttng_ust_ctx *ctx) size_t largest_align = 8; /* in bits */ for (i = 0; i < ctx->nr_fields; i++) { - struct lttng_type *type; size_t field_align = 8; - type = &ctx->fields[i]->event_field->type; - switch (type->atype) { - case atype_integer: - field_align = type->u.integer.alignment; - break; - case atype_array_nestable: - { - const struct lttng_type *nested_type; - - nested_type = type->u.array_nestable.elem_type; - switch (nested_type->atype) { - case atype_integer: - field_align = nested_type->u.integer.alignment; - break; - case atype_string: - break; - - case atype_array_nestable: - case atype_sequence_nestable: - default: - WARN_ON_ONCE(1); - break; - } - field_align = max_t(size_t, field_align, - type->u.array_nestable.alignment); - break; - } - case atype_sequence_nestable: - { - const struct lttng_type *nested_type; - - nested_type = type->u.sequence_nestable.elem_type; - switch (nested_type->atype) { - case atype_integer: - field_align = nested_type->u.integer.alignment; - break; - - case atype_string: - break; - - case atype_array_nestable: - case atype_sequence_nestable: - default: - WARN_ON_ONCE(1); - break; - } - field_align = max_t(size_t, field_align, - type->u.sequence_nestable.alignment); - break; - } - case atype_string: - break; - case atype_dynamic: - break; - case atype_enum_nestable: - default: - WARN_ON_ONCE(1); - break; - } + field_align = get_type_max_align(ctx->fields[i]->event_field->type); largest_align = max_t(size_t, largest_align, field_align); } ctx->largest_align = largest_align >> 3; /* bits to bytes */ @@ -277,7 +254,10 @@ void lttng_remove_context_field(struct lttng_ust_ctx **ctx_p, ctx = *ctx_p; ctx->nr_fields--; assert(ctx->fields[ctx->nr_fields] == field); - assert(field->field_name == NULL); + lttng_ust_destroy_type(field->event_field->type); + free((char *) field->event_field->name); + free(field->event_field); + free(field); ctx->fields[ctx->nr_fields] = NULL; } @@ -290,7 +270,8 @@ void lttng_destroy_context(struct lttng_ust_ctx *ctx) for (i = 0; i < ctx->nr_fields; i++) { if (ctx->fields[i]->destroy) ctx->fields[i]->destroy(ctx->fields[i]); - free(ctx->fields[i]->field_name); + lttng_ust_destroy_type(ctx->fields[i]->event_field->type); + free((char *) ctx->fields[i]->event_field->name); free(ctx->fields[i]->event_field); free(ctx->fields[i]); } diff --git a/liblttng-ust/lttng-events.c b/liblttng-ust/lttng-events.c index de4d97d1..625d98af 100644 --- a/liblttng-ust/lttng-events.c +++ b/liblttng-ust/lttng-events.c @@ -250,7 +250,7 @@ static void register_event(struct lttng_ust_event_common *event) { int ret; - const struct lttng_ust_event_desc *desc; + struct lttng_ust_event_desc *desc; assert(event->priv->registered == 0); desc = event->priv->desc; @@ -266,7 +266,7 @@ static void unregister_event(struct lttng_ust_event_common *event) { int ret; - const struct lttng_ust_event_desc *desc; + struct lttng_ust_event_desc *desc; assert(event->priv->registered == 1); desc = event->priv->desc; @@ -398,7 +398,7 @@ void lttng_enabler_destroy(struct lttng_enabler *enabler) } static -int lttng_enum_create(const struct lttng_ust_enum_desc *desc, +int lttng_enum_create(struct lttng_ust_enum_desc *desc, struct lttng_ust_session *session) { const char *enum_name = desc->name; @@ -456,16 +456,16 @@ exist: } static -int lttng_create_enum_check(const struct lttng_type *type, +int lttng_create_enum_check(struct lttng_ust_type_common *type, struct lttng_ust_session *session) { - switch (type->atype) { - case atype_enum_nestable: + switch (type->type) { + case lttng_ust_type_enum: { - const struct lttng_ust_enum_desc *enum_desc; + struct lttng_ust_enum_desc *enum_desc; int ret; - enum_desc = type->u.enum_nestable.desc; + enum_desc = lttng_ust_get_type_enum(type)->desc; ret = lttng_enum_create(enum_desc, session); if (ret && ret != -EEXIST) { DBG("Unable to create enum error: (%d)", ret); @@ -473,14 +473,14 @@ int lttng_create_enum_check(const struct lttng_type *type, } break; } - case atype_dynamic: + case lttng_ust_type_dynamic: { - const struct lttng_ust_event_field *tag_field_generic; - const struct lttng_ust_enum_desc *enum_desc; + struct lttng_ust_event_field *tag_field_generic; + struct lttng_ust_enum_desc *enum_desc; int ret; tag_field_generic = lttng_ust_dynamic_type_tag_field(); - enum_desc = tag_field_generic->type.u.enum_nestable.desc; + enum_desc = lttng_ust_get_type_enum(tag_field_generic->type)->desc; ret = lttng_enum_create(enum_desc, session); if (ret && ret != -EEXIST) { DBG("Unable to create enum error: (%d)", ret); @@ -497,7 +497,7 @@ int lttng_create_enum_check(const struct lttng_type *type, static int lttng_create_all_event_enums(size_t nr_fields, - const struct lttng_ust_event_field **event_fields, + struct lttng_ust_event_field **event_fields, struct lttng_ust_session *session) { size_t i; @@ -505,7 +505,7 @@ int lttng_create_all_event_enums(size_t nr_fields, /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - const struct lttng_type *type = &event_fields[i]->type; + struct lttng_ust_type_common *type = event_fields[i]->type; ret = lttng_create_enum_check(type, session); if (ret) @@ -524,7 +524,7 @@ int lttng_create_all_ctx_enums(size_t nr_fields, /* For each field, ensure enum is part of the session. */ for (i = 0; i < nr_fields; i++) { - const struct lttng_type *type = &ctx_fields[i]->event_field->type; + struct lttng_ust_type_common *type = ctx_fields[i]->event_field->type; ret = lttng_create_enum_check(type, session); if (ret) @@ -570,7 +570,7 @@ int lttng_session_enable(struct lttng_ust_session *session) * we need to use. */ cds_list_for_each_entry(chan, &session->priv->chan_head, node) { - const struct lttng_ust_ctx *ctx; + struct lttng_ust_ctx *ctx; struct lttng_ust_ctx_field **fields = NULL; size_t nr_fields = 0; uint32_t chan_id; @@ -675,7 +675,7 @@ static inline struct cds_hlist_head *borrow_hash_table_bucket( struct cds_hlist_head *hash_table, unsigned int hash_table_size, - const struct lttng_ust_event_desc *desc) + struct lttng_ust_event_desc *desc) { const char *event_name; size_t name_len; @@ -692,7 +692,7 @@ struct cds_hlist_head *borrow_hash_table_bucket( * Supports event creation while tracing session is active. */ static -int lttng_event_recorder_create(const struct lttng_ust_event_desc *desc, +int lttng_event_recorder_create(struct lttng_ust_event_desc *desc, struct lttng_channel *chan) { struct lttng_ust_event_recorder *event_recorder; @@ -800,7 +800,7 @@ socket_error: } static -int lttng_event_notifier_create(const struct lttng_ust_event_desc *desc, +int lttng_event_notifier_create(struct lttng_ust_event_desc *desc, uint64_t token, uint64_t error_counter_index, struct lttng_event_notifier_group *event_notifier_group) { @@ -872,7 +872,7 @@ error: } static -int lttng_desc_match_star_glob_enabler(const struct lttng_ust_event_desc *desc, +int lttng_desc_match_star_glob_enabler(struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { int loglevel = 0; @@ -895,7 +895,7 @@ int lttng_desc_match_star_glob_enabler(const struct lttng_ust_event_desc *desc, } static -int lttng_desc_match_event_enabler(const struct lttng_ust_event_desc *desc, +int lttng_desc_match_event_enabler(struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { int loglevel = 0; @@ -917,7 +917,7 @@ int lttng_desc_match_event_enabler(const struct lttng_ust_event_desc *desc, } static -int lttng_desc_match_enabler(const struct lttng_ust_event_desc *desc, +int lttng_desc_match_enabler(struct lttng_ust_event_desc *desc, struct lttng_enabler *enabler) { switch (enabler->format_type) { @@ -1006,7 +1006,7 @@ void lttng_create_event_recorder_if_missing(struct lttng_event_enabler *event_en { struct lttng_ust_session *session = event_enabler->chan->session; struct lttng_ust_probe_desc *probe_desc; - const struct lttng_ust_event_desc *desc; + struct lttng_ust_event_desc *desc; struct lttng_ust_event_recorder_private *event_recorder_priv; int i; struct cds_list_head *probe_list; @@ -1073,7 +1073,7 @@ void probe_provider_event_for_each(struct lttng_ust_probe_desc *provider_desc, * sessions to queue the unregistration of the events. */ for (i = 0; i < provider_desc->nr_events; i++) { - const struct lttng_ust_event_desc *event_desc; + struct lttng_ust_event_desc *event_desc; struct lttng_event_notifier_group *event_notifier_group; struct lttng_ust_event_recorder_private *event_recorder_priv; struct lttng_ust_event_notifier_private *event_notifier_priv; @@ -1140,14 +1140,14 @@ void _event_enum_destroy(struct lttng_ust_event_common *event) /* Destroy enums of the current event. */ for (i = 0; i < event_recorder->parent->priv->desc->nr_fields; i++) { - const struct lttng_ust_enum_desc *enum_desc; - const struct lttng_ust_event_field *field; + struct lttng_ust_enum_desc *enum_desc; + struct lttng_ust_event_field *field; struct lttng_enum *curr_enum; field = event_recorder->parent->priv->desc->fields[i]; - switch (field->type.atype) { - case atype_enum_nestable: - enum_desc = field->type.u.enum_nestable.desc; + switch (field->type->type) { + case lttng_ust_type_enum: + enum_desc = lttng_ust_get_type_enum(field->type)->desc; break; default: continue; @@ -1728,7 +1728,7 @@ void lttng_create_event_notifier_if_missing( for (i = 0; i < probe_desc->nr_events; i++) { int ret; bool found = false; - const struct lttng_ust_event_desc *desc; + struct lttng_ust_event_desc *desc; struct lttng_ust_event_notifier_private *event_notifier_priv; struct cds_hlist_head *head; struct cds_hlist_node *node; diff --git a/liblttng-ust/lttng-probes.c b/liblttng-ust/lttng-probes.c index 98998b0f..00ce54cb 100644 --- a/liblttng-ust/lttng-probes.c +++ b/liblttng-ust/lttng-probes.c @@ -354,31 +354,29 @@ int lttng_probes_get_field_list(struct lttng_ust_field_list *list) event_field->name, LTTNG_UST_ABI_SYM_NAME_LEN); list_entry->field.field_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; - switch (event_field->type.atype) { - case atype_integer: + switch (event_field->type->type) { + case lttng_ust_type_integer: list_entry->field.type = LTTNG_UST_ABI_FIELD_INTEGER; break; - case atype_string: + case lttng_ust_type_string: list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING; break; - case atype_array_nestable: - if (event_field->type.u.array_nestable.elem_type->atype != atype_integer - || event_field->type.u.array_nestable.elem_type->u.integer.encoding == lttng_encode_none) + case lttng_ust_type_array: + if (lttng_ust_get_type_array(event_field->type)->encoding == lttng_ust_string_encoding_none) list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER; else list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING; break; - case atype_sequence_nestable: - if (event_field->type.u.sequence_nestable.elem_type->atype != atype_integer - || event_field->type.u.sequence_nestable.elem_type->u.integer.encoding == lttng_encode_none) + case lttng_ust_type_sequence: + if (lttng_ust_get_type_sequence(event_field->type)->encoding == lttng_ust_string_encoding_none) list_entry->field.type = LTTNG_UST_ABI_FIELD_OTHER; else list_entry->field.type = LTTNG_UST_ABI_FIELD_STRING; break; - case atype_float: + case lttng_ust_type_float: list_entry->field.type = LTTNG_UST_ABI_FIELD_FLOAT; break; - case atype_enum_nestable: + case lttng_ust_type_enum: list_entry->field.type = LTTNG_UST_ABI_FIELD_ENUM; break; default: diff --git a/liblttng-ust/lttng-ust-abi.c b/liblttng-ust/lttng-ust-abi.c index 42806129..12cb91f7 100644 --- a/liblttng-ust/lttng-ust-abi.c +++ b/liblttng-ust/lttng-ust-abi.c @@ -444,7 +444,7 @@ int lttng_abi_map_channel(int session_objd, { struct lttng_ust_session *session = objd_private(session_objd); const char *transport_name; - const struct lttng_transport *transport; + struct lttng_transport *transport; const char *chan_name; int chan_objd; struct lttng_ust_shm_handle *channel_handle; diff --git a/liblttng-ust/lttng-ust-dynamic-type.c b/liblttng-ust/lttng-ust-dynamic-type.c index ccda6475..4b58d82c 100644 --- a/liblttng-ust/lttng-ust-dynamic-type.c +++ b/liblttng-ust/lttng-ust-dynamic-type.c @@ -31,7 +31,7 @@ .string = (_string), \ }), -static const struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = { +static struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = { [LTTNG_UST_DYNAMIC_TYPE_NONE] = ctf_enum_value("_none", 0) [LTTNG_UST_DYNAMIC_TYPE_S8] = ctf_enum_value("_int8", 1) [LTTNG_UST_DYNAMIC_TYPE_S16] = ctf_enum_value("_int16", 2) @@ -46,119 +46,129 @@ static const struct lttng_ust_enum_entry *dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = [LTTNG_UST_DYNAMIC_TYPE_STRING] = ctf_enum_value("_string", 11) }; -static const struct lttng_ust_enum_desc dt_enum_desc = { +static struct lttng_ust_enum_desc dt_enum_desc = { .name = "dynamic_type_enum", .entries = dt_enum, .nr_entries = LTTNG_ARRAY_SIZE(dt_enum), }; -const struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = { +struct lttng_ust_event_field *dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = { [LTTNG_UST_DYNAMIC_TYPE_NONE] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "none", - .type = { - .atype = atype_struct_nestable, - .u.struct_nestable.nr_fields = 0, /* empty struct. */ - .u.struct_nestable.alignment = 0, - }, + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_struct, { + .parent = { + .type = lttng_ust_type_struct, + }, + .struct_size = sizeof(struct lttng_ust_type_struct), + .nr_fields = 0, /* empty struct */ + .alignment = 0, + }), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_S8] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "int8", - .type = __type_integer(int8_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(int8_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_S16] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "int16", - .type = __type_integer(int16_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(int16_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_S32] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "int32", - .type = __type_integer(int32_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(int32_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_S64] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "int64", - .type = __type_integer(int64_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(int64_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_U8] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "uint8", - .type = __type_integer(uint8_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(uint8_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_U16] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "uint16", - .type = __type_integer(uint16_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(uint16_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_U32] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "uint32", - .type = __type_integer(uint32_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(uint32_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_U64] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "uint64", - .type = __type_integer(uint64_t, BYTE_ORDER, 10, none), + .type = lttng_ust_type_integer_define(uint64_t, BYTE_ORDER, 10), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "float", - .type = __type_float(float), + .type = lttng_ust_type_float_define(float), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "double", - .type = __type_float(double), + .type = lttng_ust_type_float_define(double), .nowrite = 0, }), [LTTNG_UST_DYNAMIC_TYPE_STRING] = __LTTNG_COMPOUND_LITERAL(struct lttng_ust_event_field, { .struct_size = sizeof(struct lttng_ust_event_field), .name = "string", - .type = { - .atype = atype_string, - .u.string.encoding = lttng_encode_UTF8, - }, + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_string, { + .parent = { + .type = lttng_ust_type_string, + }, + .struct_size = sizeof(struct lttng_ust_type_string), + .encoding = lttng_ust_string_encoding_UTF8, + }), .nowrite = 0, }), }; -static const struct lttng_ust_event_field dt_enum_field = { +static struct lttng_ust_event_field dt_enum_field = { + .struct_size = sizeof(struct lttng_ust_event_field), .name = NULL, - .type.atype = atype_enum_nestable, - .type.u.enum_nestable.desc = &dt_enum_desc, - .type.u.enum_nestable.container_type = - __LTTNG_COMPOUND_LITERAL(struct lttng_type, - __type_integer(char, BYTE_ORDER, 10, none)), + .type = (struct lttng_ust_type_common *) __LTTNG_COMPOUND_LITERAL(struct lttng_ust_type_enum, { + .parent = { + .type = lttng_ust_type_enum, + }, + .struct_size = sizeof(struct lttng_ust_type_enum), + .desc = &dt_enum_desc, + .container_type = lttng_ust_type_integer_define(char, BYTE_ORDER, 10), + }), .nowrite = 0, }; -const struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value) +struct lttng_ust_event_field *lttng_ust_dynamic_type_field(int64_t value) { if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0) return NULL; return dt_var_fields[value]; } -int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_ust_event_field ***choices) +int lttng_ust_dynamic_type_choices(size_t *nr_choices, struct lttng_ust_event_field ***choices) { *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES; *choices = dt_var_fields; return 0; } -const struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void) +struct lttng_ust_event_field *lttng_ust_dynamic_type_tag_field(void) { return &dt_enum_field; } diff --git a/liblttng-ust/ust-core.c b/liblttng-ust/ust-core.c index ca44c8f0..0b1fcf0b 100644 --- a/liblttng-ust/ust-core.c +++ b/liblttng-ust/ust-core.c @@ -87,7 +87,7 @@ void lttng_counter_transport_unregister(struct lttng_counter_transport *transpor * Needed by comm layer. */ struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session, - const struct lttng_ust_enum_desc *enum_desc) + struct lttng_ust_enum_desc *enum_desc) { struct lttng_enum *_enum; struct cds_hlist_head *head; diff --git a/liblttng-ust/ust-events-internal.h b/liblttng-ust/ust-events-internal.h index 44d605c6..5466f25e 100644 --- a/liblttng-ust/ust-events-internal.h +++ b/liblttng-ust/ust-events-internal.h @@ -14,6 +14,7 @@ #include +#include #include "ust-context-provider.h" struct lttng_ust_abi_obj; @@ -244,7 +245,7 @@ struct lttng_counter_transport { struct lttng_ust_event_common_private { struct lttng_ust_event_common *pub; /* Public event interface */ - const struct lttng_ust_event_desc *desc; + struct lttng_ust_event_desc *desc; /* Backward references: list of lttng_enabler_ref (ref to enablers) */ struct cds_list_head enablers_ref_head; int registered; /* has reg'd tracepoint probe */ @@ -308,7 +309,7 @@ struct lttng_ust_session_private { }; struct lttng_enum { - const struct lttng_ust_enum_desc *desc; + struct lttng_ust_enum_desc *desc; struct lttng_ust_session *session; struct cds_list_head node; /* Enum list in session */ struct cds_hlist_node hlist; /* Session ht of enums */ @@ -341,6 +342,160 @@ struct lttng_ust_channel_ops_private { struct lttng_ust_shm_handle *handle); }; +static inline +struct lttng_ust_type_integer *lttng_ust_get_type_integer(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_integer) + return NULL; + return caa_container_of(type, struct lttng_ust_type_integer, parent); +} + +static inline +struct lttng_ust_type_float *lttng_ust_get_type_float(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_float) + return NULL; + return caa_container_of(type, struct lttng_ust_type_float, parent); +} + +static inline +struct lttng_ust_type_string *lttng_ust_get_type_string(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_string) + return NULL; + return caa_container_of(type, struct lttng_ust_type_string, parent); +} + +static inline +struct lttng_ust_type_enum *lttng_ust_get_type_enum(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_enum) + return NULL; + return caa_container_of(type, struct lttng_ust_type_enum, parent); +} + +static inline +struct lttng_ust_type_array *lttng_ust_get_type_array(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_array) + return NULL; + return caa_container_of(type, struct lttng_ust_type_array, parent); +} + +static inline +struct lttng_ust_type_sequence *lttng_ust_get_type_sequence(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_sequence) + return NULL; + return caa_container_of(type, struct lttng_ust_type_sequence, parent); +} + +static inline +struct lttng_ust_type_struct *lttng_ust_get_type_struct(struct lttng_ust_type_common *type) +{ + if (type->type != lttng_ust_type_struct) + return NULL; + return caa_container_of(type, struct lttng_ust_type_struct, parent); +} + +/* Create dynamically allocated types. */ +static inline +struct lttng_ust_type_common *lttng_ust_create_type_integer(unsigned int size, + unsigned short alignment, bool signedness, unsigned int byte_order, + unsigned int base) +{ + struct lttng_ust_type_integer *integer_type; + + integer_type = zmalloc(sizeof(struct lttng_ust_type_integer)); + if (!integer_type) + return NULL; + integer_type->parent.type = lttng_ust_type_integer; + integer_type->struct_size = sizeof(struct lttng_ust_type_integer); + integer_type->size = size; + integer_type->alignment = alignment; + integer_type->signedness = signedness; + integer_type->reverse_byte_order = byte_order != BYTE_ORDER; + integer_type->base = base; + return (struct lttng_ust_type_common *) integer_type; +} + +static inline +struct lttng_ust_type_common *lttng_ust_create_type_array_text(unsigned int length) +{ + struct lttng_ust_type_array *array_type; + + array_type = zmalloc(sizeof(struct lttng_ust_type_array)); + if (!array_type) + return NULL; + array_type->parent.type = lttng_ust_type_array; + array_type->struct_size = sizeof(struct lttng_ust_type_array); + array_type->length = length; + array_type->alignment = 0; + array_type->encoding = lttng_ust_string_encoding_UTF8; + array_type->elem_type = lttng_ust_create_type_integer(sizeof(char) * CHAR_BIT, + lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), + BYTE_ORDER, 10); + if (!array_type->elem_type) + goto error_elem; + return (struct lttng_ust_type_common *) array_type; + +error_elem: + free(array_type); + return NULL; +} + +/* + * Destroy dynamically allocated types, including nested types. + * For enumerations, it does not free the enumeration mapping description. + */ +static inline +void lttng_ust_destroy_type(struct lttng_ust_type_common *type) +{ + if (!type) + return; + + switch (type->type) { + case lttng_ust_type_integer: + case lttng_ust_type_string: + case lttng_ust_type_float: + case lttng_ust_type_dynamic: + free(type); + break; + case lttng_ust_type_enum: + { + struct lttng_ust_type_enum *enum_type = (struct lttng_ust_type_enum *) type; + + lttng_ust_destroy_type(enum_type->container_type); + break; + } + case lttng_ust_type_array: + { + struct lttng_ust_type_array *array_type = (struct lttng_ust_type_array *) type; + + lttng_ust_destroy_type(array_type->elem_type); + break; + } + case lttng_ust_type_sequence: + { + struct lttng_ust_type_sequence *sequence_type = (struct lttng_ust_type_sequence *) type; + + lttng_ust_destroy_type(sequence_type->elem_type); + break; + } + case lttng_ust_type_struct: + { + struct lttng_ust_type_struct *struct_type = (struct lttng_ust_type_struct *) type; + unsigned int i; + + for (i = 0; i < struct_type->nr_fields; i++) + lttng_ust_destroy_type(struct_type->fields[i]->type); + break; + } + default: + abort(); + } +} + static inline struct lttng_enabler *lttng_event_enabler_as_enabler( struct lttng_event_enabler *event_enabler) @@ -421,7 +576,7 @@ int lttng_event_enabler_attach_exclusion(struct lttng_event_enabler *enabler, * event_notifier enabler) to ensure each is linked to the provided instance. */ __attribute__((visibility("hidden"))) -void lttng_enabler_link_bytecode(const struct lttng_ust_event_desc *event_desc, +void lttng_enabler_link_bytecode(struct lttng_ust_event_desc *event_desc, struct lttng_ust_ctx **ctx, struct cds_list_head *instance_bytecode_runtime_head, struct cds_list_head *enabler_bytecode_runtime_head); @@ -641,7 +796,7 @@ struct cds_list_head *lttng_get_probe_list_head(void); __attribute__((visibility("hidden"))) struct lttng_enum *lttng_ust_enum_get_from_desc(struct lttng_ust_session *session, - const struct lttng_ust_enum_desc *enum_desc); + struct lttng_ust_enum_desc *enum_desc); __attribute__((visibility("hidden"))) int lttng_abi_create_root_handle(void); -- 2.34.1