Commit | Line | Data |
---|---|---|
53569322 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: LGPL-2.1-only |
53569322 MD |
3 | * |
4 | * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
c0c0989a | 6 | * UST dynamic type implementation. |
53569322 MD |
7 | */ |
8 | ||
3fbec7dc | 9 | #define _LGPL_SOURCE |
53569322 MD |
10 | #include <stdio.h> |
11 | #include <stdint.h> | |
12 | #include <stddef.h> | |
13 | #include <inttypes.h> | |
14 | ||
15 | #include <helper.h> | |
16 | #include <lttng/ust-dynamic-type.h> | |
17 | ||
a6f80644 MD |
18 | #define ctf_enum_value(_string, _value) \ |
19 | { \ | |
20 | .start = { \ | |
21 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
22 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
23 | (long long) (_value) : (_value), \ | |
24 | }, \ | |
25 | .end = { \ | |
26 | .signedness = lttng_is_signed_type(__typeof__(_value)), \ | |
27 | .value = lttng_is_signed_type(__typeof__(_value)) ? \ | |
28 | (long long) (_value) : (_value), \ | |
29 | }, \ | |
30 | .string = (_string), \ | |
53569322 | 31 | }, |
a6f80644 MD |
32 | |
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) | |
53569322 MD |
46 | }; |
47 | ||
48 | static const struct lttng_enum_desc dt_enum_desc = { | |
49 | .name = "dynamic_type_enum", | |
50 | .entries = dt_enum, | |
51 | .nr_entries = LTTNG_ARRAY_SIZE(dt_enum), | |
52 | }; | |
53 | ||
54 | const struct lttng_event_field dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = { | |
55 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = { | |
56 | .name = "none", | |
57 | .type = { | |
218deb69 MD |
58 | .atype = atype_struct_nestable, |
59 | .u.struct_nestable.nr_fields = 0, /* empty struct. */ | |
60 | .u.struct_nestable.alignment = 0, | |
53569322 MD |
61 | }, |
62 | .nowrite = 0, | |
63 | }, | |
64 | [LTTNG_UST_DYNAMIC_TYPE_S8] = { | |
65 | .name = "int8", | |
66 | .type = __type_integer(int8_t, BYTE_ORDER, 10, none), | |
67 | .nowrite = 0, | |
68 | }, | |
69 | [LTTNG_UST_DYNAMIC_TYPE_S16] = { | |
70 | .name = "int16", | |
71 | .type = __type_integer(int16_t, BYTE_ORDER, 10, none), | |
72 | .nowrite = 0, | |
73 | }, | |
74 | [LTTNG_UST_DYNAMIC_TYPE_S32] = { | |
75 | .name = "int32", | |
76 | .type = __type_integer(int32_t, BYTE_ORDER, 10, none), | |
77 | .nowrite = 0, | |
78 | }, | |
79 | [LTTNG_UST_DYNAMIC_TYPE_S64] = { | |
80 | .name = "int64", | |
81 | .type = __type_integer(int64_t, BYTE_ORDER, 10, none), | |
82 | .nowrite = 0, | |
83 | }, | |
84 | [LTTNG_UST_DYNAMIC_TYPE_U8] = { | |
85 | .name = "uint8", | |
86 | .type = __type_integer(uint8_t, BYTE_ORDER, 10, none), | |
87 | .nowrite = 0, | |
88 | }, | |
89 | [LTTNG_UST_DYNAMIC_TYPE_U16] = { | |
90 | .name = "uint16", | |
91 | .type = __type_integer(uint16_t, BYTE_ORDER, 10, none), | |
92 | .nowrite = 0, | |
93 | }, | |
94 | [LTTNG_UST_DYNAMIC_TYPE_U32] = { | |
95 | .name = "uint32", | |
96 | .type = __type_integer(uint32_t, BYTE_ORDER, 10, none), | |
97 | .nowrite = 0, | |
98 | }, | |
99 | [LTTNG_UST_DYNAMIC_TYPE_U64] = { | |
100 | .name = "uint64", | |
101 | .type = __type_integer(uint64_t, BYTE_ORDER, 10, none), | |
102 | .nowrite = 0, | |
103 | }, | |
104 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = { | |
105 | .name = "float", | |
106 | .type = __type_float(float), | |
107 | .nowrite = 0, | |
108 | }, | |
109 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = { | |
110 | .name = "double", | |
111 | .type = __type_float(double), | |
112 | .nowrite = 0, | |
113 | }, | |
114 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = { | |
115 | .name = "string", | |
116 | .type = { | |
117 | .atype = atype_string, | |
218deb69 | 118 | .u.string.encoding = lttng_encode_UTF8, |
53569322 MD |
119 | }, |
120 | .nowrite = 0, | |
121 | }, | |
122 | }; | |
123 | ||
124 | static const struct lttng_event_field dt_enum_field = { | |
125 | .name = NULL, | |
218deb69 MD |
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)), | |
53569322 MD |
131 | .nowrite = 0, |
132 | }; | |
133 | ||
134 | const struct lttng_event_field *lttng_ust_dynamic_type_field(int64_t value) | |
135 | { | |
136 | if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0) | |
137 | return NULL; | |
138 | return &dt_var_fields[value]; | |
139 | } | |
140 | ||
141 | int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_event_field **choices) | |
142 | { | |
143 | *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES; | |
144 | *choices = dt_var_fields; | |
145 | return 0; | |
146 | } | |
147 | ||
148 | const struct lttng_event_field *lttng_ust_dynamic_type_tag_field(void) | |
149 | { | |
150 | return &dt_enum_field; | |
151 | } |