2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * UST dynamic type implementation.
16 #include <lttng/ust-dynamic-type.h>
18 #define ctf_enum_value(_string, _value) \
21 .signedness = lttng_is_signed_type(__typeof__(_value)), \
22 .value = lttng_is_signed_type(__typeof__(_value)) ? \
23 (long long) (_value) : (_value), \
26 .signedness = lttng_is_signed_type(__typeof__(_value)), \
27 .value = lttng_is_signed_type(__typeof__(_value)) ? \
28 (long long) (_value) : (_value), \
30 .string = (_string), \
33 static const struct lttng_enum_entry dt_enum
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
34 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = ctf_enum_value("_none", 0)
35 [LTTNG_UST_DYNAMIC_TYPE_S8
] = ctf_enum_value("_int8", 1)
36 [LTTNG_UST_DYNAMIC_TYPE_S16
] = ctf_enum_value("_int16", 2)
37 [LTTNG_UST_DYNAMIC_TYPE_S32
] = ctf_enum_value("_int32", 3)
38 [LTTNG_UST_DYNAMIC_TYPE_S64
] = ctf_enum_value("_int64", 4)
39 [LTTNG_UST_DYNAMIC_TYPE_U8
] = ctf_enum_value("_uint8", 5)
40 [LTTNG_UST_DYNAMIC_TYPE_U16
] = ctf_enum_value("_uint16", 6)
41 [LTTNG_UST_DYNAMIC_TYPE_U32
] = ctf_enum_value("_uint32", 7)
42 [LTTNG_UST_DYNAMIC_TYPE_U64
] = ctf_enum_value("_uint64", 8)
43 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = ctf_enum_value("_float", 9)
44 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = ctf_enum_value("_double", 10)
45 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = ctf_enum_value("_string", 11)
48 static const struct lttng_enum_desc dt_enum_desc
= {
49 .name
= "dynamic_type_enum",
51 .nr_entries
= LTTNG_ARRAY_SIZE(dt_enum
),
54 const struct lttng_event_field dt_var_fields
[_NR_LTTNG_UST_DYNAMIC_TYPES
] = {
55 [LTTNG_UST_DYNAMIC_TYPE_NONE
] = {
58 .atype
= atype_struct_nestable
,
59 .u
.struct_nestable
.nr_fields
= 0, /* empty struct. */
60 .u
.struct_nestable
.alignment
= 0,
64 [LTTNG_UST_DYNAMIC_TYPE_S8
] = {
66 .type
= __type_integer(int8_t, BYTE_ORDER
, 10, none
),
69 [LTTNG_UST_DYNAMIC_TYPE_S16
] = {
71 .type
= __type_integer(int16_t, BYTE_ORDER
, 10, none
),
74 [LTTNG_UST_DYNAMIC_TYPE_S32
] = {
76 .type
= __type_integer(int32_t, BYTE_ORDER
, 10, none
),
79 [LTTNG_UST_DYNAMIC_TYPE_S64
] = {
81 .type
= __type_integer(int64_t, BYTE_ORDER
, 10, none
),
84 [LTTNG_UST_DYNAMIC_TYPE_U8
] = {
86 .type
= __type_integer(uint8_t, BYTE_ORDER
, 10, none
),
89 [LTTNG_UST_DYNAMIC_TYPE_U16
] = {
91 .type
= __type_integer(uint16_t, BYTE_ORDER
, 10, none
),
94 [LTTNG_UST_DYNAMIC_TYPE_U32
] = {
96 .type
= __type_integer(uint32_t, BYTE_ORDER
, 10, none
),
99 [LTTNG_UST_DYNAMIC_TYPE_U64
] = {
101 .type
= __type_integer(uint64_t, BYTE_ORDER
, 10, none
),
104 [LTTNG_UST_DYNAMIC_TYPE_FLOAT
] = {
106 .type
= __type_float(float),
109 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE
] = {
111 .type
= __type_float(double),
114 [LTTNG_UST_DYNAMIC_TYPE_STRING
] = {
117 .atype
= atype_string
,
118 .u
.string
.encoding
= lttng_encode_UTF8
,
124 static const struct lttng_event_field dt_enum_field
= {
126 .type
.atype
= atype_enum_nestable
,
127 .type
.u
.enum_nestable
.desc
= &dt_enum_desc
,
128 .type
.u
.enum_nestable
.container_type
=
129 __LTTNG_COMPOUND_LITERAL(struct lttng_type
,
130 __type_integer(char, BYTE_ORDER
, 10, none
)),
134 const struct lttng_event_field
*lttng_ust_dynamic_type_field(int64_t value
)
136 if (value
>= _NR_LTTNG_UST_DYNAMIC_TYPES
|| value
< 0)
138 return &dt_var_fields
[value
];
141 int lttng_ust_dynamic_type_choices(size_t *nr_choices
, const struct lttng_event_field
**choices
)
143 *nr_choices
= _NR_LTTNG_UST_DYNAMIC_TYPES
;
144 *choices
= dt_var_fields
;
148 const struct lttng_event_field
*lttng_ust_dynamic_type_tag_field(void)
150 return &dt_enum_field
;