| 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 | static const struct lttng_enum_entry dt_enum[_NR_LTTNG_UST_DYNAMIC_TYPES] = { |
| 33 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = { |
| 34 | .start = 0, |
| 35 | .end = 0, |
| 36 | .string = "_none", |
| 37 | }, |
| 38 | [LTTNG_UST_DYNAMIC_TYPE_S8] = { |
| 39 | .start = 1, |
| 40 | .end = 1, |
| 41 | .string = "_int8", |
| 42 | }, |
| 43 | [LTTNG_UST_DYNAMIC_TYPE_S16] = { |
| 44 | .start = 2, |
| 45 | .end = 2, |
| 46 | .string = "_int16", |
| 47 | }, |
| 48 | [LTTNG_UST_DYNAMIC_TYPE_S32] = { |
| 49 | .start = 3, |
| 50 | .end = 3, |
| 51 | .string = "_int32", |
| 52 | }, |
| 53 | [LTTNG_UST_DYNAMIC_TYPE_S64] = { |
| 54 | .start = 4, |
| 55 | .end = 4, |
| 56 | .string = "_int64", |
| 57 | }, |
| 58 | [LTTNG_UST_DYNAMIC_TYPE_U8] = { |
| 59 | .start = 5, |
| 60 | .end = 5, |
| 61 | .string = "_uint8", |
| 62 | }, |
| 63 | [LTTNG_UST_DYNAMIC_TYPE_U16] = { |
| 64 | .start = 6, |
| 65 | .end = 6, |
| 66 | .string = "_uint16", |
| 67 | }, |
| 68 | [LTTNG_UST_DYNAMIC_TYPE_U32] = { |
| 69 | .start = 7, |
| 70 | .end = 7, |
| 71 | .string = "_uint32", |
| 72 | }, |
| 73 | [LTTNG_UST_DYNAMIC_TYPE_U64] = { |
| 74 | .start = 8, |
| 75 | .end = 8, |
| 76 | .string = "_uint64", |
| 77 | }, |
| 78 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = { |
| 79 | .start = 9, |
| 80 | .end = 9, |
| 81 | .string = "_float", |
| 82 | }, |
| 83 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = { |
| 84 | .start = 10, |
| 85 | .end = 10, |
| 86 | .string = "_double", |
| 87 | }, |
| 88 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = { |
| 89 | .start = 11, |
| 90 | .end = 11, |
| 91 | .string = "_string", |
| 92 | }, |
| 93 | }; |
| 94 | |
| 95 | static const struct lttng_enum_desc dt_enum_desc = { |
| 96 | .name = "dynamic_type_enum", |
| 97 | .entries = dt_enum, |
| 98 | .nr_entries = LTTNG_ARRAY_SIZE(dt_enum), |
| 99 | }; |
| 100 | |
| 101 | const struct lttng_event_field dt_var_fields[_NR_LTTNG_UST_DYNAMIC_TYPES] = { |
| 102 | [LTTNG_UST_DYNAMIC_TYPE_NONE] = { |
| 103 | .name = "none", |
| 104 | .type = { |
| 105 | .atype = atype_struct, |
| 106 | .u._struct.nr_fields = 0, /* empty struct. */ |
| 107 | }, |
| 108 | .nowrite = 0, |
| 109 | }, |
| 110 | [LTTNG_UST_DYNAMIC_TYPE_S8] = { |
| 111 | .name = "int8", |
| 112 | .type = __type_integer(int8_t, BYTE_ORDER, 10, none), |
| 113 | .nowrite = 0, |
| 114 | }, |
| 115 | [LTTNG_UST_DYNAMIC_TYPE_S16] = { |
| 116 | .name = "int16", |
| 117 | .type = __type_integer(int16_t, BYTE_ORDER, 10, none), |
| 118 | .nowrite = 0, |
| 119 | }, |
| 120 | [LTTNG_UST_DYNAMIC_TYPE_S32] = { |
| 121 | .name = "int32", |
| 122 | .type = __type_integer(int32_t, BYTE_ORDER, 10, none), |
| 123 | .nowrite = 0, |
| 124 | }, |
| 125 | [LTTNG_UST_DYNAMIC_TYPE_S64] = { |
| 126 | .name = "int64", |
| 127 | .type = __type_integer(int64_t, BYTE_ORDER, 10, none), |
| 128 | .nowrite = 0, |
| 129 | }, |
| 130 | [LTTNG_UST_DYNAMIC_TYPE_U8] = { |
| 131 | .name = "uint8", |
| 132 | .type = __type_integer(uint8_t, BYTE_ORDER, 10, none), |
| 133 | .nowrite = 0, |
| 134 | }, |
| 135 | [LTTNG_UST_DYNAMIC_TYPE_U16] = { |
| 136 | .name = "uint16", |
| 137 | .type = __type_integer(uint16_t, BYTE_ORDER, 10, none), |
| 138 | .nowrite = 0, |
| 139 | }, |
| 140 | [LTTNG_UST_DYNAMIC_TYPE_U32] = { |
| 141 | .name = "uint32", |
| 142 | .type = __type_integer(uint32_t, BYTE_ORDER, 10, none), |
| 143 | .nowrite = 0, |
| 144 | }, |
| 145 | [LTTNG_UST_DYNAMIC_TYPE_U64] = { |
| 146 | .name = "uint64", |
| 147 | .type = __type_integer(uint64_t, BYTE_ORDER, 10, none), |
| 148 | .nowrite = 0, |
| 149 | }, |
| 150 | [LTTNG_UST_DYNAMIC_TYPE_FLOAT] = { |
| 151 | .name = "float", |
| 152 | .type = __type_float(float), |
| 153 | .nowrite = 0, |
| 154 | }, |
| 155 | [LTTNG_UST_DYNAMIC_TYPE_DOUBLE] = { |
| 156 | .name = "double", |
| 157 | .type = __type_float(double), |
| 158 | .nowrite = 0, |
| 159 | }, |
| 160 | [LTTNG_UST_DYNAMIC_TYPE_STRING] = { |
| 161 | .name = "string", |
| 162 | .type = { |
| 163 | .atype = atype_string, |
| 164 | .u.basic.string.encoding = lttng_encode_UTF8, |
| 165 | }, |
| 166 | .nowrite = 0, |
| 167 | }, |
| 168 | }; |
| 169 | |
| 170 | static const struct lttng_event_field dt_enum_field = { |
| 171 | .name = NULL, |
| 172 | .type.atype = atype_enum, |
| 173 | .type.u.basic.enumeration.desc = &dt_enum_desc, |
| 174 | .type.u.basic.enumeration.container_type = { |
| 175 | .size = sizeof(char) * CHAR_BIT, |
| 176 | .alignment = lttng_alignof(char) * CHAR_BIT, |
| 177 | .signedness = lttng_is_signed_type(char), |
| 178 | .reverse_byte_order = 0, |
| 179 | .base = 10, |
| 180 | .encoding = lttng_encode_none, |
| 181 | }, |
| 182 | .nowrite = 0, |
| 183 | }; |
| 184 | |
| 185 | const struct lttng_event_field *lttng_ust_dynamic_type_field(int64_t value) |
| 186 | { |
| 187 | if (value >= _NR_LTTNG_UST_DYNAMIC_TYPES || value < 0) |
| 188 | return NULL; |
| 189 | return &dt_var_fields[value]; |
| 190 | } |
| 191 | |
| 192 | int lttng_ust_dynamic_type_choices(size_t *nr_choices, const struct lttng_event_field **choices) |
| 193 | { |
| 194 | *nr_choices = _NR_LTTNG_UST_DYNAMIC_TYPES; |
| 195 | *choices = dt_var_fields; |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | const struct lttng_event_field *lttng_ust_dynamic_type_tag_field(void) |
| 200 | { |
| 201 | return &dt_enum_field; |
| 202 | } |