2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * UST dynamic type implementation.
15 #include "common/macros.h"
16 #include "common/dynamic-type.h"
18 #define ctf_enum_value(_string, _value) \
19 LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_enum_entry, { \
20 .struct_size = sizeof(struct lttng_ust_enum_entry), \
22 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
23 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
24 (long long) (_value) : (_value), \
27 .signedness = lttng_ust_is_signed_type(__typeof__(_value)), \
28 .value = lttng_ust_is_signed_type(__typeof__(_value)) ? \
29 (long long) (_value) : (_value), \
31 .string = (_string), \
34 static const struct lttng_ust_enum_entry
*dt_enum
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
35 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = ctf_enum_value("_none", 0)
36 [LTTNG_UST_DYNAMIC_TYPE_S8
] = ctf_enum_value("_int8", 1)
37 [LTTNG_UST_DYNAMIC_TYPE_S16
] = ctf_enum_value("_int16", 2)
38 [LTTNG_UST_DYNAMIC_TYPE_S32
] = ctf_enum_value("_int32", 3)
39 [LTTNG_UST_DYNAMIC_TYPE_S64
] = ctf_enum_value("_int64", 4)
40 [LTTNG_UST_DYNAMIC_TYPE_U8
] = ctf_enum_value("_uint8", 5)
41 [LTTNG_UST_DYNAMIC_TYPE_U16
] = ctf_enum_value("_uint16", 6)
42 [LTTNG_UST_DYNAMIC_TYPE_U32
] = ctf_enum_value("_uint32", 7)
43 [LTTNG_UST_DYNAMIC_TYPE_U64
] = ctf_enum_value("_uint64", 8)
44 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = ctf_enum_value("_float", 9)
45 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = ctf_enum_value("_double", 10)
46 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = ctf_enum_value("_string", 11)
49 static struct lttng_ust_enum_desc dt_enum_desc
= {
50 .name
= "dynamic_type_enum",
52 .nr_entries
= LTTNG_ARRAY_SIZE(dt_enum
),
55 const struct lttng_ust_event_field
*dt_var_fields
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
56 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
57 .struct_size
= sizeof(struct lttng_ust_event_field
),
59 .type
= (struct lttng_ust_type_common
*) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_struct
, {
61 .type
= lttng_ust_type_struct
,
63 .struct_size
= sizeof(struct lttng_ust_type_struct
),
64 .nr_fields
= 0, /* empty struct */
69 [LTTNG_UST_DYNAMIC_TYPE_S8
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
70 .struct_size
= sizeof(struct lttng_ust_event_field
),
72 .type
= lttng_ust_type_integer_define(int8_t, BYTE_ORDER
, 10),
75 [LTTNG_UST_DYNAMIC_TYPE_S16
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
76 .struct_size
= sizeof(struct lttng_ust_event_field
),
78 .type
= lttng_ust_type_integer_define(int16_t, BYTE_ORDER
, 10),
81 [LTTNG_UST_DYNAMIC_TYPE_S32
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
82 .struct_size
= sizeof(struct lttng_ust_event_field
),
84 .type
= lttng_ust_type_integer_define(int32_t, BYTE_ORDER
, 10),
87 [LTTNG_UST_DYNAMIC_TYPE_S64
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
88 .struct_size
= sizeof(struct lttng_ust_event_field
),
90 .type
= lttng_ust_type_integer_define(int64_t, BYTE_ORDER
, 10),
93 [LTTNG_UST_DYNAMIC_TYPE_U8
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
94 .struct_size
= sizeof(struct lttng_ust_event_field
),
96 .type
= lttng_ust_type_integer_define(uint8_t, BYTE_ORDER
, 10),
99 [LTTNG_UST_DYNAMIC_TYPE_U16
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
100 .struct_size
= sizeof(struct lttng_ust_event_field
),
102 .type
= lttng_ust_type_integer_define(uint16_t, BYTE_ORDER
, 10),
105 [LTTNG_UST_DYNAMIC_TYPE_U32
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
106 .struct_size
= sizeof(struct lttng_ust_event_field
),
108 .type
= lttng_ust_type_integer_define(uint32_t, BYTE_ORDER
, 10),
111 [LTTNG_UST_DYNAMIC_TYPE_U64
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
112 .struct_size
= sizeof(struct lttng_ust_event_field
),
114 .type
= lttng_ust_type_integer_define(uint64_t, BYTE_ORDER
, 10),
117 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
118 .struct_size
= sizeof(struct lttng_ust_event_field
),
120 .type
= lttng_ust_type_float_define(float),
123 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
124 .struct_size
= sizeof(struct lttng_ust_event_field
),
126 .type
= lttng_ust_type_float_define(double),
129 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = LTTNG_UST_COMPOUND_LITERAL(const struct lttng_ust_event_field
, {
130 .struct_size
= sizeof(struct lttng_ust_event_field
),
132 .type
= (struct lttng_ust_type_common
*) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_string
, {
134 .type
= lttng_ust_type_string
,
136 .struct_size
= sizeof(struct lttng_ust_type_string
),
137 .encoding
= lttng_ust_string_encoding_UTF8
,
143 static const struct lttng_ust_event_field dt_enum_field
= {
144 .struct_size
= sizeof(struct lttng_ust_event_field
),
146 .type
= (struct lttng_ust_type_common
*) LTTNG_UST_COMPOUND_LITERAL(struct lttng_ust_type_enum
, {
148 .type
= lttng_ust_type_enum
,
150 .struct_size
= sizeof(struct lttng_ust_type_enum
),
151 .desc
= &dt_enum_desc
,
152 .container_type
= lttng_ust_type_integer_define(char, BYTE_ORDER
, 10),
157 const struct lttng_ust_event_field
*lttng_ust_dynamic_type_field(int64_t value
)
159 if (value
>= _NR_LTTNG_UST_DYNAMIC_TYPES
|| value
< 0)
161 return dt_var_fields
[value
];
164 int lttng_ust_dynamic_type_choices(size_t *nr_choices
, const struct lttng_ust_event_field
* const **choices
)
166 *nr_choices
= _NR_LTTNG_UST_DYNAMIC_TYPES
;
167 *choices
= dt_var_fields
;
171 const struct lttng_ust_event_field
*lttng_ust_dynamic_type_tag_field(void)
173 return &dt_enum_field
;