Fix: convey enum value signedness into metadata
[lttng-ust.git] / liblttng-ust / lttng-ust-dynamic-type.c
1 /*
2 * lttng-ust-dynamic-type.c
3 *
4 * UST dynamic type implementation.
5 *
6 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #define _GNU_SOURCE
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <stddef.h>
27 #include <inttypes.h>
28
29 #include <helper.h>
30 #include <lttng/ust-dynamic-type.h>
31
32 #define ctf_enum_value(_string, _value) \
33 { \
34 .start = { \
35 .signedness = lttng_is_signed_type(__typeof__(_value)), \
36 .value = lttng_is_signed_type(__typeof__(_value)) ? \
37 (long long) (_value) : (_value), \
38 }, \
39 .end = { \
40 .signedness = lttng_is_signed_type(__typeof__(_value)), \
41 .value = lttng_is_signed_type(__typeof__(_value)) ? \
42 (long long) (_value) : (_value), \
43 }, \
44 .string = (_string), \
45 },
46
47 static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
48 [LTTNG_UST_DYNAMIC_TYPE_NONE] = ctf_enum_value("_none", 0)
49 [LTTNG_UST_DYNAMIC_TYPE_S8] = ctf_enum_value("_int8", 1)
50 [LTTNG_UST_DYNAMIC_TYPE_S16] = ctf_enum_value("_int16", 2)
51 [LTTNG_UST_DYNAMIC_TYPE_S32] = ctf_enum_value("_int32", 3)
52 [LTTNG_UST_DYNAMIC_TYPE_S64] = ctf_enum_value("_int64", 4)
53 [LTTNG_UST_DYNAMIC_TYPE_U8] = ctf_enum_value("_uint8", 5)
54 [LTTNG_UST_DYNAMIC_TYPE_U16] = ctf_enum_value("_uint16", 6)
55 [LTTNG_UST_DYNAMIC_TYPE_U32] = ctf_enum_value("_uint32", 7)
56 [LTTNG_UST_DYNAMIC_TYPE_U64] = ctf_enum_value("_uint64", 8)
57 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = ctf_enum_value("_float", 9)
58 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = ctf_enum_value("_double", 10)
59 [LTTNG_UST_DYNAMIC_TYPE_STRING] = ctf_enum_value("_string", 11)
60 };
61
62 static const struct lttng_enum_desc dt_enum_desc = {
63 .name = "dynamic_type_enum",
64 .entries = dt_enum,
65 .nr_entries = LTTNG_ARRAY_SIZE(dt_enum),
66 };
67
68 const struct lttng_event_field dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = {
69 [LTTNG_UST_DYNAMIC_TYPE_NONE] = {
70 .name = "none",
71 .type = {
72 .atype = atype_struct,
73 .u._struct.nr_fields = 0, /* empty struct. */
74 },
75 .nowrite = 0,
76 },
77 [LTTNG_UST_DYNAMIC_TYPE_S8] = {
78 .name = "int8",
79 .type = __type_integer(int8_t, BYTE_ORDER, 10, none),
80 .nowrite = 0,
81 },
82 [LTTNG_UST_DYNAMIC_TYPE_S16] = {
83 .name = "int16",
84 .type = __type_integer(int16_t, BYTE_ORDER, 10, none),
85 .nowrite = 0,
86 },
87 [LTTNG_UST_DYNAMIC_TYPE_S32] = {
88 .name = "int32",
89 .type = __type_integer(int32_t, BYTE_ORDER, 10, none),
90 .nowrite = 0,
91 },
92 [LTTNG_UST_DYNAMIC_TYPE_S64] = {
93 .name = "int64",
94 .type = __type_integer(int64_t, BYTE_ORDER, 10, none),
95 .nowrite = 0,
96 },
97 [LTTNG_UST_DYNAMIC_TYPE_U8] = {
98 .name = "uint8",
99 .type = __type_integer(uint8_t, BYTE_ORDER, 10, none),
100 .nowrite = 0,
101 },
102 [LTTNG_UST_DYNAMIC_TYPE_U16] = {
103 .name = "uint16",
104 .type = __type_integer(uint16_t, BYTE_ORDER, 10, none),
105 .nowrite = 0,
106 },
107 [LTTNG_UST_DYNAMIC_TYPE_U32] = {
108 .name = "uint32",
109 .type = __type_integer(uint32_t, BYTE_ORDER, 10, none),
110 .nowrite = 0,
111 },
112 [LTTNG_UST_DYNAMIC_TYPE_U64] = {
113 .name = "uint64",
114 .type = __type_integer(uint64_t, BYTE_ORDER, 10, none),
115 .nowrite = 0,
116 },
117 [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = {
118 .name = "float",
119 .type = __type_float(float),
120 .nowrite = 0,
121 },
122 [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = {
123 .name = "double",
124 .type = __type_float(double),
125 .nowrite = 0,
126 },
127 [LTTNG_UST_DYNAMIC_TYPE_STRING] = {
128 .name = "string",
129 .type = {
130 .atype = atype_string,
131 .u.basic.string.encoding = lttng_encode_UTF8,
132 },
133 .nowrite = 0,
134 },
135 };
136
137 static const struct lttng_event_field dt_enum_field = {
138 .name = NULL,
139 .type.atype = atype_enum,
140 .type.u.basic.enumeration.desc = &dt_enum_desc,
141 .type.u.basic.enumeration.container_type = {
142 .size = sizeof(char) * CHAR_BIT,
143 .alignment = lttng_alignof(char) * CHAR_BIT,
144 .signedness = lttng_is_signed_type(char),
145 .reverse_byte_order = 0,
146 .base = 10,
147 .encoding = lttng_encode_none,
148 },
149 .nowrite = 0,
150 };
151
152 const struct lttng_event_field *lttng_ust_dynamic_type_field(int64_t value)
153 {
154 if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0)
155 return NULL;
156 return &dt_var_fields[value];
157 }
158
159 int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_event_field **choices)
160 {
161 *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES;
162 *choices = dt_var_fields;
163 return 0;
164 }
165
166 const struct lttng_event_field *lttng_ust_dynamic_type_tag_field(void)
167 {
168 return &dt_enum_field;
169 }
This page took 0.035203 seconds and 5 git commands to generate.