From 3b34b490662585394be7352f3544367d4e50a5bc Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 16 Oct 2019 09:51:59 -0400 Subject: [PATCH] debug-info: have `copy_*_content()` function return _STATUS This commit also changes the uses of error logging macros to append the cause of the failure. Signed-off-by: Francis Deslauriers Change-Id: I5fd97b52b42f74f96c64bdd794efd45a0b961144 Reviewed-on: https://review.lttng.org/c/babeltrace/+/2208 Tested-by: jenkins --- src/plugins/lttng-utils/debug-info/bin-info.c | 6 +- .../lttng-utils/debug-info/debug-info.c | 66 ++-- .../debug-info/trace-ir-data-copy.c | 197 +++++++--- .../debug-info/trace-ir-data-copy.h | 15 +- .../lttng-utils/debug-info/trace-ir-mapping.c | 165 +++++--- .../lttng-utils/debug-info/trace-ir-mapping.h | 5 + .../debug-info/trace-ir-metadata-copy.c | 356 +++++++++++------- .../debug-info/trace-ir-metadata-copy.h | 14 +- .../trace-ir-metadata-field-class-copy.c | 351 +++++++++-------- 9 files changed, 750 insertions(+), 425 deletions(-) diff --git a/src/plugins/lttng-utils/debug-info/bin-info.c b/src/plugins/lttng-utils/debug-info/bin-info.c index 080472a9..81abbe5d 100644 --- a/src/plugins/lttng-utils/debug-info/bin-info.c +++ b/src/plugins/lttng-utils/debug-info/bin-info.c @@ -177,14 +177,16 @@ int bin_info_set_elf_file(struct bin_info *bin) elf_file = elf_begin(bt_fd_cache_handle_get_fd(bin->elf_handle), ELF_C_READ, NULL); if (!elf_file) { - BT_COMP_LOGE("elf_begin failed: %s", elf_errmsg(-1)); + BT_COMP_LOGE_APPEND_CAUSE(bin->self_comp, + "elf_begin failed: %s", elf_errmsg(-1)); goto error; } bin->elf_file = elf_file; if (elf_kind(elf_file) != ELF_K_ELF) { - BT_COMP_LOGE("Error: %s is not an ELF object", bin->elf_path); + BT_COMP_LOGE_APPEND_CAUSE(bin->self_comp, + "Error: %s is not an ELF object", bin->elf_path); goto error; } diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index 71bb4c1a..88f1ccba 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -205,7 +205,8 @@ struct debug_info_source *debug_info_source_create_from_bin( debug_info_src->line_no = g_strdup_printf("%"PRId64, src_loc->line_no); if (!debug_info_src->line_no) { - BT_COMP_LOGE("Error occured when setting line_no field."); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error occured when setting `line_no` field."); goto error; } @@ -962,7 +963,7 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src, dbg_info_src->short_bin_path); } if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set path component of \"bin\" " + BT_COMP_LOGE("Cannot set path component of `bin` " "curr_field field's value: str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); @@ -971,7 +972,7 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src, append_status = bt_field_string_append(curr_field, dbg_info_src->bin_loc); if (append_status != BT_FIELD_STRING_APPEND_STATUS_OK) { - BT_COMP_LOGE("Cannot set bin location component of \"bin\" " + BT_COMP_LOGE("Cannot set bin location component of `bin` " "curr_field field's value: str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); @@ -979,7 +980,7 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src, } else { set_status = bt_field_string_set_value(curr_field, ""); if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set \"bin\" curr_field field's value: " + BT_COMP_LOGE("Cannot set `bin` curr_field field's value: " "str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); } @@ -1002,7 +1003,7 @@ void fill_debug_info_func_field(struct debug_info_source *dbg_info_src, status = bt_field_string_set_value(curr_field, ""); } if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set \"func\" curr_field field's value: " + BT_COMP_LOGE("Cannot set `func` curr_field field's value: " "str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); } @@ -1029,7 +1030,7 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src, dbg_info_src->short_src_path); } if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set path component of \"src\" " + BT_COMP_LOGE("Cannot set path component of `src` " "curr_field field's value: str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); @@ -1037,7 +1038,7 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src, append_status = bt_field_string_append(curr_field, ":"); if (append_status != BT_FIELD_STRING_APPEND_STATUS_OK) { - BT_COMP_LOGE("Cannot set colon component of \"src\" " + BT_COMP_LOGE("Cannot set colon component of `src` " "curr_field field's value: str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); @@ -1046,7 +1047,7 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src, append_status = bt_field_string_append(curr_field, dbg_info_src->line_no); if (append_status != BT_FIELD_STRING_APPEND_STATUS_OK) { - BT_COMP_LOGE("Cannot set line number component of \"src\" " + BT_COMP_LOGE("Cannot set line number component of `src` " "curr_field field's value: str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); @@ -1054,7 +1055,7 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src, } else { set_status = bt_field_string_set_value(curr_field, ""); if (set_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set \"src\" curr_field field's value: " + BT_COMP_LOGE("Cannot set `src` curr_field field's value: " "str-fc-addr=%p", curr_field); bt_current_thread_clear_error(); } @@ -1087,21 +1088,21 @@ void fill_debug_info_field_empty(bt_field *debug_info_field, status = bt_field_string_set_value(bin_field, ""); if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set \"bin\" bin_field field's value: " + BT_COMP_LOGE("Cannot set `bin` field's value: " "str-fc-addr=%p", bin_field); bt_current_thread_clear_error(); } status = bt_field_string_set_value(func_field, ""); if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set \"func\" func_field field's value: " + BT_COMP_LOGE("Cannot set `func` field's value: " "str-fc-addr=%p", func_field); bt_current_thread_clear_error(); } status = bt_field_string_set_value(src_field, ""); if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set \"src\" src_field field's value: " + BT_COMP_LOGE("Cannot set `src` field's value: " "str-fc-addr=%p", src_field); bt_current_thread_clear_error(); } @@ -1328,14 +1329,21 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it, } if (!out_message) { - BT_COMP_LOGE("Error creating output event message."); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output event message."); goto error; } out_event = bt_message_event_borrow_event(out_message); /* Copy the original fields to the output event. */ - copy_event_content(in_event, out_event, log_level, self_comp); + if (copy_event_content(in_event, out_event, log_level, self_comp) != + DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying event message content output event message: " + "in-ev-addr=%p, out-ev-addr=%p", in_event, out_event); + goto error; + } /* * Try to set the debug-info fields based on debug information that is @@ -1343,7 +1351,11 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it, */ fill_debug_info_event_if_needed(debug_it, in_event, out_event); + goto end; + error: + BT_MESSAGE_PUT_REF_AND_RESET(out_message); +end: return out_message; } @@ -1372,7 +1384,8 @@ bt_message *handle_stream_begin_message(struct debug_info_msg_iter *debug_it, out_message = bt_message_stream_beginning_create( debug_it->input_iterator, out_stream); if (!out_message) { - BT_COMP_LOGE("Error creating output stream beginning message: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output stream beginning message: " "out-s-addr=%p", out_stream); } error: @@ -1400,8 +1413,9 @@ bt_message *handle_stream_end_message(struct debug_info_msg_iter *debug_it, out_message = bt_message_stream_end_create(debug_it->input_iterator, out_stream); if (!out_message) { - BT_COMP_LOGE("Error creating output stream end message: out-s-addr=%p", - out_stream); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output stream end message: " + "out-s-addr=%p", out_stream); goto end; } @@ -1454,7 +1468,8 @@ bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it, debug_it->input_iterator, out_packet); } if (!out_message) { - BT_COMP_LOGE("Error creating output packet beginning message: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output packet beginning message: " "out-p-addr=%p", out_packet); } @@ -1498,7 +1513,8 @@ bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it, } if (!out_message) { - BT_COMP_LOGE("Error creating output packet end message: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output packet end message: " "out-p-addr=%p", out_packet); goto end; } @@ -1564,7 +1580,8 @@ bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it debug_it->input_iterator, out_stream); } if (!out_message) { - BT_COMP_LOGE("Error creating output discarded events message: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output discarded events message: " "out-s-addr=%p", out_stream); goto error; } @@ -1624,7 +1641,8 @@ bt_message *handle_discarded_packets_message(struct debug_info_msg_iter *debug_i debug_it->input_iterator, out_stream); } if (!out_message) { - BT_COMP_LOGE("Error creating output discarded packet message: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output discarded packet message: " "out-s-addr=%p", out_stream); goto error; } @@ -1774,7 +1792,8 @@ bt_component_class_initialize_method_status debug_info_comp_init( debug_info_comp = g_new0(struct debug_info_component, 1); if (!debug_info_comp) { - BT_COMP_LOGE_STR("Failed to allocate one debug_info component."); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to allocate one debug_info component."); goto error; } @@ -1798,7 +1817,8 @@ bt_component_class_initialize_method_status debug_info_comp_init( status = init_from_params(debug_info_comp, params); if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) { - BT_COMP_LOGE("Cannot configure debug_info component: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot configure debug_info component: " "debug_info-comp-addr=%p, params-addr=%p", debug_info_comp, params); goto error; diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c b/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c index 42395904..19ad1f2f 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c +++ b/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c @@ -36,23 +36,28 @@ #include "trace-ir-data-copy.h" BT_HIDDEN -void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace, +enum debug_info_trace_ir_mapping_status copy_trace_content( + const bt_trace *in_trace, bt_trace *out_trace, bt_logging_level log_level, bt_self_component *self_comp) { - bt_trace_set_name_status status; + enum debug_info_trace_ir_mapping_status status; const char *trace_name; uint64_t i, env_field_count; BT_COMP_LOGD("Copying content of trace: in-t-addr=%p, out-t-addr=%p", in_trace, out_trace); + trace_name = bt_trace_get_name(in_trace); + /* Copy the trace name. */ if (trace_name) { - status = bt_trace_set_name(out_trace, trace_name); - if (status != BT_TRACE_SET_NAME_STATUS_OK) { - BT_COMP_LOGE("Cannot set trace's name: trace-addr=%p, name=\"%s\"", - out_trace, trace_name); - bt_current_thread_clear_error(); + bt_trace_set_name_status set_name_status = + bt_trace_set_name(out_trace, trace_name); + if (set_name_status != BT_TRACE_SET_NAME_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot set trace's name: " + "out-t-addr=%p, name=\"%s\"", out_trace, + trace_name); + status = (int) set_name_status; goto end; } } @@ -65,7 +70,7 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace, bt_trace_borrow_user_attributes_const(in_trace)); /* - * Do not copy the trace UUID as it may be modified and should + * Do not copy the trace UUID as the trace may be modified and should * no longer have the same UUID. */ @@ -83,7 +88,7 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace, in_trace, i, &value_name, &value); BT_COMP_LOGD("Copying trace environnement entry: " - "index=%" PRId64 ", value-addr=%p, value-name=%s", + "index=%" PRId64 ", value-addr=%p, value-name=\"%s\"", i, value, value_name); BT_ASSERT(value_name); @@ -102,36 +107,43 @@ void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace, } if (set_env_status != BT_TRACE_SET_ENVIRONMENT_ENTRY_STATUS_OK) { - BT_COMP_LOGE("Cannot copy trace's environment: " - "trace-addr=%p, name=\"%s\"", + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy trace's environment: " + "out-t-addr=%p, name=\"%s\"", out_trace, trace_name); - bt_current_thread_clear_error(); + status = (int) set_env_status; goto end; } } BT_COMP_LOGD("Copied content of trace: in-t-addr=%p, out-t-addr=%p", - in_trace, out_trace); + in_trace, out_trace); + + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; end: - return; + return status; } BT_HIDDEN -void copy_stream_content(const bt_stream *in_stream, bt_stream *out_stream, +enum debug_info_trace_ir_mapping_status copy_stream_content( + const bt_stream *in_stream, bt_stream *out_stream, bt_logging_level log_level, bt_self_component *self_comp) { + enum debug_info_trace_ir_mapping_status status; const char *stream_name; - bt_stream_set_name_status status; BT_COMP_LOGD("Copying content of stream: in-s-addr=%p, out-s-addr=%p", in_stream, out_stream); stream_name = bt_stream_get_name(in_stream); + if (stream_name) { - status = bt_stream_set_name(out_stream, stream_name); - if (status != BT_STREAM_SET_NAME_STATUS_OK) { - BT_COMP_LOGE("Cannot set stream's name: stream-addr=%p, " - "name=%s", out_stream, stream_name); + bt_stream_set_name_status set_name_status = + bt_stream_set_name(out_stream, stream_name); + if (set_name_status != BT_STREAM_SET_NAME_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot set stream's name: " + "stream-addr=%p, name=\"%s\"", out_stream, + stream_name); + status = (int) set_name_status; goto end; } } @@ -142,16 +154,20 @@ void copy_stream_content(const bt_stream *in_stream, bt_stream *out_stream, */ 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); + in_stream, out_stream); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; end: - return; + return status; } BT_HIDDEN -void copy_packet_content(const bt_packet *in_packet, bt_packet *out_packet, +enum debug_info_trace_ir_mapping_status copy_packet_content( + const bt_packet *in_packet, bt_packet *out_packet, bt_logging_level log_level, bt_self_component *self_comp) { + enum debug_info_trace_ir_mapping_status status; const bt_field *in_context_field; bt_field *out_context_field; @@ -163,19 +179,29 @@ void copy_packet_content(const bt_packet *in_packet, bt_packet *out_packet, if (in_context_field) { out_context_field = bt_packet_borrow_context_field(out_packet); BT_ASSERT(out_context_field); - copy_field_content(in_context_field, out_context_field, + status = copy_field_content(in_context_field, out_context_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy context field: " + "in-ctx-f-addr=%p, out-ctx-f-addr=%p", + in_context_field, out_context_field); + goto end; + } } BT_COMP_LOGD("Copied content of packet: in-p-addr=%p, out-p-addr=%p", in_packet, out_packet); - return; + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } BT_HIDDEN -void copy_event_content(const bt_event *in_event, bt_event *out_event, +enum debug_info_trace_ir_mapping_status copy_event_content( + const bt_event *in_event, bt_event *out_event, bt_logging_level log_level, bt_self_component *self_comp) { + enum debug_info_trace_ir_mapping_status status; const bt_field *in_common_ctx_field, *in_specific_ctx_field, *in_payload_field; bt_field *out_common_ctx_field, *out_specific_ctx_field, @@ -189,8 +215,15 @@ void copy_event_content(const bt_event *in_event, bt_event *out_event, out_common_ctx_field = bt_event_borrow_common_context_field(out_event); BT_ASSERT_DBG(out_common_ctx_field); - copy_field_content(in_common_ctx_field, + + status = copy_field_content(in_common_ctx_field, out_common_ctx_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy common context field: " + "in-comm-ctx-f-addr=%p, out-comm-ctx-f-addr=%p", + in_common_ctx_field, out_common_ctx_field); + goto end; + } } in_specific_ctx_field = @@ -199,26 +232,45 @@ void copy_event_content(const bt_event *in_event, bt_event *out_event, out_specific_ctx_field = bt_event_borrow_specific_context_field(out_event); BT_ASSERT_DBG(out_specific_ctx_field); - copy_field_content(in_specific_ctx_field, + + status = copy_field_content(in_specific_ctx_field, out_specific_ctx_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy specific context field: " + "in-spec-ctx-f-addr=%p, out-spec-ctx-f-addr=%p", + in_specific_ctx_field, out_specific_ctx_field); + goto end; + } } 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_DBG(out_payload_field); - copy_field_content(in_payload_field, + + status = copy_field_content(in_payload_field, out_payload_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy payloat field: " + "in-payload-f-addr=%p, out-payload-f-addr=%p", + in_payload_field, out_payload_field); + goto end; + } } BT_COMP_LOGD("Copied content of event: in-e-addr=%p, out-e-addr=%p", in_event, out_event); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } BT_HIDDEN -void copy_field_content(const bt_field *in_field, bt_field *out_field, +enum debug_info_trace_ir_mapping_status copy_field_content( + const bt_field *in_field, bt_field *out_field, bt_logging_level log_level, bt_self_component *self_comp) { + enum debug_info_trace_ir_mapping_status status; bt_field_class_type in_fc_type, out_fc_type; in_fc_type = bt_field_get_class_type(in_field); @@ -237,27 +289,27 @@ void copy_field_content(const bt_field *in_field, bt_field *out_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)); + bt_field_integer_unsigned_get_value(in_field)); } 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)); + bt_field_integer_signed_get_value(in_field)); } 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)); + 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)); + 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_status set_value_status = bt_field_string_set_value(out_field, str); - if (status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { - BT_COMP_LOGE("Cannot set string field's value: " - "str-field-addr=%p, str=%s" PRId64, + if (set_value_status != BT_FIELD_STRING_SET_VALUE_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot set string field's value: " + "out-str-f-addr=%p, str=\"%s\"" PRId64, out_field, str); - bt_current_thread_clear_error(); - + status = (int) set_value_status; + goto end; } } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) { uint64_t i, nb_member_struct; @@ -268,7 +320,7 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field, in_field_class = bt_field_borrow_class_const(in_field); nb_member_struct = bt_field_class_structure_get_member_count( - in_field_class); + in_field_class); /* * Iterate over the fields by names in the input field to avoid @@ -290,8 +342,18 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field, bt_field_structure_borrow_member_field_by_name( out_field, in_member_name); - copy_field_content(in_member_field, + status = copy_field_content(in_member_field, out_member_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy struct member field: " + "out-struct-f-addr=%p, " + "out-struct-member-f-addr=%p, " + "member-name=\"%s\"", + out_field, out_member_field, + in_member_name); + goto end; + } } } else if (bt_field_class_type_is(in_fc_type, BT_FIELD_CLASS_TYPE_ARRAY)) { @@ -308,10 +370,12 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field, out_field, array_len); if (set_len_status != BT_FIELD_DYNAMIC_ARRAY_SET_LENGTH_STATUS_OK) { - BT_COMP_LOGE("Cannot set dynamic array field's " - "length field: field-addr=%p, " - "length=%" PRIu64, out_field, array_len); - bt_current_thread_clear_error(); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot set dynamic array field's length field: " + "out-arr-f-addr=%p, arr-length=%" PRIu64, + out_field, array_len); + status = (int) set_len_status; + goto end; } } @@ -322,8 +386,15 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field, out_element_field = bt_field_array_borrow_element_field_by_index( out_field, i); - copy_field_content(in_element_field, out_element_field, - log_level, self_comp); + status = copy_field_content(in_element_field, + out_element_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy element field: " + "out-arr-f-addr=%p, out-arr-elem-f-addr=%p", + out_field, out_element_field); + goto end; + } } } else if (bt_field_class_type_is(in_fc_type, BT_FIELD_CLASS_TYPE_OPTION)) { @@ -337,8 +408,15 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field, 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, + status = copy_field_content(in_option_field, out_option_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy option field: " + "out-opt-f-addr=%p, out-opt-field-f-addr=%p", + out_field, out_option_field); + goto end; + } } else { bt_field_option_set_has_field(out_field, BT_FALSE); } @@ -356,21 +434,34 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field, 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: " - "var-field-addr=%p, opt-index=%" PRId64, + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot select variant field's option field: " + "out-var-f-addr=%p, opt-index=%" PRId64, out_field, in_selected_option_idx); - bt_current_thread_clear_error(); + status = (int) sel_opt_status; + goto end; } in_option_field = bt_field_variant_borrow_selected_option_field_const(in_field); out_option_field = bt_field_variant_borrow_selected_option_field(out_field); - copy_field_content(in_option_field, out_option_field, + status = copy_field_content(in_option_field, out_option_field, log_level, self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy element field: " + "out-var-f-addr=%p, out-opt-f-addr=%p", + out_field, out_option_field); + goto end; + } } else { abort(); } BT_COMP_LOGT("Copied content of field: in-f-addr=%p, out-f-addr=%p", in_field, out_field); + + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.h b/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.h index baa28689..be0531cf 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.h +++ b/src/plugins/lttng-utils/debug-info/trace-ir-data-copy.h @@ -32,19 +32,24 @@ #include "trace-ir-mapping.h" BT_HIDDEN -void copy_trace_content(const bt_trace *in_trace, bt_trace *out_trace, +enum debug_info_trace_ir_mapping_status copy_trace_content( + const bt_trace *in_trace, bt_trace *out_trace, bt_logging_level log_level, bt_self_component *self_comp); BT_HIDDEN -void copy_stream_content(const bt_stream *in_stream, bt_stream *out_stream, +enum debug_info_trace_ir_mapping_status copy_stream_content( + const bt_stream *in_stream, bt_stream *out_stream, bt_logging_level log_level, bt_self_component *self_comp); BT_HIDDEN -void copy_packet_content(const bt_packet *in_packet, bt_packet *out_packet, +enum debug_info_trace_ir_mapping_status copy_packet_content( + const bt_packet *in_packet, bt_packet *out_packet, bt_logging_level log_level, bt_self_component *self_comp); BT_HIDDEN -void copy_event_content(const bt_event *in_event, bt_event *out_event, +enum debug_info_trace_ir_mapping_status copy_event_content( + const bt_event *in_event, bt_event *out_event, bt_logging_level log_level, bt_self_component *self_comp); BT_HIDDEN -void copy_field_content(const bt_field *in_field, bt_field *out_field, +enum debug_info_trace_ir_mapping_status copy_field_content( + const bt_field *in_field, bt_field *out_field, bt_logging_level log_level, bt_self_component *self_comp); #endif /* BABELTRACE_PLUGIN_DEBUG_INFO_TRACE_DATA_COPY_H */ diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-mapping.c b/src/plugins/lttng-utils/debug-info/trace-ir-mapping.c index 3acc1d33..439407a5 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-mapping.c +++ b/src/plugins/lttng-utils/debug-info/trace-ir-mapping.c @@ -46,8 +46,9 @@ static bt_trace_class *create_new_mapped_trace_class(struct trace_ir_maps *ir_maps, const bt_trace_class *in_trace_class) { + bt_self_component *self_comp = ir_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; struct trace_ir_metadata_maps *metadata_maps; - int ret; BT_COMP_LOGD("Creating new mapped trace class: in-tc-addr=%p", in_trace_class); @@ -63,24 +64,30 @@ bt_trace_class *create_new_mapped_trace_class(struct trace_ir_maps *ir_maps, metadata_maps->output_trace_class = bt_trace_class_create(ir_maps->self_comp); if (!metadata_maps->output_trace_class) { - BT_COMP_LOGE_STR("Error create output trace class"); - goto end; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error create output trace class"); + goto error; } /* Copy the content over and add to the mapping. */ - ret = copy_trace_class_content(ir_maps, in_trace_class, + status = copy_trace_class_content(ir_maps, in_trace_class, metadata_maps->output_trace_class, ir_maps->log_level, ir_maps->self_comp); - if (ret) { - BT_COMP_LOGE_STR("Error copy content to output trace class"); - BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata_maps->output_trace_class); - metadata_maps->output_trace_class = NULL; - goto end; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copy content to output trace class" + "in-tc-addr=%p, out-tc-addr=%p", in_trace_class, + metadata_maps->output_trace_class); + goto error; } - BT_COMP_LOGD("Created new mapped trace class: in-tc-addr=%p, out-tc-addr=%p", + BT_COMP_LOGD("Created new mapped trace class: " + "in-tc-addr=%p, out-tc-addr=%p", in_trace_class, metadata_maps->output_trace_class); + goto end; +error: + BT_TRACE_CLASS_PUT_REF_AND_RESET(metadata_maps->output_trace_class); end: return metadata_maps->output_trace_class; } @@ -89,6 +96,8 @@ static bt_trace *create_new_mapped_trace(struct trace_ir_maps *ir_maps, const bt_trace *in_trace) { + bt_self_component *self_comp = ir_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; struct trace_ir_metadata_maps *metadata_maps; const bt_trace_class *in_trace_class; bt_trace *out_trace; @@ -109,6 +118,8 @@ bt_trace *create_new_mapped_trace(struct trace_ir_maps *ir_maps, metadata_maps->output_trace_class = create_new_mapped_trace_class(ir_maps, in_trace_class); if (!metadata_maps->output_trace_class) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error create output trace class"); out_trace = NULL; goto end; } @@ -117,16 +128,27 @@ bt_trace *create_new_mapped_trace(struct trace_ir_maps *ir_maps, /* Create the output trace from the output trace class. */ out_trace = bt_trace_create(metadata_maps->output_trace_class); if (!out_trace) { - BT_COMP_LOGE_STR("Error create output trace"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error create output trace"); goto end; } /* Copy the content over to the output trace. */ - copy_trace_content(in_trace, out_trace, ir_maps->log_level, + status = copy_trace_content(in_trace, out_trace, ir_maps->log_level, ir_maps->self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copy content to output trace" + "in-t-addr=%p, out-t-addr=%p", in_trace, out_trace); + goto error; + } BT_COMP_LOGD("Created new mapped trace: in-t-addr=%p, out-t-addr=%p", in_trace, out_trace); + goto end; + +error: + BT_TRACE_PUT_REF_AND_RESET(out_trace); end: return out_trace; } @@ -151,9 +173,10 @@ bt_stream_class *trace_ir_mapping_create_new_mapped_stream_class( struct trace_ir_maps *ir_maps, const bt_stream_class *in_stream_class) { + bt_self_component *self_comp = ir_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; struct trace_ir_metadata_maps *md_maps; bt_stream_class *out_stream_class; - int ret; BT_COMP_LOGD("Creating new mapped stream class: in-sc-addr=%p", in_stream_class); @@ -173,26 +196,33 @@ bt_stream_class *trace_ir_mapping_create_new_mapped_stream_class( md_maps->output_trace_class, bt_stream_class_get_id(in_stream_class)); if (!out_stream_class) { - BT_COMP_LOGE_STR("Error create output stream class"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error create output stream class"); goto end; } - /* Add it to the mapping. */ + /* Add it to the mapping. The mapping now owns out_stream_class. */ g_hash_table_insert(md_maps->stream_class_map, (gpointer) in_stream_class, out_stream_class); /* Copy the content over to the output stream class. */ - ret = copy_stream_class_content(ir_maps, in_stream_class, + status = copy_stream_class_content(ir_maps, in_stream_class, out_stream_class); - if (ret) { - BT_COMP_LOGE_STR("Error copy content to output stream class"); - out_stream_class = NULL; - goto end; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copy content to output stream class: " + "in-sc-addr=%p, out-sc-addr=%p", in_stream_class, + out_stream_class); + goto error; } - BT_COMP_LOGD("Created new mapped stream class: in-sc-addr=%p, out-sc-addr=%p", + BT_COMP_LOGD("Created new mapped stream class: " + "in-sc-addr=%p, out-sc-addr=%p", in_stream_class, out_stream_class); + goto end; +error: + out_stream_class = NULL; end: return out_stream_class; } @@ -211,6 +241,8 @@ BT_HIDDEN bt_stream *trace_ir_mapping_create_new_mapped_stream( struct trace_ir_maps *ir_maps, const bt_stream *in_stream) { + bt_self_component *self_comp = ir_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; struct trace_ir_data_maps *d_maps; const bt_stream_class *in_stream_class; const bt_trace *in_trace; @@ -228,7 +260,9 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream( /* Create the output trace for this input trace. */ d_maps->output_trace = create_new_mapped_trace(ir_maps, in_trace); if (!d_maps->output_trace) { - goto end; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating mapped trace"); + goto error; } } @@ -244,7 +278,9 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream( out_stream_class = trace_ir_mapping_create_new_mapped_stream_class( ir_maps, in_stream_class); if (!out_stream_class) { - goto end; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating mapped stream class"); + goto error; } } BT_ASSERT(out_stream_class); @@ -253,21 +289,31 @@ bt_stream *trace_ir_mapping_create_new_mapped_stream( out_stream = bt_stream_create_with_id(out_stream_class, d_maps->output_trace, bt_stream_get_id(in_stream)); if (!out_stream) { - BT_COMP_LOGE_STR("Error creating output stream"); - goto end; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output stream"); + goto error; } - /* Add it to the mapping. */ + /* Add it to the mapping. The mapping now owns out_stream.*/ g_hash_table_insert(d_maps->stream_map, (gpointer) in_stream, out_stream); /* Copy the content over to the output stream. */ - copy_stream_content(in_stream, out_stream, ir_maps->log_level, + status = copy_stream_content(in_stream, out_stream, ir_maps->log_level, ir_maps->self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copy content to output stream: " + "in-s-addr=%p, out-s-addr=%p", in_stream, out_stream); + goto error; + } BT_COMP_LOGD("Created new mapped stream: in-s-addr=%p, out-s-addr=%p", in_stream, out_stream); + goto end; +error: + out_stream = NULL; end: return out_stream; } @@ -299,11 +345,12 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class( struct trace_ir_maps *ir_maps, const bt_event_class *in_event_class) { + bt_self_component *self_comp = ir_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; struct trace_ir_metadata_maps *md_maps; const bt_stream_class *in_stream_class; bt_stream_class *out_stream_class; bt_event_class *out_event_class; - int ret; BT_COMP_LOGD("Creating new mapped event class: in-ec-addr=%p", in_event_class); @@ -330,26 +377,32 @@ bt_event_class *trace_ir_mapping_create_new_mapped_event_class( out_event_class = bt_event_class_create_with_id(out_stream_class, bt_event_class_get_id(in_event_class)); if (!out_event_class) { - BT_COMP_LOGE_STR("Error creating output event class"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output event class"); goto end; } - /* Add it to the mapping. */ - g_hash_table_insert(md_maps->event_class_map, - (gpointer) in_event_class, out_event_class); + /* Add it to the mapping. The mapping now owns out_event_class. */ + g_hash_table_insert(md_maps->event_class_map, (gpointer) in_event_class, + out_event_class); /* Copy the content over to the output event class. */ - ret = copy_event_class_content(ir_maps, in_event_class, + status = copy_event_class_content(ir_maps, in_event_class, out_event_class); - if (ret) { - BT_COMP_LOGE_STR("Error copy content to output event class"); - out_event_class = NULL; - goto end; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copy content to output event class: " + "in-ec-addr=%p, out-ec-addr=%p", in_event_class, + out_event_class); + goto error; } BT_COMP_LOGD("Created new mapped event class: in-ec-addr=%p, out-ec-addr=%p", in_event_class, out_event_class); + goto end; +error: + out_event_class = NULL; end: return out_event_class; } @@ -386,6 +439,8 @@ bt_packet *trace_ir_mapping_create_new_mapped_packet( struct trace_ir_maps *ir_maps, const bt_packet *in_packet) { + bt_self_component *self_comp = ir_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; struct trace_ir_data_maps *d_maps; const bt_stream *in_stream; const bt_trace *in_trace; @@ -409,21 +464,31 @@ bt_packet *trace_ir_mapping_create_new_mapped_packet( /* Create the output packet. */ out_packet = bt_packet_create(out_stream); if (!out_packet) { - BT_COMP_LOGE_STR("Error create output packet"); - goto end; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error create output packet"); + goto error; } - /* Add it to the mapping. */ - g_hash_table_insert(d_maps->packet_map, - (gpointer) in_packet, out_packet); + /* Add it to the mapping. The mapping now owns out_packet. */ + g_hash_table_insert(d_maps->packet_map, (gpointer) in_packet, + out_packet); /* Copy the content over to the output packet. */ - copy_packet_content(in_packet, out_packet, ir_maps->log_level, + status = copy_packet_content(in_packet, out_packet, ir_maps->log_level, ir_maps->self_comp); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copy content to output packet: " + "in-p-addr=%p, out-p-addr=%p", in_packet, out_packet); + goto error; + } BT_COMP_LOGD("Created new mapped packet: in-p-addr=%p, out-p-addr=%p", in_packet, out_packet); + goto end; +error: + out_packet = NULL; end: return out_packet; } @@ -502,11 +567,13 @@ void trace_ir_data_maps_remove_func(const bt_trace *in_trace, void *data) struct trace_ir_data_maps *trace_ir_data_maps_create(struct trace_ir_maps *ir_maps, const bt_trace *in_trace) { + bt_self_component *self_comp = ir_maps->self_comp; bt_trace_add_listener_status add_listener_status; struct trace_ir_data_maps *d_maps = g_new0(struct trace_ir_data_maps, 1); if (!d_maps) { - BT_COMP_LOGE_STR("Error allocating trace_ir_maps"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error allocating trace_ir_maps"); goto error; } @@ -533,12 +600,14 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create( struct trace_ir_maps *ir_maps, const bt_trace_class *in_trace_class) { + bt_self_component *self_comp = ir_maps->self_comp; bt_trace_class_add_listener_status add_listener_status; struct trace_ir_metadata_maps *md_maps = g_new0(struct trace_ir_metadata_maps, 1); if (!md_maps) { - BT_COMP_LOGE_STR("Error allocating trace_ir_maps"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error allocating trace_ir_maps"); goto error; } @@ -553,7 +622,8 @@ struct trace_ir_metadata_maps *trace_ir_metadata_maps_create( md_maps->fc_resolving_ctx = g_new0(struct field_class_resolving_context, 1); if (!md_maps->fc_resolving_ctx) { - BT_COMP_LOGE_STR("Error allocating field_class_resolving_context"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error allocating field_class_resolving_context"); goto error; } @@ -702,7 +772,8 @@ struct trace_ir_maps *trace_ir_maps_create(bt_self_component *self_comp, /* Copy debug info field name received from the user. */ ir_maps->debug_info_field_class_name = g_strdup(debug_info_field_name); if (!ir_maps->debug_info_field_class_name) { - BT_COMP_LOGE_STR("Cannot copy debug info field name"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy debug info field name"); goto error; } diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-mapping.h b/src/plugins/lttng-utils/debug-info/trace-ir-mapping.h index 9e5caa9f..45a51995 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-mapping.h +++ b/src/plugins/lttng-utils/debug-info/trace-ir-mapping.h @@ -30,6 +30,11 @@ #include "debug-info.h" +enum debug_info_trace_ir_mapping_status { + DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK = 0, + DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR = -12, +}; + /* Used to resolve field paths for dynamic arrays and variant field classes. */ struct field_class_resolving_context { /* Weak reference. Owned by input stream class. */ diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c index 4f14cd6c..a31da24a 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c +++ b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c @@ -39,11 +39,15 @@ #include "utils.h" BT_HIDDEN -int copy_trace_class_content(struct trace_ir_maps *ir_maps, - const bt_trace_class *in_trace_class, bt_trace_class *out_trace_class, +enum debug_info_trace_ir_mapping_status copy_trace_class_content( + struct trace_ir_maps *ir_maps, + const bt_trace_class *in_trace_class, + bt_trace_class *out_trace_class, bt_logging_level log_level, bt_self_component *self_comp) { + enum debug_info_trace_ir_mapping_status status; uint64_t sc_number, sc_idx; + BT_COMP_LOGD("Copying content of trace class: in-tc-addr=%p, out-tc-addr=%p", in_trace_class, out_trace_class); @@ -69,30 +73,34 @@ int copy_trace_class_content(struct trace_ir_maps *ir_maps, out_stream_class = trace_ir_mapping_borrow_mapped_stream_class( ir_maps, in_stream_class); if (!out_stream_class) { - /* - * We don't need the new stream_class yet. We simply - * want to create it and keep it in the map. - */ - (void) trace_ir_mapping_create_new_mapped_stream_class( + out_stream_class = trace_ir_mapping_create_new_mapped_stream_class( ir_maps, in_stream_class); + if (!out_stream_class) { + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; + goto end; + } } } BT_COMP_LOGD("Copied content of trace class: in-tc-addr=%p, out-tc-addr=%p", in_trace_class, out_trace_class); - return 0; + + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } static -int copy_clock_class_content(const bt_clock_class *in_clock_class, +enum debug_info_trace_ir_mapping_status copy_clock_class_content( + const bt_clock_class *in_clock_class, bt_clock_class *out_clock_class, bt_logging_level log_level, bt_self_component *self_comp) { + enum debug_info_trace_ir_mapping_status status; const char *clock_class_name, *clock_class_description; int64_t seconds; uint64_t cycles; bt_uuid in_uuid; - int ret = 0; BT_COMP_LOGD("Copying content of clock class: in-cc-addr=%p, out-cc-addr=%p", in_clock_class, out_clock_class); @@ -100,13 +108,15 @@ int copy_clock_class_content(const bt_clock_class *in_clock_class, clock_class_name = bt_clock_class_get_name(in_clock_class); if (clock_class_name) { - if (bt_clock_class_set_name(out_clock_class, clock_class_name) - != BT_CLOCK_CLASS_SET_NAME_STATUS_OK) { - BT_COMP_LOGE("Error setting clock class' name cc-addr=%p, name=%p", - out_clock_class, clock_class_name); - out_clock_class = NULL; - ret = -1; - goto error; + enum bt_clock_class_set_name_status set_name_status = + bt_clock_class_set_name(out_clock_class, clock_class_name); + if (set_name_status != BT_CLOCK_CLASS_SET_NAME_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error setting clock class' name: " + "cc-addr=%p, name=%s", out_clock_class, + clock_class_name); + status = (int) set_name_status; + goto end; } } @@ -120,14 +130,15 @@ int copy_clock_class_content(const bt_clock_class *in_clock_class, clock_class_description = bt_clock_class_get_description(in_clock_class); if (clock_class_description) { - if (bt_clock_class_set_description(out_clock_class, - clock_class_description) != - BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK) { - BT_COMP_LOGE("Error setting clock class' description cc-addr=%p, " - "name=%p", out_clock_class, clock_class_description); - out_clock_class = NULL; - ret = -1; - goto error; + enum bt_clock_class_set_description_status set_desc_status = + bt_clock_class_set_description(out_clock_class, clock_class_description); + if (set_desc_status!= BT_CLOCK_CLASS_SET_DESCRIPTION_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error setting clock class' description: " + "cc-addr=%p, cc-desc=%s", out_clock_class, + clock_class_description); + status = (int) set_desc_status; + goto end; } } @@ -148,8 +159,9 @@ int copy_clock_class_content(const bt_clock_class *in_clock_class, BT_COMP_LOGD("Copied content of clock class: in-cc-addr=%p, out-cc-addr=%p", in_clock_class, out_clock_class); -error: - return ret; + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } static @@ -169,9 +181,9 @@ bt_clock_class *create_new_mapped_clock_class(bt_self_component *self_comp, struct trace_ir_metadata_maps *md_maps, const bt_clock_class *in_clock_class) { + enum debug_info_trace_ir_mapping_status status; bt_clock_class *out_clock_class; bt_logging_level log_level = md_maps->log_level; - int ret; BT_COMP_LOGD("Creating new mapped clock class: in-cc-addr=%p", in_clock_class); @@ -183,14 +195,17 @@ bt_clock_class *create_new_mapped_clock_class(bt_self_component *self_comp, out_clock_class = bt_clock_class_create(self_comp); if (!out_clock_class) { - BT_COMP_LOGE_STR("Cannot create clock class"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot create clock class"); goto end; } /* If not, create a new one and add it to the mapping. */ - ret = copy_clock_class_content(in_clock_class, out_clock_class, + status = copy_clock_class_content(in_clock_class, out_clock_class, log_level, self_comp); - if (ret) { - BT_COMP_LOGE_STR("Cannot copy clock class"); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy clock class"); + BT_CLOCK_CLASS_PUT_REF_AND_RESET(out_clock_class); goto end; } @@ -204,10 +219,12 @@ end: } BT_HIDDEN -int copy_stream_class_content(struct trace_ir_maps *ir_maps, +enum debug_info_trace_ir_mapping_status copy_stream_class_content( + struct trace_ir_maps *ir_maps, const bt_stream_class *in_stream_class, bt_stream_class *out_stream_class) { + enum debug_info_trace_ir_mapping_status status; struct trace_ir_metadata_maps *md_maps; const bt_clock_class *in_clock_class; bt_clock_class *out_clock_class; @@ -217,7 +234,6 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, uint64_t ec_number, ec_idx; bt_logging_level log_level = ir_maps->log_level; bt_self_component *self_comp = ir_maps->self_comp; - int ret = 0; BT_COMP_LOGD("Copying content of stream class: in-sc-addr=%p, out-sc-addr=%p", in_stream_class, out_stream_class); @@ -227,15 +243,24 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, in_stream_class); if (in_clock_class) { + enum bt_stream_class_set_default_clock_class_status set_def_cc_status; /* Copy the clock class. */ out_clock_class = borrow_mapped_clock_class(md_maps, in_clock_class); if (!out_clock_class) { out_clock_class = create_new_mapped_clock_class( ir_maps->self_comp, md_maps, in_clock_class); + if (!out_clock_class) { + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; + goto end; + } + } + set_def_cc_status = bt_stream_class_set_default_clock_class( + out_stream_class, out_clock_class); + if (set_def_cc_status != BT_STREAM_CLASS_SET_DEFAULT_CLOCK_CLASS_STATUS_OK) { + status = (int) set_def_cc_status; + goto end; } - bt_stream_class_set_default_clock_class(out_stream_class, - out_clock_class); } /* @@ -265,12 +290,15 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, in_name = bt_stream_class_get_name(in_stream_class); if (in_name) { - if (bt_stream_class_set_name(out_stream_class, in_name) != - BT_STREAM_CLASS_SET_NAME_STATUS_OK) { - BT_COMP_LOGE("Error set stream class name: out-sc-addr=%p, " - "name=%s", out_stream_class, in_name); - ret = -1; - goto error; + enum bt_stream_class_set_name_status set_name_status = + bt_stream_class_set_name(out_stream_class, in_name); + if (set_name_status != BT_STREAM_CLASS_SET_NAME_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error set stream class name: " + "out-sc-addr=%p, name=%s", out_stream_class, + in_name); + status = (int) set_name_status; + goto end; } } @@ -290,25 +318,30 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, in_packet_context_fc; if (in_packet_context_fc) { + enum bt_stream_class_set_field_class_status set_fc_status; /* Copy packet context. */ out_packet_context_fc = create_field_class_copy(md_maps, in_packet_context_fc); - ret = copy_field_class_content(md_maps, in_packet_context_fc, + status = copy_field_class_content(md_maps, in_packet_context_fc, out_packet_context_fc); - if (ret) { - ret = -1; - goto error; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying stream class' packet context field class: " + "in-packet-ctx-fc-addr=%p, out-packet-ctx-fc-addr=%p", + in_packet_context_fc, out_packet_context_fc); + goto end; } - if (bt_stream_class_set_packet_context_field_class( - out_stream_class, out_packet_context_fc) != - BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { - BT_COMP_LOGE("Error setting stream class' packet context " - "field class: sc-addr=%p, packet-fc-addr=%p", + set_fc_status = bt_stream_class_set_packet_context_field_class( + out_stream_class, out_packet_context_fc); + if (set_fc_status != BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error setting stream class' packet context field class: " + "out-sc-addr=%p, out-packet-ctx-fc-addr=%p", out_stream_class, out_packet_context_fc); - ret = -1; - goto error; + status = (int) set_fc_status; + goto end; } } @@ -322,28 +355,33 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, md_maps->fc_resolving_ctx->event_common_context = in_common_context_fc; if (in_common_context_fc) { + enum bt_stream_class_set_field_class_status set_fc_status; /* Copy common context. */ /* TODO: I find it a bit awkward to have this special function * here to add the debug-info field class. I would like to * abstract that.*/ out_common_context_fc = create_field_class_copy(md_maps, in_common_context_fc); - - ret = copy_event_common_context_field_class_content(md_maps, + status = copy_event_common_context_field_class_content(md_maps, ir_maps->debug_info_field_class_name, in_common_context_fc, out_common_context_fc); - if (ret) { - goto error; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying stream class' common context field class: " + "in-comm-ctx-fc-addr=%p, out-comm-ctx-fc-addr=%p", + in_common_context_fc, out_common_context_fc); + goto end; } - if (bt_stream_class_set_event_common_context_field_class( - out_stream_class, out_common_context_fc) != - BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { - BT_COMP_LOGE("Error setting stream class' packet context " - "field class: sc-addr=%p, packet-fc-addr=%p", + set_fc_status = bt_stream_class_set_event_common_context_field_class( + out_stream_class, out_common_context_fc); + if (set_fc_status != BT_STREAM_CLASS_SET_FIELD_CLASS_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error setting stream class' common context field class: " + "out-sc-addr=%p, out-comm-ctx-fc-addr=%p", out_stream_class, out_common_context_fc); - ret = -1; - goto error; + status = (int) set_fc_status; + goto end; } } @@ -361,29 +399,36 @@ int copy_stream_class_content(struct trace_ir_maps *ir_maps, * We don't need the new event_class yet. We simply * want to create it and keep it in the map. */ - (void) trace_ir_mapping_create_new_mapped_event_class( + out_event_class = trace_ir_mapping_create_new_mapped_event_class( ir_maps, in_event_class); + if (!out_event_class) { + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; + goto end; + } } } BT_COMP_LOGD("Copied content of stream class: in-sc-addr=%p, out-sc-addr=%p", in_stream_class, out_stream_class); -error: - return ret; + + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } BT_HIDDEN -int copy_event_class_content(struct trace_ir_maps *ir_maps, +enum debug_info_trace_ir_mapping_status copy_event_class_content( + struct trace_ir_maps *ir_maps, const bt_event_class *in_event_class, bt_event_class *out_event_class) { + enum debug_info_trace_ir_mapping_status status; struct trace_ir_metadata_maps *md_maps; const char *in_event_class_name, *in_emf_uri; bt_property_availability prop_avail; bt_event_class_log_level ec_log_level; bt_field_class *out_specific_context_fc, *out_payload_fc; const bt_field_class *in_event_specific_context, *in_event_payload; - int ret = 0; bt_logging_level log_level = ir_maps->log_level; bt_self_component *self_comp = ir_maps->self_comp; @@ -393,13 +438,13 @@ int copy_event_class_content(struct trace_ir_maps *ir_maps, /* Copy event class name. */ in_event_class_name = bt_event_class_get_name(in_event_class); if (in_event_class_name) { - if (bt_event_class_set_name(out_event_class, - in_event_class_name) != - BT_EVENT_CLASS_SET_NAME_STATUS_OK) { - BT_COMP_LOGE("Error setting event class' name: ec-addr=%p, " + enum bt_event_class_set_name_status set_name_status = + bt_event_class_set_name(out_event_class, in_event_class_name); + if (set_name_status != BT_EVENT_CLASS_SET_NAME_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error setting event class' name: ec-addr=%p, " "name=%s", out_event_class, in_event_class_name); - ret = -1; - goto error; + status = (int) set_name_status; + goto end; } } @@ -420,12 +465,15 @@ int copy_event_class_content(struct trace_ir_maps *ir_maps, /* Copy event class emf uri. */ in_emf_uri = bt_event_class_get_emf_uri(in_event_class); if (in_emf_uri) { - if (bt_event_class_set_emf_uri(out_event_class, in_emf_uri) != - BT_EVENT_CLASS_SET_EMF_URI_STATUS_OK) { - BT_COMP_LOGE("Error setting event class' emf uri: ec-addr=%p, " - "emf uri=%s", out_event_class, in_emf_uri); - ret = -1; - goto error; + enum bt_event_class_set_emf_uri_status set_emf_status = + bt_event_class_set_emf_uri(out_event_class, in_emf_uri); + if (set_emf_status != BT_EVENT_CLASS_SET_EMF_URI_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error setting event class' emf uri: " + "out-ec-addr=%p, emf-uri=\"%s\"", + out_event_class, in_emf_uri); + status = (int) set_emf_status; + goto end; } } @@ -443,27 +491,33 @@ int copy_event_class_content(struct trace_ir_maps *ir_maps, in_event_specific_context; if (in_event_specific_context) { + enum bt_event_class_set_field_class_status set_fc_status; /* Copy the specific context of this event class. */ out_specific_context_fc = create_field_class_copy(md_maps, in_event_specific_context); - ret = copy_field_class_content(md_maps, + status = copy_field_class_content(md_maps, in_event_specific_context, out_specific_context_fc); - if (ret) { - goto error; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying event class' specific context field class:" + "in-spec-ctx-fc-addr=%p, out-spec-ctx-fc-addr=%p", + in_event_specific_context, out_specific_context_fc); + goto end; } /* * Add the output specific context to the output event * class. */ - if (bt_event_class_set_specific_context_field_class( - out_event_class, out_specific_context_fc) != - BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { - BT_COMP_LOGE("Error setting event class' specific context " - "field class: ec-addr=%p, ctx-fc-addr=%p", + set_fc_status = bt_event_class_set_specific_context_field_class( out_event_class, out_specific_context_fc); - ret = -1; - goto error; + if (set_fc_status != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error setting event class' specific context field class:" + "out-ec-addr=%p, out-spec-ctx-fc-addr=%p", + out_event_class, out_specific_context_fc); + status = (int) set_fc_status; + goto end; } } @@ -477,51 +531,64 @@ int copy_event_class_content(struct trace_ir_maps *ir_maps, md_maps->fc_resolving_ctx->event_payload = in_event_payload; if (in_event_payload) { - /* Copy the payload of this event class. */ + enum bt_event_class_set_field_class_status set_fc_status; + /* Copy the payload of this event class. */ out_payload_fc = create_field_class_copy(md_maps, in_event_payload); - ret = copy_field_class_content(md_maps, in_event_payload, + status = copy_field_class_content(md_maps, in_event_payload, out_payload_fc); - if (ret) { - goto error; + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying event class' specific context field class:" + "in-payload-fc-addr=%p, out-payload-fc-addr=%p", + in_event_payload, out_payload_fc); + goto end; } /* Add the output payload to the output event class. */ - if (bt_event_class_set_payload_field_class(out_event_class, - out_payload_fc) != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { - BT_COMP_LOGE("Error setting event class' payload " - "field class: ec-addr=%p, payload-fc-addr=%p", + set_fc_status = bt_event_class_set_payload_field_class( + out_event_class, out_payload_fc); + if (set_fc_status != BT_EVENT_CLASS_SET_FIELD_CLASS_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error setting event class' payload field class: " + "out-ec-addr=%p, out-payload-fc-addr=%p", out_event_class, out_payload_fc); - ret = -1; - goto error; + status = (int) set_fc_status; + goto end; } } BT_COMP_LOGD("Copied content of event class: in-ec-addr=%p, out-ec-addr=%p", in_event_class, out_event_class); -error: - return ret; + + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } BT_HIDDEN -int copy_event_common_context_field_class_content( +enum debug_info_trace_ir_mapping_status +copy_event_common_context_field_class_content( struct trace_ir_metadata_maps *md_maps, const char *debug_info_fc_name, const bt_field_class *in_field_class, bt_field_class *out_field_class) { + enum debug_info_trace_ir_mapping_status status; bt_field_class *debug_field_class = NULL, *bin_field_class = NULL, *func_field_class = NULL, *src_field_class = NULL; bt_logging_level log_level = md_maps->log_level; bt_self_component *self_comp = md_maps->self_comp; - int ret = 0; BT_COMP_LOGD("Copying content of event common context field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); /* Copy the content of the input common context. */ - ret = copy_field_class_content(md_maps, in_field_class, out_field_class); - if (ret) { + status = copy_field_class_content(md_maps, in_field_class, out_field_class); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying content of event common context field class: " + "in-fc-addr=%p, out-fc-addr=%p", in_field_class, + out_field_class); goto error; } @@ -531,6 +598,7 @@ int copy_event_common_context_field_class_content( * common context. */ if (is_event_common_ctx_dbg_info_compatible(in_field_class, debug_info_fc_name)) { + enum bt_field_class_structure_append_member_status append_member_status; /* * The struct field and 3 sub-fields are not stored in the * field class map because they don't have input equivalent. @@ -541,78 +609,91 @@ int copy_event_common_context_field_class_content( debug_field_class = bt_field_class_structure_create( md_maps->output_trace_class); if (!debug_field_class) { - BT_COMP_LOGE_STR("Failed to create debug_info structure."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create debug_info structure."); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; goto error; } bin_field_class = bt_field_class_string_create( md_maps->output_trace_class); if (!bin_field_class) { - BT_COMP_LOGE_STR("Failed to create string for field=bin."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create string for field=\"bin\"."); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; goto error; } func_field_class = bt_field_class_string_create( md_maps->output_trace_class); if (!func_field_class) { - BT_COMP_LOGE_STR("Failed to create string for field=func."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create string for field=\"func\"."); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; goto error; } src_field_class = bt_field_class_string_create( md_maps->output_trace_class); if (!src_field_class) { - BT_COMP_LOGE_STR("Failed to create string for field=src."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to create string for field=\"src\"."); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; goto error; } - if (bt_field_class_structure_append_member(debug_field_class, - "bin", bin_field_class) != + append_member_status = bt_field_class_structure_append_member( + debug_field_class, "bin", bin_field_class); + if (append_member_status != BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { - BT_COMP_LOGE_STR("Failed to add a field to debug_info " - "struct: field=bin."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to add a field to debug_info struct: " + "field=\"bin\"."); + status = (int) append_member_status; goto error; } BT_FIELD_CLASS_PUT_REF_AND_RESET(bin_field_class); - if (bt_field_class_structure_append_member(debug_field_class, - "func", func_field_class) != + append_member_status = bt_field_class_structure_append_member( + debug_field_class, "func", func_field_class); + if (append_member_status != BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { - BT_COMP_LOGE_STR("Failed to add a field to debug_info " - "struct: field=func."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to add a field to debug_info struct: " + "field=\"func\"."); + status = (int) append_member_status; goto error; } BT_FIELD_CLASS_PUT_REF_AND_RESET(func_field_class); - if (bt_field_class_structure_append_member(debug_field_class, - "src", src_field_class) != + append_member_status = bt_field_class_structure_append_member( + debug_field_class, "src", src_field_class); + if (append_member_status != BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { - BT_COMP_LOGE_STR("Failed to add a field to debug_info " - "struct: field=src."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to add a field to debug_info struct: " + "field=\"src\"."); + status = (int) append_member_status; goto error; } BT_FIELD_CLASS_PUT_REF_AND_RESET(src_field_class); /*Add the filled debug-info field class to the common context. */ - if (bt_field_class_structure_append_member(out_field_class, - debug_info_fc_name, debug_field_class) != + append_member_status = bt_field_class_structure_append_member( + out_field_class, debug_info_fc_name, debug_field_class); + if (append_member_status != BT_FIELD_CLASS_STRUCTURE_APPEND_MEMBER_STATUS_OK) { - BT_COMP_LOGE_STR("Failed to add debug_info field to " - "event common context."); - ret = -1; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Failed to add debug_info field to event common context."); + status = (int) append_member_status; goto error; } BT_FIELD_CLASS_PUT_REF_AND_RESET(debug_field_class); } BT_COMP_LOGD("Copied content of event common context field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); + + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; goto end; error: @@ -629,7 +710,7 @@ error: bt_field_class_put_ref(src_field_class); } end: - return ret; + return status; } BT_HIDDEN @@ -640,7 +721,8 @@ bt_field_class *create_field_class_copy(struct trace_ir_metadata_maps *md_maps, } BT_HIDDEN -int copy_field_class_content(struct trace_ir_metadata_maps *md_maps, +enum debug_info_trace_ir_mapping_status copy_field_class_content( + struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { diff --git a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.h b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.h index 0a70c3c9..e57c1474 100644 --- a/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.h +++ b/src/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.h @@ -32,29 +32,33 @@ #include "trace-ir-mapping.h" BT_HIDDEN -int copy_trace_class_content(struct trace_ir_maps *trace_ir_maps, +enum debug_info_trace_ir_mapping_status copy_trace_class_content( + struct trace_ir_maps *trace_ir_maps, const bt_trace_class *in_trace_class, bt_trace_class *out_trace_class, bt_logging_level log_level, bt_self_component *self_comp); BT_HIDDEN -int copy_stream_class_content(struct trace_ir_maps *trace_ir_maps, +enum debug_info_trace_ir_mapping_status copy_stream_class_content( + struct trace_ir_maps *trace_ir_maps, const bt_stream_class *in_stream_class, bt_stream_class *out_stream_class); BT_HIDDEN -int copy_event_class_content(struct trace_ir_maps *trace_ir_maps, +enum debug_info_trace_ir_mapping_status copy_event_class_content( + struct trace_ir_maps *trace_ir_maps, const bt_event_class *in_event_class, bt_event_class *out_event_class); BT_HIDDEN -int copy_field_class_content(struct trace_ir_metadata_maps *trace_ir_metadata_maps, +enum debug_info_trace_ir_mapping_status copy_field_class_content( + struct trace_ir_metadata_maps *trace_ir_metadata_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class); BT_HIDDEN -int copy_event_common_context_field_class_content( +enum debug_info_trace_ir_mapping_status copy_event_common_context_field_class_content( struct trace_ir_metadata_maps *trace_ir_metadata_maps, const char *debug_info_field_class_name, const bt_field_class *in_field_class, 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 f149281a..31c9f71a 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 @@ -149,7 +149,8 @@ void field_class_integer_set_props(const bt_field_class *input_fc, } static inline -int field_class_bool_copy(struct trace_ir_metadata_maps *md_maps, +enum debug_info_trace_ir_mapping_status field_class_bool_copy( + struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { @@ -161,11 +162,11 @@ int field_class_bool_copy(struct trace_ir_metadata_maps *md_maps, */ 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_bit_array_copy( +enum debug_info_trace_ir_mapping_status 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) @@ -178,11 +179,11 @@ int field_class_bit_array_copy( */ 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_unsigned_integer_copy( +enum debug_info_trace_ir_mapping_status 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) @@ -194,11 +195,11 @@ int field_class_unsigned_integer_copy( 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_signed_integer_copy( +enum debug_info_trace_ir_mapping_status field_class_signed_integer_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) @@ -210,17 +211,17 @@ int field_class_signed_integer_copy( 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } BT_HIDDEN -int field_class_unsigned_enumeration_copy( +enum debug_info_trace_ir_mapping_status field_class_unsigned_enumeration_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { + enum debug_info_trace_ir_mapping_status status; uint64_t i, enum_mapping_count; - int ret = 0; BT_COMP_LOGD("Copying content of unsigned enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -236,6 +237,7 @@ int field_class_unsigned_enumeration_copy( const bt_integer_range_set_unsigned *range_set; const bt_field_class_enumeration_unsigned_mapping *u_mapping; const bt_field_class_enumeration_mapping *mapping; + enum bt_field_class_enumeration_add_mapping_status add_mapping_status; u_mapping = bt_field_class_enumeration_unsigned_borrow_mapping_by_index_const( in_field_class, i); @@ -244,28 +246,30 @@ int field_class_unsigned_enumeration_copy( 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( + add_mapping_status = bt_field_class_enumeration_unsigned_add_mapping( out_field_class, label, range_set); - if (ret) { - goto error; + if (add_mapping_status != BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_OK) { + status = (int) add_mapping_status; + goto end; } } BT_COMP_LOGD("Copied content of unsigned enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); -error: - return ret; + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } static inline -int field_class_signed_enumeration_copy( +enum debug_info_trace_ir_mapping_status field_class_signed_enumeration_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { + enum debug_info_trace_ir_mapping_status status; uint64_t i, enum_mapping_count; - int ret = 0; BT_COMP_LOGD("Copying content of signed enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -281,6 +285,7 @@ int field_class_signed_enumeration_copy( const bt_integer_range_set_signed *range_set; const bt_field_class_enumeration_signed_mapping *s_mapping; const bt_field_class_enumeration_mapping *mapping; + enum bt_field_class_enumeration_add_mapping_status add_mapping_status; s_mapping = bt_field_class_enumeration_signed_borrow_mapping_by_index_const( in_field_class, i); @@ -289,22 +294,24 @@ int field_class_signed_enumeration_copy( 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( + add_mapping_status = bt_field_class_enumeration_signed_add_mapping( out_field_class, label, range_set); - if (ret) { - goto error; + if (add_mapping_status != BT_FIELD_CLASS_ENUMERATION_ADD_MAPPING_STATUS_OK) { + status = (int) add_mapping_status; + goto end; } } BT_COMP_LOGD("Copied content of signed enumeration field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); -error: - return ret; + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } static inline -int field_class_single_precision_real_copy( +enum debug_info_trace_ir_mapping_status 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) @@ -315,11 +322,11 @@ int field_class_single_precision_real_copy( BT_COMP_LOGD("Copied content single-precision real field class:" "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - return 0; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_double_precision_real_copy( +enum debug_info_trace_ir_mapping_status 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) @@ -330,17 +337,18 @@ int field_class_double_precision_real_copy( 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_structure_copy( +enum debug_info_trace_ir_mapping_status field_class_structure_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { + bt_self_component *self_comp = md_maps->self_comp; uint64_t i, struct_member_count; - int ret = 0; + enum debug_info_trace_ir_mapping_status status; BT_COMP_LOGD("Copying content of structure field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -350,46 +358,54 @@ int field_class_structure_copy( /* Iterate over all the members of the struct. */ for (i = 0; i < struct_member_count; i++) { + enum bt_field_class_structure_append_member_status append_member_status; const bt_field_class_structure_member *in_member; bt_field_class_structure_member *out_member; const char *member_name; const bt_field_class *in_member_fc; - bt_field_class *out_member_field_class; + bt_field_class *out_member_fc; in_member = bt_field_class_structure_borrow_member_by_index_const( in_field_class, i); 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\"", + BT_COMP_LOGD("Copying structure field class's member: " + "index=%" PRId64 ", member-fc-addr=%p, member-name=\"%s\"", i, in_member_fc, member_name); - out_member_field_class = create_field_class_copy(md_maps, - in_member_fc); - if (!out_member_field_class) { - BT_COMP_LOGE("Cannot copy structure field class's field: " - "index=%" PRId64 ", field-fc-addr=%p, field-name=\"%s\"", - i, in_member_fc, member_name); - ret = -1; - goto error; + out_member_fc = create_field_class_copy(md_maps, in_member_fc); + if (!out_member_fc) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy structure field class's member: " + "index=%" PRId64 ", in-member-fc-addr=%p, " + "member-name=\"%s\"", i, in_member_fc, + member_name); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; + goto end; } - ret = copy_field_class_content(md_maps, in_member_fc, - out_member_field_class); - if (ret) { - goto error; + + status = copy_field_class_content(md_maps, in_member_fc, + out_member_fc); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy content of structure field class's member: " + "index=%" PRId64 ", in-member-fc-addr=%p, " + "member-name=\"%s\"", i, in_member_fc, + member_name); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_fc); + goto end; } - if (bt_field_class_structure_append_member(out_field_class, - member_name, out_member_field_class) != + append_member_status = bt_field_class_structure_append_member(out_field_class, + member_name, out_member_fc); + if (append_member_status != 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, in_member_fc, member_name); - BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_field_class); - ret = -1; - goto error; + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append structure field class's field: " + "index=%" PRId64 ", field-fc-addr=%p, " + "field-name=\"%s\"", i, in_member_fc, + member_name); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_member_fc); + status = (int) append_member_status; + goto end; } out_member = bt_field_class_structure_borrow_member_by_index( @@ -409,20 +425,22 @@ int field_class_structure_copy( BT_COMP_LOGD("Copied structure field class: original-fc-addr=%p, copy-fc-addr=%p", in_field_class, out_field_class); -error: - return ret; + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } static inline -int field_class_variant_copy( +enum debug_info_trace_ir_mapping_status field_class_variant_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { + bt_self_component *self_comp = md_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; bt_field_class *out_tag_field_class = NULL; uint64_t i, variant_option_count; bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); - int ret = 0; BT_COMP_LOGD("Copying content of variant field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); @@ -431,7 +449,7 @@ int field_class_variant_copy( for (i = 0; i < variant_option_count; i++) { const bt_field_class *in_option_fc; const char *option_name; - bt_field_class *out_option_field_class; + bt_field_class *out_option_fc; const bt_field_class_variant_option *in_option; bt_field_class_variant_option *out_option; @@ -440,19 +458,25 @@ int field_class_variant_copy( 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, in_option_fc); - if (!out_option_field_class) { - BT_COMP_LOGE_STR("Cannot copy field class."); - ret = -1; - goto error; + + out_option_fc = create_field_class_copy_internal( + md_maps, in_option_fc); + if (!out_option_fc) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot copy variant option field class: " + "in-option-fc=%p, in-option-name=\"%s\"", + in_option_fc, option_name); + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_MEMORY_ERROR; + goto end; } - ret = copy_field_class_content_internal(md_maps, in_option_fc, - out_option_field_class); - if (ret) { - BT_COMP_LOGE_STR("Error copying content of option variant " - "field class'"); - goto error; + + status = copy_field_class_content_internal(md_maps, in_option_fc, + out_option_fc); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Error copying content of variant option field class: " + "in-option-fc=%p, in-option-name=\"%s\"", + in_option_fc, option_name); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_option_fc); + goto end; } if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_INTEGER_SELECTOR_FIELD) { @@ -462,15 +486,20 @@ int field_class_variant_copy( const bt_integer_range_set_unsigned *ranges = bt_field_class_variant_with_selector_field_integer_unsigned_option_borrow_ranges_const( spec_opt); - - if (bt_field_class_variant_with_selector_field_integer_unsigned_append_option( + enum bt_field_class_variant_with_selector_field_integer_append_option_status append_opt_status = + bt_field_class_variant_with_selector_field_integer_unsigned_append_option( out_field_class, option_name, - out_option_field_class, ranges) != + out_option_fc, ranges); + + if (append_opt_status != BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK) { - BT_COMP_LOGE_STR("Cannot append option to variant field class with unsigned integer selector'"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append option to variant field class with unsigned integer selector" + "out-fc-addr=%p, out-option-fc-addr=%p, " + "out-option-name=\"%s\"", out_field_class, + out_option_fc, option_name); BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); - ret = -1; - goto error; + status = (int) append_opt_status; + goto end; } } else if (fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_INTEGER_SELECTOR_FIELD) { const bt_field_class_variant_with_selector_field_integer_signed_option *spec_opt = @@ -480,26 +509,36 @@ int field_class_variant_copy( bt_field_class_variant_with_selector_field_integer_signed_option_borrow_ranges_const( spec_opt); - if (bt_field_class_variant_with_selector_field_integer_signed_append_option( + enum bt_field_class_variant_with_selector_field_integer_append_option_status append_opt_status = + bt_field_class_variant_with_selector_field_integer_signed_append_option( out_field_class, option_name, - out_option_field_class, ranges) != + out_option_fc, ranges); + if (append_opt_status != BT_FIELD_CLASS_VARIANT_WITH_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK) { - BT_COMP_LOGE_STR("Cannot append option to variant field class with signed integer selector'"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append option to variant field class with signed integer selector" + "out-fc-addr=%p, out-option-fc-addr=%p, " + "out-option-name=\"%s\"", out_field_class, + out_option_fc, option_name); BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); - ret = -1; - goto error; + status = (int) append_opt_status; + goto end; } } else { BT_ASSERT(fc_type == BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR_FIELD); - if (bt_field_class_variant_without_selector_append_option( + enum bt_field_class_variant_without_selector_append_option_status append_opt_status = + bt_field_class_variant_without_selector_append_option( out_field_class, option_name, - out_option_field_class) != + out_option_fc); + if (append_opt_status != BT_FIELD_CLASS_VARIANT_WITHOUT_SELECTOR_FIELD_APPEND_OPTION_STATUS_OK) { - BT_COMP_LOGE_STR("Cannot append option to variant field class'"); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Cannot append option to variant field class" + "out-fc-addr=%p, out-option-fc-addr=%p, " + "out-option-name=\"%s\"", out_field_class, + out_option_fc, option_name); BT_FIELD_CLASS_PUT_REF_AND_RESET(out_tag_field_class); - ret = -1; - goto error; + status = (int) append_opt_status; + goto end; } } @@ -519,13 +558,13 @@ int field_class_variant_copy( BT_COMP_LOGD("Copied content of variant field class: in-fc-addr=%p, " "out-fc-addr=%p", in_field_class, out_field_class); - -error: - return ret; + status = DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; +end: + return status; } static inline -int field_class_static_array_copy( +enum debug_info_trace_ir_mapping_status field_class_static_array_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) @@ -539,11 +578,11 @@ int field_class_static_array_copy( 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_dynamic_array_copy( +enum debug_info_trace_ir_mapping_status field_class_dynamic_array_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) @@ -557,11 +596,11 @@ int field_class_dynamic_array_copy( BT_COMP_LOGD("Copied content of dynamic array field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - return 0; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_option_copy( +enum debug_info_trace_ir_mapping_status field_class_option_copy( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) @@ -580,11 +619,12 @@ int field_class_option_copy( BT_COMP_LOGD("Copied content of option field class: " "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class); - return 0; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static inline -int field_class_string_copy(struct trace_ir_metadata_maps *md_maps, +enum debug_info_trace_ir_mapping_status field_class_string_copy( + struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { @@ -597,40 +637,44 @@ int field_class_string_copy(struct trace_ir_metadata_maps *md_maps, 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; + return DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK; } static -bt_field_class *copy_field_class_array_element(struct trace_ir_metadata_maps *md_maps, +bt_field_class *copy_field_class_array_element( + struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_elem_fc) { - int ret; + bt_self_component *self_comp = md_maps->self_comp; bt_field_class *out_elem_fc = create_field_class_copy_internal(md_maps, in_elem_fc); if (!out_elem_fc) { - BT_COMP_LOGE("Error creating output elem field class " - "from input elem field class for static array: " + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output elem field class from input elem field class for static array: " "in-fc-addr=%p", in_elem_fc); - goto error; + goto end; } - ret = copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc); - if (ret) { - BT_COMP_LOGE("Error creating output elem field class " - "from input elem field class for static array: " + if (copy_field_class_content_internal(md_maps, in_elem_fc, out_elem_fc) != + DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "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); - goto error; + goto end; } -error: +end: return out_elem_fc; } BT_HIDDEN -bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *md_maps, +bt_field_class *create_field_class_copy_internal( + struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class) { + bt_self_component *self_comp = md_maps->self_comp; + enum debug_info_trace_ir_mapping_status status; bt_field_class *out_field_class = NULL; bt_field_class_type fc_type = bt_field_class_get_type(in_field_class); @@ -733,29 +777,31 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * } out_field_class = bt_field_class_array_dynamic_create( - md_maps->output_trace_class, - out_elem_fc, out_length_fc); - } else if (bt_field_class_type_is(fc_type, - BT_FIELD_CLASS_TYPE_OPTION)) { + md_maps->output_trace_class, out_elem_fc, out_length_fc); + } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_OPTION)) { 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."); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Cannot copy option's content field class: " + "in-content-fc-addr=%p", in_content_fc); goto error; } - ret = copy_field_class_content_internal(md_maps, + status = 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"); + if (status != DEBUG_INFO_TRACE_IR_MAPPING_STATUS_OK) { + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error copying content of option's content field class: " + "in-content-fc-addr=%p, out-content-fc-addr=%p", + in_content_fc, out_content_fc); + BT_FIELD_CLASS_PUT_REF_AND_RESET(out_content_fc); goto error; } @@ -807,8 +853,6 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps * ranges); } } - - BT_ASSERT(out_field_class); } else if (bt_field_class_type_is(fc_type, BT_FIELD_CLASS_TYPE_VARIANT)) { bt_field_class *out_sel_fc = NULL; @@ -847,20 +891,21 @@ error: 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_COMP_LOGE("Error creating output field class from input field " - "class: in-fc-addr=%p", in_field_class); + BT_COMP_LOGE_APPEND_CAUSE(self_comp, + "Error creating output field class from input field class: " + "in-fc-addr=%p", in_field_class); } return out_field_class; } BT_HIDDEN -int copy_field_class_content_internal( +enum debug_info_trace_ir_mapping_status copy_field_class_content_internal( struct trace_ir_metadata_maps *md_maps, const bt_field_class *in_field_class, bt_field_class *out_field_class) { - int ret = 0; + enum debug_info_trace_ir_mapping_status status; bt_field_class_type in_fc_type = bt_field_class_get_type(in_field_class); @@ -872,53 +917,53 @@ int copy_field_class_content_internal( bt_field_class_borrow_user_attributes_const(in_field_class)); if (in_fc_type == BT_FIELD_CLASS_TYPE_BOOL) { - ret = field_class_bool_copy(md_maps, - in_field_class, out_field_class); + status = field_class_bool_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_BIT_ARRAY) { - ret = field_class_bit_array_copy(md_maps, - in_field_class, out_field_class); + status = field_class_bit_array_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER) { - ret = field_class_unsigned_integer_copy(md_maps, - in_field_class, out_field_class); + status = field_class_unsigned_integer_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_INTEGER) { - ret = field_class_signed_integer_copy(md_maps, - in_field_class, out_field_class); + status = field_class_signed_integer_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION) { - ret = field_class_unsigned_enumeration_copy(md_maps, - in_field_class, out_field_class); + status = field_class_unsigned_enumeration_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION) { - ret = field_class_signed_enumeration_copy(md_maps, - in_field_class, out_field_class); + status = field_class_signed_enumeration_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) { - ret = field_class_single_precision_real_copy(md_maps, - in_field_class, out_field_class); + status = field_class_single_precision_real_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL) { - ret = field_class_double_precision_real_copy(md_maps, - in_field_class, out_field_class); + status = field_class_double_precision_real_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRING) { - ret = field_class_string_copy(md_maps, - in_field_class, out_field_class); + status = field_class_string_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STRUCTURE) { - ret = field_class_structure_copy(md_maps, - in_field_class, out_field_class); + status = field_class_structure_copy(md_maps, + in_field_class, out_field_class); } else if (in_fc_type == BT_FIELD_CLASS_TYPE_STATIC_ARRAY) { - ret = field_class_static_array_copy(md_maps, - in_field_class, out_field_class); + status = field_class_static_array_copy(md_maps, + in_field_class, out_field_class); } else if (bt_field_class_type_is(in_fc_type, BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY)) { - ret = field_class_dynamic_array_copy(md_maps, - in_field_class, out_field_class); + status = field_class_dynamic_array_copy(md_maps, + in_field_class, out_field_class); } else if (bt_field_class_type_is(in_fc_type, BT_FIELD_CLASS_TYPE_OPTION)) { - ret = field_class_option_copy(md_maps, - in_field_class, out_field_class); + status = field_class_option_copy(md_maps, + in_field_class, out_field_class); } else if (bt_field_class_type_is(in_fc_type, BT_FIELD_CLASS_TYPE_VARIANT)) { - ret = field_class_variant_copy(md_maps, - in_field_class, out_field_class); + status = field_class_variant_copy(md_maps, + in_field_class, out_field_class); } else { abort(); } - return ret; + return status; } -- 2.34.1