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_unsigned_integer_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 unsigned integer field class: "
186 "in-fc-addr=%p, out-fc-addr=%p",
187 in_field_class
, out_field_class
);
189 field_class_integer_set_props(in_field_class
, out_field_class
);
191 BT_COMP_LOGD("Copied content of unsigned integer field class: "
192 "in-fc-addr=%p, out-fc-addr=%p",
193 in_field_class
, out_field_class
);
198 int field_class_signed_integer_copy(
199 struct trace_ir_metadata_maps
*md_maps
,
200 const bt_field_class
*in_field_class
,
201 bt_field_class
*out_field_class
)
203 BT_COMP_LOGD("Copying content of signed integer field class: "
204 "in-fc-addr=%p, out-fc-addr=%p",
205 in_field_class
, out_field_class
);
207 field_class_integer_set_props(in_field_class
, out_field_class
);
209 BT_COMP_LOGD("Copied content of signed integer field class: "
210 "in-fc-addr=%p, out-fc-addr=%p",
211 in_field_class
, out_field_class
);
216 int field_class_unsigned_enumeration_copy(
217 struct trace_ir_metadata_maps
*md_maps
,
218 const bt_field_class
*in_field_class
,
219 bt_field_class
*out_field_class
)
221 uint64_t i
, enum_mapping_count
;
224 BT_COMP_LOGD("Copying content of unsigned enumeration field class: "
225 "in-fc-addr=%p, out-fc-addr=%p",
226 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(in_field_class
);
233 for (i
= 0; i
< enum_mapping_count
; i
++) {
235 const bt_integer_range_set_unsigned
*range_set
;
236 const bt_field_class_enumeration_unsigned_mapping
*u_mapping
;
237 const bt_field_class_enumeration_mapping
*mapping
;
239 u_mapping
= bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const(
241 mapping
= bt_field_class_enumeration_unsigned_mapping_as_mapping_const(
243 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
244 range_set
= bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const(
246 ret
= bt_field_class_enumeration_unsigned_add_mapping(
247 out_field_class
, label
, range_set
);
253 BT_COMP_LOGD("Copied content of unsigned enumeration field class: "
254 "in-fc-addr=%p, out-fc-addr=%p",
255 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",
272 in_field_class
, out_field_class
);
274 /* Copy properties of the inner integer. */
275 field_class_integer_set_props(in_field_class
, out_field_class
);
277 /* Copy all enumeration entries. */
279 bt_field_class_enumeration_get_mapping_count(in_field_class
);
280 for (i
= 0; i
< enum_mapping_count
; i
++) {
282 const bt_integer_range_set_signed
*range_set
;
283 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
284 const bt_field_class_enumeration_mapping
*mapping
;
286 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
288 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
290 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
291 range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
293 ret
= bt_field_class_enumeration_signed_add_mapping(
294 out_field_class
, label
, range_set
);
300 BT_COMP_LOGD("Copied content of signed enumeration field class: "
301 "in-fc-addr=%p, out-fc-addr=%p",
302 in_field_class
, out_field_class
);
309 int field_class_real_copy(
310 struct trace_ir_metadata_maps
*md_maps
,
311 const bt_field_class
*in_field_class
,
312 bt_field_class
*out_field_class
)
314 BT_COMP_LOGD("Copying content of real field class: "
315 "in-fc-addr=%p, out-fc-addr=%p",
316 in_field_class
, out_field_class
);
318 bt_field_class_real_set_is_single_precision(out_field_class
,
319 bt_field_class_real_is_single_precision(in_field_class
));
321 BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, "
322 "out-fc-addr=%p", in_field_class
, out_field_class
);
328 int field_class_structure_copy(
329 struct trace_ir_metadata_maps
*md_maps
,
330 const bt_field_class
*in_field_class
,
331 bt_field_class
*out_field_class
)
333 uint64_t i
, struct_member_count
;
336 BT_COMP_LOGD("Copying content of structure field class: "
337 "in-fc-addr=%p, out-fc-addr=%p",
338 in_field_class
, out_field_class
);
339 /* Get the number of member in that struct. */
340 struct_member_count
=
341 bt_field_class_structure_get_member_count(in_field_class
);
343 /* Iterate over all the members of the struct. */
344 for (i
= 0; i
< struct_member_count
; i
++) {
345 const bt_field_class_structure_member
*member
;
346 const char *member_name
;
347 const bt_field_class
*member_fc
;
348 bt_field_class
*out_member_field_class
;
350 member
= bt_field_class_structure_borrow_member_by_index_const(
352 member_fc
= bt_field_class_structure_member_borrow_field_class_const(
354 member_name
= bt_field_class_structure_member_get_name(member
);
355 BT_COMP_LOGD("Copying structure field class's field: "
356 "index=%" PRId64
", "
357 "member-fc-addr=%p, field-name=\"%s\"",
358 i
, member_fc
, member_name
);
360 out_member_field_class
= create_field_class_copy(md_maps
,
362 if (!out_member_field_class
) {
363 BT_COMP_LOGE("Cannot copy structure field class's field: "
364 "index=%" PRId64
", "
365 "field-fc-addr=%p, field-name=\"%s\"",
366 i
, member_fc
, member_name
);
370 ret
= copy_field_class_content(md_maps
, member_fc
,
371 out_member_field_class
);
376 if (bt_field_class_structure_append_member(out_field_class
,
377 member_name
, out_member_field_class
) !=
378 BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK
) {
379 BT_COMP_LOGE("Cannot append structure field class's field: "
380 "index=%" PRId64
", "
381 "field-fc-addr=%p, field-name=\"%s\"",
382 i
, member_fc
, member_name
);
383 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class
);
389 BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
390 in_field_class
, out_field_class
);
397 int field_class_variant_copy(
398 struct trace_ir_metadata_maps
*md_maps
,
399 const bt_field_class
*in_field_class
,
400 bt_field_class
*out_field_class
)
402 bt_field_class
*out_tag_field_class
= NULL
;
403 uint64_t i
, variant_option_count
;
404 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
407 BT_COMP_LOGD("Copying content of variant field class: "
408 "in-fc-addr=%p, out-fc-addr=%p",
409 in_field_class
, out_field_class
);
410 variant_option_count
=
411 bt_field_class_variant_get_option_count(in_field_class
);
412 for (i
= 0; i
< variant_option_count
; i
++) {
413 const bt_field_class
*option_fc
;
414 const char *option_name
;
415 bt_field_class
*out_option_field_class
;
416 const bt_field_class_variant_option
*option
;
418 option
= bt_field_class_variant_borrow_option_by_index_const(
420 option_fc
= bt_field_class_variant_option_borrow_field_class_const(
422 option_name
= bt_field_class_variant_option_get_name(option
);
423 out_option_field_class
= create_field_class_copy_internal(
425 if (!out_option_field_class
) {
426 BT_COMP_LOGE_STR("Cannot copy field class.");
430 ret
= copy_field_class_content_internal(md_maps
, option_fc
,
431 out_option_field_class
);
433 BT_COMP_LOGE_STR("Error copying content of option variant "
438 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
) {
439 const bt_field_class_variant_with_selector_unsigned_option
*spec_opt
=
440 bt_field_class_variant_with_selector_unsigned_borrow_option_by_index_const(
442 const bt_integer_range_set_unsigned
*ranges
=
443 bt_field_class_variant_with_selector_unsigned_option_borrow_ranges_const(
446 if (bt_field_class_variant_with_selector_unsigned_append_option(
447 out_field_class
, option_name
,
448 out_option_field_class
, ranges
) !=
449 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK
) {
450 BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned selector'");
451 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
455 } else if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
) {
456 const bt_field_class_variant_with_selector_signed_option
*spec_opt
=
457 bt_field_class_variant_with_selector_signed_borrow_option_by_index_const(
459 const bt_integer_range_set_signed
*ranges
=
460 bt_field_class_variant_with_selector_signed_option_borrow_ranges_const(
463 if (bt_field_class_variant_with_selector_signed_append_option(
464 out_field_class
, option_name
,
465 out_option_field_class
, ranges
) !=
466 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK
) {
467 BT_COMP_LOGE_STR("Cannot append option to variant field class with signed selector'");
468 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
473 BT_ASSERT(fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
);
475 if (bt_field_class_variant_without_selector_append_option(
476 out_field_class
, option_name
,
477 out_option_field_class
) !=
478 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_APPEND_OPTION_STATUS_OK
) {
479 BT_COMP_LOGE_STR("Cannot append option to variant field class'");
480 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
487 BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
488 "out-fc-addr=%p", in_field_class
, out_field_class
);
495 int field_class_static_array_copy(
496 struct trace_ir_metadata_maps
*md_maps
,
497 const bt_field_class
*in_field_class
,
498 bt_field_class
*out_field_class
)
500 BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, "
501 "out-fc-addr=%p", in_field_class
, out_field_class
);
503 * There is no content to copy. Keep this function call anyway for
506 BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, "
507 "out-fc-addr=%p", in_field_class
, out_field_class
);
513 int field_class_dynamic_array_copy(
514 struct trace_ir_metadata_maps
*md_maps
,
515 const bt_field_class
*in_field_class
,
516 bt_field_class
*out_field_class
)
518 BT_COMP_LOGD("Copying content of dynamic array field class: "
519 "in-fc-addr=%p, out-fc-addr=%p",
520 in_field_class
, out_field_class
);
523 * There is no content to copy. Keep this function call anyway for
526 BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, "
527 "out-fc-addr=%p", in_field_class
, out_field_class
);
533 int field_class_option_copy(
534 struct trace_ir_metadata_maps
*md_maps
,
535 const bt_field_class
*in_field_class
,
536 bt_field_class
*out_field_class
)
538 BT_COMP_LOGD("Copying content of option field class: "
539 "in-fc-addr=%p, out-fc-addr=%p",
540 in_field_class
, out_field_class
);
543 * There is no content to copy. Keep this function call anyway for
546 BT_COMP_LOGD("Copied option field class: in-fc-addr=%p, "
547 "out-fc-addr=%p", in_field_class
, out_field_class
);
553 int field_class_string_copy(struct trace_ir_metadata_maps
*md_maps
,
554 const bt_field_class
*in_field_class
,
555 bt_field_class
*out_field_class
)
557 BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, "
558 "out-fc-addr=%p", in_field_class
, out_field_class
);
560 * There is no content to copy. Keep this function call anyway for
563 BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, "
564 "out-fc-addr=%p", in_field_class
, out_field_class
);
570 bt_field_class
*copy_field_class_array_element(struct trace_ir_metadata_maps
*md_maps
,
571 const bt_field_class
*in_elem_fc
)
574 bt_field_class
*out_elem_fc
=
575 create_field_class_copy_internal(md_maps
, in_elem_fc
);
577 BT_COMP_LOGE("Error creating output elem field class "
578 "from input elem field class for static array: "
579 "in-fc-addr=%p", in_elem_fc
);
583 ret
= copy_field_class_content_internal(md_maps
, in_elem_fc
, out_elem_fc
);
585 BT_COMP_LOGE("Error creating output elem field class "
586 "from input elem field class for static array: "
587 "in-fc-addr=%p", in_elem_fc
);
588 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc
);
597 bt_field_class
*create_field_class_copy_internal(struct trace_ir_metadata_maps
*md_maps
,
598 const bt_field_class
*in_field_class
)
600 bt_field_class
*out_field_class
= NULL
;
601 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
603 BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p",
607 case BT_FIELD_CLASS_TYPE_BOOL
:
608 out_field_class
= bt_field_class_bool_create(
609 md_maps
->output_trace_class
);
611 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
612 out_field_class
= bt_field_class_integer_unsigned_create(
613 md_maps
->output_trace_class
);
615 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
616 out_field_class
= bt_field_class_integer_signed_create(
617 md_maps
->output_trace_class
);
619 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
620 out_field_class
= bt_field_class_enumeration_unsigned_create(
621 md_maps
->output_trace_class
);
623 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
624 out_field_class
= bt_field_class_enumeration_signed_create(
625 md_maps
->output_trace_class
);
627 case BT_FIELD_CLASS_TYPE_REAL
:
628 out_field_class
= bt_field_class_real_create(
629 md_maps
->output_trace_class
);
631 case BT_FIELD_CLASS_TYPE_STRING
:
632 out_field_class
= bt_field_class_string_create(
633 md_maps
->output_trace_class
);
635 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
636 out_field_class
= bt_field_class_structure_create(
637 md_maps
->output_trace_class
);
639 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
641 const bt_field_class
*in_elem_fc
=
642 bt_field_class_array_borrow_element_field_class_const(
645 bt_field_class_array_static_get_length(in_field_class
);
647 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
648 md_maps
, in_elem_fc
);
650 out_field_class
= NULL
;
654 out_field_class
= bt_field_class_array_static_create(
655 md_maps
->output_trace_class
,
656 out_elem_fc
, array_len
);
659 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
661 const bt_field_class
*in_elem_fc
=
662 bt_field_class_array_borrow_element_field_class_const(
664 const bt_field_path
*length_fp
=
665 bt_field_class_array_dynamic_borrow_length_field_path_const(
667 bt_field_class
*out_length_fc
= NULL
;
669 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
670 md_maps
, in_elem_fc
);
672 out_field_class
= NULL
;
677 const bt_field_class
*in_length_fc
=
678 resolve_field_path_to_field_class(length_fp
,
681 BT_ASSERT(in_length_fc
);
682 out_length_fc
= g_hash_table_lookup(md_maps
->field_class_map
,
684 BT_ASSERT(out_length_fc
);
687 out_field_class
= bt_field_class_array_dynamic_create(
688 md_maps
->output_trace_class
,
689 out_elem_fc
, out_length_fc
);
692 case BT_FIELD_CLASS_TYPE_OPTION
:
694 const bt_field_class
*in_content_fc
=
695 bt_field_class_option_borrow_field_class_const(
697 const bt_field_path
*in_selector_fp
=
698 bt_field_class_option_borrow_selector_field_path_const(
700 bt_field_class
*out_selector_fc
= NULL
;
701 bt_field_class
*out_content_fc
;
704 out_content_fc
= create_field_class_copy_internal(
705 md_maps
, in_content_fc
);
706 if (!out_content_fc
) {
707 BT_COMP_LOGE_STR("Cannot copy option's content field class.");
711 ret
= copy_field_class_content_internal(md_maps
,
712 in_content_fc
, out_content_fc
);
714 BT_COMP_LOGE_STR("Error copying content of option's "
715 "content field class");
719 if (in_selector_fp
) {
720 const bt_field_class
*in_selector_fc
=
721 resolve_field_path_to_field_class(
722 in_selector_fp
, md_maps
);
724 BT_ASSERT(in_selector_fc
);
725 out_selector_fc
= g_hash_table_lookup(
726 md_maps
->field_class_map
, in_selector_fc
);
727 BT_ASSERT(out_selector_fc
);
730 out_field_class
= bt_field_class_option_create(
731 md_maps
->output_trace_class
,
732 out_content_fc
, out_selector_fc
);
735 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
736 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
737 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
739 bt_field_class
*out_sel_fc
= NULL
;
741 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
||
742 fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
) {
743 const bt_field_class
*in_sel_fc
;
744 const bt_field_path
*sel_fp
=
745 bt_field_class_variant_with_selector_borrow_selector_field_path_const(
749 in_sel_fc
= resolve_field_path_to_field_class(sel_fp
,
751 BT_ASSERT(in_sel_fc
);
752 out_sel_fc
= g_hash_table_lookup(
753 md_maps
->field_class_map
, in_sel_fc
);
754 BT_ASSERT(out_sel_fc
);
757 out_field_class
= bt_field_class_variant_create(
758 md_maps
->output_trace_class
, out_sel_fc
);
766 * Add mapping from in_field_class to out_field_class. This simplifies
767 * the resolution of field paths in variant and dynamic array field
770 g_hash_table_insert(md_maps
->field_class_map
,
771 (gpointer
) in_field_class
, out_field_class
);
775 BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, "
776 "out-fc-addr=%p", in_field_class
, out_field_class
);
778 BT_COMP_LOGE("Error creating output field class from input field "
779 "class: in-fc-addr=%p", in_field_class
);
782 return out_field_class
;
786 int copy_field_class_content_internal(
787 struct trace_ir_metadata_maps
*md_maps
,
788 const bt_field_class
*in_field_class
,
789 bt_field_class
*out_field_class
)
792 switch(bt_field_class_get_type(in_field_class
)) {
793 case BT_FIELD_CLASS_TYPE_BOOL
:
794 ret
= field_class_bool_copy(md_maps
,
795 in_field_class
, out_field_class
);
797 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
798 ret
= field_class_unsigned_integer_copy(md_maps
,
799 in_field_class
, out_field_class
);
801 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
802 ret
= field_class_signed_integer_copy(md_maps
,
803 in_field_class
, out_field_class
);
805 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
806 ret
= field_class_unsigned_enumeration_copy(md_maps
,
807 in_field_class
, out_field_class
);
809 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
810 ret
= field_class_signed_enumeration_copy(md_maps
,
811 in_field_class
, out_field_class
);
813 case BT_FIELD_CLASS_TYPE_REAL
:
814 ret
= field_class_real_copy(md_maps
,
815 in_field_class
, out_field_class
);
817 case BT_FIELD_CLASS_TYPE_STRING
:
818 ret
= field_class_string_copy(md_maps
,
819 in_field_class
, out_field_class
);
821 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
822 ret
= field_class_structure_copy(md_maps
,
823 in_field_class
, out_field_class
);
825 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
826 ret
= field_class_static_array_copy(md_maps
,
827 in_field_class
, out_field_class
);
829 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
830 ret
= field_class_dynamic_array_copy(md_maps
,
831 in_field_class
, out_field_class
);
833 case BT_FIELD_CLASS_TYPE_OPTION
:
834 ret
= field_class_option_copy(md_maps
,
835 in_field_class
, out_field_class
);
837 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
838 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR
:
839 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR
:
840 ret
= field_class_variant_copy(md_maps
,
841 in_field_class
, out_field_class
);