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
);
63 if (fc_type
== BT_FIELD_CLASS_TYPE_STRUCTURE
) {
64 const bt_field_class_structure_member
*member
;
66 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
67 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
68 member
= bt_field_class_structure_borrow_member_by_index_const(
70 bt_field_path_item_index_get_index(fp_item
));
71 curr_fc
= bt_field_class_structure_member_borrow_field_class_const(
73 } else if (bt_field_class_type_is(fc_type
, BT_FIELD_CLASS_TYPE_OPTION
)) {
74 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
75 BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
);
76 curr_fc
= bt_field_class_option_borrow_field_class_const(
79 } else if (bt_field_class_type_is(fc_type
, BT_FIELD_CLASS_TYPE_VARIANT
)) {
80 const bt_field_class_variant_option
*option
;
82 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
83 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
84 option
= bt_field_class_variant_borrow_option_by_index_const(
86 bt_field_path_item_index_get_index(fp_item
));
87 curr_fc
= bt_field_class_variant_option_borrow_field_class_const(
90 } else if (bt_field_class_type_is(fc_type
, BT_FIELD_CLASS_TYPE_ARRAY
)) {
91 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
92 BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
);
93 curr_fc
= bt_field_class_array_borrow_element_field_class_const(
105 const bt_field_class
*resolve_field_path_to_field_class(const bt_field_path
*fp
,
106 struct trace_ir_metadata_maps
*md_maps
)
108 struct field_class_resolving_context
*fc_resolving_ctx
;
109 const bt_field_class
*fc
;
110 bt_field_path_scope fp_scope
;
112 BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp
);
114 fc_resolving_ctx
= md_maps
->fc_resolving_ctx
;
115 fp_scope
= bt_field_path_get_root_scope(fp
);
118 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
119 fc
= walk_field_path(md_maps
, fp
,
120 fc_resolving_ctx
->packet_context
);
122 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
123 fc
= walk_field_path(md_maps
, fp
,
124 fc_resolving_ctx
->event_common_context
);
126 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
127 fc
= walk_field_path(md_maps
, fp
,
128 fc_resolving_ctx
->event_specific_context
);
130 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
131 fc
= walk_field_path(md_maps
, fp
,
132 fc_resolving_ctx
->event_payload
);
142 void field_class_integer_set_props(const bt_field_class
*input_fc
,
143 bt_field_class
*output_fc
)
145 bt_field_class_integer_set_preferred_display_base(output_fc
,
146 bt_field_class_integer_get_preferred_display_base(input_fc
));
147 bt_field_class_integer_set_field_value_range(output_fc
,
148 bt_field_class_integer_get_field_value_range(input_fc
));
152 int field_class_bool_copy(struct trace_ir_metadata_maps
*md_maps
,
153 const bt_field_class
*in_field_class
,
154 bt_field_class
*out_field_class
)
156 BT_COMP_LOGD("Copying content of boolean field class: "
157 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
159 * There is no content to copy. Keep this function call anyway for
162 BT_COMP_LOGD("Copied content of boolean field class: "
163 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
168 int field_class_bit_array_copy(
169 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 bit array 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 bit array field class: "
180 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
185 int field_class_unsigned_integer_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 unsigned integer field class: "
191 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
193 field_class_integer_set_props(in_field_class
, out_field_class
);
195 BT_COMP_LOGD("Copied content of unsigned integer field class: "
196 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
201 int field_class_signed_integer_copy(
202 struct trace_ir_metadata_maps
*md_maps
,
203 const bt_field_class
*in_field_class
,
204 bt_field_class
*out_field_class
)
206 BT_COMP_LOGD("Copying content of signed integer field class: "
207 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
209 field_class_integer_set_props(in_field_class
, out_field_class
);
211 BT_COMP_LOGD("Copied content of signed integer field class: "
212 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
217 int field_class_unsigned_enumeration_copy(
218 struct trace_ir_metadata_maps
*md_maps
,
219 const bt_field_class
*in_field_class
,
220 bt_field_class
*out_field_class
)
222 uint64_t i
, enum_mapping_count
;
225 BT_COMP_LOGD("Copying content of unsigned enumeration field class: "
226 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
228 /* Copy properties of the inner integer. */
229 field_class_integer_set_props(in_field_class
, out_field_class
);
231 /* Copy all enumeration entries. */
232 enum_mapping_count
= bt_field_class_enumeration_get_mapping_count(
234 for (i
= 0; i
< enum_mapping_count
; i
++) {
236 const bt_integer_range_set_unsigned
*range_set
;
237 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
238 const bt_field_class_enumeration_mapping
*mapping
;
240 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
242 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
244 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
245 range_set
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
247 ret
= bt_field_class_enumeration_unsigned_add_mapping(
248 out_field_class
, label
, range_set
);
254 BT_COMP_LOGD("Copied content of unsigned enumeration field class: "
255 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
262 int field_class_signed_enumeration_copy(
263 struct trace_ir_metadata_maps
*md_maps
,
264 const bt_field_class
*in_field_class
,
265 bt_field_class
*out_field_class
)
267 uint64_t i
, enum_mapping_count
;
270 BT_COMP_LOGD("Copying content of signed enumeration field class: "
271 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
273 /* Copy properties of the inner integer. */
274 field_class_integer_set_props(in_field_class
, out_field_class
);
276 /* Copy all enumeration entries. */
278 bt_field_class_enumeration_get_mapping_count(in_field_class
);
279 for (i
= 0; i
< enum_mapping_count
; i
++) {
281 const bt_integer_range_set_signed
*range_set
;
282 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
283 const bt_field_class_enumeration_mapping
*mapping
;
285 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
287 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
289 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
290 range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
292 ret
= bt_field_class_enumeration_signed_add_mapping(
293 out_field_class
, label
, range_set
);
299 BT_COMP_LOGD("Copied content of signed enumeration field class: "
300 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
307 int field_class_single_precision_real_copy(
308 struct trace_ir_metadata_maps
*md_maps
,
309 const bt_field_class
*in_field_class
,
310 bt_field_class
*out_field_class
)
312 BT_COMP_LOGD("Copying content of single-precision real field class: "
313 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
315 BT_COMP_LOGD("Copied content single-precision real field class:"
316 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
322 int field_class_double_precision_real_copy(
323 struct trace_ir_metadata_maps
*md_maps
,
324 const bt_field_class
*in_field_class
,
325 bt_field_class
*out_field_class
)
327 BT_COMP_LOGD("Copying content of double-precision real field class: "
328 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
330 BT_COMP_LOGD("Copied content double-precision real field class:"
331 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
337 int field_class_structure_copy(
338 struct trace_ir_metadata_maps
*md_maps
,
339 const bt_field_class
*in_field_class
,
340 bt_field_class
*out_field_class
)
342 uint64_t i
, struct_member_count
;
345 BT_COMP_LOGD("Copying content of structure field class: "
346 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
347 /* Get the number of member in that struct. */
348 struct_member_count
=
349 bt_field_class_structure_get_member_count(in_field_class
);
351 /* Iterate over all the members of the struct. */
352 for (i
= 0; i
< struct_member_count
; i
++) {
353 const bt_field_class_structure_member
*in_member
;
354 bt_field_class_structure_member
*out_member
;
355 const char *member_name
;
356 const bt_field_class
*in_member_fc
;
357 bt_field_class
*out_member_field_class
;
359 in_member
= bt_field_class_structure_borrow_member_by_index_const(
361 in_member_fc
= bt_field_class_structure_member_borrow_field_class_const(
363 member_name
= bt_field_class_structure_member_get_name(in_member
);
364 BT_COMP_LOGD("Copying structure field class's field: "
365 "index=%" PRId64
", member-fc-addr=%p, field-name=\"%s\"",
366 i
, in_member_fc
, member_name
);
368 out_member_field_class
= create_field_class_copy(md_maps
,
370 if (!out_member_field_class
) {
371 BT_COMP_LOGE("Cannot copy structure field class's field: "
372 "index=%" PRId64
", field-fc-addr=%p, field-name=\"%s\"",
373 i
, in_member_fc
, member_name
);
377 ret
= copy_field_class_content(md_maps
, in_member_fc
,
378 out_member_field_class
);
383 if (bt_field_class_structure_append_member(out_field_class
,
384 member_name
, out_member_field_class
) !=
385 BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK
) {
386 BT_COMP_LOGE("Cannot append structure field class's field: "
387 "index=%" PRId64
", "
388 "field-fc-addr=%p, field-name=\"%s\"",
389 i
, in_member_fc
, member_name
);
390 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class
);
395 out_member
= bt_field_class_structure_borrow_member_by_index(
397 BT_ASSERT(out_member
);
400 * Safe to use the same value object because it's frozen
403 bt_field_class_structure_member_set_user_attributes(
405 bt_field_class_structure_member_borrow_user_attributes_const(
409 BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
410 in_field_class
, out_field_class
);
417 int field_class_variant_copy(
418 struct trace_ir_metadata_maps
*md_maps
,
419 const bt_field_class
*in_field_class
,
420 bt_field_class
*out_field_class
)
422 bt_field_class
*out_tag_field_class
= NULL
;
423 uint64_t i
, variant_option_count
;
424 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
427 BT_COMP_LOGD("Copying content of variant field class: "
428 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
429 variant_option_count
=
430 bt_field_class_variant_get_option_count(in_field_class
);
431 for (i
= 0; i
< variant_option_count
; i
++) {
432 const bt_field_class
*in_option_fc
;
433 const char *option_name
;
434 bt_field_class
*out_option_field_class
;
435 const bt_field_class_variant_option
*in_option
;
436 bt_field_class_variant_option
*out_option
;
438 in_option
= bt_field_class_variant_borrow_option_by_index_const(
440 in_option_fc
= bt_field_class_variant_option_borrow_field_class_const(
442 option_name
= bt_field_class_variant_option_get_name(in_option
);
443 out_option_field_class
= create_field_class_copy_internal(
444 md_maps
, in_option_fc
);
445 if (!out_option_field_class
) {
446 BT_COMP_LOGE_STR("Cannot copy field class.");
450 ret
= copy_field_class_content_internal(md_maps
, in_option_fc
,
451 out_option_field_class
);
453 BT_COMP_LOGE_STR("Error copying content of option variant "
458 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
) {
459 const bt_field_class_variant_with_selector_field_integer_unsigned_option
*spec_opt
=
460 bt_field_class_variant_with_selector_field_integer_unsigned_borrow_option_by_index_const(
462 const bt_integer_range_set_unsigned
*ranges
=
463 bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const(
466 if (bt_field_class_variant_with_selector_field_integer_unsigned_append_option(
467 out_field_class
, option_name
,
468 out_option_field_class
, ranges
) !=
469 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK
) {
470 BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned integer selector'");
471 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
475 } else if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
476 const bt_field_class_variant_with_selector_field_integer_signed_option
*spec_opt
=
477 bt_field_class_variant_with_selector_field_integer_signed_borrow_option_by_index_const(
479 const bt_integer_range_set_signed
*ranges
=
480 bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const(
483 if (bt_field_class_variant_with_selector_field_integer_signed_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 signed integer selector'");
488 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
493 BT_ASSERT(fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD
);
495 if (bt_field_class_variant_without_selector_append_option(
496 out_field_class
, option_name
,
497 out_option_field_class
) !=
498 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK
) {
499 BT_COMP_LOGE_STR("Cannot append option to variant field class'");
500 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
506 out_option
= bt_field_class_variant_borrow_option_by_index(
508 BT_ASSERT(out_option
);
511 * Safe to use the same value object because it's frozen
514 bt_field_class_variant_option_set_user_attributes(
516 bt_field_class_variant_option_borrow_user_attributes_const(
520 BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
521 "out-fc-addr=%p", in_field_class
, out_field_class
);
528 int field_class_static_array_copy(
529 struct trace_ir_metadata_maps
*md_maps
,
530 const bt_field_class
*in_field_class
,
531 bt_field_class
*out_field_class
)
533 BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, "
534 "out-fc-addr=%p", in_field_class
, out_field_class
);
536 * There is no content to copy. Keep this function call anyway for
539 BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, "
540 "out-fc-addr=%p", in_field_class
, out_field_class
);
546 int field_class_dynamic_array_copy(
547 struct trace_ir_metadata_maps
*md_maps
,
548 const bt_field_class
*in_field_class
,
549 bt_field_class
*out_field_class
)
551 BT_COMP_LOGD("Copying content of dynamic array field class: "
552 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
554 * There is no content to copy. Keep this function call anyway for
557 BT_COMP_LOGD("Copied content of dynamic array field class: "
558 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
564 int field_class_option_copy(
565 struct trace_ir_metadata_maps
*md_maps
,
566 const bt_field_class
*in_field_class
,
567 bt_field_class
*out_field_class
)
569 BT_COMP_LOGD("Copying content of option field class: "
570 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
572 if (bt_field_class_get_type(out_field_class
) ==
573 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
574 bt_field_class_option_with_selector_field_bool_set_selector_is_reversed(
576 bt_field_class_option_with_selector_field_bool_selector_is_reversed(
580 BT_COMP_LOGD("Copied content of option field class: "
581 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
587 int field_class_string_copy(struct trace_ir_metadata_maps
*md_maps
,
588 const bt_field_class
*in_field_class
,
589 bt_field_class
*out_field_class
)
591 BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, "
592 "out-fc-addr=%p", in_field_class
, out_field_class
);
594 * There is no content to copy. Keep this function call anyway for
597 BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, "
598 "out-fc-addr=%p", in_field_class
, out_field_class
);
604 bt_field_class
*copy_field_class_array_element(struct trace_ir_metadata_maps
*md_maps
,
605 const bt_field_class
*in_elem_fc
)
608 bt_field_class
*out_elem_fc
=
609 create_field_class_copy_internal(md_maps
, in_elem_fc
);
611 BT_COMP_LOGE("Error creating output elem field class "
612 "from input elem field class for static array: "
613 "in-fc-addr=%p", in_elem_fc
);
617 ret
= copy_field_class_content_internal(md_maps
, in_elem_fc
, out_elem_fc
);
619 BT_COMP_LOGE("Error creating output elem field class "
620 "from input elem field class for static array: "
621 "in-fc-addr=%p", in_elem_fc
);
622 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc
);
631 bt_field_class
*create_field_class_copy_internal(struct trace_ir_metadata_maps
*md_maps
,
632 const bt_field_class
*in_field_class
)
634 bt_field_class
*out_field_class
= NULL
;
635 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
637 BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p",
641 case BT_FIELD_CLASS_TYPE_BOOL
:
642 out_field_class
= bt_field_class_bool_create(
643 md_maps
->output_trace_class
);
645 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
646 out_field_class
= bt_field_class_bit_array_create(
647 md_maps
->output_trace_class
,
648 bt_field_class_bit_array_get_length(
651 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
652 out_field_class
= bt_field_class_integer_unsigned_create(
653 md_maps
->output_trace_class
);
655 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
656 out_field_class
= bt_field_class_integer_signed_create(
657 md_maps
->output_trace_class
);
659 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
660 out_field_class
= bt_field_class_enumeration_unsigned_create(
661 md_maps
->output_trace_class
);
663 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
664 out_field_class
= bt_field_class_enumeration_signed_create(
665 md_maps
->output_trace_class
);
667 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
668 out_field_class
= bt_field_class_real_single_precision_create(
669 md_maps
->output_trace_class
);
671 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
672 out_field_class
= bt_field_class_real_double_precision_create(
673 md_maps
->output_trace_class
);
675 case BT_FIELD_CLASS_TYPE_STRING
:
676 out_field_class
= bt_field_class_string_create(
677 md_maps
->output_trace_class
);
679 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
680 out_field_class
= bt_field_class_structure_create(
681 md_maps
->output_trace_class
);
683 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
685 const bt_field_class
*in_elem_fc
=
686 bt_field_class_array_borrow_element_field_class_const(
688 uint64_t array_len
= bt_field_class_array_static_get_length(
691 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
692 md_maps
, in_elem_fc
);
694 out_field_class
= NULL
;
698 out_field_class
= bt_field_class_array_static_create(
699 md_maps
->output_trace_class
,
700 out_elem_fc
, array_len
);
707 if (bt_field_class_type_is(fc_type
,
708 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
)) {
709 const bt_field_class
*in_elem_fc
=
710 bt_field_class_array_borrow_element_field_class_const(
712 bt_field_class
*out_length_fc
= NULL
;
713 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
714 md_maps
, in_elem_fc
);
717 out_field_class
= NULL
;
721 if (fc_type
== BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD
) {
722 const bt_field_path
*length_fp
=
723 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(
725 const bt_field_class
*in_length_fc
=
726 resolve_field_path_to_field_class(length_fp
,
729 BT_ASSERT(in_length_fc
);
730 out_length_fc
= g_hash_table_lookup(md_maps
->field_class_map
,
732 BT_ASSERT(out_length_fc
);
735 out_field_class
= bt_field_class_array_dynamic_create(
736 md_maps
->output_trace_class
,
737 out_elem_fc
, out_length_fc
);
738 } else if (bt_field_class_type_is(fc_type
,
739 BT_FIELD_CLASS_TYPE_OPTION
)) {
740 const bt_field_class
*in_content_fc
=
741 bt_field_class_option_borrow_field_class_const(
743 bt_field_class
*out_selector_fc
= NULL
;
744 bt_field_class
*out_content_fc
;
747 out_content_fc
= create_field_class_copy_internal(
748 md_maps
, in_content_fc
);
749 if (!out_content_fc
) {
750 BT_COMP_LOGE_STR("Cannot copy option's content field class.");
754 ret
= copy_field_class_content_internal(md_maps
,
755 in_content_fc
, out_content_fc
);
757 BT_COMP_LOGE_STR("Error copying content of option's "
758 "content field class");
762 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR_FIELD
) {
764 bt_field_class_option_without_selector_create(
765 md_maps
->output_trace_class
,
768 const bt_field_path
*in_selector_fp
=
769 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(
771 const bt_field_class
*in_selector_fc
;
773 BT_ASSERT(in_selector_fp
);
774 in_selector_fc
= resolve_field_path_to_field_class(
775 in_selector_fp
, md_maps
);
776 BT_ASSERT(in_selector_fc
);
777 out_selector_fc
= g_hash_table_lookup(
778 md_maps
->field_class_map
, in_selector_fc
);
779 BT_ASSERT(out_selector_fc
);
781 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR_FIELD
) {
783 bt_field_class_option_with_selector_field_bool_create(
784 md_maps
->output_trace_class
,
785 out_content_fc
, out_selector_fc
);
786 } else if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD
) {
787 const bt_integer_range_set_unsigned
*ranges
=
788 bt_field_class_option_with_selector_field_integer_unsigned_borrow_selector_ranges_const(
793 bt_field_class_option_with_selector_field_integer_unsigned_create(
794 md_maps
->output_trace_class
,
795 out_content_fc
, out_selector_fc
,
797 } else if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR_FIELD
) {
798 const bt_integer_range_set_signed
*ranges
=
799 bt_field_class_option_with_selector_field_integer_signed_borrow_selector_ranges_const(
804 bt_field_class_option_with_selector_field_integer_signed_create(
805 md_maps
->output_trace_class
,
806 out_content_fc
, out_selector_fc
,
811 BT_ASSERT(out_field_class
);
812 } else if (bt_field_class_type_is(fc_type
,
813 BT_FIELD_CLASS_TYPE_VARIANT
)) {
814 bt_field_class
*out_sel_fc
= NULL
;
816 if (bt_field_class_type_is(fc_type
,
817 BT_FIELD_CLASS_TYPE_VARIANT_WITH_SELECTOR_FIELD
)) {
818 const bt_field_class
*in_sel_fc
;
819 const bt_field_path
*sel_fp
=
820 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const(
824 in_sel_fc
= resolve_field_path_to_field_class(sel_fp
,
826 BT_ASSERT(in_sel_fc
);
827 out_sel_fc
= g_hash_table_lookup(
828 md_maps
->field_class_map
, in_sel_fc
);
829 BT_ASSERT(out_sel_fc
);
832 out_field_class
= bt_field_class_variant_create(
833 md_maps
->output_trace_class
, out_sel_fc
);
837 * Add mapping from in_field_class to out_field_class. This simplifies
838 * the resolution of field paths in variant and dynamic array field
841 BT_ASSERT(out_field_class
);
842 g_hash_table_insert(md_maps
->field_class_map
,
843 (gpointer
) in_field_class
, out_field_class
);
847 BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, "
848 "out-fc-addr=%p", in_field_class
, out_field_class
);
850 BT_COMP_LOGE("Error creating output field class from input field "
851 "class: in-fc-addr=%p", in_field_class
);
854 return out_field_class
;
858 int copy_field_class_content_internal(
859 struct trace_ir_metadata_maps
*md_maps
,
860 const bt_field_class
*in_field_class
,
861 bt_field_class
*out_field_class
)
864 bt_field_class_type in_fc_type
=
865 bt_field_class_get_type(in_field_class
);
868 * Safe to use the same value object because it's frozen at this
871 bt_field_class_set_user_attributes(out_field_class
,
872 bt_field_class_borrow_user_attributes_const(in_field_class
));
874 if (in_fc_type
== BT_FIELD_CLASS_TYPE_BOOL
) {
875 ret
= field_class_bool_copy(md_maps
,
876 in_field_class
, out_field_class
);
877 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_BIT_ARRAY
) {
878 ret
= field_class_bit_array_copy(md_maps
,
879 in_field_class
, out_field_class
);
880 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
) {
881 ret
= field_class_unsigned_integer_copy(md_maps
,
882 in_field_class
, out_field_class
);
883 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
) {
884 ret
= field_class_signed_integer_copy(md_maps
,
885 in_field_class
, out_field_class
);
886 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
) {
887 ret
= field_class_unsigned_enumeration_copy(md_maps
,
888 in_field_class
, out_field_class
);
889 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
) {
890 ret
= field_class_signed_enumeration_copy(md_maps
,
891 in_field_class
, out_field_class
);
892 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
) {
893 ret
= field_class_single_precision_real_copy(md_maps
,
894 in_field_class
, out_field_class
);
895 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
) {
896 ret
= field_class_double_precision_real_copy(md_maps
,
897 in_field_class
, out_field_class
);
898 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_STRING
) {
899 ret
= field_class_string_copy(md_maps
,
900 in_field_class
, out_field_class
);
901 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_STRUCTURE
) {
902 ret
= field_class_structure_copy(md_maps
,
903 in_field_class
, out_field_class
);
904 } else if (in_fc_type
== BT_FIELD_CLASS_TYPE_STATIC_ARRAY
) {
905 ret
= field_class_static_array_copy(md_maps
,
906 in_field_class
, out_field_class
);
907 } else if (bt_field_class_type_is(in_fc_type
,
908 BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
)) {
909 ret
= field_class_dynamic_array_copy(md_maps
,
910 in_field_class
, out_field_class
);
911 } else if (bt_field_class_type_is(in_fc_type
,
912 BT_FIELD_CLASS_TYPE_OPTION
)) {
913 ret
= field_class_option_copy(md_maps
,
914 in_field_class
, out_field_class
);
915 } else if (bt_field_class_type_is(in_fc_type
,
916 BT_FIELD_CLASS_TYPE_VARIANT
)) {
917 ret
= field_class_variant_copy(md_maps
,
918 in_field_class
, out_field_class
);