2 * Babeltrace - Trace IR field copy
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>
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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
27 #define BT_COMP_LOG_SELF_COMP (md_maps->self_comp)
28 #define BT_LOG_OUTPUT_LEVEL (md_maps->log_level)
29 #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-FC-COPY"
30 #include "logging/comp-logging.h"
32 #include "common/assert.h"
33 #include "common/common.h"
34 #include "compat/compiler.h"
35 #include <babeltrace2/babeltrace.h>
37 #include "trace-ir-metadata-copy.h"
38 #include "trace-ir-metadata-field-class-copy.h"
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.
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
)
49 uint64_t i
, fp_item_count
;
50 const bt_field_class
*curr_fc
;
52 BT_ASSERT(bt_field_class_get_type(fc
) == BT_FIELD_CLASS_TYPE_STRUCTURE
);
53 BT_COMP_LOGD("Walking field path on field class: fp-addr=%p, fc-addr=%p",
56 fp_item_count
= bt_field_path_get_item_count(fp
);
58 for (i
= 0; i
< fp_item_count
; i
++) {
59 bt_field_class_type fc_type
= bt_field_class_get_type(curr_fc
);
60 const bt_field_path_item
*fp_item
=
61 bt_field_path_borrow_item_by_index_const(fp
, i
);
64 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
66 const bt_field_class_structure_member
*member
;
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(
72 bt_field_path_item_index_get_index(fp_item
));
73 curr_fc
= bt_field_class_structure_member_borrow_field_class_const(
77 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
78 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
79 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
80 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
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(
88 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
89 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
90 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
92 const bt_field_class_variant_option
*option
;
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(
98 bt_field_path_item_index_get_index(fp_item
));
99 curr_fc
= bt_field_class_variant_option_borrow_field_class_const(
103 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
104 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
105 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
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(
122 const bt_field_class
*resolve_field_path_to_field_class(const bt_field_path
*fp
,
123 struct trace_ir_metadata_maps
*md_maps
)
125 struct field_class_resolving_context
*fc_resolving_ctx
;
126 const bt_field_class
*fc
;
127 bt_field_path_scope fp_scope
;
129 BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp
);
131 fc_resolving_ctx
= md_maps
->fc_resolving_ctx
;
132 fp_scope
= bt_field_path_get_root_scope(fp
);
135 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
136 fc
= walk_field_path(md_maps
, fp
,
137 fc_resolving_ctx
->packet_context
);
139 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
140 fc
= walk_field_path(md_maps
, fp
,
141 fc_resolving_ctx
->event_common_context
);
143 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
144 fc
= walk_field_path(md_maps
, fp
,
145 fc_resolving_ctx
->event_specific_context
);
147 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
148 fc
= walk_field_path(md_maps
, fp
,
149 fc_resolving_ctx
->event_payload
);
159 void field_class_integer_set_props(const bt_field_class
*input_fc
,
160 bt_field_class
*output_fc
)
162 bt_field_class_integer_set_preferred_display_base(output_fc
,
163 bt_field_class_integer_get_preferred_display_base(input_fc
));
164 bt_field_class_integer_set_field_value_range(output_fc
,
165 bt_field_class_integer_get_field_value_range(input_fc
));
169 int field_class_bool_copy(struct trace_ir_metadata_maps
*md_maps
,
170 const bt_field_class
*in_field_class
,
171 bt_field_class
*out_field_class
)
173 BT_COMP_LOGD("Copying content of boolean field class: "
174 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
176 * There is no content to copy. Keep this function call anyway for
179 BT_COMP_LOGD("Copied content of boolean field class: "
180 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
190 BT_COMP_LOGD("Copying content of bit array field class: "
191 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
193 * There is no content to copy. Keep this function call anyway for
196 BT_COMP_LOGD("Copied content of bit array field class: "
197 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
207 BT_COMP_LOGD("Copying content of unsigned integer field class: "
208 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
210 field_class_integer_set_props(in_field_class
, out_field_class
);
212 BT_COMP_LOGD("Copied content of unsigned integer field class: "
213 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
223 BT_COMP_LOGD("Copying content of signed integer field class: "
224 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
226 field_class_integer_set_props(in_field_class
, out_field_class
);
228 BT_COMP_LOGD("Copied content of signed integer field class: "
229 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
239 uint64_t i
, enum_mapping_count
;
242 BT_COMP_LOGD("Copying content of unsigned enumeration field class: "
243 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
245 /* Copy properties of the inner integer. */
246 field_class_integer_set_props(in_field_class
, out_field_class
);
248 /* Copy all enumeration entries. */
249 enum_mapping_count
= bt_field_class_enumeration_get_mapping_count(
251 for (i
= 0; i
< enum_mapping_count
; i
++) {
253 const bt_integer_range_set_unsigned
*range_set
;
254 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
255 const bt_field_class_enumeration_mapping
*mapping
;
257 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
259 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
261 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
262 range_set
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
264 ret
= bt_field_class_enumeration_unsigned_add_mapping(
265 out_field_class
, label
, range_set
);
271 BT_COMP_LOGD("Copied content of unsigned enumeration field class: "
272 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
284 uint64_t i
, enum_mapping_count
;
287 BT_COMP_LOGD("Copying content of signed enumeration field class: "
288 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
290 /* Copy properties of the inner integer. */
291 field_class_integer_set_props(in_field_class
, out_field_class
);
293 /* Copy all enumeration entries. */
295 bt_field_class_enumeration_get_mapping_count(in_field_class
);
296 for (i
= 0; i
< enum_mapping_count
; i
++) {
298 const bt_integer_range_set_signed
*range_set
;
299 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
300 const bt_field_class_enumeration_mapping
*mapping
;
302 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
304 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
306 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
307 range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
309 ret
= bt_field_class_enumeration_signed_add_mapping(
310 out_field_class
, label
, range_set
);
316 BT_COMP_LOGD("Copied content of signed enumeration field class: "
317 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
324 int field_class_single_precision_real_copy(
325 struct trace_ir_metadata_maps
*md_maps
,
326 const bt_field_class
*in_field_class
,
327 bt_field_class
*out_field_class
)
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
);
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
);
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
)
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
);
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
);
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
)
359 uint64_t i
, struct_member_count
;
362 BT_COMP_LOGD("Copying content of structure field class: "
363 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
364 /* Get the number of member in that struct. */
365 struct_member_count
=
366 bt_field_class_structure_get_member_count(in_field_class
);
368 /* Iterate over all the members of the struct. */
369 for (i
= 0; i
< struct_member_count
; i
++) {
370 const bt_field_class_structure_member
*in_member
;
371 bt_field_class_structure_member
*out_member
;
372 const char *member_name
;
373 const bt_field_class
*in_member_fc
;
374 bt_field_class
*out_member_field_class
;
376 in_member
= bt_field_class_structure_borrow_member_by_index_const(
378 in_member_fc
= bt_field_class_structure_member_borrow_field_class_const(
380 member_name
= bt_field_class_structure_member_get_name(in_member
);
381 BT_COMP_LOGD("Copying structure field class's field: "
382 "index=%" PRId64
", member-fc-addr=%p, field-name=\"%s\"",
383 i
, in_member_fc
, member_name
);
385 out_member_field_class
= create_field_class_copy(md_maps
,
387 if (!out_member_field_class
) {
388 BT_COMP_LOGE("Cannot copy structure field class's field: "
389 "index=%" PRId64
", field-fc-addr=%p, field-name=\"%s\"",
390 i
, in_member_fc
, member_name
);
394 ret
= copy_field_class_content(md_maps
, in_member_fc
,
395 out_member_field_class
);
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
) {
403 BT_COMP_LOGE("Cannot append structure field class's field: "
404 "index=%" PRId64
", "
405 "field-fc-addr=%p, field-name=\"%s\"",
406 i
, in_member_fc
, member_name
);
407 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class
);
412 out_member
= bt_field_class_structure_borrow_member_by_index(
414 BT_ASSERT(out_member
);
417 * Safe to use the same value object because it's frozen
420 bt_field_class_structure_member_set_user_attributes(
422 bt_field_class_structure_member_borrow_user_attributes_const(
426 BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
427 in_field_class
, out_field_class
);
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
)
439 bt_field_class
*out_tag_field_class
= NULL
;
440 uint64_t i
, variant_option_count
;
441 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
444 BT_COMP_LOGD("Copying content of variant field class: "
445 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
446 variant_option_count
=
447 bt_field_class_variant_get_option_count(in_field_class
);
448 for (i
= 0; i
< variant_option_count
; i
++) {
449 const bt_field_class
*in_option_fc
;
450 const char *option_name
;
451 bt_field_class
*out_option_field_class
;
452 const bt_field_class_variant_option
*in_option
;
453 bt_field_class_variant_option
*out_option
;
455 in_option
= bt_field_class_variant_borrow_option_by_index_const(
457 in_option_fc
= bt_field_class_variant_option_borrow_field_class_const(
459 option_name
= bt_field_class_variant_option_get_name(in_option
);
460 out_option_field_class
= create_field_class_copy_internal(
461 md_maps
, in_option_fc
);
462 if (!out_option_field_class
) {
463 BT_COMP_LOGE_STR("Cannot copy field class.");
467 ret
= copy_field_class_content_internal(md_maps
, in_option_fc
,
468 out_option_field_class
);
470 BT_COMP_LOGE_STR("Error copying content of option variant "
475 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
) {
476 const bt_field_class_variant_with_selector_field_integer_unsigned_option
*spec_opt
=
477 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
479 const bt_integer_range_set_unsigned
*ranges
=
480 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
483 if (bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
484 out_field_class
, option_name
,
485 out_option_field_class
, ranges
) !=
486 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK
) {
487 BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned integer selector'");
488 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
492 } else if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
493 const bt_field_class_variant_with_selector_field_integer_signed_option
*spec_opt
=
494 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
496 const bt_integer_range_set_signed
*ranges
=
497 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
500 if (bt_field_class_variant_with_selector_field_integer_signed_append_option(
501 out_field_class
, option_name
,
502 out_option_field_class
, ranges
) !=
503 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK
) {
504 BT_COMP_LOGE_STR("Cannot append option to variant field class with signed integer selector'");
505 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
510 BT_ASSERT(fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
);
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_FIELD_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
);
523 out_option
= bt_field_class_variant_borrow_option_by_index(
525 BT_ASSERT(out_option
);
528 * Safe to use the same value object because it's frozen
531 bt_field_class_variant_option_set_user_attributes(
533 bt_field_class_variant_option_borrow_user_attributes_const(
537 BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
538 "out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
550 BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, "
551 "out-fc-addr=%p", in_field_class
, out_field_class
);
553 * There is no content to copy. Keep this function call anyway for
556 BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, "
557 "out-fc-addr=%p", in_field_class
, out_field_class
);
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
)
568 BT_COMP_LOGD("Copying content of dynamic array field class: "
569 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
571 * There is no content to copy. Keep this function call anyway for
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
);
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
)
586 BT_COMP_LOGD("Copying content of option field class: "
587 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
589 if (bt_field_class_get_type(out_field_class
) ==
590 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
591 bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
593 bt_field_class_option_with_selector_field_bool_selector_is_reversed(
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
);
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
)
608 BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, "
609 "out-fc-addr=%p", in_field_class
, out_field_class
);
611 * There is no content to copy. Keep this function call anyway for
614 BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, "
615 "out-fc-addr=%p", in_field_class
, out_field_class
);
621 bt_field_class
*copy_field_class_array_element(struct trace_ir_metadata_maps
*md_maps
,
622 const bt_field_class
*in_elem_fc
)
625 bt_field_class
*out_elem_fc
=
626 create_field_class_copy_internal(md_maps
, in_elem_fc
);
628 BT_COMP_LOGE("Error creating output elem field class "
629 "from input elem field class for static array: "
630 "in-fc-addr=%p", in_elem_fc
);
634 ret
= copy_field_class_content_internal(md_maps
, in_elem_fc
, out_elem_fc
);
636 BT_COMP_LOGE("Error creating output elem field class "
637 "from input elem field class for static array: "
638 "in-fc-addr=%p", in_elem_fc
);
639 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc
);
648 bt_field_class
*create_field_class_copy_internal(struct trace_ir_metadata_maps
*md_maps
,
649 const bt_field_class
*in_field_class
)
651 bt_field_class
*out_field_class
= NULL
;
652 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
654 BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p",
658 case BT_FIELD_CLASS_TYPE_BOOL
:
659 out_field_class
= bt_field_class_bool_create(
660 md_maps
->output_trace_class
);
662 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
663 out_field_class
= bt_field_class_bit_array_create(
664 md_maps
->output_trace_class
,
665 bt_field_class_bit_array_get_length(
668 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
669 out_field_class
= bt_field_class_integer_unsigned_create(
670 md_maps
->output_trace_class
);
672 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
673 out_field_class
= bt_field_class_integer_signed_create(
674 md_maps
->output_trace_class
);
676 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
677 out_field_class
= bt_field_class_enumeration_unsigned_create(
678 md_maps
->output_trace_class
);
680 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
681 out_field_class
= bt_field_class_enumeration_signed_create(
682 md_maps
->output_trace_class
);
684 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
685 out_field_class
= bt_field_class_real_single_precision_create(
686 md_maps
->output_trace_class
);
688 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
689 out_field_class
= bt_field_class_real_double_precision_create(
690 md_maps
->output_trace_class
);
692 case BT_FIELD_CLASS_TYPE_STRING
:
693 out_field_class
= bt_field_class_string_create(
694 md_maps
->output_trace_class
);
696 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
697 out_field_class
= bt_field_class_structure_create(
698 md_maps
->output_trace_class
);
700 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
702 const bt_field_class
*in_elem_fc
=
703 bt_field_class_array_borrow_element_field_class_const(
705 uint64_t array_len
= bt_field_class_array_static_get_length(
708 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
709 md_maps
, in_elem_fc
);
711 out_field_class
= NULL
;
715 out_field_class
= bt_field_class_array_static_create(
716 md_maps
->output_trace_class
,
717 out_elem_fc
, array_len
);
720 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
721 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
723 const bt_field_class
*in_elem_fc
=
724 bt_field_class_array_borrow_element_field_class_const(
726 bt_field_class
*out_length_fc
= NULL
;
727 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
728 md_maps
, in_elem_fc
);
731 out_field_class
= NULL
;
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(
739 const bt_field_class
*in_length_fc
=
740 resolve_field_path_to_field_class(length_fp
,
743 BT_ASSERT(in_length_fc
);
744 out_length_fc
= g_hash_table_lookup(md_maps
->field_class_map
,
746 BT_ASSERT(out_length_fc
);
749 out_field_class
= bt_field_class_array_dynamic_create(
750 md_maps
->output_trace_class
,
751 out_elem_fc
, out_length_fc
);
754 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
755 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
756 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
757 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
759 const bt_field_class
*in_content_fc
=
760 bt_field_class_option_borrow_field_class_const(
762 bt_field_class
*out_selector_fc
= NULL
;
763 bt_field_class
*out_content_fc
;
766 out_content_fc
= create_field_class_copy_internal(
767 md_maps
, in_content_fc
);
768 if (!out_content_fc
) {
769 BT_COMP_LOGE_STR("Cannot copy option's content field class.");
773 ret
= copy_field_class_content_internal(md_maps
,
774 in_content_fc
, out_content_fc
);
776 BT_COMP_LOGE_STR("Error copying content of option's "
777 "content field class");
781 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
783 bt_field_class_option_without_selector_create(
784 md_maps
->output_trace_class
,
787 const bt_field_path
*in_selector_fp
=
788 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
790 const bt_field_class
*in_selector_fc
;
792 BT_ASSERT(in_selector_fp
);
793 in_selector_fc
= resolve_field_path_to_field_class(
794 in_selector_fp
, md_maps
);
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
);
800 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
802 bt_field_class_option_with_selector_field_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_FIELD
) {
806 const bt_integer_range_set_unsigned
*ranges
=
807 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
812 bt_field_class_option_with_selector_field_integer_unsigned_create(
813 md_maps
->output_trace_class
,
814 out_content_fc
, out_selector_fc
,
816 } else if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
817 const bt_integer_range_set_signed
*ranges
=
818 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
823 bt_field_class_option_with_selector_field_integer_signed_create(
824 md_maps
->output_trace_class
,
825 out_content_fc
, out_selector_fc
,
830 BT_ASSERT(out_field_class
);
833 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
834 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
835 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
837 bt_field_class
*out_sel_fc
= NULL
;
839 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
||
840 fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
841 const bt_field_class
*in_sel_fc
;
842 const bt_field_path
*sel_fp
=
843 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
847 in_sel_fc
= resolve_field_path_to_field_class(sel_fp
,
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
);
855 out_field_class
= bt_field_class_variant_create(
856 md_maps
->output_trace_class
, out_sel_fc
);
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
868 g_hash_table_insert(md_maps
->field_class_map
,
869 (gpointer
) in_field_class
, out_field_class
);
873 BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, "
874 "out-fc-addr=%p", in_field_class
, out_field_class
);
876 BT_COMP_LOGE("Error creating output field class from input field "
877 "class: in-fc-addr=%p", in_field_class
);
880 return out_field_class
;
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
)
892 * Safe to use the same value object because it's frozen at this
895 bt_field_class_set_user_attributes(out_field_class
,
896 bt_field_class_borrow_user_attributes_const(in_field_class
));
898 switch(bt_field_class_get_type(in_field_class
)) {
899 case BT_FIELD_CLASS_TYPE_BOOL
:
900 ret
= field_class_bool_copy(md_maps
,
901 in_field_class
, out_field_class
);
903 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
904 ret
= field_class_bit_array_copy(md_maps
,
905 in_field_class
, out_field_class
);
907 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
908 ret
= field_class_unsigned_integer_copy(md_maps
,
909 in_field_class
, out_field_class
);
911 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
912 ret
= field_class_signed_integer_copy(md_maps
,
913 in_field_class
, out_field_class
);
915 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
916 ret
= field_class_unsigned_enumeration_copy(md_maps
,
917 in_field_class
, out_field_class
);
919 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
920 ret
= field_class_signed_enumeration_copy(md_maps
,
921 in_field_class
, out_field_class
);
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
);
927 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
928 ret
= field_class_double_precision_real_copy(md_maps
,
929 in_field_class
, out_field_class
);
931 case BT_FIELD_CLASS_TYPE_STRING
:
932 ret
= field_class_string_copy(md_maps
,
933 in_field_class
, out_field_class
);
935 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
936 ret
= field_class_structure_copy(md_maps
,
937 in_field_class
, out_field_class
);
939 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
940 ret
= field_class_static_array_copy(md_maps
,
941 in_field_class
, out_field_class
);
943 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD
:
944 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
:
945 ret
= field_class_dynamic_array_copy(md_maps
,
946 in_field_class
, out_field_class
);
948 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
:
949 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
:
950 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
951 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
952 ret
= field_class_option_copy(md_maps
,
953 in_field_class
, out_field_class
);
955 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
:
956 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
:
957 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
:
958 ret
= field_class_variant_copy(md_maps
,
959 in_field_class
, out_field_class
);