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
:
78 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
:
79 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
:
80 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
:
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
:
89 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
:
90 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
:
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
:
106 BT_ASSERT(bt_field_path_item_get_type(fp_item
) ==
107 BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
);
108 curr_fc
= bt_field_class_array_borrow_element_field_class_const(
121 const bt_field_class
*resolve_field_path_to_field_class(const bt_field_path
*fp
,
122 struct trace_ir_metadata_maps
*md_maps
)
124 struct field_class_resolving_context
*fc_resolving_ctx
;
125 const bt_field_class
*fc
;
126 bt_field_path_scope fp_scope
;
128 BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp
);
130 fc_resolving_ctx
= md_maps
->fc_resolving_ctx
;
131 fp_scope
= bt_field_path_get_root_scope(fp
);
134 case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
:
135 fc
= walk_field_path(md_maps
, fp
,
136 fc_resolving_ctx
->packet_context
);
138 case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
:
139 fc
= walk_field_path(md_maps
, fp
,
140 fc_resolving_ctx
->event_common_context
);
142 case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
:
143 fc
= walk_field_path(md_maps
, fp
,
144 fc_resolving_ctx
->event_specific_context
);
146 case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
:
147 fc
= walk_field_path(md_maps
, fp
,
148 fc_resolving_ctx
->event_payload
);
158 void field_class_integer_set_props(const bt_field_class
*input_fc
,
159 bt_field_class
*output_fc
)
161 bt_field_class_integer_set_preferred_display_base(output_fc
,
162 bt_field_class_integer_get_preferred_display_base(input_fc
));
163 bt_field_class_integer_set_field_value_range(output_fc
,
164 bt_field_class_integer_get_field_value_range(input_fc
));
168 int field_class_bool_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 boolean field class: "
174 "in-fc-addr=%p, out-fc-addr=%p",
175 in_field_class
, out_field_class
);
176 BT_COMP_LOGD("Copied content of boolean field class: "
177 "in-fc-addr=%p, out-fc-addr=%p",
178 in_field_class
, out_field_class
);
183 int field_class_bit_array_copy(
184 struct trace_ir_metadata_maps
*md_maps
,
185 const bt_field_class
*in_field_class
,
186 bt_field_class
*out_field_class
)
188 BT_COMP_LOGD("Copying content of bit array field class: "
189 "in-fc-addr=%p, out-fc-addr=%p",
190 in_field_class
, out_field_class
);
191 BT_COMP_LOGD("Copied content of bit array field class: "
192 "in-fc-addr=%p, out-fc-addr=%p",
193 in_field_class
, out_field_class
);
198 int field_class_unsigned_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 unsigned 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 unsigned integer field class: "
210 "in-fc-addr=%p, out-fc-addr=%p",
211 in_field_class
, out_field_class
);
216 int field_class_signed_integer_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 BT_COMP_LOGD("Copying content of signed integer field class: "
222 "in-fc-addr=%p, out-fc-addr=%p",
223 in_field_class
, out_field_class
);
225 field_class_integer_set_props(in_field_class
, out_field_class
);
227 BT_COMP_LOGD("Copied content of signed integer field class: "
228 "in-fc-addr=%p, out-fc-addr=%p",
229 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",
244 in_field_class
, out_field_class
);
246 /* Copy properties of the inner integer. */
247 field_class_integer_set_props(in_field_class
, out_field_class
);
249 /* Copy all enumeration entries. */
250 enum_mapping_count
= bt_field_class_enumeration_get_mapping_count(in_field_class
);
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",
273 in_field_class
, out_field_class
);
280 int field_class_signed_enumeration_copy(
281 struct trace_ir_metadata_maps
*md_maps
,
282 const bt_field_class
*in_field_class
,
283 bt_field_class
*out_field_class
)
285 uint64_t i
, enum_mapping_count
;
288 BT_COMP_LOGD("Copying content of signed enumeration field class: "
289 "in-fc-addr=%p, out-fc-addr=%p",
290 in_field_class
, out_field_class
);
292 /* Copy properties of the inner integer. */
293 field_class_integer_set_props(in_field_class
, out_field_class
);
295 /* Copy all enumeration entries. */
297 bt_field_class_enumeration_get_mapping_count(in_field_class
);
298 for (i
= 0; i
< enum_mapping_count
; i
++) {
300 const bt_integer_range_set_signed
*range_set
;
301 const bt_field_class_enumeration_signed_mapping
*s_mapping
;
302 const bt_field_class_enumeration_mapping
*mapping
;
304 s_mapping
= bt_field_class_enumeration_signed_borrow_mapping_by_index_const(
306 mapping
= bt_field_class_enumeration_signed_mapping_as_mapping_const(
308 label
= bt_field_class_enumeration_mapping_get_label(mapping
);
309 range_set
= bt_field_class_enumeration_signed_mapping_borrow_ranges_const(
311 ret
= bt_field_class_enumeration_signed_add_mapping(
312 out_field_class
, label
, range_set
);
318 BT_COMP_LOGD("Copied content of signed enumeration field class: "
319 "in-fc-addr=%p, out-fc-addr=%p",
320 in_field_class
, out_field_class
);
327 int field_class_single_precision_real_copy(
328 struct trace_ir_metadata_maps
*md_maps
,
329 const bt_field_class
*in_field_class
,
330 bt_field_class
*out_field_class
)
332 BT_COMP_LOGD("Copying content of single-precision real field class: "
333 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
335 BT_COMP_LOGD("Copied content single-precision real field class:"
336 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
342 int field_class_double_precision_real_copy(
343 struct trace_ir_metadata_maps
*md_maps
,
344 const bt_field_class
*in_field_class
,
345 bt_field_class
*out_field_class
)
347 BT_COMP_LOGD("Copying content of double-precision real field class: "
348 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
350 BT_COMP_LOGD("Copied content double-precision real field class:"
351 "in-fc-addr=%p, out-fc-addr=%p", in_field_class
, out_field_class
);
357 int field_class_structure_copy(
358 struct trace_ir_metadata_maps
*md_maps
,
359 const bt_field_class
*in_field_class
,
360 bt_field_class
*out_field_class
)
362 uint64_t i
, struct_member_count
;
365 BT_COMP_LOGD("Copying content of structure field class: "
366 "in-fc-addr=%p, out-fc-addr=%p",
367 in_field_class
, out_field_class
);
368 /* Get the number of member in that struct. */
369 struct_member_count
=
370 bt_field_class_structure_get_member_count(in_field_class
);
372 /* Iterate over all the members of the struct. */
373 for (i
= 0; i
< struct_member_count
; i
++) {
374 const bt_field_class_structure_member
*in_member
;
375 bt_field_class_structure_member
*out_member
;
376 const char *member_name
;
377 const bt_field_class
*in_member_fc
;
378 bt_field_class
*out_member_field_class
;
380 in_member
= bt_field_class_structure_borrow_member_by_index_const(
382 in_member_fc
= bt_field_class_structure_member_borrow_field_class_const(
384 member_name
= bt_field_class_structure_member_get_name(in_member
);
385 BT_COMP_LOGD("Copying structure field class's field: "
386 "index=%" PRId64
", "
387 "member-fc-addr=%p, field-name=\"%s\"",
388 i
, in_member_fc
, member_name
);
390 out_member_field_class
= create_field_class_copy(md_maps
,
392 if (!out_member_field_class
) {
393 BT_COMP_LOGE("Cannot copy structure field class's field: "
394 "index=%" PRId64
", "
395 "field-fc-addr=%p, field-name=\"%s\"",
396 i
, in_member_fc
, member_name
);
400 ret
= copy_field_class_content(md_maps
, in_member_fc
,
401 out_member_field_class
);
406 if (bt_field_class_structure_append_member(out_field_class
,
407 member_name
, out_member_field_class
) !=
408 BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK
) {
409 BT_COMP_LOGE("Cannot append structure field class's field: "
410 "index=%" PRId64
", "
411 "field-fc-addr=%p, field-name=\"%s\"",
412 i
, in_member_fc
, member_name
);
413 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class
);
418 out_member
= bt_field_class_structure_borrow_member_by_index(
420 BT_ASSERT(out_member
);
423 * Safe to use the same value object because it's frozen
426 bt_field_class_structure_member_set_user_attributes(
428 bt_field_class_structure_member_borrow_user_attributes_const(
432 BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p",
433 in_field_class
, out_field_class
);
440 int field_class_variant_copy(
441 struct trace_ir_metadata_maps
*md_maps
,
442 const bt_field_class
*in_field_class
,
443 bt_field_class
*out_field_class
)
445 bt_field_class
*out_tag_field_class
= NULL
;
446 uint64_t i
, variant_option_count
;
447 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
450 BT_COMP_LOGD("Copying content of variant field class: "
451 "in-fc-addr=%p, out-fc-addr=%p",
452 in_field_class
, out_field_class
);
453 variant_option_count
=
454 bt_field_class_variant_get_option_count(in_field_class
);
455 for (i
= 0; i
< variant_option_count
; i
++) {
456 const bt_field_class
*in_option_fc
;
457 const char *option_name
;
458 bt_field_class
*out_option_field_class
;
459 const bt_field_class_variant_option
*in_option
;
460 bt_field_class_variant_option
*out_option
;
462 in_option
= bt_field_class_variant_borrow_option_by_index_const(
464 in_option_fc
= bt_field_class_variant_option_borrow_field_class_const(
466 option_name
= bt_field_class_variant_option_get_name(in_option
);
467 out_option_field_class
= create_field_class_copy_internal(
468 md_maps
, in_option_fc
);
469 if (!out_option_field_class
) {
470 BT_COMP_LOGE_STR("Cannot copy field class.");
474 ret
= copy_field_class_content_internal(md_maps
, in_option_fc
,
475 out_option_field_class
);
477 BT_COMP_LOGE_STR("Error copying content of option variant "
482 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
) {
483 const bt_field_class_variant_with_selector_integer_unsigned_option
*spec_opt
=
484 bt_field_class_variant_with_selector_integer_unsigned_borrow_option_by_index_const(
486 const bt_integer_range_set_unsigned
*ranges
=
487 bt_field_class_variant_with_selector_integer_unsigned_option_borrow_ranges_const(
490 if (bt_field_class_variant_with_selector_integer_unsigned_append_option(
491 out_field_class
, option_name
,
492 out_option_field_class
, ranges
) !=
493 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK
) {
494 BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned integer selector'");
495 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
499 } else if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
) {
500 const bt_field_class_variant_with_selector_integer_signed_option
*spec_opt
=
501 bt_field_class_variant_with_selector_integer_signed_borrow_option_by_index_const(
503 const bt_integer_range_set_signed
*ranges
=
504 bt_field_class_variant_with_selector_integer_signed_option_borrow_ranges_const(
507 if (bt_field_class_variant_with_selector_integer_signed_append_option(
508 out_field_class
, option_name
,
509 out_option_field_class
, ranges
) !=
510 BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK
) {
511 BT_COMP_LOGE_STR("Cannot append option to variant field class with signed integer selector'");
512 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
517 BT_ASSERT(fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
);
519 if (bt_field_class_variant_without_selector_append_option(
520 out_field_class
, option_name
,
521 out_option_field_class
) !=
522 BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_APPEND_OPTION_STATUS_OK
) {
523 BT_COMP_LOGE_STR("Cannot append option to variant field class'");
524 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class
);
530 out_option
= bt_field_class_variant_borrow_option_by_index(
532 BT_ASSERT(out_option
);
535 * Safe to use the same value object because it's frozen
538 bt_field_class_variant_option_set_user_attributes(
540 bt_field_class_variant_option_borrow_user_attributes_const(
544 BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, "
545 "out-fc-addr=%p", in_field_class
, out_field_class
);
552 int field_class_static_array_copy(
553 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 static array 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 static array field class: in-fc-addr=%p, "
564 "out-fc-addr=%p", in_field_class
, out_field_class
);
570 int field_class_dynamic_array_copy(
571 struct trace_ir_metadata_maps
*md_maps
,
572 const bt_field_class
*in_field_class
,
573 bt_field_class
*out_field_class
)
575 BT_COMP_LOGD("Copying content of dynamic array field class: "
576 "in-fc-addr=%p, out-fc-addr=%p",
577 in_field_class
, out_field_class
);
580 * There is no content to copy. Keep this function call anyway for
583 BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, "
584 "out-fc-addr=%p", in_field_class
, out_field_class
);
590 int field_class_option_copy(
591 struct trace_ir_metadata_maps
*md_maps
,
592 const bt_field_class
*in_field_class
,
593 bt_field_class
*out_field_class
)
595 BT_COMP_LOGD("Copying content of option field class: "
596 "in-fc-addr=%p, out-fc-addr=%p",
597 in_field_class
, out_field_class
);
599 if (bt_field_class_get_type(out_field_class
) ==
600 BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
) {
601 bt_field_class_option_with_selector_bool_set_selector_is_reversed(
603 bt_field_class_option_with_selector_bool_selector_is_reversed(
607 BT_COMP_LOGD("Copied option field class: in-fc-addr=%p, "
608 "out-fc-addr=%p", in_field_class
, out_field_class
);
614 int field_class_string_copy(struct trace_ir_metadata_maps
*md_maps
,
615 const bt_field_class
*in_field_class
,
616 bt_field_class
*out_field_class
)
618 BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, "
619 "out-fc-addr=%p", in_field_class
, out_field_class
);
621 * There is no content to copy. Keep this function call anyway for
624 BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, "
625 "out-fc-addr=%p", in_field_class
, out_field_class
);
631 bt_field_class
*copy_field_class_array_element(struct trace_ir_metadata_maps
*md_maps
,
632 const bt_field_class
*in_elem_fc
)
635 bt_field_class
*out_elem_fc
=
636 create_field_class_copy_internal(md_maps
, in_elem_fc
);
638 BT_COMP_LOGE("Error creating output elem field class "
639 "from input elem field class for static array: "
640 "in-fc-addr=%p", in_elem_fc
);
644 ret
= copy_field_class_content_internal(md_maps
, in_elem_fc
, out_elem_fc
);
646 BT_COMP_LOGE("Error creating output elem field class "
647 "from input elem field class for static array: "
648 "in-fc-addr=%p", in_elem_fc
);
649 BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc
);
658 bt_field_class
*create_field_class_copy_internal(struct trace_ir_metadata_maps
*md_maps
,
659 const bt_field_class
*in_field_class
)
661 bt_field_class
*out_field_class
= NULL
;
662 bt_field_class_type fc_type
= bt_field_class_get_type(in_field_class
);
664 BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p",
668 case BT_FIELD_CLASS_TYPE_BOOL
:
669 out_field_class
= bt_field_class_bool_create(
670 md_maps
->output_trace_class
);
672 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
673 out_field_class
= bt_field_class_bit_array_create(
674 md_maps
->output_trace_class
,
675 bt_field_class_bit_array_get_length(
678 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
679 out_field_class
= bt_field_class_integer_unsigned_create(
680 md_maps
->output_trace_class
);
682 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
683 out_field_class
= bt_field_class_integer_signed_create(
684 md_maps
->output_trace_class
);
686 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
687 out_field_class
= bt_field_class_enumeration_unsigned_create(
688 md_maps
->output_trace_class
);
690 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
691 out_field_class
= bt_field_class_enumeration_signed_create(
692 md_maps
->output_trace_class
);
694 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
695 out_field_class
= bt_field_class_real_single_precision_create(
696 md_maps
->output_trace_class
);
698 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
699 out_field_class
= bt_field_class_real_double_precision_create(
700 md_maps
->output_trace_class
);
702 case BT_FIELD_CLASS_TYPE_STRING
:
703 out_field_class
= bt_field_class_string_create(
704 md_maps
->output_trace_class
);
706 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
707 out_field_class
= bt_field_class_structure_create(
708 md_maps
->output_trace_class
);
710 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
712 const bt_field_class
*in_elem_fc
=
713 bt_field_class_array_borrow_element_field_class_const(
716 bt_field_class_array_static_get_length(in_field_class
);
718 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
719 md_maps
, in_elem_fc
);
721 out_field_class
= NULL
;
725 out_field_class
= bt_field_class_array_static_create(
726 md_maps
->output_trace_class
,
727 out_elem_fc
, array_len
);
730 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
732 const bt_field_class
*in_elem_fc
=
733 bt_field_class_array_borrow_element_field_class_const(
735 const bt_field_path
*length_fp
=
736 bt_field_class_array_dynamic_borrow_length_field_path_const(
738 bt_field_class
*out_length_fc
= NULL
;
740 bt_field_class
*out_elem_fc
= copy_field_class_array_element(
741 md_maps
, in_elem_fc
);
743 out_field_class
= NULL
;
748 const bt_field_class
*in_length_fc
=
749 resolve_field_path_to_field_class(length_fp
,
752 BT_ASSERT(in_length_fc
);
753 out_length_fc
= g_hash_table_lookup(md_maps
->field_class_map
,
755 BT_ASSERT(out_length_fc
);
758 out_field_class
= bt_field_class_array_dynamic_create(
759 md_maps
->output_trace_class
,
760 out_elem_fc
, out_length_fc
);
763 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
:
764 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
:
765 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
:
766 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
:
768 const bt_field_class
*in_content_fc
=
769 bt_field_class_option_borrow_field_class_const(
771 bt_field_class
*out_selector_fc
= NULL
;
772 bt_field_class
*out_content_fc
;
775 out_content_fc
= create_field_class_copy_internal(
776 md_maps
, in_content_fc
);
777 if (!out_content_fc
) {
778 BT_COMP_LOGE_STR("Cannot copy option's content field class.");
782 ret
= copy_field_class_content_internal(md_maps
,
783 in_content_fc
, out_content_fc
);
785 BT_COMP_LOGE_STR("Error copying content of option's "
786 "content field class");
790 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
) {
792 bt_field_class_option_without_selector_create(
793 md_maps
->output_trace_class
,
796 const bt_field_path
*in_selector_fp
=
797 bt_field_class_option_with_selector_borrow_selector_field_path_const(
799 const bt_field_class
*in_selector_fc
;
801 BT_ASSERT(in_selector_fp
);
802 in_selector_fc
= resolve_field_path_to_field_class(
803 in_selector_fp
, md_maps
);
804 BT_ASSERT(in_selector_fc
);
805 out_selector_fc
= g_hash_table_lookup(
806 md_maps
->field_class_map
, in_selector_fc
);
807 BT_ASSERT(out_selector_fc
);
809 if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
) {
811 bt_field_class_option_with_selector_bool_create(
812 md_maps
->output_trace_class
,
813 out_content_fc
, out_selector_fc
);
814 } else if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
) {
815 const bt_integer_range_set_unsigned
*ranges
=
816 bt_field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const(
821 bt_field_class_option_with_selector_integer_unsigned_create(
822 md_maps
->output_trace_class
,
823 out_content_fc
, out_selector_fc
,
825 } else if (fc_type
== BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
) {
826 const bt_integer_range_set_signed
*ranges
=
827 bt_field_class_option_with_selector_integer_signed_borrow_selector_ranges_const(
832 bt_field_class_option_with_selector_integer_signed_create(
833 md_maps
->output_trace_class
,
834 out_content_fc
, out_selector_fc
,
839 BT_ASSERT(out_field_class
);
842 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
843 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
:
844 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
:
846 bt_field_class
*out_sel_fc
= NULL
;
848 if (fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
||
849 fc_type
== BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
) {
850 const bt_field_class
*in_sel_fc
;
851 const bt_field_path
*sel_fp
=
852 bt_field_class_variant_with_selector_borrow_selector_field_path_const(
856 in_sel_fc
= resolve_field_path_to_field_class(sel_fp
,
858 BT_ASSERT(in_sel_fc
);
859 out_sel_fc
= g_hash_table_lookup(
860 md_maps
->field_class_map
, in_sel_fc
);
861 BT_ASSERT(out_sel_fc
);
864 out_field_class
= bt_field_class_variant_create(
865 md_maps
->output_trace_class
, out_sel_fc
);
873 * Add mapping from in_field_class to out_field_class. This simplifies
874 * the resolution of field paths in variant and dynamic array field
877 g_hash_table_insert(md_maps
->field_class_map
,
878 (gpointer
) in_field_class
, out_field_class
);
882 BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, "
883 "out-fc-addr=%p", in_field_class
, out_field_class
);
885 BT_COMP_LOGE("Error creating output field class from input field "
886 "class: in-fc-addr=%p", in_field_class
);
889 return out_field_class
;
893 int copy_field_class_content_internal(
894 struct trace_ir_metadata_maps
*md_maps
,
895 const bt_field_class
*in_field_class
,
896 bt_field_class
*out_field_class
)
901 * Safe to use the same value object because it's frozen at this
904 bt_field_class_set_user_attributes(out_field_class
,
905 bt_field_class_borrow_user_attributes_const(in_field_class
));
907 switch(bt_field_class_get_type(in_field_class
)) {
908 case BT_FIELD_CLASS_TYPE_BOOL
:
909 ret
= field_class_bool_copy(md_maps
,
910 in_field_class
, out_field_class
);
912 case BT_FIELD_CLASS_TYPE_BIT_ARRAY
:
913 ret
= field_class_bit_array_copy(md_maps
,
914 in_field_class
, out_field_class
);
916 case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER
:
917 ret
= field_class_unsigned_integer_copy(md_maps
,
918 in_field_class
, out_field_class
);
920 case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER
:
921 ret
= field_class_signed_integer_copy(md_maps
,
922 in_field_class
, out_field_class
);
924 case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION
:
925 ret
= field_class_unsigned_enumeration_copy(md_maps
,
926 in_field_class
, out_field_class
);
928 case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION
:
929 ret
= field_class_signed_enumeration_copy(md_maps
,
930 in_field_class
, out_field_class
);
932 case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
:
933 ret
= field_class_single_precision_real_copy(md_maps
,
934 in_field_class
, out_field_class
);
936 case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL
:
937 ret
= field_class_double_precision_real_copy(md_maps
,
938 in_field_class
, out_field_class
);
940 case BT_FIELD_CLASS_TYPE_STRING
:
941 ret
= field_class_string_copy(md_maps
,
942 in_field_class
, out_field_class
);
944 case BT_FIELD_CLASS_TYPE_STRUCTURE
:
945 ret
= field_class_structure_copy(md_maps
,
946 in_field_class
, out_field_class
);
948 case BT_FIELD_CLASS_TYPE_STATIC_ARRAY
:
949 ret
= field_class_static_array_copy(md_maps
,
950 in_field_class
, out_field_class
);
952 case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY
:
953 ret
= field_class_dynamic_array_copy(md_maps
,
954 in_field_class
, out_field_class
);
956 case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR
:
957 case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR
:
958 case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR
:
959 case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR
:
960 ret
= field_class_option_copy(md_maps
,
961 in_field_class
, out_field_class
);
963 case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR
:
964 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR
:
965 case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR
:
966 ret
= field_class_variant_copy(md_maps
,
967 in_field_class
, out_field_class
);