Commit | Line | Data |
---|---|---|
ca9f27f3 FD |
1 | /* |
2 | * Babeltrace - Trace IR field copy | |
3 | * | |
4 | * Copyright (c) 2015-2019 EfficiOS Inc. and Linux Foundation | |
5 | * Copyright (c) 2018 Philippe Proulx <pproulx@efficios.com> | |
6 | * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> | |
7 | * | |
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
9 | * of this software and associated documentation files (the "Software"), to deal | |
10 | * in the Software without restriction, including without limitation the rights | |
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
12 | * copies of the Software, and to permit persons to whom the Software is | |
13 | * furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
24 | * SOFTWARE. | |
25 | */ | |
26 | ||
91bc8451 | 27 | #define BT_COMP_LOG_SELF_COMP (md_maps->self_comp) |
3a3d15f3 | 28 | #define BT_LOG_OUTPUT_LEVEL (md_maps->log_level) |
350ad6c1 | 29 | #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-FC-COPY" |
d9c39b0a | 30 | #include "logging/comp-logging.h" |
ca9f27f3 | 31 | |
578e048b MJ |
32 | #include "common/assert.h" |
33 | #include "common/common.h" | |
34 | #include "compat/compiler.h" | |
3fadfbc0 | 35 | #include <babeltrace2/babeltrace.h> |
ca9f27f3 FD |
36 | |
37 | #include "trace-ir-metadata-copy.h" | |
38 | #include "trace-ir-metadata-field-class-copy.h" | |
39 | ||
40 | /* | |
41 | * This fonction walks througth the nested structures field class to resolve a | |
42 | * field path object. A field path is made of indexes inside possibly nested | |
43 | * structures ultimately leading to a field class. | |
44 | */ | |
45 | static | |
3a3d15f3 PP |
46 | const bt_field_class *walk_field_path(struct trace_ir_metadata_maps *md_maps, |
47 | const bt_field_path *fp, const bt_field_class *fc) | |
ca9f27f3 | 48 | { |
66ddcddf | 49 | uint64_t i, fp_item_count; |
ca9f27f3 FD |
50 | const bt_field_class *curr_fc; |
51 | ||
52 | BT_ASSERT(bt_field_class_get_type(fc) == BT_FIELD_CLASS_TYPE_STRUCTURE); | |
91bc8451 | 53 | BT_COMP_LOGD("Walking field path on field class: fp-addr=%p, fc-addr=%p", |
bc463d34 | 54 | fp, fc); |
ca9f27f3 | 55 | |
66ddcddf | 56 | fp_item_count = bt_field_path_get_item_count(fp); |
ca9f27f3 | 57 | curr_fc = fc; |
66ddcddf | 58 | for (i = 0; i < fp_item_count; i++) { |
ca9f27f3 | 59 | bt_field_class_type fc_type = bt_field_class_get_type(curr_fc); |
66ddcddf PP |
60 | const bt_field_path_item *fp_item = |
61 | bt_field_path_borrow_item_by_index_const(fp, i); | |
ca9f27f3 FD |
62 | |
63 | switch (fc_type) { | |
64 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
1e6fd1d7 | 65 | { |
66ddcddf PP |
66 | const bt_field_class_structure_member *member; |
67 | ||
68 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
69 | BT_FIELD_PATH_ITEM_TYPE_INDEX); | |
70 | member = bt_field_class_structure_borrow_member_by_index_const( | |
71 | curr_fc, | |
72 | bt_field_path_item_index_get_index(fp_item)); | |
1e6fd1d7 PP |
73 | curr_fc = bt_field_class_structure_member_borrow_field_class_const( |
74 | member); | |
ca9f27f3 | 75 | break; |
1e6fd1d7 | 76 | } |
0aa006b7 PP |
77 | case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: |
78 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: | |
79 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: | |
80 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: | |
f29ef814 PP |
81 | { |
82 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
83 | BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT); | |
84 | curr_fc = bt_field_class_option_borrow_field_class_const( | |
85 | curr_fc); | |
86 | break; | |
87 | } | |
45c51519 | 88 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
fabfe034 PP |
89 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: |
90 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: | |
1e6fd1d7 | 91 | { |
66ddcddf PP |
92 | const bt_field_class_variant_option *option; |
93 | ||
94 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
95 | BT_FIELD_PATH_ITEM_TYPE_INDEX); | |
96 | option = bt_field_class_variant_borrow_option_by_index_const( | |
97 | curr_fc, | |
98 | bt_field_path_item_index_get_index(fp_item)); | |
1e6fd1d7 PP |
99 | curr_fc = bt_field_class_variant_option_borrow_field_class_const( |
100 | option); | |
ca9f27f3 | 101 | break; |
1e6fd1d7 | 102 | } |
66ddcddf | 103 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: |
81b8fa44 PP |
104 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: |
105 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: | |
66ddcddf PP |
106 | { |
107 | BT_ASSERT(bt_field_path_item_get_type(fp_item) == | |
108 | BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT); | |
109 | curr_fc = bt_field_class_array_borrow_element_field_class_const( | |
110 | curr_fc); | |
111 | break; | |
112 | } | |
ca9f27f3 FD |
113 | default: |
114 | abort(); | |
115 | } | |
116 | } | |
117 | ||
118 | return curr_fc; | |
119 | } | |
120 | ||
121 | static | |
122 | const bt_field_class *resolve_field_path_to_field_class(const bt_field_path *fp, | |
123 | struct trace_ir_metadata_maps *md_maps) | |
124 | { | |
125 | struct field_class_resolving_context *fc_resolving_ctx; | |
126 | const bt_field_class *fc; | |
e7ceb9df | 127 | bt_field_path_scope fp_scope; |
ca9f27f3 | 128 | |
91bc8451 | 129 | BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp); |
ca9f27f3 FD |
130 | |
131 | fc_resolving_ctx = md_maps->fc_resolving_ctx; | |
132 | fp_scope = bt_field_path_get_root_scope(fp); | |
133 | ||
134 | switch (fp_scope) { | |
e7ceb9df | 135 | case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT: |
3a3d15f3 PP |
136 | fc = walk_field_path(md_maps, fp, |
137 | fc_resolving_ctx->packet_context); | |
ca9f27f3 | 138 | break; |
e7ceb9df | 139 | case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT: |
3a3d15f3 PP |
140 | fc = walk_field_path(md_maps, fp, |
141 | fc_resolving_ctx->event_common_context); | |
ca9f27f3 | 142 | break; |
e7ceb9df | 143 | case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT: |
3a3d15f3 PP |
144 | fc = walk_field_path(md_maps, fp, |
145 | fc_resolving_ctx->event_specific_context); | |
ca9f27f3 | 146 | break; |
e7ceb9df | 147 | case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD: |
3a3d15f3 PP |
148 | fc = walk_field_path(md_maps, fp, |
149 | fc_resolving_ctx->event_payload); | |
ca9f27f3 FD |
150 | break; |
151 | default: | |
152 | abort(); | |
153 | } | |
154 | ||
155 | return fc; | |
156 | } | |
157 | ||
158 | static inline | |
159 | void field_class_integer_set_props(const bt_field_class *input_fc, | |
160 | bt_field_class *output_fc) | |
161 | { | |
162 | bt_field_class_integer_set_preferred_display_base(output_fc, | |
bc463d34 | 163 | bt_field_class_integer_get_preferred_display_base(input_fc)); |
ca9f27f3 | 164 | bt_field_class_integer_set_field_value_range(output_fc, |
bc463d34 | 165 | bt_field_class_integer_get_field_value_range(input_fc)); |
ca9f27f3 FD |
166 | } |
167 | ||
f7cfbcc3 | 168 | static inline |
bc463d34 | 169 | int field_class_bool_copy(struct trace_ir_metadata_maps *md_maps, |
f7cfbcc3 PP |
170 | const bt_field_class *in_field_class, |
171 | bt_field_class *out_field_class) | |
172 | { | |
173 | BT_COMP_LOGD("Copying content of boolean field class: " | |
bc463d34 FD |
174 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
175 | /* | |
176 | * There is no content to copy. Keep this function call anyway for | |
177 | * logging purposes. | |
178 | */ | |
f7cfbcc3 | 179 | BT_COMP_LOGD("Copied content of boolean field class: " |
bc463d34 | 180 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
f7cfbcc3 PP |
181 | return 0; |
182 | } | |
183 | ||
dc7ac074 PP |
184 | static inline |
185 | int field_class_bit_array_copy( | |
186 | struct trace_ir_metadata_maps *md_maps, | |
187 | const bt_field_class *in_field_class, | |
188 | bt_field_class *out_field_class) | |
189 | { | |
190 | BT_COMP_LOGD("Copying content of bit array field class: " | |
bc463d34 FD |
191 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
192 | /* | |
193 | * There is no content to copy. Keep this function call anyway for | |
194 | * logging purposes. | |
195 | */ | |
dc7ac074 | 196 | BT_COMP_LOGD("Copied content of bit array field class: " |
bc463d34 | 197 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
dc7ac074 PP |
198 | return 0; |
199 | } | |
200 | ||
ca9f27f3 FD |
201 | static inline |
202 | int field_class_unsigned_integer_copy( | |
203 | struct trace_ir_metadata_maps *md_maps, | |
204 | const bt_field_class *in_field_class, | |
205 | bt_field_class *out_field_class) | |
206 | { | |
91bc8451 | 207 | BT_COMP_LOGD("Copying content of unsigned integer field class: " |
bc463d34 | 208 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
209 | |
210 | field_class_integer_set_props(in_field_class, out_field_class); | |
211 | ||
91bc8451 | 212 | BT_COMP_LOGD("Copied content of unsigned integer field class: " |
bc463d34 | 213 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
214 | return 0; |
215 | } | |
216 | ||
217 | static inline | |
218 | int field_class_signed_integer_copy( | |
219 | struct trace_ir_metadata_maps *md_maps, | |
220 | const bt_field_class *in_field_class, | |
221 | bt_field_class *out_field_class) | |
222 | { | |
91bc8451 | 223 | BT_COMP_LOGD("Copying content of signed integer field class: " |
bc463d34 | 224 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
225 | |
226 | field_class_integer_set_props(in_field_class, out_field_class); | |
227 | ||
91bc8451 | 228 | BT_COMP_LOGD("Copied content of signed integer field class: " |
bc463d34 | 229 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
230 | return 0; |
231 | } | |
232 | ||
233 | BT_HIDDEN | |
234 | int field_class_unsigned_enumeration_copy( | |
235 | struct trace_ir_metadata_maps *md_maps, | |
236 | const bt_field_class *in_field_class, | |
237 | bt_field_class *out_field_class) | |
238 | { | |
239 | uint64_t i, enum_mapping_count; | |
240 | int ret = 0; | |
241 | ||
91bc8451 | 242 | BT_COMP_LOGD("Copying content of unsigned enumeration field class: " |
bc463d34 | 243 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
244 | |
245 | /* Copy properties of the inner integer. */ | |
246 | field_class_integer_set_props(in_field_class, out_field_class); | |
247 | ||
248 | /* Copy all enumeration entries. */ | |
bc463d34 FD |
249 | enum_mapping_count = bt_field_class_enumeration_get_mapping_count( |
250 | in_field_class); | |
ca9f27f3 FD |
251 | for (i = 0; i < enum_mapping_count; i++) { |
252 | const char *label; | |
45c51519 | 253 | const bt_integer_range_set_unsigned *range_set; |
9c08c816 | 254 | const bt_field_class_enumeration_unsigned_mapping *u_mapping; |
8f3ccfbc | 255 | const bt_field_class_enumeration_mapping *mapping; |
ca9f27f3 | 256 | |
9c08c816 | 257 | u_mapping = bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( |
bc463d34 | 258 | in_field_class, i); |
9c08c816 | 259 | mapping = bt_field_class_enumeration_unsigned_mapping_as_mapping_const( |
8f3ccfbc | 260 | u_mapping); |
45c51519 | 261 | label = bt_field_class_enumeration_mapping_get_label(mapping); |
9c08c816 | 262 | range_set = bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( |
45c51519 | 263 | u_mapping); |
9c08c816 | 264 | ret = bt_field_class_enumeration_unsigned_add_mapping( |
45c51519 PP |
265 | out_field_class, label, range_set); |
266 | if (ret) { | |
267 | goto error; | |
ca9f27f3 FD |
268 | } |
269 | } | |
270 | ||
91bc8451 | 271 | BT_COMP_LOGD("Copied content of unsigned enumeration field class: " |
bc463d34 | 272 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
273 | |
274 | error: | |
275 | return ret; | |
276 | } | |
277 | ||
278 | static inline | |
279 | int field_class_signed_enumeration_copy( | |
280 | struct trace_ir_metadata_maps *md_maps, | |
281 | const bt_field_class *in_field_class, | |
282 | bt_field_class *out_field_class) | |
283 | { | |
284 | uint64_t i, enum_mapping_count; | |
285 | int ret = 0; | |
286 | ||
91bc8451 | 287 | BT_COMP_LOGD("Copying content of signed enumeration field class: " |
bc463d34 | 288 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
289 | |
290 | /* Copy properties of the inner integer. */ | |
291 | field_class_integer_set_props(in_field_class, out_field_class); | |
292 | ||
293 | /* Copy all enumeration entries. */ | |
294 | enum_mapping_count = | |
295 | bt_field_class_enumeration_get_mapping_count(in_field_class); | |
296 | for (i = 0; i < enum_mapping_count; i++) { | |
297 | const char *label; | |
45c51519 | 298 | const bt_integer_range_set_signed *range_set; |
9c08c816 | 299 | const bt_field_class_enumeration_signed_mapping *s_mapping; |
8f3ccfbc | 300 | const bt_field_class_enumeration_mapping *mapping; |
ca9f27f3 | 301 | |
9c08c816 | 302 | s_mapping = bt_field_class_enumeration_signed_borrow_mapping_by_index_const( |
bc463d34 | 303 | in_field_class, i); |
9c08c816 | 304 | mapping = bt_field_class_enumeration_signed_mapping_as_mapping_const( |
45c51519 PP |
305 | s_mapping); |
306 | label = bt_field_class_enumeration_mapping_get_label(mapping); | |
9c08c816 | 307 | range_set = bt_field_class_enumeration_signed_mapping_borrow_ranges_const( |
45c51519 | 308 | s_mapping); |
9c08c816 | 309 | ret = bt_field_class_enumeration_signed_add_mapping( |
45c51519 PP |
310 | out_field_class, label, range_set); |
311 | if (ret) { | |
312 | goto error; | |
ca9f27f3 FD |
313 | } |
314 | } | |
315 | ||
91bc8451 | 316 | BT_COMP_LOGD("Copied content of signed enumeration field class: " |
bc463d34 | 317 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
318 | |
319 | error: | |
320 | return ret; | |
321 | } | |
322 | ||
323 | static inline | |
fe4df857 | 324 | int field_class_single_precision_real_copy( |
ca9f27f3 FD |
325 | struct trace_ir_metadata_maps *md_maps, |
326 | const bt_field_class *in_field_class, | |
327 | bt_field_class *out_field_class) | |
328 | { | |
fe4df857 FD |
329 | BT_COMP_LOGD("Copying content of single-precision real field class: " |
330 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); | |
ca9f27f3 | 331 | |
fe4df857 FD |
332 | BT_COMP_LOGD("Copied content single-precision real field class:" |
333 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); | |
ca9f27f3 | 334 | |
fe4df857 FD |
335 | return 0; |
336 | } | |
337 | ||
338 | static inline | |
339 | int field_class_double_precision_real_copy( | |
340 | struct trace_ir_metadata_maps *md_maps, | |
341 | const bt_field_class *in_field_class, | |
342 | bt_field_class *out_field_class) | |
343 | { | |
344 | BT_COMP_LOGD("Copying content of double-precision real field class: " | |
345 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); | |
346 | ||
347 | BT_COMP_LOGD("Copied content double-precision real field class:" | |
348 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); | |
ca9f27f3 FD |
349 | |
350 | return 0; | |
351 | } | |
352 | ||
353 | static inline | |
354 | int field_class_structure_copy( | |
355 | struct trace_ir_metadata_maps *md_maps, | |
356 | const bt_field_class *in_field_class, | |
357 | bt_field_class *out_field_class) | |
358 | { | |
359 | uint64_t i, struct_member_count; | |
ca9f27f3 FD |
360 | int ret = 0; |
361 | ||
91bc8451 | 362 | BT_COMP_LOGD("Copying content of structure field class: " |
bc463d34 | 363 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
364 | /* Get the number of member in that struct. */ |
365 | struct_member_count = | |
366 | bt_field_class_structure_get_member_count(in_field_class); | |
367 | ||
368 | /* Iterate over all the members of the struct. */ | |
369 | for (i = 0; i < struct_member_count; i++) { | |
ce45f74a PP |
370 | const bt_field_class_structure_member *in_member; |
371 | bt_field_class_structure_member *out_member; | |
ca9f27f3 | 372 | const char *member_name; |
ce45f74a | 373 | const bt_field_class *in_member_fc; |
ca9f27f3 FD |
374 | bt_field_class *out_member_field_class; |
375 | ||
ce45f74a | 376 | in_member = bt_field_class_structure_borrow_member_by_index_const( |
1e6fd1d7 | 377 | in_field_class, i); |
ce45f74a PP |
378 | in_member_fc = bt_field_class_structure_member_borrow_field_class_const( |
379 | in_member); | |
380 | member_name = bt_field_class_structure_member_get_name(in_member); | |
91bc8451 | 381 | BT_COMP_LOGD("Copying structure field class's field: " |
bc463d34 | 382 | "index=%" PRId64 ", member-fc-addr=%p, field-name=\"%s\"", |
ce45f74a | 383 | i, in_member_fc, member_name); |
ca9f27f3 FD |
384 | |
385 | out_member_field_class = create_field_class_copy(md_maps, | |
ce45f74a | 386 | in_member_fc); |
ca9f27f3 | 387 | if (!out_member_field_class) { |
91bc8451 | 388 | BT_COMP_LOGE("Cannot copy structure field class's field: " |
bc463d34 | 389 | "index=%" PRId64 ", field-fc-addr=%p, field-name=\"%s\"", |
ce45f74a | 390 | i, in_member_fc, member_name); |
ca9f27f3 FD |
391 | ret = -1; |
392 | goto error; | |
393 | } | |
ce45f74a | 394 | ret = copy_field_class_content(md_maps, in_member_fc, |
ca9f27f3 FD |
395 | out_member_field_class); |
396 | if (ret) { | |
397 | goto error; | |
398 | } | |
399 | ||
d24d5663 PP |
400 | if (bt_field_class_structure_append_member(out_field_class, |
401 | member_name, out_member_field_class) != | |
402 | BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { | |
91bc8451 | 403 | BT_COMP_LOGE("Cannot append structure field class's field: " |
ca9f27f3 FD |
404 | "index=%" PRId64 ", " |
405 | "field-fc-addr=%p, field-name=\"%s\"", | |
ce45f74a | 406 | i, in_member_fc, member_name); |
ca9f27f3 FD |
407 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class); |
408 | ret = -1; | |
409 | goto error; | |
410 | } | |
ce45f74a PP |
411 | |
412 | out_member = bt_field_class_structure_borrow_member_by_index( | |
413 | out_field_class, i); | |
414 | BT_ASSERT(out_member); | |
415 | ||
416 | /* | |
417 | * Safe to use the same value object because it's frozen | |
418 | * at this point. | |
419 | */ | |
420 | bt_field_class_structure_member_set_user_attributes( | |
421 | out_member, | |
422 | bt_field_class_structure_member_borrow_user_attributes_const( | |
423 | in_member)); | |
ca9f27f3 FD |
424 | } |
425 | ||
91bc8451 | 426 | BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p", |
ca9f27f3 FD |
427 | in_field_class, out_field_class); |
428 | ||
429 | error: | |
430 | return ret; | |
431 | } | |
432 | ||
433 | static inline | |
434 | int field_class_variant_copy( | |
435 | struct trace_ir_metadata_maps *md_maps, | |
436 | const bt_field_class *in_field_class, | |
437 | bt_field_class *out_field_class) | |
438 | { | |
1ec009b2 | 439 | bt_field_class *out_tag_field_class = NULL; |
ca9f27f3 | 440 | uint64_t i, variant_option_count; |
45c51519 | 441 | bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); |
ca9f27f3 FD |
442 | int ret = 0; |
443 | ||
91bc8451 | 444 | BT_COMP_LOGD("Copying content of variant field class: " |
bc463d34 | 445 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
446 | variant_option_count = |
447 | bt_field_class_variant_get_option_count(in_field_class); | |
448 | for (i = 0; i < variant_option_count; i++) { | |
ce45f74a | 449 | const bt_field_class *in_option_fc; |
ca9f27f3 FD |
450 | const char *option_name; |
451 | bt_field_class *out_option_field_class; | |
ce45f74a PP |
452 | const bt_field_class_variant_option *in_option; |
453 | bt_field_class_variant_option *out_option; | |
ca9f27f3 | 454 | |
ce45f74a | 455 | in_option = bt_field_class_variant_borrow_option_by_index_const( |
1e6fd1d7 | 456 | in_field_class, i); |
ce45f74a PP |
457 | in_option_fc = bt_field_class_variant_option_borrow_field_class_const( |
458 | in_option); | |
459 | option_name = bt_field_class_variant_option_get_name(in_option); | |
ca9f27f3 | 460 | out_option_field_class = create_field_class_copy_internal( |
ce45f74a | 461 | md_maps, in_option_fc); |
ca9f27f3 | 462 | if (!out_option_field_class) { |
91bc8451 | 463 | BT_COMP_LOGE_STR("Cannot copy field class."); |
ca9f27f3 FD |
464 | ret = -1; |
465 | goto error; | |
466 | } | |
ce45f74a | 467 | ret = copy_field_class_content_internal(md_maps, in_option_fc, |
bc463d34 | 468 | out_option_field_class); |
ca9f27f3 | 469 | if (ret) { |
91bc8451 | 470 | BT_COMP_LOGE_STR("Error copying content of option variant " |
ca9f27f3 FD |
471 | "field class'"); |
472 | goto error; | |
473 | } | |
474 | ||
fabfe034 PP |
475 | if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR) { |
476 | const bt_field_class_variant_with_selector_integer_unsigned_option *spec_opt = | |
477 | bt_field_class_variant_with_selector_integer_unsigned_borrow_option_by_index_const( | |
45c51519 PP |
478 | in_field_class, i); |
479 | const bt_integer_range_set_unsigned *ranges = | |
fabfe034 | 480 | bt_field_class_variant_with_selector_integer_unsigned_option_borrow_ranges_const( |
45c51519 PP |
481 | spec_opt); |
482 | ||
fabfe034 | 483 | if (bt_field_class_variant_with_selector_integer_unsigned_append_option( |
45c51519 PP |
484 | out_field_class, option_name, |
485 | out_option_field_class, ranges) != | |
486 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK) { | |
fabfe034 | 487 | BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned integer selector'"); |
45c51519 PP |
488 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); |
489 | ret = -1; | |
490 | goto error; | |
491 | } | |
fabfe034 PP |
492 | } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR) { |
493 | const bt_field_class_variant_with_selector_integer_signed_option *spec_opt = | |
494 | bt_field_class_variant_with_selector_integer_signed_borrow_option_by_index_const( | |
45c51519 PP |
495 | in_field_class, i); |
496 | const bt_integer_range_set_signed *ranges = | |
fabfe034 | 497 | bt_field_class_variant_with_selector_integer_signed_option_borrow_ranges_const( |
45c51519 PP |
498 | spec_opt); |
499 | ||
fabfe034 | 500 | if (bt_field_class_variant_with_selector_integer_signed_append_option( |
45c51519 PP |
501 | out_field_class, option_name, |
502 | out_option_field_class, ranges) != | |
503 | BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK) { | |
fabfe034 | 504 | BT_COMP_LOGE_STR("Cannot append option to variant field class with signed integer selector'"); |
45c51519 PP |
505 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); |
506 | ret = -1; | |
507 | goto error; | |
508 | } | |
509 | } else { | |
510 | BT_ASSERT(fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR); | |
511 | ||
512 | if (bt_field_class_variant_without_selector_append_option( | |
513 | out_field_class, option_name, | |
514 | out_option_field_class) != | |
515 | BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_APPEND_OPTION_STATUS_OK) { | |
516 | BT_COMP_LOGE_STR("Cannot append option to variant field class'"); | |
517 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); | |
518 | ret = -1; | |
519 | goto error; | |
520 | } | |
ca9f27f3 | 521 | } |
ce45f74a PP |
522 | |
523 | out_option = bt_field_class_variant_borrow_option_by_index( | |
524 | out_field_class, i); | |
525 | BT_ASSERT(out_option); | |
526 | ||
527 | /* | |
528 | * Safe to use the same value object because it's frozen | |
529 | * at this point. | |
530 | */ | |
531 | bt_field_class_variant_option_set_user_attributes( | |
532 | out_option, | |
533 | bt_field_class_variant_option_borrow_user_attributes_const( | |
534 | in_option)); | |
ca9f27f3 FD |
535 | } |
536 | ||
91bc8451 | 537 | BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, " |
ca9f27f3 FD |
538 | "out-fc-addr=%p", in_field_class, out_field_class); |
539 | ||
540 | error: | |
541 | return ret; | |
542 | } | |
543 | ||
544 | static inline | |
545 | int field_class_static_array_copy( | |
546 | struct trace_ir_metadata_maps *md_maps, | |
547 | const bt_field_class *in_field_class, | |
548 | bt_field_class *out_field_class) | |
549 | { | |
91bc8451 | 550 | BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, " |
bc463d34 | 551 | "out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
552 | /* |
553 | * There is no content to copy. Keep this function call anyway for | |
554 | * logging purposes. | |
555 | */ | |
91bc8451 | 556 | BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, " |
bc463d34 | 557 | "out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
558 | |
559 | return 0; | |
560 | } | |
561 | ||
562 | static inline | |
563 | int field_class_dynamic_array_copy( | |
564 | struct trace_ir_metadata_maps *md_maps, | |
565 | const bt_field_class *in_field_class, | |
566 | bt_field_class *out_field_class) | |
567 | { | |
91bc8451 | 568 | BT_COMP_LOGD("Copying content of dynamic array field class: " |
bc463d34 | 569 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
1367bc7c PP |
570 | /* |
571 | * There is no content to copy. Keep this function call anyway for | |
572 | * logging purposes. | |
573 | */ | |
bc463d34 FD |
574 | BT_COMP_LOGD("Copied content of dynamic array field class: " |
575 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); | |
ca9f27f3 | 576 | |
1367bc7c | 577 | return 0; |
ca9f27f3 FD |
578 | } |
579 | ||
f29ef814 PP |
580 | static inline |
581 | int field_class_option_copy( | |
582 | struct trace_ir_metadata_maps *md_maps, | |
583 | const bt_field_class *in_field_class, | |
584 | bt_field_class *out_field_class) | |
585 | { | |
586 | BT_COMP_LOGD("Copying content of option field class: " | |
bc463d34 | 587 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); |
f29ef814 | 588 | |
0aa006b7 PP |
589 | if (bt_field_class_get_type(out_field_class) == |
590 | BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) { | |
591 | bt_field_class_option_with_selector_bool_set_selector_is_reversed( | |
592 | out_field_class, | |
593 | bt_field_class_option_with_selector_bool_selector_is_reversed( | |
594 | in_field_class)); | |
595 | } | |
596 | ||
bc463d34 FD |
597 | BT_COMP_LOGD("Copied content of option field class: " |
598 | "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); | |
f29ef814 PP |
599 | |
600 | return 0; | |
601 | } | |
602 | ||
ca9f27f3 FD |
603 | static inline |
604 | int field_class_string_copy(struct trace_ir_metadata_maps *md_maps, | |
605 | const bt_field_class *in_field_class, | |
606 | bt_field_class *out_field_class) | |
607 | { | |
91bc8451 | 608 | BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, " |
bc463d34 | 609 | "out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
610 | /* |
611 | * There is no content to copy. Keep this function call anyway for | |
612 | * logging purposes. | |
613 | */ | |
91bc8451 | 614 | BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, " |
bc463d34 | 615 | "out-fc-addr=%p", in_field_class, out_field_class); |
ca9f27f3 FD |
616 | |
617 | return 0; | |
618 | } | |
619 | ||
620 | static | |
621 | bt_field_class *copy_field_class_array_element(struct trace_ir_metadata_maps *md_maps, | |
622 | const bt_field_class *in_elem_fc) | |
623 | { | |
624 | int ret; | |
625 | bt_field_class *out_elem_fc = | |
626 | create_field_class_copy_internal(md_maps, in_elem_fc); | |
627 | if (!out_elem_fc) { | |
91bc8451 | 628 | BT_COMP_LOGE("Error creating output elem field class " |
bc463d34 FD |
629 | "from input elem field class for static array: " |
630 | "in-fc-addr=%p", in_elem_fc); | |
ca9f27f3 FD |
631 | goto error; |
632 | } | |
633 | ||
634 | ret = copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc); | |
635 | if (ret) { | |
91bc8451 | 636 | BT_COMP_LOGE("Error creating output elem field class " |
bc463d34 FD |
637 | "from input elem field class for static array: " |
638 | "in-fc-addr=%p", in_elem_fc); | |
ca9f27f3 FD |
639 | BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc); |
640 | goto error; | |
641 | } | |
642 | ||
643 | error: | |
644 | return out_elem_fc; | |
645 | } | |
646 | ||
647 | BT_HIDDEN | |
648 | bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *md_maps, | |
649 | const bt_field_class *in_field_class) | |
650 | { | |
651 | bt_field_class *out_field_class = NULL; | |
45c51519 | 652 | bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); |
ca9f27f3 | 653 | |
91bc8451 | 654 | BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p", |
bc463d34 | 655 | in_field_class); |
ca9f27f3 | 656 | |
45c51519 | 657 | switch (fc_type) { |
f7cfbcc3 PP |
658 | case BT_FIELD_CLASS_TYPE_BOOL: |
659 | out_field_class = bt_field_class_bool_create( | |
bc463d34 | 660 | md_maps->output_trace_class); |
f7cfbcc3 | 661 | break; |
dc7ac074 PP |
662 | case BT_FIELD_CLASS_TYPE_BIT_ARRAY: |
663 | out_field_class = bt_field_class_bit_array_create( | |
bc463d34 FD |
664 | md_maps->output_trace_class, |
665 | bt_field_class_bit_array_get_length( | |
666 | in_field_class)); | |
dc7ac074 | 667 | break; |
ca9f27f3 | 668 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: |
9c08c816 | 669 | out_field_class = bt_field_class_integer_unsigned_create( |
bc463d34 | 670 | md_maps->output_trace_class); |
ca9f27f3 FD |
671 | break; |
672 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
9c08c816 | 673 | out_field_class = bt_field_class_integer_signed_create( |
bc463d34 | 674 | md_maps->output_trace_class); |
ca9f27f3 FD |
675 | break; |
676 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
9c08c816 | 677 | out_field_class = bt_field_class_enumeration_unsigned_create( |
bc463d34 | 678 | md_maps->output_trace_class); |
ca9f27f3 FD |
679 | break; |
680 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
9c08c816 | 681 | out_field_class = bt_field_class_enumeration_signed_create( |
bc463d34 | 682 | md_maps->output_trace_class); |
ca9f27f3 | 683 | break; |
fe4df857 FD |
684 | case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: |
685 | out_field_class = bt_field_class_real_single_precision_create( | |
bc463d34 | 686 | md_maps->output_trace_class); |
fe4df857 FD |
687 | break; |
688 | case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: | |
689 | out_field_class = bt_field_class_real_double_precision_create( | |
bc463d34 | 690 | md_maps->output_trace_class); |
ca9f27f3 FD |
691 | break; |
692 | case BT_FIELD_CLASS_TYPE_STRING: | |
693 | out_field_class = bt_field_class_string_create( | |
bc463d34 | 694 | md_maps->output_trace_class); |
ca9f27f3 FD |
695 | break; |
696 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
697 | out_field_class = bt_field_class_structure_create( | |
bc463d34 | 698 | md_maps->output_trace_class); |
ca9f27f3 FD |
699 | break; |
700 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: | |
701 | { | |
702 | const bt_field_class *in_elem_fc = | |
703 | bt_field_class_array_borrow_element_field_class_const( | |
704 | in_field_class); | |
bc463d34 FD |
705 | uint64_t array_len = bt_field_class_array_static_get_length( |
706 | in_field_class); | |
ca9f27f3 FD |
707 | |
708 | bt_field_class *out_elem_fc = copy_field_class_array_element( | |
709 | md_maps, in_elem_fc); | |
710 | if (!out_elem_fc) { | |
711 | out_field_class = NULL; | |
712 | goto error; | |
713 | } | |
714 | ||
9c08c816 | 715 | out_field_class = bt_field_class_array_static_create( |
bc463d34 FD |
716 | md_maps->output_trace_class, |
717 | out_elem_fc, array_len); | |
ca9f27f3 FD |
718 | break; |
719 | } | |
81b8fa44 PP |
720 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: |
721 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: | |
ca9f27f3 FD |
722 | { |
723 | const bt_field_class *in_elem_fc = | |
724 | bt_field_class_array_borrow_element_field_class_const( | |
725 | in_field_class); | |
1367bc7c | 726 | bt_field_class *out_length_fc = NULL; |
ca9f27f3 | 727 | bt_field_class *out_elem_fc = copy_field_class_array_element( |
1367bc7c | 728 | md_maps, in_elem_fc); |
81b8fa44 | 729 | |
ca9f27f3 FD |
730 | if (!out_elem_fc) { |
731 | out_field_class = NULL; | |
732 | goto error; | |
733 | } | |
734 | ||
81b8fa44 PP |
735 | if (fc_type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD) { |
736 | const bt_field_path *length_fp = | |
737 | bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const( | |
738 | in_field_class); | |
1367bc7c PP |
739 | const bt_field_class *in_length_fc = |
740 | resolve_field_path_to_field_class(length_fp, | |
741 | md_maps); | |
742 | ||
743 | BT_ASSERT(in_length_fc); | |
744 | out_length_fc = g_hash_table_lookup(md_maps->field_class_map, | |
745 | in_length_fc); | |
746 | BT_ASSERT(out_length_fc); | |
747 | } | |
748 | ||
9c08c816 | 749 | out_field_class = bt_field_class_array_dynamic_create( |
bc463d34 FD |
750 | md_maps->output_trace_class, |
751 | out_elem_fc, out_length_fc); | |
ca9f27f3 FD |
752 | break; |
753 | } | |
0aa006b7 PP |
754 | case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: |
755 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: | |
756 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: | |
757 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: | |
f29ef814 PP |
758 | { |
759 | const bt_field_class *in_content_fc = | |
760 | bt_field_class_option_borrow_field_class_const( | |
bc463d34 | 761 | in_field_class); |
f29ef814 PP |
762 | bt_field_class *out_selector_fc = NULL; |
763 | bt_field_class *out_content_fc; | |
764 | int ret; | |
765 | ||
766 | out_content_fc = create_field_class_copy_internal( | |
bc463d34 | 767 | md_maps, in_content_fc); |
f29ef814 PP |
768 | if (!out_content_fc) { |
769 | BT_COMP_LOGE_STR("Cannot copy option's content field class."); | |
770 | goto error; | |
771 | } | |
772 | ||
773 | ret = copy_field_class_content_internal(md_maps, | |
774 | in_content_fc, out_content_fc); | |
775 | if (ret) { | |
776 | BT_COMP_LOGE_STR("Error copying content of option's " | |
777 | "content field class"); | |
778 | goto error; | |
779 | } | |
780 | ||
0aa006b7 PP |
781 | if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR) { |
782 | out_field_class = | |
783 | bt_field_class_option_without_selector_create( | |
784 | md_maps->output_trace_class, | |
785 | out_content_fc); | |
786 | } else { | |
787 | const bt_field_path *in_selector_fp = | |
788 | bt_field_class_option_with_selector_borrow_selector_field_path_const( | |
789 | in_field_class); | |
790 | const bt_field_class *in_selector_fc; | |
f29ef814 | 791 | |
0aa006b7 PP |
792 | BT_ASSERT(in_selector_fp); |
793 | in_selector_fc = resolve_field_path_to_field_class( | |
794 | in_selector_fp, md_maps); | |
f29ef814 PP |
795 | BT_ASSERT(in_selector_fc); |
796 | out_selector_fc = g_hash_table_lookup( | |
797 | md_maps->field_class_map, in_selector_fc); | |
798 | BT_ASSERT(out_selector_fc); | |
0aa006b7 PP |
799 | |
800 | if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) { | |
801 | out_field_class = | |
802 | bt_field_class_option_with_selector_bool_create( | |
803 | md_maps->output_trace_class, | |
804 | out_content_fc, out_selector_fc); | |
805 | } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR) { | |
806 | const bt_integer_range_set_unsigned *ranges = | |
807 | bt_field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const( | |
808 | in_field_class); | |
809 | ||
810 | BT_ASSERT(ranges); | |
811 | out_field_class = | |
812 | bt_field_class_option_with_selector_integer_unsigned_create( | |
813 | md_maps->output_trace_class, | |
814 | out_content_fc, out_selector_fc, | |
815 | ranges); | |
816 | } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR) { | |
817 | const bt_integer_range_set_signed *ranges = | |
818 | bt_field_class_option_with_selector_integer_signed_borrow_selector_ranges_const( | |
819 | in_field_class); | |
820 | ||
821 | BT_ASSERT(ranges); | |
822 | out_field_class = | |
823 | bt_field_class_option_with_selector_integer_signed_create( | |
824 | md_maps->output_trace_class, | |
825 | out_content_fc, out_selector_fc, | |
826 | ranges); | |
827 | } | |
f29ef814 PP |
828 | } |
829 | ||
0aa006b7 | 830 | BT_ASSERT(out_field_class); |
f29ef814 PP |
831 | break; |
832 | } | |
45c51519 | 833 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
fabfe034 PP |
834 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: |
835 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: | |
45c51519 PP |
836 | { |
837 | bt_field_class *out_sel_fc = NULL; | |
838 | ||
fabfe034 PP |
839 | if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR || |
840 | fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR) { | |
45c51519 PP |
841 | const bt_field_class *in_sel_fc; |
842 | const bt_field_path *sel_fp = | |
843 | bt_field_class_variant_with_selector_borrow_selector_field_path_const( | |
844 | in_field_class); | |
845 | ||
846 | BT_ASSERT(sel_fp); | |
847 | in_sel_fc = resolve_field_path_to_field_class(sel_fp, | |
848 | md_maps); | |
849 | BT_ASSERT(in_sel_fc); | |
850 | out_sel_fc = g_hash_table_lookup( | |
851 | md_maps->field_class_map, in_sel_fc); | |
852 | BT_ASSERT(out_sel_fc); | |
853 | } | |
854 | ||
ca9f27f3 | 855 | out_field_class = bt_field_class_variant_create( |
45c51519 | 856 | md_maps->output_trace_class, out_sel_fc); |
ca9f27f3 | 857 | break; |
45c51519 | 858 | } |
ca9f27f3 FD |
859 | default: |
860 | abort(); | |
861 | } | |
862 | ||
863 | /* | |
864 | * Add mapping from in_field_class to out_field_class. This simplifies | |
865 | * the resolution of field paths in variant and dynamic array field | |
866 | * classes. | |
867 | */ | |
868 | g_hash_table_insert(md_maps->field_class_map, | |
bc463d34 | 869 | (gpointer) in_field_class, out_field_class); |
ca9f27f3 FD |
870 | |
871 | error: | |
872 | if(out_field_class){ | |
91bc8451 | 873 | BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, " |
ca9f27f3 FD |
874 | "out-fc-addr=%p", in_field_class, out_field_class); |
875 | } else { | |
91bc8451 | 876 | BT_COMP_LOGE("Error creating output field class from input field " |
ca9f27f3 FD |
877 | "class: in-fc-addr=%p", in_field_class); |
878 | } | |
879 | ||
880 | return out_field_class; | |
881 | } | |
882 | ||
883 | BT_HIDDEN | |
884 | int copy_field_class_content_internal( | |
885 | struct trace_ir_metadata_maps *md_maps, | |
886 | const bt_field_class *in_field_class, | |
887 | bt_field_class *out_field_class) | |
888 | { | |
889 | int ret = 0; | |
ce45f74a PP |
890 | |
891 | /* | |
892 | * Safe to use the same value object because it's frozen at this | |
893 | * point. | |
894 | */ | |
895 | bt_field_class_set_user_attributes(out_field_class, | |
896 | bt_field_class_borrow_user_attributes_const(in_field_class)); | |
897 | ||
ca9f27f3 | 898 | switch(bt_field_class_get_type(in_field_class)) { |
f7cfbcc3 PP |
899 | case BT_FIELD_CLASS_TYPE_BOOL: |
900 | ret = field_class_bool_copy(md_maps, | |
901 | in_field_class, out_field_class); | |
902 | break; | |
dc7ac074 PP |
903 | case BT_FIELD_CLASS_TYPE_BIT_ARRAY: |
904 | ret = field_class_bit_array_copy(md_maps, | |
905 | in_field_class, out_field_class); | |
906 | break; | |
ca9f27f3 FD |
907 | case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: |
908 | ret = field_class_unsigned_integer_copy(md_maps, | |
909 | in_field_class, out_field_class); | |
910 | break; | |
911 | case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: | |
912 | ret = field_class_signed_integer_copy(md_maps, | |
913 | in_field_class, out_field_class); | |
914 | break; | |
915 | case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: | |
916 | ret = field_class_unsigned_enumeration_copy(md_maps, | |
917 | in_field_class, out_field_class); | |
918 | break; | |
919 | case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: | |
920 | ret = field_class_signed_enumeration_copy(md_maps, | |
921 | in_field_class, out_field_class); | |
922 | break; | |
fe4df857 FD |
923 | case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: |
924 | ret = field_class_single_precision_real_copy(md_maps, | |
925 | in_field_class, out_field_class); | |
926 | break; | |
927 | case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: | |
928 | ret = field_class_double_precision_real_copy(md_maps, | |
ca9f27f3 FD |
929 | in_field_class, out_field_class); |
930 | break; | |
931 | case BT_FIELD_CLASS_TYPE_STRING: | |
932 | ret = field_class_string_copy(md_maps, | |
933 | in_field_class, out_field_class); | |
934 | break; | |
935 | case BT_FIELD_CLASS_TYPE_STRUCTURE: | |
936 | ret = field_class_structure_copy(md_maps, | |
937 | in_field_class, out_field_class); | |
938 | break; | |
939 | case BT_FIELD_CLASS_TYPE_STATIC_ARRAY: | |
940 | ret = field_class_static_array_copy(md_maps, | |
941 | in_field_class, out_field_class); | |
942 | break; | |
81b8fa44 PP |
943 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD: |
944 | case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD: | |
ca9f27f3 FD |
945 | ret = field_class_dynamic_array_copy(md_maps, |
946 | in_field_class, out_field_class); | |
947 | break; | |
0aa006b7 PP |
948 | case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: |
949 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: | |
950 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: | |
951 | case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: | |
f29ef814 PP |
952 | ret = field_class_option_copy(md_maps, |
953 | in_field_class, out_field_class); | |
954 | break; | |
45c51519 | 955 | case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: |
fabfe034 PP |
956 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: |
957 | case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: | |
ca9f27f3 FD |
958 | ret = field_class_variant_copy(md_maps, |
959 | in_field_class, out_field_class); | |
960 | break; | |
961 | default: | |
962 | abort(); | |
963 | } | |
964 | ||
965 | return ret; | |
966 | } |