+enum debug_info_stream_state *insert_new_stream_state(
+ struct debug_info_iterator *debug_it,
+ struct debug_info_trace *di_trace, struct bt_ctf_stream *stream)
+{
+ enum debug_info_stream_state *v = NULL;
+
+ v = g_new0(enum debug_info_stream_state, 1);
+ if (!v) {
+ fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto end;
+ }
+ *v = DEBUG_INFO_UNKNOWN_STREAM;
+
+ g_hash_table_insert(di_trace->stream_states, stream, v);
+
+end:
+ return v;
+}
+
+static
+void check_completed_trace(gpointer key, gpointer value, gpointer user_data)
+{
+ enum debug_info_stream_state *state = value;
+ int *trace_completed = user_data;
+
+ if (*state != DEBUG_INFO_COMPLETED_STREAM) {
+ *trace_completed = 0;
+ }
+}
+
+static
+gboolean empty_ht(gpointer key, gpointer value, gpointer user_data)
+{
+ return TRUE;
+}
+
+BT_HIDDEN
+void debug_info_close_trace(struct debug_info_iterator *debug_it,
+ struct debug_info_trace *di_trace)
+{
+ if (di_trace->static_listener_id >= 0) {
+ bt_ctf_trace_remove_is_static_listener(di_trace->trace,
+ di_trace->static_listener_id);
+ }
+
+ /* Empty the stream class HT. */
+ g_hash_table_foreach_remove(di_trace->stream_class_map,
+ empty_ht, NULL);
+ g_hash_table_destroy(di_trace->stream_class_map);
+
+ /* Empty the stream HT. */
+ g_hash_table_foreach_remove(di_trace->stream_map,
+ empty_ht, NULL);
+ g_hash_table_destroy(di_trace->stream_map);
+
+ /* Empty the stream state HT. */
+ g_hash_table_foreach_remove(di_trace->stream_states,
+ empty_ht, NULL);
+ g_hash_table_destroy(di_trace->stream_states);
+
+ /* Empty the packet HT. */
+ g_hash_table_foreach_remove(di_trace->packet_map,
+ empty_ht, NULL);
+ g_hash_table_destroy(di_trace->packet_map);
+
+ /* Empty the trace_debug HT. */
+ g_hash_table_foreach_remove(di_trace->trace_debug_map,
+ empty_ht, NULL);
+ g_hash_table_destroy(di_trace->trace_debug_map);
+}
+
+static
+int sync_event_classes(struct debug_info_iterator *debug_it,
+ struct bt_ctf_stream *stream,
+ struct bt_ctf_stream *writer_stream)
+{
+ int int_ret;
+ struct bt_ctf_stream_class *stream_class = NULL,
+ *writer_stream_class = NULL;
+ enum bt_component_status ret;
+
+ stream_class = bt_ctf_stream_get_class(stream);
+ if (!stream_class) {
+ fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto error;
+ }
+
+ writer_stream_class = bt_ctf_stream_get_class(writer_stream);
+ if (!writer_stream_class) {
+ fprintf(debug_it->err, "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto error;
+ }
+
+ ret = ctf_copy_event_classes(debug_it->err, stream_class,
+ writer_stream_class);
+ if (ret != BT_COMPONENT_STATUS_OK) {
+ goto error;
+ }
+
+ int_ret = 0;
+ goto end;
+
+error:
+ int_ret = -1;
+end:
+ bt_put(stream_class);
+ bt_put(writer_stream_class);
+ return int_ret;
+}
+
+static
+void trace_is_static_listener(struct bt_ctf_trace *trace, void *data)
+{
+ struct debug_info_trace *di_trace = data;
+ struct debug_info_iterator *debug_it = di_trace->debug_it;
+ int trace_completed = 1, ret, nr_stream, i;
+ struct bt_ctf_stream *stream = NULL, *writer_stream = NULL;
+ struct bt_ctf_trace *writer_trace = di_trace->writer_trace;
+
+ /*
+ * When the trace becomes static, make sure that we have all
+ * the event classes in our stream_class copies before setting it
+ * static as well.
+ */
+ nr_stream = bt_ctf_trace_get_stream_count(trace);
+ for (i = 0; i < nr_stream; i++) {
+ stream = bt_ctf_trace_get_stream_by_index(trace, i);
+ if (!stream) {
+ fprintf(debug_it->err,
+ "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto error;
+ }
+ writer_stream = bt_ctf_trace_get_stream_by_index(writer_trace, i);
+ if (!writer_stream) {
+ fprintf(debug_it->err,
+ "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto error;
+ }
+ ret = sync_event_classes(di_trace->debug_it, stream, writer_stream);
+ if (ret) {
+ fprintf(debug_it->err,
+ "[error] %s in %s:%d\n", __func__,
+ __FILE__, __LINE__);
+ goto error;
+ }
+ BT_PUT(stream);
+ BT_PUT(writer_stream);
+ }
+
+ bt_ctf_trace_set_is_static(di_trace->writer_trace);
+ di_trace->trace_static = 1;
+
+ g_hash_table_foreach(di_trace->stream_states,
+ check_completed_trace, &trace_completed);
+ if (trace_completed) {
+ debug_info_close_trace(di_trace->debug_it, di_trace);
+ g_hash_table_remove(di_trace->debug_it->trace_map,
+ di_trace->trace);
+ }
+
+error:
+ bt_put(writer_stream);
+ bt_put(stream);
+}
+
+static
+struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
+ struct bt_ctf_stream *stream) {