lib: rename include dir to babeltrace2
[babeltrace.git] / plugins / lttng-utils / debug-info / debug-info.c
index b2620b6ad08aa9845e4aaf434dfaa592bbd50350..1e7a2381ed7fe062da9494c7c47c430d12141f70 100644 (file)
@@ -32,9 +32,9 @@
 #include <glib.h>
 #include <plugins-common.h>
 
-#include <babeltrace/assert-internal.h>
-#include <babeltrace/common-internal.h>
-#include <babeltrace/fd-cache-internal.h>
+#include <babeltrace2/assert-internal.h>
+#include <babeltrace2/common-internal.h>
+#include <babeltrace2/fd-cache-internal.h>
 
 #include "bin-info.h"
 #include "debug-info.h"
@@ -948,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\" "
@@ -1214,7 +1207,6 @@ 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;
-       bt_clock_snapshot_state cs_state;
        bt_event_class *out_event_class;
        bt_packet *out_packet;
        bt_event *out_event;
@@ -1246,12 +1238,10 @@ bt_message *handle_event_message(struct debug_info_msg_iter *debug_it,
                        bt_event_class_borrow_stream_class_const(in_event_class));
        if (default_cc) {
                /* Borrow event clock snapshot. */
-               cs_state =
-                       bt_message_event_borrow_default_clock_snapshot_const(
-                               in_message, &cs);
+               cs = bt_message_event_borrow_default_clock_snapshot_const(
+                               in_message);
 
                /* Create an output event message. */
-               BT_ASSERT (cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
                out_message = bt_message_event_create_with_default_clock_snapshot(
                                        debug_it->input_iterator,
                                        out_event_class, out_packet,
@@ -1344,8 +1334,7 @@ static
 bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it,
                const bt_message *in_message)
 {
-       const bt_clock_class *default_cc;
-       bt_clock_snapshot_state cs_state;
+       bool has_default_clock_snapshot;
        const bt_clock_snapshot *cs;
        bt_message *out_message = NULL;
        bt_packet *out_packet;
@@ -1363,17 +1352,16 @@ bt_message *handle_packet_begin_message(struct debug_info_msg_iter *debug_it,
 
        BT_ASSERT(out_packet);
 
-       default_cc = bt_stream_class_borrow_default_clock_class_const(
+       has_default_clock_snapshot =
+               bt_stream_class_packets_have_beginning_default_clock_snapshot(
                        bt_stream_borrow_class_const(
                                bt_packet_borrow_stream_const(in_packet)));
-       if (default_cc) {
+       if (has_default_clock_snapshot) {
                /* Borrow clock snapshot. */
-               cs_state =
-                       bt_message_packet_beginning_borrow_default_clock_snapshot_const(
-                                       in_message, &cs);
+               cs = bt_message_packet_beginning_borrow_default_clock_snapshot_const(
+                                       in_message);
 
                /* Create an output packet beginning message. */
-               BT_ASSERT(cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
                out_message = bt_message_packet_beginning_create_with_default_clock_snapshot(
                                debug_it->input_iterator, out_packet,
                                bt_clock_snapshot_get_value(cs));
@@ -1393,10 +1381,9 @@ static
 bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it,
                const bt_message *in_message)
 {
+       bool has_default_clock_snapshot;
        const bt_clock_snapshot *cs;
        const bt_packet *in_packet;
-       const bt_clock_class *default_cc;
-       bt_clock_snapshot_state cs_state;
        bt_message *out_message = NULL;
        bt_packet *out_packet;
 
@@ -1406,17 +1393,16 @@ bt_message *handle_packet_end_message(struct debug_info_msg_iter *debug_it,
        out_packet = trace_ir_mapping_borrow_mapped_packet(debug_it->ir_maps, in_packet);
        BT_ASSERT(out_packet);
 
-       default_cc = bt_stream_class_borrow_default_clock_class_const(
+       has_default_clock_snapshot =
+               bt_stream_class_packets_have_end_default_clock_snapshot(
                        bt_stream_borrow_class_const(
                                bt_packet_borrow_stream_const(in_packet)));
-       if (default_cc) {
+       if (has_default_clock_snapshot) {
                /* Borrow clock snapshot. */
-               cs_state =
-                       bt_message_packet_end_borrow_default_clock_snapshot_const(
-                                       in_message, &cs);
+               cs = bt_message_packet_end_borrow_default_clock_snapshot_const(
+                                       in_message);
 
                /* Create an outpute packet end message. */
-               BT_ASSERT(cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
                out_message = bt_message_packet_end_create_with_default_clock_snapshot(
                                debug_it->input_iterator, out_packet,
                                bt_clock_snapshot_get_value(cs));
@@ -1514,7 +1500,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(
@@ -1553,9 +1540,8 @@ bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it
 {
        const bt_clock_snapshot *begin_cs, *end_cs;
        const bt_stream *in_stream;
-       const bt_clock_class *default_cc;
+       bool has_default_clock_snapshots;
        uint64_t discarded_events, begin_cs_value, end_cs_value;
-       bt_clock_snapshot_state begin_cs_state, end_cs_state;
        bt_property_availability prop_avail;
        bt_message *out_message = NULL;
        bt_stream *out_stream;
@@ -1568,22 +1554,16 @@ bt_message *handle_discarded_events_message(struct debug_info_msg_iter *debug_it
                                debug_it->ir_maps, in_stream);
        BT_ASSERT(out_stream);
 
-       default_cc = bt_stream_class_borrow_default_clock_class_const(
+       has_default_clock_snapshots =
+               bt_stream_class_discarded_events_have_default_clock_snapshots(
                        bt_stream_borrow_class_const(in_stream));
-       if (default_cc) {
-               begin_cs_state =
-                       bt_message_discarded_events_borrow_default_beginning_clock_snapshot_const(
-                                       in_message, &begin_cs);
-               end_cs_state =
-                       bt_message_discarded_events_borrow_default_end_clock_snapshot_const(
-                                       in_message, &end_cs);
-               /*
-                * Both clock snapshots should be known as we check that the
-                * all input stream classes have an always known clock. Unknown
-                * clock is not yet supported.
-                */
-               BT_ASSERT(begin_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN &&
-                               end_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
+       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_value = bt_clock_snapshot_get_value(begin_cs);
                end_cs_value = bt_clock_snapshot_get_value(end_cs);
@@ -1619,10 +1599,9 @@ bt_message *handle_discarded_packets_message(struct debug_info_msg_iter *debug_i
                const bt_message *in_message)
 {
        const bt_clock_snapshot *begin_cs, *end_cs;
-       const bt_clock_class *default_cc;
+       bool has_default_clock_snapshots;
        const bt_stream *in_stream;
        uint64_t discarded_packets, begin_cs_value, end_cs_value;
-       bt_clock_snapshot_state begin_cs_state, end_cs_state;
        bt_property_availability prop_avail;
        bt_message *out_message = NULL;
        bt_stream *out_stream;
@@ -1635,24 +1614,17 @@ bt_message *handle_discarded_packets_message(struct debug_info_msg_iter *debug_i
                        debug_it->ir_maps, in_stream);
        BT_ASSERT(out_stream);
 
-       default_cc = bt_stream_class_borrow_default_clock_class_const(
+       has_default_clock_snapshots =
+               bt_stream_class_discarded_packets_have_default_clock_snapshots(
                        bt_stream_borrow_class_const(in_stream));
-       if (default_cc) {
-               begin_cs_state =
-                       bt_message_discarded_packets_borrow_default_beginning_clock_snapshot_const(
-                                       in_message, &begin_cs);
-
-               end_cs_state =
-                       bt_message_discarded_packets_borrow_default_end_clock_snapshot_const(
-                                       in_message, &end_cs);
+       if (has_default_clock_snapshots) {
+               begin_cs =
+                       bt_message_discarded_packets_borrow_beginning_default_clock_snapshot_const(
+                               in_message);
 
-               /*
-                * Both clock snapshots should be known as we check that the
-                * all input stream classes have an always known clock. Unknown
-                * clock is not yet supported.
-                */
-               BT_ASSERT(begin_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN &&
-                               end_cs_state == BT_CLOCK_SNAPSHOT_STATE_KNOWN);
+               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);
@@ -1932,6 +1904,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,
@@ -1939,18 +1938,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. */
@@ -1958,63 +1963,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;
        }
 
        ret = bt_fd_cache_init(&debug_info_msg_iter->fd_cache);
        if (ret) {
-               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);
                status = BT_SELF_MESSAGE_ITERATOR_STATUS_NOMEM;
-               goto end;
+               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;
 }
@@ -2063,13 +2057,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);
-
-       bt_fd_cache_fini(&debug_info_msg_iter->fd_cache);
-
-       g_free(debug_info_msg_iter);
+       debug_info_msg_iter_destroy(debug_info_msg_iter);
 }
This page took 0.031248 seconds and 4 git commands to generate.