Always evaluate BT_ASSERT(); add BT_ASSERT_DBG() for debug mode only
[babeltrace.git] / src / plugins / lttng-utils / debug-info / trace-ir-data-copy.c
index 3bb1fba17fa73426cebb6f156b42fbba7c336265..42395904cf8bd8893870eb2783413d29c033ba45 100644 (file)
@@ -57,6 +57,13 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
                }
        }
 
+       /*
+        * Safe to use the same value object because it's frozen at this
+        * point.
+        */
+       bt_trace_set_user_attributes(out_trace,
+               bt_trace_borrow_user_attributes_const(in_trace));
+
        /*
         * Do not copy the trace UUID as it may be modified and should
         * no longer have the same UUID.
@@ -83,22 +90,18 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace,
                BT_ASSERT(value);
 
                if (bt_value_is_signed_integer(value)) {
-                       set_env_status =
-                               bt_trace_set_environment_entry_integer(
-                                               out_trace, value_name,
-                                               bt_value_integer_signed_get(
-                                                       value));
+                       set_env_status = bt_trace_set_environment_entry_integer(
+                               out_trace, value_name,
+                               bt_value_integer_signed_get( value));
                } else if (bt_value_is_string(value)) {
-                       set_env_status =
-                               bt_trace_set_environment_entry_string(
-                                       out_trace, value_name,
-                                       bt_value_string_get(value));
+                       set_env_status = bt_trace_set_environment_entry_string(
+                               out_trace, value_name,
+                               bt_value_string_get(value));
                } else {
                        abort();
                }
 
-               if (set_env_status !=
-                               BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK) {
+               if (set_env_status != BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK) {
                        BT_COMP_LOGE("Cannot copy trace's environment: "
                                "trace-addr=%p, name=\"%s\"",
                                out_trace, trace_name);
@@ -133,6 +136,12 @@ void copy_stream_content(const bt_stream *in_stream, bt_stream *out_stream,
                }
        }
 
+       /*
+        * Safe to use the same value object because it's frozen at this
+        * point.
+        */
+       bt_stream_set_user_attributes(out_stream,
+               bt_stream_borrow_user_attributes_const(in_stream));
        BT_COMP_LOGD("Copied content of stream: in-s-addr=%p, out-s-addr=%p",
                        in_stream, out_stream);
 end:
@@ -179,7 +188,7 @@ void copy_event_content(const bt_event *in_event, bt_event *out_event,
        if (in_common_ctx_field) {
                out_common_ctx_field =
                        bt_event_borrow_common_context_field(out_event);
-               BT_ASSERT(out_common_ctx_field);
+               BT_ASSERT_DBG(out_common_ctx_field);
                copy_field_content(in_common_ctx_field,
                        out_common_ctx_field, log_level, self_comp);
        }
@@ -189,7 +198,7 @@ void copy_event_content(const bt_event *in_event, bt_event *out_event,
        if (in_specific_ctx_field) {
                out_specific_ctx_field =
                        bt_event_borrow_specific_context_field(out_event);
-               BT_ASSERT(out_specific_ctx_field);
+               BT_ASSERT_DBG(out_specific_ctx_field);
                copy_field_content(in_specific_ctx_field,
                        out_specific_ctx_field, log_level, self_comp);
        }
@@ -197,7 +206,7 @@ void copy_event_content(const bt_event *in_event, bt_event *out_event,
        in_payload_field = bt_event_borrow_payload_field_const(in_event);
        if (in_payload_field) {
                out_payload_field = bt_event_borrow_payload_field(out_event);
-               BT_ASSERT(out_payload_field);
+               BT_ASSERT_DBG(out_payload_field);
                copy_field_content(in_payload_field,
                        out_payload_field, log_level, self_comp);
        }
@@ -214,27 +223,32 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
 
        in_fc_type = bt_field_get_class_type(in_field);
        out_fc_type = bt_field_get_class_type(out_field);
-       BT_ASSERT(in_fc_type == out_fc_type);
+       BT_ASSERT_DBG(in_fc_type == out_fc_type);
 
        BT_COMP_LOGT("Copying content of field: in-f-addr=%p, out-f-addr=%p",
                        in_field, out_field);
-       switch (in_fc_type) {
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
-       case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
+
+       if (in_fc_type == BT_FIELD_CLASS_TYPE_BOOL) {
+               bt_field_bool_set_value(out_field,
+                       bt_field_bool_get_value(in_field));
+       } else if (in_fc_type == BT_FIELD_CLASS_TYPE_BIT_ARRAY) {
+               bt_field_bit_array_set_value_as_integer(out_field,
+                       bt_field_bit_array_get_value_as_integer(in_field));
+       } else if (bt_field_class_type_is(in_fc_type,
+                       BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER)) {
                bt_field_integer_unsigned_set_value(out_field,
                                bt_field_integer_unsigned_get_value(in_field));
-               break;
-       case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
-       case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
+       } else if (bt_field_class_type_is(in_fc_type,
+                       BT_FIELD_CLASS_TYPE_SIGNED_INTEGER)) {
                bt_field_integer_signed_set_value(out_field,
                                bt_field_integer_signed_get_value(in_field));
-               break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               bt_field_real_set_value(out_field,
-                               bt_field_real_get_value(in_field));
-               break;
-       case BT_FIELD_CLASS_TYPE_STRING:
-       {
+       } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+               bt_field_real_single_precision_set_value(out_field,
+                               bt_field_real_single_precision_get_value(in_field));
+       } else if (in_fc_type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL) {
+               bt_field_real_double_precision_set_value(out_field,
+                               bt_field_real_double_precision_get_value(in_field));
+       } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRING) {
                const char *str = bt_field_string_get_value(in_field);
                bt_field_string_set_value_status status =
                        bt_field_string_set_value(out_field, str);
@@ -245,10 +259,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                        bt_current_thread_clear_error();
 
                }
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_STRUCTURE:
-       {
+       } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) {
                uint64_t i, nb_member_struct;
                const bt_field *in_member_field;
                bt_field *out_member_field;
@@ -274,20 +285,16 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                                        member);
                        in_member_field =
                                bt_field_structure_borrow_member_field_by_name_const(
-                                               in_field, in_member_name);
+                                       in_field, in_member_name);
                        out_member_field =
                                bt_field_structure_borrow_member_field_by_name(
-                                               out_field, in_member_name);
+                                       out_field, in_member_name);
 
                        copy_field_content(in_member_field,
                                out_member_field, log_level, self_comp);
                }
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY:
-               /* fall through */
-       case BT_FIELD_CLASS_TYPE_STATIC_ARRAY:
-       {
+       } else if (bt_field_class_type_is(in_fc_type,
+                       BT_FIELD_CLASS_TYPE_ARRAY)) {
                const bt_field *in_element_field;
                bt_field *out_element_field;
                uint64_t i, array_len;
@@ -295,7 +302,8 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
 
                array_len = bt_field_array_get_length(in_field);
 
-               if (in_fc_type == BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY) {
+               if (bt_field_class_type_is(in_fc_type,
+                               BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) {
                        set_len_status = bt_field_array_dynamic_set_length(
                                out_field, array_len);
                        if (set_len_status !=
@@ -317,12 +325,25 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                        copy_field_content(in_element_field, out_element_field,
                                log_level, self_comp);
                }
-               break;
-       }
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR:
-       case BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR:
-       {
+       } else if (bt_field_class_type_is(in_fc_type,
+                       BT_FIELD_CLASS_TYPE_OPTION)) {
+               const bt_field *in_option_field;
+               bt_field *out_option_field;
+
+               in_option_field = bt_field_option_borrow_field_const(in_field);
+
+               if (in_option_field) {
+                       bt_field_option_set_has_field(out_field, BT_TRUE);
+                       out_option_field = bt_field_option_borrow_field(
+                               out_field);
+                       BT_ASSERT_DBG(out_option_field);
+                       copy_field_content(in_option_field, out_option_field,
+                               log_level, self_comp);
+               } else {
+                       bt_field_option_set_has_field(out_field, BT_FALSE);
+               }
+       } else if (bt_field_class_type_is(in_fc_type,
+                       BT_FIELD_CLASS_TYPE_VARIANT)) {
                bt_field_variant_select_option_field_by_index_status sel_opt_status;
                uint64_t in_selected_option_idx;
                const bt_field *in_option_field;
@@ -330,9 +351,9 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
 
                in_selected_option_idx =
                        bt_field_variant_get_selected_option_field_index(
-                                       in_field);
+                               in_field);
                sel_opt_status = bt_field_variant_select_option_field_by_index(out_field,
-                               in_selected_option_idx);
+                       in_selected_option_idx);
                if (sel_opt_status !=
                                BT_FIELD_VARIANT_SELECT_OPTION_FIELD_STATUS_OK) {
                        BT_COMP_LOGE("Cannot select variant field's option field: "
@@ -346,12 +367,10 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
 
                copy_field_content(in_option_field, out_option_field,
                        log_level, self_comp);
-
-               break;
-       }
-       default:
+       } else {
                abort();
        }
+
        BT_COMP_LOGT("Copied content of field: in-f-addr=%p, out-f-addr=%p",
                        in_field, out_field);
 }
This page took 0.026327 seconds and 4 git commands to generate.