X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Flttng-utils%2Fdebug-info%2Ftrace-ir-metadata-field-class-copy.c;h=1face29d15ccc809dc90586000560637ac6d3fc1;hb=fabfe03472e26e997f9bfaec3fb075e6dbb029dd;hp=f7cab92fe005249b6f1f5a75a3b72b22a34f7383;hpb=350ad6c1c5f45a4e90c33e3c1354125c209bbf02;p=babeltrace.git diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c index f7cab92f..1face29d 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c +++ b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c @@ -24,8 +24,10 @@ * SOFTWARE. */ +#define BT_COMP_LOG_SELF_COMP (md_maps->self_comp) +#define BT_LOG_OUTPUT_LEVEL (md_maps->log_level) #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO/TRACE-IR-META-FC-COPY" -#include "logging.h" +#include "logging/comp-logging.h" #include "common/assert.h" #include "common/common.h" @@ -41,14 +43,14 @@ * structures ultimately leading to a field class. */ static -const bt_field_class *walk_field_path(const bt_field_path *fp, - const bt_field_class *fc) +const bt_field_class *walk_field_path(struct trace_ir_metadata_maps *md_maps, + const bt_field_path *fp, const bt_field_class *fc) { uint64_t i, fp_item_count; const bt_field_class *curr_fc; BT_ASSERT(bt_field_class_get_type(fc) == BT_FIELD_CLASS_TYPE_STRUCTURE); - BT_LOGD("Walking field path on field class: fp-addr=%p, fc-addr=%p", + BT_COMP_LOGD("Walking field path on field class: fp-addr=%p, fc-addr=%p", fp, fc); fp_item_count = bt_field_path_get_item_count(fp); @@ -72,7 +74,20 @@ const bt_field_class *walk_field_path(const bt_field_path *fp, member); break; } - case BT_FIELD_CLASS_TYPE_VARIANT: + case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: + { + BT_ASSERT(bt_field_path_item_get_type(fp_item) == + BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT); + curr_fc = bt_field_class_option_borrow_field_class_const( + curr_fc); + break; + } + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: { const bt_field_class_variant_option *option; @@ -108,25 +123,29 @@ const bt_field_class *resolve_field_path_to_field_class(const bt_field_path *fp, { struct field_class_resolving_context *fc_resolving_ctx; const bt_field_class *fc; - bt_scope fp_scope; + bt_field_path_scope fp_scope; - BT_LOGD("Resolving field path: fp-addr=%p", fp); + BT_COMP_LOGD("Resolving field path: fp-addr=%p", fp); fc_resolving_ctx = md_maps->fc_resolving_ctx; fp_scope = bt_field_path_get_root_scope(fp); switch (fp_scope) { - case BT_SCOPE_PACKET_CONTEXT: - fc = walk_field_path(fp, fc_resolving_ctx->packet_context); + case BT_FIELD_PATH_SCOPE_PACKET_CONTEXT: + fc = walk_field_path(md_maps, fp, + fc_resolving_ctx->packet_context); break; - case BT_SCOPE_EVENT_COMMON_CONTEXT: - fc = walk_field_path(fp, fc_resolving_ctx->event_common_context); + case BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT: + fc = walk_field_path(md_maps, fp, + fc_resolving_ctx->event_common_context); break; - case BT_SCOPE_EVENT_SPECIFIC_CONTEXT: - fc = walk_field_path(fp, fc_resolving_ctx->event_specific_context); + case BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT: + fc = walk_field_path(md_maps, fp, + fc_resolving_ctx->event_specific_context); break; - case BT_SCOPE_EVENT_PAYLOAD: - fc = walk_field_path(fp, fc_resolving_ctx->event_payload); + case BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD: + fc = walk_field_path(md_maps, fp, + fc_resolving_ctx->event_payload); break; default: abort(); @@ -145,19 +164,49 @@ void field_class_integer_set_props(const bt_field_class *input_fc, bt_field_class_integer_get_field_value_range(input_fc)); } +static inline +int field_class_bool_copy( + struct trace_ir_metadata_maps *md_maps, + const bt_field_class *in_field_class, + bt_field_class *out_field_class) +{ + BT_COMP_LOGD("Copying content of boolean field class: " + "in-fc-addr=%p, out-fc-addr=%p", + in_field_class, out_field_class); + BT_COMP_LOGD("Copied content of boolean field class: " + "in-fc-addr=%p, out-fc-addr=%p", + in_field_class, out_field_class); + return 0; +} + +static inline +int field_class_bit_array_copy( + struct trace_ir_metadata_maps *md_maps, + const bt_field_class *in_field_class, + bt_field_class *out_field_class) +{ + BT_COMP_LOGD("Copying content of bit array field class: " + "in-fc-addr=%p, out-fc-addr=%p", + in_field_class, out_field_class); + BT_COMP_LOGD("Copied content of bit array field class: " + "in-fc-addr=%p, out-fc-addr=%p", + in_field_class, out_field_class); + return 0; +} + static inline int field_class_unsigned_integer_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { - BT_LOGD("Copying content of unsigned integer field class: " + BT_COMP_LOGD("Copying content of unsigned integer field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); field_class_integer_set_props(in_field_class, out_field_class); - BT_LOGD("Copied content of unsigned integer field class: " + BT_COMP_LOGD("Copied content of unsigned integer field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); return 0; @@ -169,13 +218,13 @@ int field_class_signed_integer_copy( const bt_field_class *in_field_class, bt_field_class *out_field_class) { - BT_LOGD("Copying content of signed integer field class: " + BT_COMP_LOGD("Copying content of signed integer field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); field_class_integer_set_props(in_field_class, out_field_class); - BT_LOGD("Copied content of signed integer field class: " + BT_COMP_LOGD("Copied content of signed integer field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); return 0; @@ -190,7 +239,7 @@ int field_class_unsigned_enumeration_copy( uint64_t i, enum_mapping_count; int ret = 0; - BT_LOGD("Copying content of unsigned enumeration field class: " + BT_COMP_LOGD("Copying content of unsigned enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -201,50 +250,25 @@ int field_class_unsigned_enumeration_copy( enum_mapping_count = bt_field_class_enumeration_get_mapping_count(in_field_class); for (i = 0; i < enum_mapping_count; i++) { const char *label; - const bt_field_class_unsigned_enumeration_mapping *u_mapping; + const bt_integer_range_set_unsigned *range_set; + const bt_field_class_enumeration_unsigned_mapping *u_mapping; const bt_field_class_enumeration_mapping *mapping; - uint64_t range_index, range_count; - /* Get the ranges and the range count. */ - u_mapping = bt_field_class_unsigned_enumeration_borrow_mapping_by_index_const( + u_mapping = bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( in_field_class, i); - mapping = bt_field_class_unsigned_enumeration_mapping_as_mapping_const( + mapping = bt_field_class_enumeration_unsigned_mapping_as_mapping_const( u_mapping); - range_count = - bt_field_class_enumeration_mapping_get_range_count( - mapping); - label = bt_field_class_enumeration_mapping_get_label( - mapping); - - /* - * Iterate over all the ranges to add them to copied field - * class. - */ - for (range_index = 0; range_index < range_count; range_index++) { - uint64_t lower, upper; - bt_field_class_status status; - bt_field_class_unsigned_enumeration_mapping_get_range_by_index( - u_mapping, range_index, &lower, &upper); - - BT_LOGD("Copying range in enumeration field class: " - "label=%s, lower=%"PRId64", upper=%"PRId64, - label, lower, upper); - - /* Add the label and its range to the copy field class. */ - status = bt_field_class_unsigned_enumeration_map_range( - out_field_class, label, lower, upper); - - if (status != BT_FIELD_CLASS_STATUS_OK) { - BT_LOGE_STR("Failed to add range to unsigned " - "enumeration."); - BT_FIELD_CLASS_PUT_REF_AND_RESET(out_field_class); - ret = -1; - goto error; - } + label = bt_field_class_enumeration_mapping_get_label(mapping); + range_set = bt_field_class_enumeration_unsigned_mapping_borrow_ranges_const( + u_mapping); + ret = bt_field_class_enumeration_unsigned_add_mapping( + out_field_class, label, range_set); + if (ret) { + goto error; } } - BT_LOGD("Copied content of unsigned enumeration field class: " + BT_COMP_LOGD("Copied content of unsigned enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -261,7 +285,7 @@ int field_class_signed_enumeration_copy( uint64_t i, enum_mapping_count; int ret = 0; - BT_LOGD("Copying content of signed enumeration field class: " + BT_COMP_LOGD("Copying content of signed enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -273,49 +297,25 @@ int field_class_signed_enumeration_copy( bt_field_class_enumeration_get_mapping_count(in_field_class); for (i = 0; i < enum_mapping_count; i++) { const char *label; - const bt_field_class_signed_enumeration_mapping *i_mapping; + const bt_integer_range_set_signed *range_set; + const bt_field_class_enumeration_signed_mapping *s_mapping; const bt_field_class_enumeration_mapping *mapping; - uint64_t range_index, range_count; - /* Get the ranges and the range count. */ - i_mapping = bt_field_class_signed_enumeration_borrow_mapping_by_index_const( + s_mapping = bt_field_class_enumeration_signed_borrow_mapping_by_index_const( in_field_class, i); - mapping = bt_field_class_signed_enumeration_mapping_as_mapping_const( - i_mapping); - range_count = - bt_field_class_enumeration_mapping_get_range_count( - mapping); - label = bt_field_class_enumeration_mapping_get_label( - mapping); - - /* - * Iterate over all the ranges to add them to copied field - * class. - */ - for (range_index = 0; range_index < range_count; range_index++) { - int64_t lower, upper; - bt_field_class_status status; - bt_field_class_signed_enumeration_mapping_get_range_by_index( - i_mapping, range_index, &lower, &upper); - - BT_LOGD("Copying range in enumeration field class: " - "label=%s, lower=%"PRId64", upper=%"PRId64, - label, lower, upper); - - /* Add the label and its range to the copy field class. */ - status = bt_field_class_signed_enumeration_map_range( - out_field_class, label, lower, upper); - if (status != BT_FIELD_CLASS_STATUS_OK) { - BT_LOGE_STR("Failed to add range to signed " - "enumeration."); - BT_FIELD_CLASS_PUT_REF_AND_RESET(out_field_class); - ret = -1; - goto error; - } + mapping = bt_field_class_enumeration_signed_mapping_as_mapping_const( + s_mapping); + label = bt_field_class_enumeration_mapping_get_label(mapping); + range_set = bt_field_class_enumeration_signed_mapping_borrow_ranges_const( + s_mapping); + ret = bt_field_class_enumeration_signed_add_mapping( + out_field_class, label, range_set); + if (ret) { + goto error; } } - BT_LOGD("Copied content of signed enumeration field class: " + BT_COMP_LOGD("Copied content of signed enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -324,20 +324,31 @@ error: } static inline -int field_class_real_copy( +int field_class_single_precision_real_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { - BT_LOGD("Copying content of real field class: " - "in-fc-addr=%p, out-fc-addr=%p", - in_field_class, out_field_class); + BT_COMP_LOGD("Copying content of single-precision real field class: " + "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - bt_field_class_real_set_is_single_precision(out_field_class, - bt_field_class_real_is_single_precision(in_field_class)); + BT_COMP_LOGD("Copied content single-precision real field class:" + "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - BT_LOGD("Copied content real field class: in-fc-addr=%p, " - "out-fc-addr=%p", in_field_class, out_field_class); + return 0; +} + +static inline +int field_class_double_precision_real_copy( + struct trace_ir_metadata_maps *md_maps, + const bt_field_class *in_field_class, + bt_field_class *out_field_class) +{ + BT_COMP_LOGD("Copying content of double-precision real field class: " + "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); + + BT_COMP_LOGD("Copied content double-precision real field class:" + "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); return 0; } @@ -349,10 +360,9 @@ int field_class_structure_copy( bt_field_class *out_field_class) { uint64_t i, struct_member_count; - bt_field_class_status status; int ret = 0; - BT_LOGD("Copying content of structure field class: " + BT_COMP_LOGD("Copying content of structure field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); /* Get the number of member in that struct. */ @@ -361,51 +371,65 @@ int field_class_structure_copy( /* Iterate over all the members of the struct. */ for (i = 0; i < struct_member_count; i++) { - const bt_field_class_structure_member *member; + const bt_field_class_structure_member *in_member; + bt_field_class_structure_member *out_member; const char *member_name; - const bt_field_class *member_fc; + const bt_field_class *in_member_fc; bt_field_class *out_member_field_class; - member = bt_field_class_structure_borrow_member_by_index_const( + in_member = bt_field_class_structure_borrow_member_by_index_const( in_field_class, i); - member_fc = bt_field_class_structure_member_borrow_field_class_const( - member); - member_name = bt_field_class_structure_member_get_name(member); - BT_LOGD("Copying structure field class's field: " + in_member_fc = bt_field_class_structure_member_borrow_field_class_const( + in_member); + member_name = bt_field_class_structure_member_get_name(in_member); + BT_COMP_LOGD("Copying structure field class's field: " "index=%" PRId64 ", " "member-fc-addr=%p, field-name=\"%s\"", - i, member_fc, member_name); + i, in_member_fc, member_name); out_member_field_class = create_field_class_copy(md_maps, - member_fc); + in_member_fc); if (!out_member_field_class) { - BT_LOGE("Cannot copy structure field class's field: " + BT_COMP_LOGE("Cannot copy structure field class's field: " "index=%" PRId64 ", " "field-fc-addr=%p, field-name=\"%s\"", - i, member_fc, member_name); + i, in_member_fc, member_name); ret = -1; goto error; } - ret = copy_field_class_content(md_maps, member_fc, + ret = copy_field_class_content(md_maps, in_member_fc, out_member_field_class); if (ret) { goto error; } - status = bt_field_class_structure_append_member(out_field_class, - member_name, out_member_field_class); - if (status != BT_FIELD_CLASS_STATUS_OK) { - BT_LOGE("Cannot append structure field class's field: " + if (bt_field_class_structure_append_member(out_field_class, + member_name, out_member_field_class) != + BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { + BT_COMP_LOGE("Cannot append structure field class's field: " "index=%" PRId64 ", " "field-fc-addr=%p, field-name=\"%s\"", - i, member_fc, member_name); + i, in_member_fc, member_name); BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class); ret = -1; goto error; } + + out_member = bt_field_class_structure_borrow_member_by_index( + out_field_class, i); + BT_ASSERT(out_member); + + /* + * Safe to use the same value object because it's frozen + * at this point. + */ + bt_field_class_structure_member_set_user_attributes( + out_member, + bt_field_class_structure_member_borrow_user_attributes_const( + in_member)); } - BT_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p", + BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p", in_field_class, out_field_class); error: @@ -420,72 +444,104 @@ int field_class_variant_copy( { bt_field_class *out_tag_field_class = NULL; uint64_t i, variant_option_count; - const bt_field_path *tag_fp; - const bt_field_class *tag_fc; + bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); int ret = 0; - BT_LOGD("Copying content of variant field class: " + BT_COMP_LOGD("Copying content of variant field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - - tag_fp = bt_field_class_variant_borrow_selector_field_path_const( - in_field_class); - if (tag_fp) { - tag_fc = resolve_field_path_to_field_class(tag_fp, - md_maps); - - out_tag_field_class = g_hash_table_lookup( - md_maps->field_class_map, tag_fc); - if (!out_tag_field_class) { - BT_LOGE_STR("Cannot find the tag field class."); - ret = -1; - goto error; - } - bt_field_class_variant_set_selector_field_class(out_field_class, - out_tag_field_class); - } - variant_option_count = bt_field_class_variant_get_option_count(in_field_class); for (i = 0; i < variant_option_count; i++) { - const bt_field_class *option_fc; + const bt_field_class *in_option_fc; const char *option_name; bt_field_class *out_option_field_class; - bt_field_class_status status; - const bt_field_class_variant_option *option; + const bt_field_class_variant_option *in_option; + bt_field_class_variant_option *out_option; - option = bt_field_class_variant_borrow_option_by_index_const( + in_option = bt_field_class_variant_borrow_option_by_index_const( in_field_class, i); - option_fc = bt_field_class_variant_option_borrow_field_class_const( - option); - option_name = bt_field_class_variant_option_get_name(option); + in_option_fc = bt_field_class_variant_option_borrow_field_class_const( + in_option); + option_name = bt_field_class_variant_option_get_name(in_option); out_option_field_class = create_field_class_copy_internal( - md_maps, option_fc); + md_maps, in_option_fc); if (!out_option_field_class) { - BT_LOGE_STR("Cannot copy field class."); + BT_COMP_LOGE_STR("Cannot copy field class."); ret = -1; goto error; } - ret = copy_field_class_content_internal(md_maps, option_fc, + ret = copy_field_class_content_internal(md_maps, in_option_fc, out_option_field_class); if (ret) { - BT_LOGE_STR("Error copying content of option variant " + BT_COMP_LOGE_STR("Error copying content of option variant " "field class'"); goto error; } - status = bt_field_class_variant_append_option( - out_field_class, option_name, - out_option_field_class); - if (status != BT_FIELD_CLASS_STATUS_OK) { - BT_LOGE_STR("Cannot append option to variant field class'"); - BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); - ret = -1; - goto error; + if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR) { + const bt_field_class_variant_with_selector_integer_unsigned_option *spec_opt = + bt_field_class_variant_with_selector_integer_unsigned_borrow_option_by_index_const( + in_field_class, i); + const bt_integer_range_set_unsigned *ranges = + bt_field_class_variant_with_selector_integer_unsigned_option_borrow_ranges_const( + spec_opt); + + if (bt_field_class_variant_with_selector_integer_unsigned_append_option( + out_field_class, option_name, + out_option_field_class, ranges) != + BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK) { + BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned integer selector'"); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); + ret = -1; + goto error; + } + } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR) { + const bt_field_class_variant_with_selector_integer_signed_option *spec_opt = + bt_field_class_variant_with_selector_integer_signed_borrow_option_by_index_const( + in_field_class, i); + const bt_integer_range_set_signed *ranges = + bt_field_class_variant_with_selector_integer_signed_option_borrow_ranges_const( + spec_opt); + + if (bt_field_class_variant_with_selector_integer_signed_append_option( + out_field_class, option_name, + out_option_field_class, ranges) != + BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_APPEND_OPTION_STATUS_OK) { + BT_COMP_LOGE_STR("Cannot append option to variant field class with signed integer selector'"); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); + ret = -1; + goto error; + } + } else { + BT_ASSERT(fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR); + + if (bt_field_class_variant_without_selector_append_option( + out_field_class, option_name, + out_option_field_class) != + BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_APPEND_OPTION_STATUS_OK) { + BT_COMP_LOGE_STR("Cannot append option to variant field class'"); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); + ret = -1; + goto error; + } } + + out_option = bt_field_class_variant_borrow_option_by_index( + out_field_class, i); + BT_ASSERT(out_option); + + /* + * Safe to use the same value object because it's frozen + * at this point. + */ + bt_field_class_variant_option_set_user_attributes( + out_option, + bt_field_class_variant_option_borrow_user_attributes_const( + in_option)); } - BT_LOGD("Copied content of variant field class: in-fc-addr=%p, " + BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); error: @@ -498,13 +554,13 @@ int field_class_static_array_copy( const bt_field_class *in_field_class, bt_field_class *out_field_class) { - BT_LOGD("Copying content of static array field class: in-fc-addr=%p, " + BT_COMP_LOGD("Copying content of static array field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); /* * There is no content to copy. Keep this function call anyway for * logging purposes. */ - BT_LOGD("Copied content of static array field class: in-fc-addr=%p, " + BT_COMP_LOGD("Copied content of static array field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); return 0; @@ -516,49 +572,42 @@ int field_class_dynamic_array_copy( const bt_field_class *in_field_class, bt_field_class *out_field_class) { - const bt_field_class *len_fc; - const bt_field_path *len_fp; - bt_field_class_status status; - bt_field_class *out_len_field_class; - int ret = 0; - - BT_LOGD("Copying content of dynamic array field class: " + BT_COMP_LOGD("Copying content of dynamic array field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - len_fp = bt_field_class_dynamic_array_borrow_length_field_path_const( - in_field_class); + /* + * There is no content to copy. Keep this function call anyway for + * logging purposes. + */ + BT_COMP_LOGD("Copied dynamic array field class: in-fc-addr=%p, " + "out-fc-addr=%p", in_field_class, out_field_class); - if (len_fp) { - BT_LOGD("Copying dynamic array length field class using " - "field path: in-len-fp=%p", len_fp); - len_fc = resolve_field_path_to_field_class( - len_fp, md_maps); - out_len_field_class = g_hash_table_lookup( - md_maps->field_class_map, len_fc); - if (!out_len_field_class) { - BT_LOGE_STR("Cannot find the output matching length" - "field class."); - ret = -1; - goto error; - } + return 0; +} - status = bt_field_class_dynamic_array_set_length_field_class( - out_field_class, out_len_field_class); - if (status != BT_FIELD_CLASS_STATUS_OK) { - BT_LOGE_STR("Cannot set dynamic array field class' " - "length field class."); - BT_FIELD_CLASS_PUT_REF_AND_RESET(out_len_field_class); - ret = -1; - goto error; - } +static inline +int field_class_option_copy( + struct trace_ir_metadata_maps *md_maps, + const bt_field_class *in_field_class, + bt_field_class *out_field_class) +{ + BT_COMP_LOGD("Copying content of option field class: " + "in-fc-addr=%p, out-fc-addr=%p", + in_field_class, out_field_class); + + if (bt_field_class_get_type(out_field_class) == + BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) { + bt_field_class_option_with_selector_bool_set_selector_is_reversed( + out_field_class, + bt_field_class_option_with_selector_bool_selector_is_reversed( + in_field_class)); } - BT_LOGD("Copied dynamic array field class: in-fc-addr=%p, " + BT_COMP_LOGD("Copied option field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); -error: - return ret; + return 0; } static inline @@ -566,13 +615,13 @@ int field_class_string_copy(struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { - BT_LOGD("Copying content of string field class: in-fc-addr=%p, " + BT_COMP_LOGD("Copying content of string field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); /* * There is no content to copy. Keep this function call anyway for * logging purposes. */ - BT_LOGD("Copied content of string field class: in-fc-addr=%p, " + BT_COMP_LOGD("Copied content of string field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); return 0; @@ -586,7 +635,7 @@ bt_field_class *copy_field_class_array_element(struct trace_ir_metadata_maps *md bt_field_class *out_elem_fc = create_field_class_copy_internal(md_maps, in_elem_fc); if (!out_elem_fc) { - BT_LOGE("Error creating output elem field class " + BT_COMP_LOGE("Error creating output elem field class " "from input elem field class for static array: " "in-fc-addr=%p", in_elem_fc); goto error; @@ -594,7 +643,7 @@ bt_field_class *copy_field_class_array_element(struct trace_ir_metadata_maps *md ret = copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc); if (ret) { - BT_LOGE("Error creating output elem field class " + BT_COMP_LOGE("Error creating output elem field class " "from input elem field class for static array: " "in-fc-addr=%p", in_elem_fc); BT_FIELD_CLASS_PUT_REF_AND_RESET(out_elem_fc); @@ -610,29 +659,44 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * const bt_field_class *in_field_class) { bt_field_class *out_field_class = NULL; + bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); - BT_LOGD("Creating bare field class based on field class: in-fc-addr=%p", + BT_COMP_LOGD("Creating bare field class based on field class: in-fc-addr=%p", in_field_class); - switch(bt_field_class_get_type(in_field_class)) { + switch (fc_type) { + case BT_FIELD_CLASS_TYPE_BOOL: + out_field_class = bt_field_class_bool_create( + md_maps->output_trace_class); + break; + case BT_FIELD_CLASS_TYPE_BIT_ARRAY: + out_field_class = bt_field_class_bit_array_create( + md_maps->output_trace_class, + bt_field_class_bit_array_get_length( + in_field_class)); + break; case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: - out_field_class = bt_field_class_unsigned_integer_create( + out_field_class = bt_field_class_integer_unsigned_create( md_maps->output_trace_class); break; case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER: - out_field_class = bt_field_class_signed_integer_create( + out_field_class = bt_field_class_integer_signed_create( md_maps->output_trace_class); break; case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: - out_field_class = bt_field_class_unsigned_enumeration_create( + out_field_class = bt_field_class_enumeration_unsigned_create( md_maps->output_trace_class); break; case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION: - out_field_class = bt_field_class_signed_enumeration_create( + out_field_class = bt_field_class_enumeration_signed_create( + md_maps->output_trace_class); + break; + case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: + out_field_class = bt_field_class_real_single_precision_create( md_maps->output_trace_class); break; - case BT_FIELD_CLASS_TYPE_REAL: - out_field_class = bt_field_class_real_create( + case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: + out_field_class = bt_field_class_real_double_precision_create( md_maps->output_trace_class); break; case BT_FIELD_CLASS_TYPE_STRING: @@ -649,7 +713,7 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * bt_field_class_array_borrow_element_field_class_const( in_field_class); uint64_t array_len = - bt_field_class_static_array_get_length(in_field_class); + bt_field_class_array_static_get_length(in_field_class); bt_field_class *out_elem_fc = copy_field_class_array_element( md_maps, in_elem_fc); @@ -658,7 +722,7 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * goto error; } - out_field_class = bt_field_class_static_array_create( + out_field_class = bt_field_class_array_static_create( md_maps->output_trace_class, out_elem_fc, array_len); break; @@ -668,23 +732,139 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * const bt_field_class *in_elem_fc = bt_field_class_array_borrow_element_field_class_const( in_field_class); + const bt_field_path *length_fp = + bt_field_class_array_dynamic_borrow_length_field_path_const( + in_field_class); + bt_field_class *out_length_fc = NULL; bt_field_class *out_elem_fc = copy_field_class_array_element( - md_maps, in_elem_fc); + md_maps, in_elem_fc); if (!out_elem_fc) { out_field_class = NULL; goto error; } - out_field_class = bt_field_class_dynamic_array_create( + if (length_fp) { + const bt_field_class *in_length_fc = + resolve_field_path_to_field_class(length_fp, + md_maps); + + BT_ASSERT(in_length_fc); + out_length_fc = g_hash_table_lookup(md_maps->field_class_map, + in_length_fc); + BT_ASSERT(out_length_fc); + } + + out_field_class = bt_field_class_array_dynamic_create( md_maps->output_trace_class, - out_elem_fc); + out_elem_fc, out_length_fc); + break; + } + case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: + { + const bt_field_class *in_content_fc = + bt_field_class_option_borrow_field_class_const( + in_field_class); + bt_field_class *out_selector_fc = NULL; + bt_field_class *out_content_fc; + int ret; + + out_content_fc = create_field_class_copy_internal( + md_maps, in_content_fc); + if (!out_content_fc) { + BT_COMP_LOGE_STR("Cannot copy option's content field class."); + goto error; + } + + ret = copy_field_class_content_internal(md_maps, + in_content_fc, out_content_fc); + if (ret) { + BT_COMP_LOGE_STR("Error copying content of option's " + "content field class"); + goto error; + } + + if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR) { + out_field_class = + bt_field_class_option_without_selector_create( + md_maps->output_trace_class, + out_content_fc); + } else { + const bt_field_path *in_selector_fp = + bt_field_class_option_with_selector_borrow_selector_field_path_const( + in_field_class); + const bt_field_class *in_selector_fc; + + BT_ASSERT(in_selector_fp); + in_selector_fc = resolve_field_path_to_field_class( + in_selector_fp, md_maps); + BT_ASSERT(in_selector_fc); + out_selector_fc = g_hash_table_lookup( + md_maps->field_class_map, in_selector_fc); + BT_ASSERT(out_selector_fc); + + if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR) { + out_field_class = + bt_field_class_option_with_selector_bool_create( + md_maps->output_trace_class, + out_content_fc, out_selector_fc); + } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR) { + const bt_integer_range_set_unsigned *ranges = + bt_field_class_option_with_selector_integer_unsigned_borrow_selector_ranges_const( + in_field_class); + + BT_ASSERT(ranges); + out_field_class = + bt_field_class_option_with_selector_integer_unsigned_create( + md_maps->output_trace_class, + out_content_fc, out_selector_fc, + ranges); + } else if (fc_type == BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR) { + const bt_integer_range_set_signed *ranges = + bt_field_class_option_with_selector_integer_signed_borrow_selector_ranges_const( + in_field_class); + + BT_ASSERT(ranges); + out_field_class = + bt_field_class_option_with_selector_integer_signed_create( + md_maps->output_trace_class, + out_content_fc, out_selector_fc, + ranges); + } + } + + BT_ASSERT(out_field_class); break; } - case BT_FIELD_CLASS_TYPE_VARIANT: + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: + { + bt_field_class *out_sel_fc = NULL; + + if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR || + fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR) { + const bt_field_class *in_sel_fc; + const bt_field_path *sel_fp = + bt_field_class_variant_with_selector_borrow_selector_field_path_const( + in_field_class); + + BT_ASSERT(sel_fp); + in_sel_fc = resolve_field_path_to_field_class(sel_fp, + md_maps); + BT_ASSERT(in_sel_fc); + out_sel_fc = g_hash_table_lookup( + md_maps->field_class_map, in_sel_fc); + BT_ASSERT(out_sel_fc); + } + out_field_class = bt_field_class_variant_create( - md_maps->output_trace_class); + md_maps->output_trace_class, out_sel_fc); break; + } default: abort(); } @@ -699,10 +879,10 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * error: if(out_field_class){ - BT_LOGD("Created bare field class based on field class: in-fc-addr=%p, " + BT_COMP_LOGD("Created bare field class based on field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); } else { - BT_LOGE("Error creating output field class from input field " + BT_COMP_LOGE("Error creating output field class from input field " "class: in-fc-addr=%p", in_field_class); } @@ -716,7 +896,23 @@ int copy_field_class_content_internal( bt_field_class *out_field_class) { int ret = 0; + + /* + * Safe to use the same value object because it's frozen at this + * point. + */ + bt_field_class_set_user_attributes(out_field_class, + bt_field_class_borrow_user_attributes_const(in_field_class)); + switch(bt_field_class_get_type(in_field_class)) { + case BT_FIELD_CLASS_TYPE_BOOL: + ret = field_class_bool_copy(md_maps, + in_field_class, out_field_class); + break; + case BT_FIELD_CLASS_TYPE_BIT_ARRAY: + ret = field_class_bit_array_copy(md_maps, + in_field_class, out_field_class); + break; case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER: ret = field_class_unsigned_integer_copy(md_maps, in_field_class, out_field_class); @@ -733,8 +929,12 @@ int copy_field_class_content_internal( ret = field_class_signed_enumeration_copy(md_maps, in_field_class, out_field_class); break; - case BT_FIELD_CLASS_TYPE_REAL: - ret = field_class_real_copy(md_maps, + case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: + ret = field_class_single_precision_real_copy(md_maps, + in_field_class, out_field_class); + break; + case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: + ret = field_class_double_precision_real_copy(md_maps, in_field_class, out_field_class); break; case BT_FIELD_CLASS_TYPE_STRING: @@ -753,7 +953,16 @@ int copy_field_class_content_internal( ret = field_class_dynamic_array_copy(md_maps, in_field_class, out_field_class); break; - case BT_FIELD_CLASS_TYPE_VARIANT: + case BT_FIELD_CLASS_TYPE_OPTION_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_BOOL_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_OPTION_WITH_SIGNED_INTEGER_SELECTOR: + ret = field_class_option_copy(md_maps, + in_field_class, out_field_class); + break; + case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR: + case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR: ret = field_class_variant_copy(md_maps, in_field_class, out_field_class); break;