Move to kernel style SPDX license identifiers
[babeltrace.git] / src / plugins / lttng-utils / debug-info / debug-info.c
index 80f96e7b5e5f1dc758a28849013585533d03cd25..fd47e3dfc80cad57c270563bbb6e45e654370383 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Babeltrace - Debug Information State Tracker
+ * SPDX-License-Identifier: MIT
  *
  * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
  * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
@@ -7,29 +7,15 @@
  * Copyright (c) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  * Copyright (c) 2019 Francis Deslauriers <francis.deslauriers@efficios.com>
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Babeltrace - Debug Information State Tracker
  */
 
 #define BT_COMP_LOG_SELF_COMP self_comp
 #define BT_LOG_OUTPUT_LEVEL log_level
 #define BT_LOG_TAG "PLUGIN/FLT.LTTNG-UTILS.DEBUG-INFO"
-#include "plugins/comp-logging.h"
+#include "logging/comp-logging.h"
+
+#include <stdbool.h>
 
 #include <glib.h>
 
@@ -43,6 +29,7 @@
 #include "trace-ir-mapping.h"
 #include "trace-ir-metadata-copy.h"
 #include "utils.h"
+#include "plugins/common/param-validation/param-validation.h"
 
 #define DEFAULT_DEBUG_INFO_FIELD_NAME  "debug_info"
 #define LTTNG_UST_STATEDUMP_PREFIX     "lttng_ust"
@@ -59,6 +46,7 @@
 struct debug_info_component {
        bt_logging_level log_level;
        bt_self_component *self_comp;
+       bt_self_component_filter *self_comp_filter;
        gchar *arg_debug_dir;
        gchar *arg_debug_info_field_name;
        gchar *arg_target_prefix;
@@ -70,7 +58,7 @@ struct debug_info_msg_iter {
        struct debug_info_component *debug_info_component;
        bt_self_message_iterator *input_iterator;
        bt_self_component *self_comp;
-       bt_self_component_port_input_message_iterator *msg_iter;
+       bt_message_iterator *msg_iter;
 
        struct trace_ir_maps *ir_maps;
        /* in_trace -> debug_info_mapping. */
@@ -119,7 +107,7 @@ struct debug_info {
        bt_self_component *self_comp;
        struct debug_info_component *comp;
        const bt_trace *input_trace;
-       uint64_t destruction_listener_id;
+       bt_listener_id destruction_listener_id;
 
        /*
         * Hash table of VPIDs (pointer to int64_t) to
@@ -177,7 +165,11 @@ struct debug_info_source *debug_info_source_create_from_bin(
        int ret;
        struct debug_info_source *debug_info_src = NULL;
        struct source_location *src_loc = NULL;
-       bt_logging_level log_level = bin->log_level;
+       bt_logging_level log_level;
+
+       BT_ASSERT(bin);
+
+       log_level = bin->log_level;
 
        debug_info_src = g_new0(struct debug_info_source, 1);
 
@@ -204,7 +196,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 occurred when setting `line_no` field.");
                        goto error;
                }
 
@@ -215,7 +208,7 @@ struct debug_info_source *debug_info_source_create_from_bin(
                        }
 
                        debug_info_src->short_src_path = get_filename_from_path(
-                                       debug_info_src->src_path);
+                               debug_info_src->src_path);
                }
                source_location_destroy(src_loc);
        }
@@ -227,7 +220,7 @@ struct debug_info_source *debug_info_source_create_from_bin(
                }
 
                debug_info_src->short_bin_path = get_filename_from_path(
-                               debug_info_src->bin_path);
+                       debug_info_src->bin_path);
 
                ret = bin_info_get_bin_loc(bin, ip, &(debug_info_src->bin_loc));
                if (ret) {
@@ -273,15 +266,15 @@ struct proc_debug_info_sources *proc_debug_info_sources_create(void)
        }
 
        proc_dbg_info_src->baddr_to_bin_info = g_hash_table_new_full(
-                       g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
-                       (GDestroyNotify) bin_info_destroy);
+               g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
+               (GDestroyNotify) bin_info_destroy);
        if (!proc_dbg_info_src->baddr_to_bin_info) {
                goto error;
        }
 
        proc_dbg_info_src->ip_to_debug_info_src = g_hash_table_new_full(
-                       g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
-                       (GDestroyNotify) debug_info_source_destroy);
+               g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
+               (GDestroyNotify) debug_info_source_destroy);
        if (!proc_dbg_info_src->ip_to_debug_info_src) {
                goto error;
        }
@@ -334,10 +327,10 @@ const bt_field *event_borrow_payload_field(const bt_event *event,
        const bt_field *event_payload, *field;
 
        event_payload =  bt_event_borrow_payload_field_const(event);
-       BT_ASSERT(event_payload);
+       BT_ASSERT_DBG(event_payload);
 
        field = bt_field_structure_borrow_member_field_by_name_const(
-                       event_payload, field_name);
+               event_payload, field_name);
        return field;
 }
 
@@ -353,7 +346,7 @@ const bt_field *event_borrow_common_context_field(const bt_event *event,
        }
 
        field = bt_field_structure_borrow_member_field_by_name_const(
-                       event_common_ctx, field_name);
+               event_common_ctx, field_name);
 
 end:
        return field;
@@ -363,12 +356,12 @@ static inline
 void event_get_common_context_signed_integer_field_value(
                const bt_event *event, const char *field_name, int64_t *value)
 {
-       *value = bt_field_signed_integer_get_value(
-                       event_borrow_common_context_field(event, field_name));
+       *value = bt_field_integer_signed_get_value(
+               event_borrow_common_context_field(event, field_name));
 }
 
 static inline
-int event_get_payload_build_id_length(const bt_event *event,
+void event_get_payload_build_id_length(const bt_event *event,
                const char *field_name, uint64_t *build_id_len)
 {
        const bt_field *build_id_field;
@@ -378,57 +371,53 @@ int event_get_payload_build_id_length(const bt_event *event,
        build_id_field_class = bt_field_borrow_class_const(build_id_field);
 
        BT_ASSERT(bt_field_class_get_type(build_id_field_class) ==
-                       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
+               BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD ||
+               bt_field_class_get_type(build_id_field_class) ==
+               BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD);
        BT_ASSERT(bt_field_class_get_type(
-                       bt_field_class_array_borrow_element_field_class_const(
-                               build_id_field_class)) ==
-                       BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
+               bt_field_class_array_borrow_element_field_class_const(
+                       build_id_field_class)) ==
+               BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
 
        *build_id_len = bt_field_array_get_length(build_id_field);
-
-       return 0;
 }
 
 static inline
-int event_get_payload_build_id_value(const bt_event *event,
+void event_get_payload_build_id_value(const bt_event *event,
                const char *field_name, uint8_t *build_id)
 {
        const bt_field *curr_field, *build_id_field;
        const bt_field_class *build_id_field_class;
        uint64_t i, build_id_len;
-       int ret;
-
-       ret = 0;
 
        build_id_field = event_borrow_payload_field(event, field_name);
        build_id_field_class = bt_field_borrow_class_const(build_id_field);
 
        BT_ASSERT(bt_field_class_get_type(build_id_field_class) ==
-                       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY);
+               BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITHOUT_LENGTH_FIELD ||
+               bt_field_class_get_type(build_id_field_class) ==
+               BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY_WITH_LENGTH_FIELD);
        BT_ASSERT(bt_field_class_get_type(
-                       bt_field_class_array_borrow_element_field_class_const(
-                               build_id_field_class)) ==
-                       BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
+               bt_field_class_array_borrow_element_field_class_const(
+                       build_id_field_class)) ==
+               BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER);
 
        build_id_len = bt_field_array_get_length(build_id_field);
 
        for (i = 0; i < build_id_len; i++) {
-               curr_field =
-                       bt_field_array_borrow_element_field_by_index_const(
-                                       build_id_field, i);
+               curr_field = bt_field_array_borrow_element_field_by_index_const(
+                       build_id_field, i);
 
-               build_id[i] = bt_field_unsigned_integer_get_value(curr_field);
+               build_id[i] = bt_field_integer_unsigned_get_value(curr_field);
        }
-
-       return ret;
 }
 
 static
 void event_get_payload_unsigned_integer_field_value(const bt_event *event,
                const char *field_name, uint64_t *value)
 {
-       *value = bt_field_unsigned_integer_get_value(
-                       event_borrow_payload_field(event, field_name));
+       *value = bt_field_integer_unsigned_get_value(
+               event_borrow_payload_field(event, field_name));
 }
 
 static
@@ -436,14 +425,14 @@ void event_get_payload_string_field_value(const bt_event *event,
                const char *field_name, const char **value)
 {
        *value = bt_field_string_get_value(
-                       event_borrow_payload_field(event, field_name));
+               event_borrow_payload_field(event, field_name));
 }
 
 static inline
 bool event_has_payload_field(const bt_event *event,
                const char *field_name)
 {
-       return event_borrow_payload_field(event, field_name) != NULL;
+       return event_borrow_payload_field(event, field_name);
 }
 
 static
@@ -464,8 +453,7 @@ struct debug_info_source *proc_debug_info_sources_get_entry(
 
        /* Look in IP to debug infos hash table first. */
        debug_info_src = g_hash_table_lookup(
-                       proc_dbg_info_src->ip_to_debug_info_src,
-                       key);
+               proc_dbg_info_src->ip_to_debug_info_src, key);
        if (debug_info_src) {
                goto end;
        }
@@ -492,8 +480,8 @@ struct debug_info_source *proc_debug_info_sources_get_entry(
                        debug_info->self_comp);
                if (debug_info_src) {
                        g_hash_table_insert(
-                                       proc_dbg_info_src->ip_to_debug_info_src,
-                                       key, debug_info_src);
+                               proc_dbg_info_src->ip_to_debug_info_src, key,
+                               debug_info_src);
                        /* Ownership passed to ht. */
                        key = NULL;
                }
@@ -513,7 +501,7 @@ struct debug_info_source *debug_info_query(struct debug_info *debug_info,
        struct proc_debug_info_sources *proc_dbg_info_src;
 
        proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
-                       debug_info->vpid_to_proc_dbg_info_src, vpid);
+               debug_info->vpid_to_proc_dbg_info_src, vpid);
        if (!proc_dbg_info_src) {
                goto end;
        }
@@ -544,8 +532,8 @@ struct debug_info *debug_info_create(struct debug_info_component *comp,
        debug_info->log_level = comp->log_level;
        debug_info->self_comp = comp->self_comp;
        debug_info->vpid_to_proc_dbg_info_src = g_hash_table_new_full(
-                       g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
-                       (GDestroyNotify) proc_debug_info_sources_destroy);
+               g_int64_hash, g_int64_equal, (GDestroyNotify) g_free,
+               (GDestroyNotify) proc_debug_info_sources_destroy);
        if (!debug_info->vpid_to_proc_dbg_info_src) {
                goto error;
        }
@@ -584,10 +572,11 @@ void debug_info_destroy(struct debug_info *debug_info)
        }
 
        remove_listener_status = bt_trace_remove_destruction_listener(
-                       debug_info->input_trace,
-                       debug_info->destruction_listener_id);
+               debug_info->input_trace,
+               debug_info->destruction_listener_id);
        if (remove_listener_status != BT_TRACE_REMOVE_LISTENER_STATUS_OK) {
                BT_COMP_LOGE("Trace destruction listener removal failed.");
+               bt_current_thread_clear_error();
        }
 
        g_free(debug_info);
@@ -607,18 +596,18 @@ void handle_event_statedump_build_id(struct debug_info *debug_info,
        int ret = 0;
 
        event_get_common_context_signed_integer_field_value(event,
-                       VPID_FIELD_NAME, &vpid);
+               VPID_FIELD_NAME, &vpid);
        event_get_payload_unsigned_integer_field_value(event,
-                       BADDR_FIELD_NAME, &baddr);
+               BADDR_FIELD_NAME, &baddr);
 
        proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
-                       debug_info->vpid_to_proc_dbg_info_src, vpid);
+               debug_info->vpid_to_proc_dbg_info_src, vpid);
        if (!proc_dbg_info_src) {
                goto end;
        }
 
        bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
-                       (gpointer) &baddr);
+               (gpointer) &baddr);
        if (!bin) {
                /*
                 * The build_id event comes after the bin has been
@@ -626,19 +615,16 @@ void handle_event_statedump_build_id(struct debug_info *debug_info,
                 */
                goto end;
        }
-       ret = event_get_payload_build_id_length(event, BUILD_ID_FIELD_NAME,
-                       &build_id_len);
+
+       event_get_payload_build_id_length(event, BUILD_ID_FIELD_NAME,
+               &build_id_len);
 
        build_id = g_new0(uint8_t, build_id_len);
        if (!build_id) {
                goto end;
        }
 
-       ret = event_get_payload_build_id_value(event, BUILD_ID_FIELD_NAME,
-                       build_id);
-       if (ret) {
-               goto end;
-       }
+       event_get_payload_build_id_value(event, BUILD_ID_FIELD_NAME, build_id);
 
        ret = bin_info_set_build_id(bin, build_id, build_id_len);
        if (ret) {
@@ -670,27 +656,27 @@ void handle_event_statedump_debug_link(struct debug_info *debug_info,
        uint64_t crc_field_value;
 
        event_get_common_context_signed_integer_field_value(event,
-                       VPID_FIELD_NAME, &vpid);
+               VPID_FIELD_NAME, &vpid);
 
        event_get_payload_unsigned_integer_field_value(event,
-                       BADDR_FIELD_NAME, &baddr);
+               BADDR_FIELD_NAME, &baddr);
 
        event_get_payload_unsigned_integer_field_value(event,
-                       CRC32_FIELD_NAME, &crc_field_value);
+               CRC32_FIELD_NAME, &crc_field_value);
 
        crc32 = (uint32_t) crc_field_value;
 
        event_get_payload_string_field_value(event,
-                       FILENAME_FIELD_NAME, &filename);
+               FILENAME_FIELD_NAME, &filename);
 
        proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
-                       debug_info->vpid_to_proc_dbg_info_src, vpid);
+               debug_info->vpid_to_proc_dbg_info_src, vpid);
        if (!proc_dbg_info_src) {
                goto end;
        }
 
        bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
-                       (gpointer) &baddr);
+               (gpointer) &baddr);
        if (!bin) {
                /*
                 * The debug_link event comes after the bin has been
@@ -718,14 +704,14 @@ void handle_bin_info_event(struct debug_info *debug_info,
        bool is_pic;
 
        event_get_payload_unsigned_integer_field_value(event,
-                       MEMSZ_FIELD_NAME, &memsz);
+               MEMSZ_FIELD_NAME, &memsz);
        if (memsz == 0) {
                /* Ignore VDSO. */
                goto end;
        }
 
        event_get_payload_unsigned_integer_field_value(event,
-                       BADDR_FIELD_NAME, &baddr);
+               BADDR_FIELD_NAME, &baddr);
 
        /*
         * This field is not produced by the dlopen event emitted before
@@ -812,13 +798,13 @@ void handle_event_lib_unload(struct debug_info *debug_info,
        int64_t vpid;
 
        event_get_payload_unsigned_integer_field_value(event, BADDR_FIELD_NAME,
-                       &baddr);
+               &baddr);
 
        event_get_common_context_signed_integer_field_value(event,
-                       VPID_FIELD_NAME, &vpid);
+               VPID_FIELD_NAME, &vpid);
 
        proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
-                       debug_info->vpid_to_proc_dbg_info_src, vpid);
+               debug_info->vpid_to_proc_dbg_info_src, vpid);
        if (!proc_dbg_info_src) {
                /*
                 * It's an unload event for a library for which no load event
@@ -828,7 +814,7 @@ void handle_event_lib_unload(struct debug_info *debug_info,
        }
 
        ret = g_hash_table_remove(proc_dbg_info_src->baddr_to_bin_info,
-                       (gpointer) &baddr);
+               (gpointer) &baddr);
        BT_ASSERT(ret);
 end:
        return;
@@ -842,10 +828,10 @@ void handle_event_statedump_start(struct debug_info *debug_info,
        int64_t vpid;
 
        event_get_common_context_signed_integer_field_value(
-                       event, VPID_FIELD_NAME, &vpid);
+               event, VPID_FIELD_NAME, &vpid);
 
        proc_dbg_info_src = proc_debug_info_sources_ht_get_entry(
-                       debug_info->vpid_to_proc_dbg_info_src, vpid);
+               debug_info->vpid_to_proc_dbg_info_src, vpid);
        if (!proc_dbg_info_src) {
                goto end;
        }
@@ -857,13 +843,14 @@ end:
        return;
 }
 
+static
 void trace_debug_info_remove_func(const bt_trace *in_trace, void *data)
 {
        struct debug_info_msg_iter *debug_it = data;
        if (debug_it->debug_info_map) {
                gboolean ret;
                ret = g_hash_table_remove(debug_it->debug_info_map,
-                               (gpointer) in_trace);
+                       (gpointer) in_trace);
                BT_ASSERT(ret);
        }
 }
@@ -886,17 +873,20 @@ void handle_event_statedump(struct debug_info_msg_iter *debug_it,
        event_name = bt_event_class_get_name(event_class);
 
        trace = bt_stream_borrow_trace_const(
-                       bt_event_borrow_stream_const(event));
+               bt_event_borrow_stream_const(event));
 
        debug_info = g_hash_table_lookup(debug_it->debug_info_map, trace);
        if (!debug_info) {
+               bt_trace_add_listener_status add_listener_status;
+
                debug_info = debug_info_create(debug_it->debug_info_component,
-                               trace, &debug_it->fd_cache);
+                       trace, &debug_it->fd_cache);
                g_hash_table_insert(debug_it->debug_info_map, (gpointer) trace,
-                               debug_info);
-               bt_trace_add_destruction_listener(trace,
-                               trace_debug_info_remove_func, debug_it,
-                               &debug_info->destruction_listener_id);
+                       debug_info);
+               add_listener_status = bt_trace_add_destruction_listener(
+                       trace, trace_debug_info_remove_func, debug_it,
+                       &debug_info->destruction_listener_id);
+               BT_ASSERT(add_listener_status == BT_TRACE_ADD_LISTENER_STATUS_OK);
        }
 
        q_event_name = g_quark_try_string(event_name);
@@ -953,8 +943,8 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src,
        bt_field_string_set_value_status set_status;
        bt_field_string_append_status append_status;
 
-       BT_ASSERT(bt_field_get_class_type(curr_field) ==
-                       BT_FIELD_CLASS_TYPE_STRING);
+       BT_ASSERT_DBG(bt_field_get_class_type(curr_field) ==
+               BT_FIELD_CLASS_TYPE_STRING);
 
        if (dbg_info_src) {
                if (full_path) {
@@ -965,23 +955,26 @@ 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();
                }
 
                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();
                }
        } 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();
                }
        }
 }
@@ -993,7 +986,7 @@ void fill_debug_info_func_field(struct debug_info_source *dbg_info_src,
 {
        bt_field_string_set_value_status status;
 
-       BT_ASSERT(bt_field_get_class_type(curr_field) ==
+       BT_ASSERT_DBG(bt_field_get_class_type(curr_field) ==
                        BT_FIELD_CLASS_TYPE_STRING);
        if (dbg_info_src && dbg_info_src->func) {
                status = bt_field_string_set_value(curr_field,
@@ -1002,8 +995,9 @@ 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();
        }
 }
 
@@ -1016,42 +1010,46 @@ void fill_debug_info_src_field(struct debug_info_source *dbg_info_src,
        bt_field_string_set_value_status set_status;
        bt_field_string_append_status append_status;
 
-       BT_ASSERT(bt_field_get_class_type(curr_field) ==
-                       BT_FIELD_CLASS_TYPE_STRING);
+       BT_ASSERT_DBG(bt_field_get_class_type(curr_field) ==
+               BT_FIELD_CLASS_TYPE_STRING);
 
        if (dbg_info_src && dbg_info_src->src_path) {
                if (full_path) {
                        set_status = bt_field_string_set_value(curr_field,
-                                       dbg_info_src->src_path);
+                               dbg_info_src->src_path);
                } else {
                        set_status = bt_field_string_set_value(curr_field,
-                                       dbg_info_src->short_src_path);
+                               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();
                }
 
                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();
                }
 
                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();
                }
        } 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();
                }
        }
 }
@@ -1063,39 +1061,42 @@ void fill_debug_info_field_empty(bt_field *debug_info_field,
        bt_field_string_set_value_status status;
        bt_field *bin_field, *func_field, *src_field;
 
-       BT_ASSERT(bt_field_get_class_type(debug_info_field) ==
-                       BT_FIELD_CLASS_TYPE_STRUCTURE);
+       BT_ASSERT_DBG(bt_field_get_class_type(debug_info_field) ==
+               BT_FIELD_CLASS_TYPE_STRUCTURE);
 
        bin_field = bt_field_structure_borrow_member_field_by_name(
-                       debug_info_field, "bin");
+               debug_info_field, "bin");
        func_field = bt_field_structure_borrow_member_field_by_name(
-                       debug_info_field, "func");
+               debug_info_field, "func");
        src_field = bt_field_structure_borrow_member_field_by_name(
-                       debug_info_field, "src");
+               debug_info_field, "src");
 
-       BT_ASSERT(bt_field_get_class_type(bin_field) ==
-                       BT_FIELD_CLASS_TYPE_STRING);
-       BT_ASSERT(bt_field_get_class_type(func_field) ==
-                       BT_FIELD_CLASS_TYPE_STRING);
-       BT_ASSERT(bt_field_get_class_type(src_field) ==
-                       BT_FIELD_CLASS_TYPE_STRING);
+       BT_ASSERT_DBG(bt_field_get_class_type(bin_field) ==
+               BT_FIELD_CLASS_TYPE_STRING);
+       BT_ASSERT_DBG(bt_field_get_class_type(func_field) ==
+               BT_FIELD_CLASS_TYPE_STRING);
+       BT_ASSERT_DBG(bt_field_get_class_type(src_field) ==
+               BT_FIELD_CLASS_TYPE_STRING);
 
        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();
        }
 }
 static
@@ -1105,12 +1106,13 @@ void fill_debug_info_field(struct debug_info *debug_info, int64_t vpid,
        struct debug_info_source *dbg_info_src;
        const bt_field_class *debug_info_fc;
 
-       BT_ASSERT(bt_field_get_class_type(debug_info_field) ==
-                       BT_FIELD_CLASS_TYPE_STRUCTURE);
+       BT_ASSERT_DBG(bt_field_get_class_type(debug_info_field) ==
+               BT_FIELD_CLASS_TYPE_STRUCTURE);
 
        debug_info_fc = bt_field_borrow_class_const(debug_info_field);
 
-       BT_ASSERT(bt_field_class_structure_get_member_count(debug_info_fc) == 3);
+       BT_ASSERT_DBG(bt_field_class_structure_get_member_count(
+               debug_info_fc) == 3);
 
        dbg_info_src = debug_info_query(debug_info, vpid, ip);
 
@@ -1146,7 +1148,7 @@ void fill_debug_info_event_if_needed(struct debug_info_msg_iter *debug_it,
        bt_self_component *self_comp = debug_it->self_comp;
 
        in_common_ctx_field = bt_event_borrow_common_context_field_const(
-                       in_event);
+               in_event);
        if (!in_common_ctx_field) {
                /*
                 * There is no event common context so no need to add debug
@@ -1157,7 +1159,7 @@ void fill_debug_info_event_if_needed(struct debug_info_msg_iter *debug_it,
 
        in_common_ctx_fc = bt_field_borrow_class_const(in_common_ctx_field);
        if (!is_event_common_ctx_dbg_info_compatible(in_common_ctx_fc,
-                               debug_it->ir_maps->debug_info_field_class_name)) {
+                       debug_it->ir_maps->debug_info_field_class_name)) {
                /*
                 * The input event common context does not have the necessary
                 * fields to resolve debug information.
@@ -1172,23 +1174,23 @@ void fill_debug_info_event_if_needed(struct debug_info_msg_iter *debug_it,
        }
 
        out_debug_info_field = bt_field_structure_borrow_member_field_by_name(
-                               out_common_ctx_field, debug_info_field_name);
+               out_common_ctx_field, debug_info_field_name);
 
        vpid_field = bt_field_structure_borrow_member_field_by_name_const(
-                       out_common_ctx_field, VPID_FIELD_NAME);
+               out_common_ctx_field, VPID_FIELD_NAME);
        ip_field = bt_field_structure_borrow_member_field_by_name_const(
-                       out_common_ctx_field, IP_FIELD_NAME);
+               out_common_ctx_field, IP_FIELD_NAME);
 
-       vpid = bt_field_signed_integer_get_value(vpid_field);
-       ip = bt_field_unsigned_integer_get_value(ip_field);
+       vpid = bt_field_integer_signed_get_value(vpid_field);
+       ip = bt_field_integer_unsigned_get_value(ip_field);
 
        /*
         * Borrow the debug_info structure needed for the source
         * resolving.
         */
        debug_info = g_hash_table_lookup(debug_it->debug_info_map,
-                       bt_stream_borrow_trace_const(
-                               bt_event_borrow_stream_const(in_event)));
+               bt_stream_borrow_trace_const(
+                       bt_event_borrow_stream_const(in_event)));
 
        if (debug_info) {
                /*
@@ -1225,7 +1227,7 @@ void update_event_statedump_if_needed(struct debug_info_msg_iter *debug_it,
 
        event_common_ctx_fc = bt_field_borrow_class_const(event_common_ctx);
        if (is_event_common_ctx_dbg_info_compatible(event_common_ctx_fc,
-                               debug_it->ir_maps->debug_info_field_class_name)) {
+                       debug_it->ir_maps->debug_info_field_class_name)) {
                /* Checkout if it might be a one of lttng ust statedump events. */
                const char *in_event_name = bt_event_class_get_name(in_event_class);
                if (strncmp(in_event_name, LTTNG_UST_STATEDUMP_PREFIX,
@@ -1245,8 +1247,10 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it,
        const bt_clock_snapshot *cs;
        const bt_clock_class *default_cc;
        const bt_packet *in_packet;
+       const bt_stream *in_stream;
+       const bt_stream *out_stream;
        bt_event_class *out_event_class;
-       bt_packet *out_packet;
+       bt_packet *out_packet = NULL;
        bt_event *out_event;
        bt_logging_level log_level = debug_it->log_level;
        bt_self_component *self_comp = debug_it->self_comp;
@@ -1265,41 +1269,73 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it,
                        debug_it->ir_maps, in_event_class);
        if (!out_event_class) {
                out_event_class = trace_ir_mapping_create_new_mapped_event_class(
-                                       debug_it->ir_maps, in_event_class);
+                       debug_it->ir_maps, in_event_class);
        }
-       BT_ASSERT(out_event_class);
+       BT_ASSERT_DBG(out_event_class);
+
+       /* Borrow the input stream. */
+       in_stream = bt_event_borrow_stream_const(in_event);
+       BT_ASSERT_DBG(in_stream);
+       out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps,
+               in_stream);
+       BT_ASSERT_DBG(in_stream);
 
        /* Borrow the input and output packets. */
        in_packet = bt_event_borrow_packet_const(in_event);
-       out_packet = trace_ir_mapping_borrow_mapped_packet(debug_it->ir_maps,
-                       in_packet);
+       if (in_packet) {
+               out_packet = trace_ir_mapping_borrow_mapped_packet(
+                       debug_it->ir_maps, in_packet);
+       }
 
        default_cc = bt_stream_class_borrow_default_clock_class_const(
-                       bt_event_class_borrow_stream_class_const(in_event_class));
+               bt_event_class_borrow_stream_class_const(in_event_class));
        if (default_cc) {
                /* Borrow event clock snapshot. */
                cs = bt_message_event_borrow_default_clock_snapshot_const(
-                               in_message);
+                       in_message);
 
                /* Create an output event message. */
-               out_message = bt_message_event_create_with_default_clock_snapshot(
+               if (out_packet) {
+                       out_message =
+                               bt_message_event_create_with_packet_and_default_clock_snapshot(
                                        debug_it->input_iterator,
                                        out_event_class, out_packet,
                                        bt_clock_snapshot_get_value(cs));
+               } else {
+                       out_message =
+                               bt_message_event_create_with_default_clock_snapshot(
+                                       debug_it->input_iterator,
+                                       out_event_class, out_stream,
+                                       bt_clock_snapshot_get_value(cs));
+               }
        } else {
-               out_message = bt_message_event_create(debug_it->input_iterator,
-                               out_event_class, out_packet);
+               if (out_packet) {
+                       out_message = bt_message_event_create_with_packet(
+                               debug_it->input_iterator, out_event_class,
+                               out_packet);
+               } else {
+                       out_message = bt_message_event_create(
+                               debug_it->input_iterator, out_event_class,
+                               out_stream);
+               }
        }
 
        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
@@ -1307,7 +1343,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;
 }
 
@@ -1326,7 +1366,7 @@ bt_message *handle_stream_begin_message(struct debug_info_msg_iter *debug_it,
 
        /* Create a duplicated output stream. */
        out_stream = trace_ir_mapping_create_new_mapped_stream(
-                       debug_it->ir_maps, in_stream);
+               debug_it->ir_maps, in_stream);
        if (!out_stream) {
                out_message = NULL;
                goto error;
@@ -1334,9 +1374,10 @@ bt_message *handle_stream_begin_message(struct debug_info_msg_iter *debug_it,
 
        /* Create an output stream beginning message. */
        out_message = bt_message_stream_beginning_create(
-                       debug_it->input_iterator, out_stream);
+               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:
@@ -1357,20 +1398,23 @@ bt_message *handle_stream_end_message(struct debug_info_msg_iter *debug_it,
        BT_ASSERT(in_stream);
 
        out_stream = trace_ir_mapping_borrow_mapped_stream(
-                       debug_it->ir_maps, in_stream);
+               debug_it->ir_maps, in_stream);
        BT_ASSERT(out_stream);
 
        /* Create an output stream end message. */
        out_message = bt_message_stream_end_create(debug_it->input_iterator,
-                       out_stream);
+               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;
        }
 
        /* Remove stream from trace mapping hashtable. */
        trace_ir_mapping_remove_mapped_stream(debug_it->ir_maps, in_stream);
 
+end:
        return out_message;
 }
 
@@ -1394,7 +1438,7 @@ bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it,
                                debug_it->ir_maps, in_packet));
 
        out_packet = trace_ir_mapping_create_new_mapped_packet(debug_it->ir_maps,
-                       in_packet);
+               in_packet);
 
        BT_ASSERT(out_packet);
 
@@ -1405,18 +1449,19 @@ bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it,
        if (has_default_clock_snapshot) {
                /* Borrow clock snapshot. */
                cs = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
-                                       in_message);
+                       in_message);
 
                /* Create an output packet beginning message. */
                out_message = bt_message_packet_beginning_create_with_default_clock_snapshot(
-                               debug_it->input_iterator, out_packet,
-                               bt_clock_snapshot_get_value(cs));
+                       debug_it->input_iterator, out_packet,
+                       bt_clock_snapshot_get_value(cs));
        } else {
                out_message = bt_message_packet_beginning_create(
-                               debug_it->input_iterator, out_packet);
+                       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);
        }
 
@@ -1448,25 +1493,28 @@ bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it,
        if (has_default_clock_snapshot) {
                /* Borrow clock snapshot. */
                cs = bt_message_packet_end_borrow_default_clock_snapshot_const(
-                                       in_message);
+                       in_message);
 
                /* Create an outpute packet end message. */
                out_message = bt_message_packet_end_create_with_default_clock_snapshot(
-                               debug_it->input_iterator, out_packet,
-                               bt_clock_snapshot_get_value(cs));
+                       debug_it->input_iterator, out_packet,
+                       bt_clock_snapshot_get_value(cs));
        } else {
                out_message = bt_message_packet_end_create(
-                               debug_it->input_iterator, out_packet);
+                       debug_it->input_iterator, out_packet);
        }
 
        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;
        }
 
        /* Remove packet from data mapping hashtable. */
        trace_ir_mapping_remove_mapped_packet(debug_it->ir_maps, in_packet);
 
+end:
        return out_message;
 }
 
@@ -1482,110 +1530,6 @@ bt_message *handle_msg_iterator_inactivity(struct debug_info_msg_iter *debug_it,
        return (bt_message*) in_message;
 }
 
-static
-bt_message *handle_stream_act_begin_message(struct debug_info_msg_iter *debug_it,
-               const bt_message *in_message)
-{
-       const bt_clock_snapshot *cs;
-       const bt_clock_class *default_cc;
-       bt_message *out_message = NULL;
-       bt_stream *out_stream;
-       uint64_t cs_value;
-       bt_message_stream_activity_clock_snapshot_state cs_state;
-       bt_logging_level log_level = debug_it->log_level;
-       bt_self_component *self_comp = debug_it->self_comp;
-
-       const bt_stream *in_stream =
-               bt_message_stream_activity_beginning_borrow_stream_const(
-                       in_message);
-       BT_ASSERT(in_stream);
-
-       out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps,
-                       in_stream);
-       BT_ASSERT(out_stream);
-
-       out_message = bt_message_stream_activity_beginning_create(
-                       debug_it->input_iterator, out_stream);
-       if (!out_message) {
-               BT_COMP_LOGE("Error creating output stream activity beginning "
-                       "message: out-s-addr=%p", out_stream);
-               goto error;
-       }
-
-       default_cc = bt_stream_class_borrow_default_clock_class_const(
-                       bt_stream_borrow_class_const(in_stream));
-       if (default_cc) {
-               /* Borrow clock snapshot. */
-               cs_state =
-                       bt_message_stream_activity_beginning_borrow_default_clock_snapshot_const(
-                                       in_message, &cs);
-
-               if (cs_state == BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN) {
-                       cs_value = bt_clock_snapshot_get_value(cs);
-                       bt_message_stream_activity_beginning_set_default_clock_snapshot(
-                                       out_message, cs_value);
-               } else {
-                       bt_message_stream_activity_beginning_set_default_clock_snapshot_state(
-                                       out_message, cs_state);
-               }
-       }
-
-error:
-       return out_message;
-}
-
-static
-bt_message *handle_stream_act_end_message(struct debug_info_msg_iter *debug_it,
-               const bt_message *in_message)
-{
-       const bt_clock_snapshot *cs;
-       const bt_clock_class *default_cc;
-       const bt_stream *in_stream;
-       bt_message *out_message;
-       bt_stream *out_stream;
-       uint64_t cs_value;
-       bt_message_stream_activity_clock_snapshot_state cs_state;
-       bt_logging_level log_level = debug_it->log_level;
-       bt_self_component *self_comp = debug_it->self_comp;
-
-       in_stream = bt_message_stream_activity_end_borrow_stream_const(
-                       in_message);
-       BT_ASSERT(in_stream);
-
-       out_stream = trace_ir_mapping_borrow_mapped_stream(debug_it->ir_maps,
-               in_stream);
-       BT_ASSERT(out_stream);
-
-       out_message = bt_message_stream_activity_end_create(
-                       debug_it->input_iterator, out_stream);
-       if (!out_message) {
-               BT_COMP_LOGE("Error creating output stream activity end message: "
-                       "out-s-addr=%p", out_stream);
-               goto error;
-       }
-
-       default_cc = bt_stream_class_borrow_default_clock_class_const(
-                       bt_stream_borrow_class_const(in_stream));
-
-       if (default_cc) {
-               cs_state =
-                       bt_message_stream_activity_end_borrow_default_clock_snapshot_const(
-                                       in_message, &cs);
-
-               if (cs_state == BT_MESSAGE_STREAM_ACTIVITY_CLOCK_SNAPSHOT_STATE_KNOWN ) {
-                       cs_value = bt_clock_snapshot_get_value(cs);
-                       bt_message_stream_activity_end_set_default_clock_snapshot(
-                                       out_message, cs_value);
-               } else {
-                       bt_message_stream_activity_end_set_default_clock_snapshot_state(
-                                       out_message, cs_state);
-               }
-       }
-
-error:
-       return out_message;
-}
-
 static
 bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it,
                const bt_message *in_message)
@@ -1604,44 +1548,42 @@ bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it
                        in_message);
        BT_ASSERT(in_stream);
 
-       out_stream = trace_ir_mapping_borrow_mapped_stream(
-                               debug_it->ir_maps, in_stream);
+       out_stream = trace_ir_mapping_borrow_mapped_stream( debug_it->ir_maps,
+               in_stream);
        BT_ASSERT(out_stream);
 
        has_default_clock_snapshots =
                bt_stream_class_discarded_events_have_default_clock_snapshots(
                        bt_stream_borrow_class_const(in_stream));
        if (has_default_clock_snapshots) {
-               begin_cs =
-                       bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
-                               in_message);
-               end_cs =
-                       bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
-                               in_message);
+               begin_cs = bt_message_discarded_events_borrow_beginning_default_clock_snapshot_const(
+                       in_message);
+               end_cs = bt_message_discarded_events_borrow_end_default_clock_snapshot_const(
+                       in_message);
 
                begin_cs_value = bt_clock_snapshot_get_value(begin_cs);
                end_cs_value = bt_clock_snapshot_get_value(end_cs);
 
-               out_message =
-                       bt_message_discarded_events_create_with_default_clock_snapshots(
-                                       debug_it->input_iterator, out_stream,
-                                       begin_cs_value, end_cs_value);
+               out_message = bt_message_discarded_events_create_with_default_clock_snapshots(
+                       debug_it->input_iterator, out_stream,
+                       begin_cs_value, end_cs_value);
        } else {
                out_message = bt_message_discarded_events_create(
-                               debug_it->input_iterator, out_stream);
+                       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;
        }
 
        prop_avail = bt_message_discarded_events_get_count(in_message,
-                       &discarded_events);
+               &discarded_events);
 
        if (prop_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
                bt_message_discarded_events_set_count(out_message,
-                               discarded_events);
+                       discarded_events);
        }
 
 error:
@@ -1663,46 +1605,45 @@ bt_message *handle_discarded_packets_message(struct debug_info_msg_iter *debug_i
        bt_self_component *self_comp = debug_it->self_comp;
 
        in_stream = bt_message_discarded_packets_borrow_stream_const(
-                       in_message);
+               in_message);
        BT_ASSERT(in_stream);
 
-       out_stream = trace_ir_mapping_borrow_mapped_stream(
-                       debug_it->ir_maps, in_stream);
+       out_stream = trace_ir_mapping_borrow_mapped_stream( debug_it->ir_maps,
+               in_stream);
        BT_ASSERT(out_stream);
 
        has_default_clock_snapshots =
                bt_stream_class_discarded_packets_have_default_clock_snapshots(
                        bt_stream_borrow_class_const(in_stream));
        if (has_default_clock_snapshots) {
-               begin_cs =
-                       bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
-                               in_message);
+               begin_cs = bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
+                       in_message);
 
-               end_cs =
-                       bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
-                               in_message);
+               end_cs = bt_message_discarded_packets_borrow_end_default_clock_snapshot_const(
+                       in_message);
 
                begin_cs_value = bt_clock_snapshot_get_value(begin_cs);
                end_cs_value = bt_clock_snapshot_get_value(end_cs);
 
                out_message = bt_message_discarded_packets_create_with_default_clock_snapshots(
-                                       debug_it->input_iterator, out_stream,
-                                       begin_cs_value, end_cs_value);
+                       debug_it->input_iterator, out_stream,
+                       begin_cs_value, end_cs_value);
        } else {
                out_message = bt_message_discarded_packets_create(
-                               debug_it->input_iterator, out_stream);
+                       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;
        }
 
        prop_avail = bt_message_discarded_packets_get_count(in_message,
-                       &discarded_packets);
+               &discarded_packets);
        if (prop_avail == BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE) {
                bt_message_discarded_packets_set_count(out_message,
-                               discarded_packets);
+                       discarded_packets);
        }
 
 error:
@@ -1717,47 +1658,31 @@ const bt_message *handle_message(struct debug_info_msg_iter *debug_it,
 
        switch (bt_message_get_type(in_message)) {
        case BT_MESSAGE_TYPE_EVENT:
-               out_message = handle_event_message(debug_it,
-                               in_message);
+               out_message = handle_event_message(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_PACKET_BEGINNING:
-               out_message = handle_packet_begin_message(debug_it,
-                               in_message);
+               out_message = handle_packet_begin_message(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_PACKET_END:
-               out_message = handle_packet_end_message(debug_it,
-                               in_message);
+               out_message = handle_packet_end_message(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_STREAM_BEGINNING:
-               out_message = handle_stream_begin_message(debug_it,
-                               in_message);
+               out_message = handle_stream_begin_message(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_STREAM_END:
-               out_message = handle_stream_end_message(debug_it,
-                               in_message);
+               out_message = handle_stream_end_message(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_MESSAGE_ITERATOR_INACTIVITY:
-               out_message = handle_msg_iterator_inactivity(debug_it,
-                               in_message);
-               break;
-       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_BEGINNING:
-               out_message = handle_stream_act_begin_message(debug_it,
-                               in_message);
-               break;
-       case BT_MESSAGE_TYPE_STREAM_ACTIVITY_END:
-               out_message = handle_stream_act_end_message(debug_it,
-                               in_message);
+               out_message = handle_msg_iterator_inactivity(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
-               out_message = handle_discarded_events_message(debug_it,
-                               in_message);
+               out_message = handle_discarded_events_message(debug_it, in_message);
                break;
        case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
-               out_message = handle_discarded_packets_message(debug_it,
-                               in_message);
+               out_message = handle_discarded_packets_message(debug_it, in_message);
                break;
        default:
-               abort();
+               bt_common_abort();
                break;
        }
 
@@ -1765,11 +1690,36 @@ const bt_message *handle_message(struct debug_info_msg_iter *debug_it,
 }
 
 static
-int init_from_params(struct debug_info_component *debug_info_component,
+struct bt_param_validation_map_value_entry_descr debug_info_params[] = {
+       { "debug-info-field-name", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } },
+       { "debug-info-dir", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } },
+       { "target-prefix", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_STRING } },
+       { "full-path", BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_OPTIONAL, { .type = BT_VALUE_TYPE_BOOL } },
+       BT_PARAM_VALIDATION_MAP_VALUE_ENTRY_END
+};
+
+static
+bt_component_class_initialize_method_status init_from_params(
+               struct debug_info_component *debug_info_component,
                const bt_value *params)
 {
-       const bt_value *value = NULL;
-       int ret = 0;
+       const bt_value *value;
+       bt_component_class_initialize_method_status status;
+       bt_logging_level log_level = debug_info_component->log_level;
+       enum bt_param_validation_status validation_status;
+       gchar *validate_error = NULL;
+
+       validation_status = bt_param_validation_validate(params,
+               debug_info_params, &validate_error);
+       if (validation_status == BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR) {
+               status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
+               goto end;
+       } else if (validation_status == BT_PARAM_VALIDATION_STATUS_VALIDATION_ERROR) {
+               status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
+               BT_COMP_LOGE_APPEND_CAUSE(debug_info_component->self_comp,
+                       "%s", validate_error);
+               goto end;
+       }
 
        BT_ASSERT(params);
 
@@ -1807,67 +1757,62 @@ int init_from_params(struct debug_info_component *debug_info_component,
                debug_info_component->arg_full_path = BT_FALSE;
        }
 
-       return ret;
+       status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
+
+end:
+       g_free(validate_error);
+
+       return status;
 }
 
 BT_HIDDEN
-bt_component_class_init_method_status debug_info_comp_init(
+bt_component_class_initialize_method_status debug_info_comp_init(
                bt_self_component_filter *self_comp_flt,
+               bt_self_component_filter_configuration *config,
                const bt_value *params, __attribute__((unused)) void *init_method_data)
 {
-       int ret;
        struct debug_info_component *debug_info_comp;
-       bt_component_class_init_method_status status =
-               BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK;
+       bt_component_class_initialize_method_status status =
+               BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
        bt_self_component_add_port_status add_port_status;
        bt_self_component *self_comp =
                bt_self_component_filter_as_self_component(self_comp_flt);
        bt_logging_level log_level = bt_component_get_logging_level(
                bt_self_component_as_component(self_comp));
 
-
        BT_COMP_LOGI("Initializing debug_info component: "
                "comp-addr=%p, params-addr=%p", self_comp, params);
 
        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;
        }
 
        debug_info_comp->log_level = log_level;
        debug_info_comp->self_comp = self_comp;
+       debug_info_comp->self_comp_filter = self_comp_flt;
        bt_self_component_set_data(self_comp, debug_info_comp);
 
        add_port_status = bt_self_component_filter_add_input_port(
                self_comp_flt, "in", NULL, NULL);
-       switch (add_port_status) {
-       case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
-               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
-               goto error;
-       case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
-               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
+       if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
+               status = (int) add_port_status;
                goto error;
-       default:
-               break;
        }
 
        add_port_status = bt_self_component_filter_add_output_port(
                        self_comp_flt, "out", NULL, NULL);
-       switch (add_port_status) {
-       case BT_SELF_COMPONENT_ADD_PORT_STATUS_ERROR:
-               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
-               goto error;
-       case BT_SELF_COMPONENT_ADD_PORT_STATUS_MEMORY_ERROR:
-               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_MEMORY_ERROR;
+       if (add_port_status != BT_SELF_COMPONENT_ADD_PORT_STATUS_OK) {
+               status = (int) add_port_status;
                goto error;
-       default:
-               break;
        }
 
-       ret = init_from_params(debug_info_comp, params);
-       if (ret) {
-               BT_COMP_LOGE("Cannot configure debug_info component: "
+       status = init_from_params(debug_info_comp, params);
+       if (status != BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) {
+               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;
@@ -1879,8 +1824,8 @@ error:
        destroy_debug_info_comp(debug_info_comp);
        bt_self_component_set_data(self_comp, NULL);
 
-       if (status == BT_COMPONENT_CLASS_INIT_METHOD_STATUS_OK) {
-               status = BT_COMPONENT_CLASS_INIT_METHOD_STATUS_ERROR;
+       if (status == BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK) {
+               status = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
        }
 end:
        return status;
@@ -1891,8 +1836,8 @@ void debug_info_comp_finalize(bt_self_component_filter *self_comp_flt)
 {
        struct debug_info_component *debug_info =
                bt_self_component_get_data(
-                               bt_self_component_filter_as_self_component(
-                                       self_comp_flt));
+                       bt_self_component_filter_as_self_component(
+                               self_comp_flt));
        bt_logging_level log_level = debug_info->log_level;
        bt_self_component *self_comp = debug_info->self_comp;
 
@@ -1903,38 +1848,38 @@ void debug_info_comp_finalize(bt_self_component_filter *self_comp_flt)
 }
 
 BT_HIDDEN
-bt_component_class_message_iterator_next_method_status debug_info_msg_iter_next(
+bt_message_iterator_class_next_method_status debug_info_msg_iter_next(
                bt_self_message_iterator *self_msg_iter,
                const bt_message_array_const msgs, uint64_t capacity,
                uint64_t *count)
 {
-       bt_self_component_port_input_message_iterator *upstream_iterator = NULL;
+       bt_message_iterator *upstream_iterator = NULL;
        bt_message_iterator_next_status upstream_iterator_ret_status;
        struct debug_info_msg_iter *debug_info_msg_iter;
        struct debug_info_component *debug_info = NULL;
-       bt_component_class_message_iterator_next_method_status status;
+       bt_message_iterator_class_next_method_status status;
        bt_self_component *self_comp = NULL;
        bt_message_array_const input_msgs;
        const bt_message *out_message;
        uint64_t curr_msg_idx, i;
 
-       status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
+       status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_OK;
 
        self_comp = bt_self_message_iterator_borrow_component(self_msg_iter);
-       BT_ASSERT(self_comp);
+       BT_ASSERT_DBG(self_comp);
 
        debug_info = bt_self_component_get_data(self_comp);
-       BT_ASSERT(debug_info);
+       BT_ASSERT_DBG(debug_info);
 
        debug_info_msg_iter = bt_self_message_iterator_get_data(self_msg_iter);
-       BT_ASSERT(debug_info_msg_iter);
+       BT_ASSERT_DBG(debug_info_msg_iter);
 
        upstream_iterator = debug_info_msg_iter->msg_iter;
-       BT_ASSERT(upstream_iterator);
+       BT_ASSERT_DBG(upstream_iterator);
 
        upstream_iterator_ret_status =
-               bt_self_component_port_input_message_iterator_next(
-                               upstream_iterator, &input_msgs, count);
+               bt_message_iterator_next(
+                       upstream_iterator, &input_msgs, count);
        if (upstream_iterator_ret_status !=
                        BT_MESSAGE_ITERATOR_NEXT_STATUS_OK) {
                /*
@@ -1950,7 +1895,7 @@ bt_component_class_message_iterator_next_method_status debug_info_msg_iter_next(
         * There should never be more received messages than the capacity we
         * provided.
         */
-       BT_ASSERT(*count <= capacity);
+       BT_ASSERT_DBG(*count <= capacity);
 
        for (curr_msg_idx = 0; curr_msg_idx < *count; curr_msg_idx++) {
                out_message = handle_message(debug_info_msg_iter,
@@ -1978,7 +1923,15 @@ handle_msg_error:
                bt_message_put_ref(msgs[i]);
        }
 
-       status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_MEMORY_ERROR;
+       /*
+        * Drop references of all the input messages not dropped before the
+        * failure.
+        */
+       for (i = curr_msg_idx; i < *count; i++) {
+               bt_message_put_ref(input_msgs[i]);
+       }
+
+       status = BT_MESSAGE_ITERATOR_CLASS_NEXT_METHOD_STATUS_MEMORY_ERROR;
 
 end:
        return status;
@@ -1992,8 +1945,8 @@ void debug_info_msg_iter_destroy(struct debug_info_msg_iter *debug_info_msg_iter
        }
 
        if (debug_info_msg_iter->msg_iter) {
-               bt_self_component_port_input_message_iterator_put_ref(
-                               debug_info_msg_iter->msg_iter);
+               bt_message_iterator_put_ref(
+                       debug_info_msg_iter->msg_iter);
        }
 
        if (debug_info_msg_iter->ir_maps) {
@@ -2012,49 +1965,54 @@ end:
 }
 
 BT_HIDDEN
-bt_component_class_message_iterator_init_method_status debug_info_msg_iter_init(
+bt_message_iterator_class_initialize_method_status debug_info_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
-               bt_self_component_filter *self_comp_flt,
+               bt_self_message_iterator_configuration *config,
                bt_self_component_port_output *self_port)
 {
-       bt_component_class_message_iterator_init_method_status status =
-               BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_OK;
+       bt_message_iterator_class_initialize_method_status status;
+       bt_message_iterator_create_from_message_iterator_status
+               msg_iter_status;
        struct bt_self_component_port_input *input_port = NULL;
-       bt_self_component_port_input_message_iterator *upstream_iterator = NULL;
+       bt_message_iterator *upstream_iterator = NULL;
        struct debug_info_msg_iter *debug_info_msg_iter = NULL;
        gchar *debug_info_field_name;
        int ret;
        bt_self_component *self_comp =
-               bt_self_component_filter_as_self_component(self_comp_flt);
+               bt_self_message_iterator_borrow_component(self_msg_iter);
        bt_logging_level log_level = bt_component_get_logging_level(
                bt_self_component_as_component(self_comp));
 
-       /* Borrow the upstream input port. */
-       input_port = bt_self_component_filter_borrow_input_port_by_name(
-               self_comp_flt, "in");
-       if (!input_port) {
-               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_ERROR;
-               goto error;
-       }
-
        debug_info_msg_iter = g_new0(struct debug_info_msg_iter, 1);
        if (!debug_info_msg_iter) {
-               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
+               status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
 
        debug_info_msg_iter->log_level = log_level;
        debug_info_msg_iter->self_comp = self_comp;
 
+       debug_info_msg_iter->debug_info_component =
+               bt_self_component_get_data(self_comp);
+
+       /* Borrow the upstream input port. */
+       input_port = bt_self_component_filter_borrow_input_port_by_name(
+                       debug_info_msg_iter->debug_info_component->self_comp_filter,
+                       "in");
+       if (!input_port) {
+               status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
+               goto error;
+       }
+
        /* Create an iterator on the upstream component. */
-       upstream_iterator = bt_self_component_port_input_message_iterator_create(
-               input_port);
-       if (!upstream_iterator) {
-               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
+       msg_iter_status = bt_message_iterator_create_from_message_iterator(
+               self_msg_iter, input_port, &upstream_iterator);
+       if (msg_iter_status != BT_MESSAGE_ITERATOR_CREATE_FROM_MESSAGE_ITERATOR_STATUS_OK) {
+               status = (int) msg_iter_status;
                goto error;
        }
 
-       BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
+       BT_MESSAGE_ITERATOR_MOVE_REF(
                debug_info_msg_iter->msg_iter, upstream_iterator);
 
        /* Create hashtable that will contain debug info mapping. */
@@ -2062,32 +2020,34 @@ bt_component_class_message_iterator_init_method_status debug_info_msg_iter_init(
                g_direct_hash, g_direct_equal, (GDestroyNotify) NULL,
                (GDestroyNotify) debug_info_destroy);
        if (!debug_info_msg_iter->debug_info_map) {
-               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
+               status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
 
-       debug_info_msg_iter->debug_info_component =
-               bt_self_component_get_data(self_comp);
-
        debug_info_field_name =
                debug_info_msg_iter->debug_info_component->arg_debug_info_field_name;
 
        debug_info_msg_iter->ir_maps = trace_ir_maps_create(self_comp,
                debug_info_field_name, log_level);
        if (!debug_info_msg_iter->ir_maps) {
-               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
+               status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
 
        ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache, log_level);
        if (ret) {
-               status = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_INIT_METHOD_STATUS_MEMORY_ERROR;
+               status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
                goto error;
        }
 
+       bt_self_message_iterator_configuration_set_can_seek_forward(config,
+               bt_message_iterator_can_seek_forward(
+                       debug_info_msg_iter->msg_iter));
+
        bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
        debug_info_msg_iter->input_iterator = self_msg_iter;
 
+       status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_OK;
        goto end;
 
 error:
@@ -2098,31 +2058,32 @@ end:
 }
 
 BT_HIDDEN
-bt_bool debug_info_msg_iter_can_seek_beginning(
-               bt_self_message_iterator *self_msg_iter)
+bt_message_iterator_class_can_seek_beginning_method_status
+debug_info_msg_iter_can_seek_beginning(bt_self_message_iterator *self_msg_iter,
+               bt_bool *can_seek)
 {
        struct debug_info_msg_iter *debug_info_msg_iter =
                bt_self_message_iterator_get_data(self_msg_iter);
        BT_ASSERT(debug_info_msg_iter);
 
-       return bt_self_component_port_input_message_iterator_can_seek_beginning(
-                       debug_info_msg_iter->msg_iter);
+       return (int) bt_message_iterator_can_seek_beginning(
+               debug_info_msg_iter->msg_iter, can_seek);
 }
 
 BT_HIDDEN
-bt_component_class_message_iterator_seek_beginning_method_status debug_info_msg_iter_seek_beginning(
-               bt_self_message_iterator *self_msg_iter)
+bt_message_iterator_class_seek_beginning_method_status
+debug_info_msg_iter_seek_beginning(bt_self_message_iterator *self_msg_iter)
 {
        struct debug_info_msg_iter *debug_info_msg_iter =
                bt_self_message_iterator_get_data(self_msg_iter);
-       bt_component_class_message_iterator_seek_beginning_method_status status =
-               BT_COMPONENT_CLASS_MESSAGE_ITERATOR_SEEK_BEGINNING_METHOD_STATUS_OK;
+       bt_message_iterator_class_seek_beginning_method_status status =
+               BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK;
        bt_message_iterator_seek_beginning_status seek_beg_status;
 
        BT_ASSERT(debug_info_msg_iter);
 
        /* Ask the upstream component to seek to the beginning. */
-       seek_beg_status = bt_self_component_port_input_message_iterator_seek_beginning(
+       seek_beg_status = bt_message_iterator_seek_beginning(
                debug_info_msg_iter->msg_iter);
        if (seek_beg_status != BT_MESSAGE_ITERATOR_SEEK_BEGINNING_STATUS_OK) {
                status = (int) seek_beg_status;
This page took 0.053182 seconds and 4 git commands to generate.