Fix: flt.lttng-utils.debug-info: extra colon in `bin` member
[babeltrace.git] / plugins / lttng-utils / debug-info / debug-info.c
index d84bf397a0af59a82b20202331e614b3008fce05..1bdd01e565038dd5a807c6aed7eae9ef01618843 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <babeltrace/assert-internal.h>
 #include <babeltrace/common-internal.h>
+#include <babeltrace/fd-cache-internal.h>
 
 #include "bin-info.h"
 #include "debug-info.h"
@@ -70,6 +71,8 @@ struct debug_info_msg_iter {
        struct trace_ir_maps *ir_maps;
        /* in_trace -> debug_info_mapping. */
        GHashTable *debug_info_map;
+
+       struct bt_fd_cache fd_cache;
 };
 
 struct debug_info_source {
@@ -124,6 +127,7 @@ struct debug_info {
        GQuark q_dl_open;
        GQuark q_lib_load;
        GQuark q_lib_unload;
+       struct bt_fd_cache *fd_cache; /* Weak ref. Owned by the iterator. */
 };
 
 static
@@ -491,7 +495,7 @@ end:
        return debug_info_src;
 }
 
-BT_HIDDEN
+static
 struct debug_info_source *debug_info_query(struct debug_info *debug_info,
                int64_t vpid, uint64_t ip)
 {
@@ -510,13 +514,17 @@ end:
        return dbg_info_src;
 }
 
-BT_HIDDEN
+static
 struct debug_info *debug_info_create(struct debug_info_component *comp,
-               const bt_trace *trace)
+               const bt_trace *trace, struct bt_fd_cache *fdc)
 {
        int ret;
        struct debug_info *debug_info;
 
+       BT_ASSERT(comp);
+       BT_ASSERT(trace);
+       BT_ASSERT(fdc);
+
        debug_info = g_new0(struct debug_info, 1);
        if (!debug_info) {
                goto end;
@@ -536,6 +544,7 @@ struct debug_info *debug_info_create(struct debug_info_component *comp,
        }
 
        debug_info->input_trace = trace;
+       debug_info->fd_cache = fdc;
 
 end:
        return debug_info;
@@ -544,7 +553,7 @@ error:
        return NULL;
 }
 
-BT_HIDDEN
+static
 void debug_info_destroy(struct debug_info *debug_info)
 {
        bt_trace_status status;
@@ -712,7 +721,7 @@ void handle_bin_info_event(struct debug_info *debug_info,
                uint64_t is_pic_field_value;
 
                event_get_payload_unsigned_integer_field_value(event,
-                               IS_PIC_FIELD_NAME, &is_pic_field_value);
+                       IS_PIC_FIELD_NAME, &is_pic_field_value);
                is_pic = is_pic_field_value == 1;
        } else {
                /*
@@ -726,7 +735,7 @@ void handle_bin_info_event(struct debug_info *debug_info,
                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;
        }
@@ -738,21 +747,19 @@ void handle_bin_info_event(struct debug_info *debug_info,
 
        *((uint64_t *) key) = baddr;
 
-       bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info,
-                       key);
+       bin = g_hash_table_lookup(proc_dbg_info_src->baddr_to_bin_info, key);
        if (bin) {
                goto end;
        }
 
-       bin = bin_info_create(path, baddr, memsz, is_pic,
+       bin = bin_info_create(debug_info->fd_cache, path, baddr, memsz, is_pic,
                debug_info->comp->arg_debug_dir,
                debug_info->comp->arg_target_prefix);
        if (!bin) {
                goto end;
        }
 
-       g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info,
-                       key, bin);
+       g_hash_table_insert(proc_dbg_info_src->baddr_to_bin_info, key, bin);
        /* Ownership passed to ht. */
        key = NULL;
 
@@ -864,7 +871,7 @@ void handle_event_statedump(struct debug_info_msg_iter *debug_it,
        debug_info = g_hash_table_lookup(debug_it->debug_info_map, trace);
        if (!debug_info) {
                debug_info = debug_info_create(debug_it->debug_info_component,
-                               trace);
+                               trace, &debug_it->fd_cache);
                g_hash_table_insert(debug_it->debug_info_map, (gpointer) trace,
                                debug_info);
                bt_trace_add_destruction_listener(trace,
@@ -941,13 +948,6 @@ void fill_debug_info_bin_field(struct debug_info_source *dbg_info_src,
                                curr_field);
                }
 
-               status = bt_field_string_append(curr_field, ":");
-               if (status != BT_FIELD_STATUS_OK) {
-                       BT_LOGE("Cannot set colon component of \"bin\" "
-                               "curr_field field's value: str-fc-addr=%p",
-                               curr_field);
-               }
-
                status = bt_field_string_append(curr_field, dbg_info_src->bin_loc);
                if (status != BT_FIELD_STATUS_OK) {
                        BT_LOGE("Cannot set bin location component of \"bin\" "
@@ -1507,7 +1507,8 @@ bt_message *handle_stream_act_end_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);
 
        out_message = bt_message_stream_activity_end_create(
@@ -1925,6 +1926,33 @@ end:
        return status;
 }
 
+static
+void debug_info_msg_iter_destroy(struct debug_info_msg_iter *debug_info_msg_iter)
+{
+       if (!debug_info_msg_iter) {
+               goto end;
+       }
+
+       if (debug_info_msg_iter->msg_iter) {
+               bt_self_component_port_input_message_iterator_put_ref(
+                               debug_info_msg_iter->msg_iter);
+       }
+
+       if (debug_info_msg_iter->ir_maps) {
+               trace_ir_maps_destroy(debug_info_msg_iter->ir_maps);
+       }
+
+       if (debug_info_msg_iter->debug_info_map) {
+               g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
+       }
+
+       bt_fd_cache_fini(&debug_info_msg_iter->fd_cache);
+       g_free(debug_info_msg_iter);
+
+end:
+       return;
+}
+
 BT_HIDDEN
 bt_self_message_iterator_status debug_info_msg_iter_init(
                bt_self_message_iterator *self_msg_iter,
@@ -1932,17 +1960,24 @@ bt_self_message_iterator_status debug_info_msg_iter_init(
                bt_self_component_port_output *self_port)
 {
        bt_self_message_iterator_status status = BT_SELF_MESSAGE_ITERATOR_STATUS_OK;
-       struct bt_self_component_port_input *input_port;
-       bt_self_component_port_input_message_iterator *upstream_iterator;
-       struct debug_info_msg_iter *debug_info_msg_iter;
+       struct bt_self_component_port_input *input_port = NULL;
+       bt_self_component_port_input_message_iterator *upstream_iterator = NULL;
+       struct debug_info_msg_iter *debug_info_msg_iter = NULL;
        gchar *debug_info_field_name;
+       int ret;
 
        /* Borrow the upstream input port. */
        input_port = bt_self_component_filter_borrow_input_port_by_name(
-                       self_comp, "in");
+               self_comp, "in");
        if (!input_port) {
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_ERROR;
-               goto end;
+               goto error;
+       }
+
+       debug_info_msg_iter = g_new0(struct debug_info_msg_iter, 1);
+       if (!debug_info_msg_iter) {
+               status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
+               goto error;
        }
 
        /* Create an iterator on the upstream component. */
@@ -1950,53 +1985,52 @@ bt_self_message_iterator_status debug_info_msg_iter_init(
                input_port);
        if (!upstream_iterator) {
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
-               goto end;
+               goto error;
        }
 
-       debug_info_msg_iter = g_new0(struct debug_info_msg_iter, 1);
-       if (!debug_info_msg_iter) {
-               status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
-               goto end;
-       }
+       BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
+               debug_info_msg_iter->msg_iter, upstream_iterator);
 
-       /* Create hashtable to will contain debug info mapping. */
+       /* Create hashtable that will contain debug info mapping. */
        debug_info_msg_iter->debug_info_map = g_hash_table_new_full(
-                       g_direct_hash, g_direct_equal,
-                       (GDestroyNotify) NULL,
-                       (GDestroyNotify) debug_info_destroy);
+               g_direct_hash, g_direct_equal, (GDestroyNotify) NULL,
+               (GDestroyNotify) debug_info_destroy);
        if (!debug_info_msg_iter->debug_info_map) {
-               g_free(debug_info_msg_iter);
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
-               goto end;
+               goto error;
        }
 
        debug_info_msg_iter->self_comp =
                bt_self_component_filter_as_self_component(self_comp);
 
-       BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_MOVE_REF(
-               debug_info_msg_iter->msg_iter, upstream_iterator);
-
        debug_info_msg_iter->debug_info_component = bt_self_component_get_data(
-                               bt_self_component_filter_as_self_component(
-                                       self_comp));
+               bt_self_component_filter_as_self_component(
+                       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(
-                       bt_self_component_filter_as_self_component(self_comp),
-                       debug_info_field_name);
+               bt_self_component_filter_as_self_component(self_comp),
+               debug_info_field_name);
        if (!debug_info_msg_iter->ir_maps) {
-               g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
-               g_free(debug_info_msg_iter);
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
-               goto end;
+               goto error;
        }
 
-       bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
+       ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache);
+       if (ret) {
+               status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
+               goto error;
+       }
 
+       bt_self_message_iterator_set_data(self_msg_iter, debug_info_msg_iter);
        debug_info_msg_iter->input_iterator = self_msg_iter;
 
+       goto end;
+
+error:
+       debug_info_msg_iter_destroy(debug_info_msg_iter);
 end:
        return status;
 }
@@ -2045,11 +2079,5 @@ void debug_info_msg_iter_finalize(bt_self_message_iterator *it)
        debug_info_msg_iter = bt_self_message_iterator_get_data(it);
        BT_ASSERT(debug_info_msg_iter);
 
-       bt_self_component_port_input_message_iterator_put_ref(
-                       debug_info_msg_iter->msg_iter);
-
-       trace_ir_maps_destroy(debug_info_msg_iter->ir_maps);
-       g_hash_table_destroy(debug_info_msg_iter->debug_info_map);
-
-       g_free(debug_info_msg_iter);
+       debug_info_msg_iter_destroy(debug_info_msg_iter);
 }
This page took 0.026708 seconds and 4 git commands to generate.