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
:
79 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
80 BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
);
81 curr_fc
= bt_field_class_option_borrow_field_class_const(
85 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
86 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
87 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
89 const bt_field_class_variant_option
*option
;
91 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
92 BT_FIELD_PATH_ITEM_TYPE_INDEX
);
93 option
= bt_field_class_variant_borrow_option_by_index_const(
95 bt_field_path_item_index_get_index(fp_item
));
96 curr_fc
= bt_field_class_variant_option_borrow_field_class_const(
100 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
101 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
103 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
104 BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
);
105 curr_fc
= bt_field_class_array_borrow_element_field_class_const(
118 const bt_field_class
*resolve_field_path_to_field_class(const bt_field_path
*fp
,
119 struct trace_ir_metadata_maps
*md_maps
)
121 struct field_class_resolving_context
*fc_resolving_ctx
;
122 const bt_field_class
*fc
;
123 bt_field_path_scope fp_scope
;
125 BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp
);
127 fc_resolving_ctx
= md_maps
->fc_resolving_ctx
;
128 fp_scope
= bt_field_path_get_root_scope(fp
);
131 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
132 fc
= walk_field_path(md_maps
, fp
,
133 fc_resolving_ctx
->packet_context
);
135 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
136 fc
= walk_field_path(md_maps
, fp
,
137 fc_resolving_ctx
->event_common_context
);
139 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
140 fc
= walk_field_path(md_maps
, fp
,
141 fc_resolving_ctx
->event_specific_context
);
143 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
144 fc
= walk_field_path(md_maps
, fp
,
145 fc_resolving_ctx
->event_payload
);
155 void field_class_integer_set_props(const bt_field_class
*input_fc
,
156 bt_field_class
*output_fc
)
158 bt_field_class_integer_set_preferred_display_base(output_fc
,
159 bt_field_class_integer_get_preferred_display_base(input_fc
));
160 bt_field_class_integer_set_field_value_range(output_fc
,
161 bt_field_class_integer_get_field_value_range(input_fc
));
165 int field_class_bool_copy(
166 struct trace_ir_metadata_maps
*md_maps
,
167 const bt_field_class
*in_field_class
,
168 bt_field_class
*out_field_class
)
170 BT_COMP_LOGD("Copying content of boolean field class: "
171 "in-fc-addr=%p, out-fc-addr=%p",
172 in_field_class
, out_field_class
);
173 BT_COMP_LOGD("Copied content of boolean field class: "
174 "in-fc-addr=%p, out-fc-addr=%p",
175 in_field_class
, out_field_class
);
180 int field_class_bit_array_copy(
181 struct trace_ir_metadata_maps
*md_maps
,
182 const bt_field_class
*in_field_class
,
183 bt_field_class
*out_field_class
)
185 BT_COMP_LOGD("Copying content of bit array field class: "
186 "in-fc-addr=%p, out-fc-addr=%p",
187 in_field_class
, out_field_class
);
188 BT_COMP_LOGD("Copied content of bit array field class: "
189 "in-fc-addr=%p, out-fc-addr=%p",
190 in_field_class
, out_field_class
);
195 int field_class_unsigned_integer_copy(
196 struct trace_ir_metadata_maps
*md_maps
,
197 const bt_field_class
*in_field_class
,
198 bt_field_class
*out_field_class
)
200 BT_COMP_LOGD("Copying content of unsigned integer field class: "
201 "in-fc-addr=%p, out-fc-addr=%p",
202 in_field_class
, out_field_class
);
204 field_class_integer_set_props(in_field_class
, out_field_class
);
206 BT_COMP_LOGD("Copied content of unsigned integer field class: "
207 "in-fc-addr=%p, out-fc-addr=%p",
208 in_field_class
, out_field_class
);
213 int field_class_signed_integer_copy(
214 struct trace_ir_metadata_maps
*md_maps
,
215 const bt_field_class
*in_field_class
,
216 bt_field_class
*out_field_class
)
218 BT_COMP_LOGD("Copying content of signed integer field class: "
219 "in-fc-addr=%p, out-fc-addr=%p",
220 in_field_class
, out_field_class
);
222 field_class_integer_set_props(in_field_class
, out_field_class
);
224 BT_COMP_LOGD("Copied content of signed integer field class: "
225 "in-fc-addr=%p, out-fc-addr=%p",
226 in_field_class
, out_field_class
);
231 int field_class_unsigned_enumeration_copy(
232 struct trace_ir_metadata_maps
*md_maps
,
233 const bt_field_class
*in_field_class
,
234 bt_field_class
*out_field_class
)
236 uint64_t i
, enum_mapping_count
;
239 BT_COMP_LOGD("Copying content of unsigned enumeration field class: "
240 "in-fc-addr=%p, out-fc-addr=%p",
241 in_field_class
, out_field_class
);
243 /* Copy properties of the inner integer. */
244 field_class_integer_set_props(in_field_class
, out_field_class
);
246 /* Copy all enumeration entries. */
247 enum_mapping_count
= bt_field_class_enumeration_get_mapping_count(in_field_class
);
248 for (i
= 0; i
< enum_mapping_count
; i
++) {
250 const bt_integer_range_set_unsigned
*range_set
;
251 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
252 const bt_field_class_enumeration_mapping
*mapping
;
254 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
256 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
258 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
259 range_set
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
261 ret
= bt_field_class_enumeration_unsigned_add_mapping(
262 out_field_class
, label
, range_set
);
268 BT_COMP_LOGD("Copied content of unsigned enumeration field class: "
269 "in-fc-addr=%p, out-fc-addr=%p",
270 in_field_class
, out_field_class
);
277 int field_class_signed_enumeration_copy(
278 struct trace_ir_metadata_maps
*md_maps
,
279 const bt_field_class
*in_field_class
,
280 bt_field_class
*out_field_class
)
282 uint64_t i
, enum_mapping_count
;
285 BT_COMP_LOGD("Copying content of signed enumeration field class: "
286 "in-fc-addr=%p, out-fc-addr=%p",
287 in_field_class
, out_field_class
);
289 /* Copy properties of the inner integer. */
290 field_class_integer_set_props(in_field_class
, out_field_class
);
292 /* Copy all enumeration entries. */
294 bt_field_class_enumeration_get_mapping_count(in_field_class
);
295 for (i
= 0; i
< enum_mapping_count
; i
++) {
297 const bt_integer_range_set_signed
*range_set
;
298 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
299 const bt_field_class_enumeration_mapping
*mapping
;
301 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
303 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
305 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
306 range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
308 ret
= bt_field_class_enumeration_signed_add_mapping(
309 out_field_class
, label
, range_set
);
315 BT_COMP_LOGD("Copied content of signed enumeration field class: "
316 "in-fc-addr=%p, out-fc-addr=%p",
317 in_field_class
, out_field_class
);
324 int field_class_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 real field class: "
330 "in-fc-addr=%p, out-fc-addr=%p",
331 in_field_class
, out_field_class
);
333 bt_field_class_real_set_is_single_precision(out_field_class
,
334 bt_field_class_real_is_single_precision(in_field_class
));
336 BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, "
337 "out-fc-addr=%p", in_field_class
, out_field_class
);
343 int field_class_structure_copy(
344 struct trace_ir_metadata_maps
*md_maps
,
345 const bt_field_class
*in_field_class
,
346 bt_field_class
*out_field_class
)
348 uint64_t i
, struct_member_count
;
351 BT_COMP_LOGD("Copying content of structure field class: "
352 "in-fc-addr=%p, out-fc-addr=%p",
353 in_field_class
, out_field_class
);
354 /* Get the number of member in that struct. */
355 struct_member_count
=
356 bt_field_class_structure_get_member_count(in_field_class
);
358 /* Iterate over all the members of the struct. */
359 for (i
= 0; i
< struct_member_count
; i
++) {
360 const bt_field_class_structure_member
*in_member
;
361 bt_field_class_structure_member
*out_member
;
362 const char *member_name
;
363 const bt_field_class
*in_member_fc
;
364 bt_field_class
*out_member_field_class
;
366 in_member
= bt_field_class_structure_borrow_member_by_index_const(
368 in_member_fc
= bt_field_class_structure_member_borrow_field_class_const(
370 member_name
= bt_field_class_structure_member_get_name(in_member
);
371 BT_COMP_LOGD("Copying structure field class's field: "
372 "index=%" PRId64
", "
373 "member-fc-addr=%p, field-name=\"%s\"",
374 i
, in_member_fc
, member_name
);
376 out_member_field_class
= create_field_class_copy(md_maps
,
378 if (!out_member_field_class
) {
379 BT_COMP_LOGE("Cannot copy structure field class's field: "
380 "index=%" PRId64
", "
381 "field-fc-addr=%p, field-name=\"%s\"",
382 i
, in_member_fc
, member_name
);
386 ret
= copy_field_class_content(md_maps
, in_member_fc
,
387 out_member_field_class
);
392 if (bt_field_class_structure_append_member(out_field_class
,
393 member_name
, out_member_field_class
) !=
394 BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK
) {
395 BT_COMP_LOGE("Cannot append structure field class's field: "
396 "index=%" PRId64
", "
397 "field-fc-addr=%p, field-name=\"%s\"",
398 i
, in_member_fc
, member_name
);
399 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class
);
404 out_member
= bt_field_class_structure_borrow_member_by_index(
406 BT_ASSERT(out_member
);
409 * Safe to use the same value object because it's frozen
412 bt_field_class_structure_member_set_user_attributes(
414 bt_field_class_structure_member_borrow_user_attributes_const(
418 BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
419 in_field_class
, out_field_class
);
426 int field_class_variant_copy(
427 struct trace_ir_metadata_maps
*md_maps
,
428 const bt_field_class
*in_field_class
,
429 bt_field_class
*out_field_class
)
431 bt_field_class
*out_tag_field_class
= NULL
;
432 uint64_t i
, variant_option_count
;
433 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
436 BT_COMP_LOGD("Copying content of variant field class: "
437 "in-fc-addr=%p, out-fc-addr=%p",
438 in_field_class
, out_field_class
);
439 variant_option_count
=
440 bt_field_class_variant_get_option_count(in_field_class
);
441 for (i
= 0; i
< variant_option_count
; i
++) {
442 const bt_field_class
*in_option_fc
;
443 const char *option_name
;
444 bt_field_class
*out_option_field_class
;
445 const bt_field_class_variant_option
*in_option
;
446 bt_field_class_variant_option
*out_option
;
448 in_option
= bt_field_class_variant_borrow_option_by_index_const(
450 in_option_fc
= bt_field_class_variant_option_borrow_field_class_const(
452 option_name
= bt_field_class_variant_option_get_name(in_option
);
453 out_option_field_class
= create_field_class_copy_internal(
454 md_maps
, in_option_fc
);
455 if (!out_option_field_class
) {
456 BT_COMP_LOGE_STR("Cannot copy field class.");
460 ret
= copy_field_class_content_internal(md_maps
, in_option_fc
,
461 out_option_field_class
);
463 BT_COMP_LOGE_STR("Error copying content of option variant "
468 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
) {
469 const bt_field_class_variant_with_selector_unsigned_option
*spec_opt
=
470 bt_field_class_variant_with_selector_unsigned_borrow_option_by_index_const(
472 const bt_integer_range_set_unsigned
*ranges
=
473 bt_field_class_variant_with_selector_unsigned_option_borrow_ranges_const(
476 if (bt_field_class_variant_with_selector_unsigned_append_option(
477 out_field_class
, option_name
,
478 out_option_field_class
, ranges
) !=
479 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK
) {
480 BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned selector'");
481 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
485 } else if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
) {
486 const bt_field_class_variant_with_selector_signed_option
*spec_opt
=
487 bt_field_class_variant_with_selector_signed_borrow_option_by_index_const(
489 const bt_integer_range_set_signed
*ranges
=
490 bt_field_class_variant_with_selector_signed_option_borrow_ranges_const(
493 if (bt_field_class_variant_with_selector_signed_append_option(
494 out_field_class
, option_name
,
495 out_option_field_class
, ranges
) !=
496 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK
) {
497 BT_COMP_LOGE_STR("Cannot append option to variant field class with signed selector'");
498 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
503 BT_ASSERT(fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
);
505 if (bt_field_class_variant_without_selector_append_option(
506 out_field_class
, option_name
,
507 out_option_field_class
) !=
508 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_APPEND_OPTION_STATUS_OK
) {
509 BT_COMP_LOGE_STR("Cannot append option to variant field class'");
510 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
516 out_option
= bt_field_class_variant_borrow_option_by_index(
518 BT_ASSERT(out_option
);
521 * Safe to use the same value object because it's frozen
524 bt_field_class_variant_option_set_user_attributes(
526 bt_field_class_variant_option_borrow_user_attributes_const(
530 BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
531 "out-fc-addr=%p", in_field_class
, out_field_class
);
538 int field_class_static_array_copy(
539 struct trace_ir_metadata_maps
*md_maps
,
540 const bt_field_class
*in_field_class
,
541 bt_field_class
*out_field_class
)
543 BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, "
544 "out-fc-addr=%p", in_field_class
, out_field_class
);
546 * There is no content to copy. Keep this function call anyway for
549 BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, "
550 "out-fc-addr=%p", in_field_class
, out_field_class
);
556 int field_class_dynamic_array_copy(
557 struct trace_ir_metadata_maps
*md_maps
,
558 const bt_field_class
*in_field_class
,
559 bt_field_class
*out_field_class
)
561 BT_COMP_LOGD("Copying content of dynamic array field class: "
562 "in-fc-addr=%p, out-fc-addr=%p",
563 in_field_class
, out_field_class
);
566 * There is no content to copy. Keep this function call anyway for
569 BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, "
570 "out-fc-addr=%p", in_field_class
, out_field_class
);
576 int field_class_option_copy(
577 struct trace_ir_metadata_maps
*md_maps
,
578 const bt_field_class
*in_field_class
,
579 bt_field_class
*out_field_class
)
581 BT_COMP_LOGD("Copying content of option field class: "
582 "in-fc-addr=%p, out-fc-addr=%p",
583 in_field_class
, out_field_class
);
586 * There is no content to copy. Keep this function call anyway for
589 BT_COMP_LOGD("Copied option field class: in-fc-addr=%p, "
590 "out-fc-addr=%p", in_field_class
, out_field_class
);
596 int field_class_string_copy(struct trace_ir_metadata_maps
*md_maps
,
597 const bt_field_class
*in_field_class
,
598 bt_field_class
*out_field_class
)
600 BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, "
601 "out-fc-addr=%p", in_field_class
, out_field_class
);
603 * There is no content to copy. Keep this function call anyway for
606 BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, "
607 "out-fc-addr=%p", in_field_class
, out_field_class
);
613 bt_field_class
*copy_field_class_array_element(struct trace_ir_metadata_maps
*md_maps
,
614 const bt_field_class
*in_elem_fc
)
617 bt_field_class
*out_elem_fc
=
618 create_field_class_copy_internal(md_maps
, in_elem_fc
);
620 BT_COMP_LOGE("Error creating output elem field class "
621 "from input elem field class for static array: "
622 "in-fc-addr=%p", in_elem_fc
);
626 ret
= copy_field_class_content_internal(md_maps
, in_elem_fc
, out_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
);
631 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc
);
640 bt_field_class
*create_field_class_copy_internal(struct trace_ir_metadata_maps
*md_maps
,
641 const bt_field_class
*in_field_class
)
643 bt_field_class
*out_field_class
= NULL
;
644 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
646 BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p",
650 case BT_FIELD_CLASS_TYPE_BOOL
:
651 out_field_class
= bt_field_class_bool_create(
652 md_maps
->output_trace_class
);
654 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
655 out_field_class
= bt_field_class_bit_array_create(
656 md_maps
->output_trace_class
,
657 bt_field_class_bit_array_get_length(
660 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
661 out_field_class
= bt_field_class_integer_unsigned_create(
662 md_maps
->output_trace_class
);
664 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
665 out_field_class
= bt_field_class_integer_signed_create(
666 md_maps
->output_trace_class
);
668 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
669 out_field_class
= bt_field_class_enumeration_unsigned_create(
670 md_maps
->output_trace_class
);
672 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
673 out_field_class
= bt_field_class_enumeration_signed_create(
674 md_maps
->output_trace_class
);
676 case BT_FIELD_CLASS_TYPE_REAL
:
677 out_field_class
= bt_field_class_real_create(
678 md_maps
->output_trace_class
);
680 case BT_FIELD_CLASS_TYPE_STRING
:
681 out_field_class
= bt_field_class_string_create(
682 md_maps
->output_trace_class
);
684 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
685 out_field_class
= bt_field_class_structure_create(
686 md_maps
->output_trace_class
);
688 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
690 const bt_field_class
*in_elem_fc
=
691 bt_field_class_array_borrow_element_field_class_const(
694 bt_field_class_array_static_get_length(in_field_class
);
696 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
697 md_maps
, in_elem_fc
);
699 out_field_class
= NULL
;
703 out_field_class
= bt_field_class_array_static_create(
704 md_maps
->output_trace_class
,
705 out_elem_fc
, array_len
);
708 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
710 const bt_field_class
*in_elem_fc
=
711 bt_field_class_array_borrow_element_field_class_const(
713 const bt_field_path
*length_fp
=
714 bt_field_class_array_dynamic_borrow_length_field_path_const(
716 bt_field_class
*out_length_fc
= NULL
;
718 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
719 md_maps
, in_elem_fc
);
721 out_field_class
= NULL
;
726 const bt_field_class
*in_length_fc
=
727 resolve_field_path_to_field_class(length_fp
,
730 BT_ASSERT(in_length_fc
);
731 out_length_fc
= g_hash_table_lookup(md_maps
->field_class_map
,
733 BT_ASSERT(out_length_fc
);
736 out_field_class
= bt_field_class_array_dynamic_create(
737 md_maps
->output_trace_class
,
738 out_elem_fc
, out_length_fc
);
741 case BT_FIELD_CLASS_TYPE_OPTION
:
743 const bt_field_class
*in_content_fc
=
744 bt_field_class_option_borrow_field_class_const(
746 const bt_field_path
*in_selector_fp
=
747 bt_field_class_option_borrow_selector_field_path_const(
749 bt_field_class
*out_selector_fc
= NULL
;
750 bt_field_class
*out_content_fc
;
753 out_content_fc
= create_field_class_copy_internal(
754 md_maps
, in_content_fc
);
755 if (!out_content_fc
) {
756 BT_COMP_LOGE_STR("Cannot copy option's content field class.");
760 ret
= copy_field_class_content_internal(md_maps
,
761 in_content_fc
, out_content_fc
);
763 BT_COMP_LOGE_STR("Error copying content of option's "
764 "content field class");
768 if (in_selector_fp
) {
769 const bt_field_class
*in_selector_fc
=
770 resolve_field_path_to_field_class(
771 in_selector_fp
, md_maps
);
773 BT_ASSERT(in_selector_fc
);
774 out_selector_fc
= g_hash_table_lookup(
775 md_maps
->field_class_map
, in_selector_fc
);
776 BT_ASSERT(out_selector_fc
);
779 out_field_class
= bt_field_class_option_create(
780 md_maps
->output_trace_class
,
781 out_content_fc
, out_selector_fc
);
784 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
785 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
786 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
788 bt_field_class
*out_sel_fc
= NULL
;
790 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
||
791 fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
) {
792 const bt_field_class
*in_sel_fc
;
793 const bt_field_path
*sel_fp
=
794 bt_field_class_variant_with_selector_borrow_selector_field_path_const(
798 in_sel_fc
= resolve_field_path_to_field_class(sel_fp
,
800 BT_ASSERT(in_sel_fc
);
801 out_sel_fc
= g_hash_table_lookup(
802 md_maps
->field_class_map
, in_sel_fc
);
803 BT_ASSERT(out_sel_fc
);
806 out_field_class
= bt_field_class_variant_create(
807 md_maps
->output_trace_class
, out_sel_fc
);
815 * Add mapping from in_field_class to out_field_class. This simplifies
816 * the resolution of field paths in variant and dynamic array field
819 g_hash_table_insert(md_maps
->field_class_map
,
820 (gpointer
) in_field_class
, out_field_class
);
824 BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, "
825 "out-fc-addr=%p", in_field_class
, out_field_class
);
827 BT_COMP_LOGE("Error creating output field class from input field "
828 "class: in-fc-addr=%p", in_field_class
);
831 return out_field_class
;
835 int copy_field_class_content_internal(
836 struct trace_ir_metadata_maps
*md_maps
,
837 const bt_field_class
*in_field_class
,
838 bt_field_class
*out_field_class
)
843 * Safe to use the same value object because it's frozen at this
846 bt_field_class_set_user_attributes(out_field_class
,
847 bt_field_class_borrow_user_attributes_const(in_field_class
));
849 switch(bt_field_class_get_type(in_field_class
)) {
850 case BT_FIELD_CLASS_TYPE_BOOL
:
851 ret
= field_class_bool_copy(md_maps
,
852 in_field_class
, out_field_class
);
854 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
855 ret
= field_class_bit_array_copy(md_maps
,
856 in_field_class
, out_field_class
);
858 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
859 ret
= field_class_unsigned_integer_copy(md_maps
,
860 in_field_class
, out_field_class
);
862 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
863 ret
= field_class_signed_integer_copy(md_maps
,
864 in_field_class
, out_field_class
);
866 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
867 ret
= field_class_unsigned_enumeration_copy(md_maps
,
868 in_field_class
, out_field_class
);
870 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
871 ret
= field_class_signed_enumeration_copy(md_maps
,
872 in_field_class
, out_field_class
);
874 case BT_FIELD_CLASS_TYPE_REAL
:
875 ret
= field_class_real_copy(md_maps
,
876 in_field_class
, out_field_class
);
878 case BT_FIELD_CLASS_TYPE_STRING
:
879 ret
= field_class_string_copy(md_maps
,
880 in_field_class
, out_field_class
);
882 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
883 ret
= field_class_structure_copy(md_maps
,
884 in_field_class
, out_field_class
);
886 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
887 ret
= field_class_static_array_copy(md_maps
,
888 in_field_class
, out_field_class
);
890 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
891 ret
= field_class_dynamic_array_copy(md_maps
,
892 in_field_class
, out_field_class
);
894 case BT_FIELD_CLASS_TYPE_OPTION
:
895 ret
= field_class_option_copy(md_maps
,
896 in_field_class
, out_field_class
);
898 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
899 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
900 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
901 ret
= field_class_variant_copy(md_maps
,
902 in_field_class
, out_field_class
);