2 * lttng-ust-dynamic-type.c
4 * UST dynamic type implementation.
6 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <lttng/ust-dynamic-type.h>
33 #define ctf_enum_value(_string, _value) \
36 .signedness = lttng_is_signed_type(__typeof__(_value)), \
37 .value = lttng_is_signed_type(__typeof__(_value)) ? \
38 (long long) (_value) : (_value), \
41 .signedness = lttng_is_signed_type(__typeof__(_value)), \
42 .value = lttng_is_signed_type(__typeof__(_value)) ? \
43 (long long) (_value) : (_value), \
45 .string = (_string), \
48 static const struct lttng_enum_entry dt_enum
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
49 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = ctf_enum_value("_none", 0)
50 [LTTNG_UST_DYNAMIC_TYPE_S8
] = ctf_enum_value("_int8", 1)
51 [LTTNG_UST_DYNAMIC_TYPE_S16
] = ctf_enum_value("_int16", 2)
52 [LTTNG_UST_DYNAMIC_TYPE_S32
] = ctf_enum_value("_int32", 3)
53 [LTTNG_UST_DYNAMIC_TYPE_S64
] = ctf_enum_value("_int64", 4)
54 [LTTNG_UST_DYNAMIC_TYPE_U8
] = ctf_enum_value("_uint8", 5)
55 [LTTNG_UST_DYNAMIC_TYPE_U16
] = ctf_enum_value("_uint16", 6)
56 [LTTNG_UST_DYNAMIC_TYPE_U32
] = ctf_enum_value("_uint32", 7)
57 [LTTNG_UST_DYNAMIC_TYPE_U64
] = ctf_enum_value("_uint64", 8)
58 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = ctf_enum_value("_float", 9)
59 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = ctf_enum_value("_double", 10)
60 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = ctf_enum_value("_string", 11)
63 static const struct lttng_enum_desc dt_enum_desc
= {
64 .name
= "dynamic_type_enum",
66 .nr_entries
= LTTNG_ARRAY_SIZE(dt_enum
),
69 const struct lttng_event_field dt_var_fields
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
70 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = {
73 .atype
= atype_struct
,
74 .u
._struct
.nr_fields
= 0, /* empty struct. */
78 [LTTNG_UST_DYNAMIC_TYPE_S8
] = {
80 .type
= __type_integer(int8_t, BYTE_ORDER
, 10, none
),
83 [LTTNG_UST_DYNAMIC_TYPE_S16
] = {
85 .type
= __type_integer(int16_t, BYTE_ORDER
, 10, none
),
88 [LTTNG_UST_DYNAMIC_TYPE_S32
] = {
90 .type
= __type_integer(int32_t, BYTE_ORDER
, 10, none
),
93 [LTTNG_UST_DYNAMIC_TYPE_S64
] = {
95 .type
= __type_integer(int64_t, BYTE_ORDER
, 10, none
),
98 [LTTNG_UST_DYNAMIC_TYPE_U8
] = {
100 .type
= __type_integer(uint8_t, BYTE_ORDER
, 10, none
),
103 [LTTNG_UST_DYNAMIC_TYPE_U16
] = {
105 .type
= __type_integer(uint16_t, BYTE_ORDER
, 10, none
),
108 [LTTNG_UST_DYNAMIC_TYPE_U32
] = {
110 .type
= __type_integer(uint32_t, BYTE_ORDER
, 10, none
),
113 [LTTNG_UST_DYNAMIC_TYPE_U64
] = {
115 .type
= __type_integer(uint64_t, BYTE_ORDER
, 10, none
),
118 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = {
120 .type
= __type_float(float),
123 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = {
125 .type
= __type_float(double),
128 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = {
131 .atype
= atype_string
,
132 .u
.basic
.string
.encoding
= lttng_encode_UTF8
,
138 static const struct lttng_event_field dt_enum_field
= {
140 .type
.atype
= atype_enum
,
141 .type
.u
.basic
.enumeration
.desc
= &dt_enum_desc
,
142 .type
.u
.basic
.enumeration
.container_type
= {
143 .size
= sizeof(char) * CHAR_BIT
,
144 .alignment
= lttng_alignof(char) * CHAR_BIT
,
145 .signedness
= lttng_is_signed_type(char),
146 .reverse_byte_order
= 0,
148 .encoding
= lttng_encode_none
,
153 const struct lttng_event_field
*lttng_ust_dynamic_type_field(int64_t value
)
155 if (value
>= _NR_LTTNG_UST_DYNAMIC_TYPES
|| value
< 0)
157 return &dt_var_fields
[value
];
160 int lttng_ust_dynamic_type_choices(size_t *nr_choices
, const struct lttng_event_field
**choices
)
162 *nr_choices
= _NR_LTTNG_UST_DYNAMIC_TYPES
;
163 *choices
= dt_var_fields
;
167 const struct lttng_event_field
*lttng_ust_dynamic_type_tag_field(void)
169 return &dt_enum_field
;