4 * Babeltrace Copy Trace Structure
6 * Copyright 2017 Julien Desfossez <jdesfossez@efficios.com>
8 * Author: Julien Desfossez <jdesfossez@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <babeltrace/ctf-ir/event.h>
31 #include <babeltrace/ctf-ir/packet.h>
32 #include <babeltrace/ctf-ir/event-class.h>
33 #include <babeltrace/ctf-ir/stream.h>
34 #include <babeltrace/ctf-ir/stream-class.h>
35 #include <babeltrace/ctf-ir/clock-class.h>
36 #include <babeltrace/ctf-ir/fields.h>
37 #include <babeltrace/ctf-writer/stream-class.h>
38 #include <babeltrace/ctf-writer/stream.h>
40 #include <ctfcopytrace.h>
41 #include "debug-info.h"
44 void unref_stream(struct bt_ctf_stream
*stream
)
50 void unref_packet(struct bt_ctf_packet
*packet
)
56 void unref_stream_class(struct bt_ctf_stream_class
*stream_class
)
62 void unref_debug_info(struct debug_info
*debug_info
)
64 debug_info_destroy(debug_info
);
68 struct bt_ctf_field
*get_payload_field(FILE *err
,
69 struct bt_ctf_event
*event
, const char *field_name
)
71 struct bt_ctf_field
*field
= NULL
, *sec
= NULL
;
72 struct bt_ctf_field_type
*sec_type
= NULL
;
74 sec
= bt_ctf_event_get_payload(event
, NULL
);
76 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
81 sec_type
= bt_ctf_field_get_type(sec
);
83 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
88 if (bt_ctf_field_type_get_type_id(sec_type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
89 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
94 field
= bt_ctf_field_structure_get_field(sec
, field_name
);
103 struct bt_ctf_field
*get_stream_event_context_field(FILE *err
,
104 struct bt_ctf_event
*event
, const char *field_name
)
106 struct bt_ctf_field
*field
= NULL
, *sec
= NULL
;
107 struct bt_ctf_field_type
*sec_type
= NULL
;
109 sec
= bt_ctf_event_get_stream_event_context(event
);
114 sec_type
= bt_ctf_field_get_type(sec
);
116 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
121 if (bt_ctf_field_type_get_type_id(sec_type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
122 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
127 field
= bt_ctf_field_structure_get_field(sec
, field_name
);
136 int get_stream_event_context_unsigned_int_field_value(FILE *err
,
137 struct bt_ctf_event
*event
, const char *field_name
,
141 struct bt_ctf_field
*field
= NULL
;
142 struct bt_ctf_field_type
*field_type
= NULL
;
144 field
= get_stream_event_context_field(err
, event
, field_name
);
149 field_type
= bt_ctf_field_get_type(field
);
151 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
156 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
157 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
162 if (bt_ctf_field_type_integer_get_signed(field_type
) != 0) {
163 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
168 ret
= bt_ctf_field_unsigned_integer_get_value(field
, value
);
180 int get_stream_event_context_int_field_value(FILE *err
, struct bt_ctf_event
*event
,
181 const char *field_name
, int64_t *value
)
183 struct bt_ctf_field
*field
= NULL
;
184 struct bt_ctf_field_type
*field_type
= NULL
;
187 field
= get_stream_event_context_field(err
, event
, field_name
);
192 field_type
= bt_ctf_field_get_type(field
);
194 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
199 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
200 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
205 if (bt_ctf_field_type_integer_get_signed(field_type
) != 1) {
206 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
211 ret
= bt_ctf_field_signed_integer_get_value(field
, value
);
223 int get_payload_unsigned_int_field_value(FILE *err
,
224 struct bt_ctf_event
*event
, const char *field_name
,
227 struct bt_ctf_field
*field
= NULL
;
228 struct bt_ctf_field_type
*field_type
= NULL
;
231 field
= get_payload_field(err
, event
, field_name
);
233 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
238 field_type
= bt_ctf_field_get_type(field
);
240 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
245 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
246 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
251 if (bt_ctf_field_type_integer_get_signed(field_type
) != 0) {
252 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
257 ret
= bt_ctf_field_unsigned_integer_get_value(field
, value
);
269 int get_payload_int_field_value(FILE *err
, struct bt_ctf_event
*event
,
270 const char *field_name
, int64_t *value
)
272 struct bt_ctf_field
*field
= NULL
;
273 struct bt_ctf_field_type
*field_type
= NULL
;
276 field
= get_payload_field(err
, event
, field_name
);
278 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
283 field_type
= bt_ctf_field_get_type(field
);
285 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
290 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_INTEGER
) {
291 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
296 if (bt_ctf_field_type_integer_get_signed(field_type
) != 1) {
297 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
302 ret
= bt_ctf_field_signed_integer_get_value(field
, value
);
314 int get_payload_string_field_value(FILE *err
,
315 struct bt_ctf_event
*event
, const char *field_name
,
318 struct bt_ctf_field
*field
= NULL
;
319 struct bt_ctf_field_type
*field_type
= NULL
;
323 * The field might not exist, no error here.
325 field
= get_payload_field(err
, event
, field_name
);
330 field_type
= bt_ctf_field_get_type(field
);
332 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
337 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_STRING
) {
338 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
343 *value
= bt_ctf_field_string_get_value(field
);
345 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
362 int get_payload_build_id_field_value(FILE *err
,
363 struct bt_ctf_event
*event
, const char *field_name
,
364 uint8_t **build_id
, uint64_t *build_id_len
)
366 struct bt_ctf_field
*field
= NULL
, *seq_len
= NULL
;
367 struct bt_ctf_field_type
*field_type
= NULL
;
368 struct bt_ctf_field
*seq_field
= NULL
;
374 field
= get_payload_field(err
, event
, field_name
);
376 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
381 field_type
= bt_ctf_field_get_type(field
);
383 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
388 if (bt_ctf_field_type_get_type_id(field_type
) != BT_CTF_FIELD_TYPE_ID_SEQUENCE
) {
389 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
395 seq_len
= bt_ctf_field_sequence_get_length(field
);
397 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
402 ret
= bt_ctf_field_unsigned_integer_get_value(seq_len
, build_id_len
);
404 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
410 *build_id
= g_new0(uint8_t, *build_id_len
);
412 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
417 for (i
= 0; i
< *build_id_len
; i
++) {
420 seq_field
= bt_ctf_field_sequence_get_field(field
, i
);
422 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
427 ret
= bt_ctf_field_unsigned_integer_get_value(seq_field
, &tmp
);
429 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
434 (*build_id
)[i
] = (uint8_t) tmp
;
449 struct debug_info
*lookup_trace_debug_info(struct debug_info_iterator
*debug_it
,
450 struct bt_ctf_trace
*writer_trace
,
451 struct debug_info_trace
*di_trace
)
453 return (struct debug_info
*) g_hash_table_lookup(
454 di_trace
->trace_debug_map
,
455 (gpointer
) writer_trace
);
459 struct debug_info
*insert_new_debug_info(struct debug_info_iterator
*debug_it
,
460 struct bt_ctf_trace
*writer_trace
,
461 struct debug_info_trace
*di_trace
)
463 struct debug_info
*debug_info
= NULL
;
464 struct bt_value
*field
= NULL
;
465 const char *str_value
;
466 enum bt_value_status ret
;
468 field
= bt_ctf_trace_get_environment_field_value_by_name(writer_trace
,
470 /* No domain field, no debug info */
474 ret
= bt_value_string_get(field
, &str_value
);
475 if (ret
!= BT_VALUE_STATUS_OK
) {
476 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
480 /* Domain not ust, no debug info */
481 if (strcmp(str_value
, "ust") != 0) {
486 /* No tracer_name, no debug info */
487 field
= bt_ctf_trace_get_environment_field_value_by_name(writer_trace
,
489 /* No tracer_name, no debug info */
493 ret
= bt_value_string_get(field
, &str_value
);
494 if (ret
!= BT_VALUE_STATUS_OK
) {
495 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
499 /* Tracer_name not lttng-ust, no debug info */
500 if (strcmp(str_value
, "lttng-ust") != 0) {
505 debug_info
= debug_info_create(debug_it
->debug_info_component
);
507 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
512 g_hash_table_insert(di_trace
->trace_debug_map
, (gpointer
) writer_trace
,
521 struct debug_info
*get_trace_debug_info(struct debug_info_iterator
*debug_it
,
522 struct bt_ctf_trace
*writer_trace
,
523 struct debug_info_trace
*di_trace
)
525 struct debug_info
*debug_info
;
527 debug_info
= lookup_trace_debug_info(debug_it
, writer_trace
, di_trace
);
532 debug_info
= insert_new_debug_info(debug_it
, writer_trace
, di_trace
);
539 struct debug_info_trace
*lookup_trace(struct debug_info_iterator
*debug_it
,
540 struct bt_ctf_trace
*trace
)
542 return (struct debug_info_trace
*) g_hash_table_lookup(
548 struct debug_info_trace
*insert_new_trace(struct debug_info_iterator
*debug_it
,
549 struct bt_ctf_stream
*stream
) {
550 struct bt_ctf_trace
*writer_trace
= NULL
;
551 struct debug_info_trace
*di_trace
= NULL
;
552 struct bt_ctf_trace
*trace
= NULL
;
553 struct bt_ctf_stream_class
*stream_class
= NULL
;
556 writer_trace
= bt_ctf_trace_create();
558 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
563 stream_class
= bt_ctf_stream_get_class(stream
);
565 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
570 trace
= bt_ctf_stream_class_get_trace(stream_class
);
572 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
577 ret
= ctf_copy_trace(debug_it
->err
, trace
, writer_trace
);
578 if (ret
!= BT_COMPONENT_STATUS_OK
) {
579 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
584 di_trace
= g_new0(struct debug_info_trace
, 1);
586 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
591 di_trace
->trace
= trace
;
592 di_trace
->writer_trace
= writer_trace
;
593 di_trace
->debug_info_component
= debug_it
->debug_info_component
;
594 di_trace
->stream_map
= g_hash_table_new_full(g_direct_hash
,
595 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream
);
596 di_trace
->stream_class_map
= g_hash_table_new_full(g_direct_hash
,
597 g_direct_equal
, NULL
, (GDestroyNotify
) unref_stream_class
);
598 di_trace
->packet_map
= g_hash_table_new_full(g_direct_hash
,
599 g_direct_equal
, NULL
, (GDestroyNotify
) unref_packet
);
600 di_trace
->trace_debug_map
= g_hash_table_new_full(g_direct_hash
,
601 g_direct_equal
, NULL
, (GDestroyNotify
) unref_debug_info
);
603 g_hash_table_insert(debug_it
->trace_map
, (gpointer
) trace
, di_trace
);
608 BT_PUT(writer_trace
);
612 bt_put(stream_class
);
618 struct bt_ctf_packet
*lookup_packet(struct debug_info_iterator
*debug_it
,
619 struct bt_ctf_packet
*packet
,
620 struct debug_info_trace
*di_trace
)
622 return (struct bt_ctf_packet
*) g_hash_table_lookup(
623 di_trace
->packet_map
,
628 struct bt_ctf_packet
*insert_new_packet(struct debug_info_iterator
*debug_it
,
629 struct bt_ctf_packet
*packet
,
630 struct bt_ctf_stream
*writer_stream
,
631 struct debug_info_trace
*di_trace
)
633 struct bt_ctf_packet
*writer_packet
;
635 writer_packet
= bt_ctf_packet_create(writer_stream
);
636 if (!writer_packet
) {
637 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
641 g_hash_table_insert(di_trace
->packet_map
, (gpointer
) packet
, writer_packet
);
644 return writer_packet
;
648 int add_debug_info_fields(FILE *err
,
649 struct bt_ctf_field_type
*writer_event_context_type
,
650 struct debug_info_component
*component
)
652 struct bt_ctf_field_type
*ip_field
= NULL
, *debug_field_type
= NULL
,
653 *bin_field_type
= NULL
, *func_field_type
= NULL
,
654 *src_field_type
= NULL
;
657 ip_field
= bt_ctf_field_type_structure_get_field_type_by_name(
658 writer_event_context_type
, "_ip");
659 /* No ip field, so no debug info. */
665 debug_field_type
= bt_ctf_field_type_structure_get_field_type_by_name(
666 writer_event_context_type
,
667 component
->arg_debug_info_field_name
);
668 /* Already existing debug_info field, no need to add it. */
669 if (debug_field_type
) {
673 debug_field_type
= bt_ctf_field_type_structure_create();
674 if (!debug_field_type
) {
675 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
680 bin_field_type
= bt_ctf_field_type_string_create();
681 if (!bin_field_type
) {
682 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
687 func_field_type
= bt_ctf_field_type_string_create();
688 if (!func_field_type
) {
689 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
694 src_field_type
= bt_ctf_field_type_string_create();
695 if (!src_field_type
) {
696 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
701 ret
= bt_ctf_field_type_structure_add_field(debug_field_type
,
702 bin_field_type
, "bin");
704 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
709 ret
= bt_ctf_field_type_structure_add_field(debug_field_type
,
710 func_field_type
, "func");
712 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
717 ret
= bt_ctf_field_type_structure_add_field(debug_field_type
,
718 src_field_type
, "src");
720 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
725 ret
= bt_ctf_field_type_structure_add_field(writer_event_context_type
,
726 debug_field_type
, component
->arg_debug_info_field_name
);
728 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
737 BT_PUT(debug_field_type
);
740 bt_put(src_field_type
);
741 bt_put(func_field_type
);
742 bt_put(bin_field_type
);
743 bt_put(debug_field_type
);
748 int create_debug_info_event_context_type(FILE *err
,
749 struct bt_ctf_field_type
*event_context_type
,
750 struct bt_ctf_field_type
*writer_event_context_type
,
751 struct debug_info_component
*component
)
753 int ret
, nr_fields
, i
;
755 nr_fields
= bt_ctf_field_type_structure_get_field_count(event_context_type
);
756 for (i
= 0; i
< nr_fields
; i
++) {
757 struct bt_ctf_field_type
*field_type
= NULL
;
758 const char *field_name
;
760 if (bt_ctf_field_type_structure_get_field(event_context_type
,
761 &field_name
, &field_type
, i
) < 0) {
762 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
767 ret
= bt_ctf_field_type_structure_add_field(writer_event_context_type
,
768 field_type
, field_name
);
771 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
777 ret
= add_debug_info_fields(err
, writer_event_context_type
,
788 struct bt_ctf_stream_class
*copy_stream_class_debug_info(FILE *err
,
789 struct bt_ctf_stream_class
*stream_class
,
790 struct bt_ctf_trace
*writer_trace
,
791 struct debug_info_component
*component
)
793 struct bt_ctf_field_type
*type
= NULL
;
794 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
795 struct bt_ctf_field_type
*writer_event_context_type
= NULL
;
797 const char *name
= bt_ctf_stream_class_get_name(stream_class
);
799 if (strlen(name
) == 0) {
803 writer_stream_class
= bt_ctf_stream_class_create(name
);
804 if (!writer_stream_class
) {
805 fprintf(err
, "[error] %s in %s:%d\n",
806 __func__
, __FILE__
, __LINE__
);
810 type
= bt_ctf_stream_class_get_packet_context_type(stream_class
);
812 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
817 ret_int
= bt_ctf_stream_class_set_packet_context_type(
818 writer_stream_class
, type
);
820 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
826 type
= bt_ctf_stream_class_get_event_header_type(stream_class
);
828 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
833 ret_int
= bt_ctf_stream_class_set_event_header_type(
834 writer_stream_class
, type
);
836 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
842 type
= bt_ctf_stream_class_get_event_context_type(stream_class
);
844 writer_event_context_type
= bt_ctf_field_type_structure_create();
845 if (!writer_event_context_type
) {
846 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
850 ret_int
= create_debug_info_event_context_type(err
, type
,
851 writer_event_context_type
, component
);
853 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
859 ret_int
= bt_ctf_stream_class_set_event_context_type(
860 writer_stream_class
, writer_event_context_type
);
862 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
866 BT_PUT(writer_event_context_type
);
872 BT_PUT(writer_stream_class
);
874 bt_put(writer_event_context_type
);
876 return writer_stream_class
;
880 * Add the original clock classes to the new trace, we do not need to copy
881 * them, and if we did, we would have to manually inspect the stream class
882 * to update the integers mapping to a clock.
885 int add_clock_classes(FILE *err
, struct bt_ctf_trace
*writer_trace
,
886 struct bt_ctf_stream_class
*writer_stream_class
,
887 struct bt_ctf_trace
*trace
)
889 int ret
, clock_class_count
, i
;
891 clock_class_count
= bt_ctf_trace_get_clock_class_count(trace
);
893 for (i
= 0; i
< clock_class_count
; i
++) {
894 struct bt_ctf_clock_class
*clock_class
=
895 bt_ctf_trace_get_clock_class_by_index(trace
, i
);
898 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
903 ret
= bt_ctf_trace_add_clock_class(writer_trace
, clock_class
);
906 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
923 struct bt_ctf_stream_class
*insert_new_stream_class(
924 struct debug_info_iterator
*debug_it
,
925 struct bt_ctf_stream_class
*stream_class
)
927 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
928 struct bt_ctf_trace
*trace
, *writer_trace
= NULL
;
929 struct debug_info_trace
*di_trace
;
930 enum bt_component_status ret
;
933 trace
= bt_ctf_stream_class_get_trace(stream_class
);
935 fprintf(debug_it
->err
,
936 "[error] %s in %s:%d\n", __func__
, __FILE__
,
941 di_trace
= lookup_trace(debug_it
, trace
);
943 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
945 ret
= BT_COMPONENT_STATUS_ERROR
;
948 writer_trace
= di_trace
->writer_trace
;
949 bt_get(writer_trace
);
951 writer_stream_class
= copy_stream_class_debug_info(debug_it
->err
, stream_class
,
952 writer_trace
, debug_it
->debug_info_component
);
953 if (!writer_stream_class
) {
954 fprintf(debug_it
->err
, "[error] Failed to copy stream class\n");
955 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
956 __func__
, __FILE__
, __LINE__
);
960 int_ret
= bt_ctf_trace_add_stream_class(writer_trace
, writer_stream_class
);
962 fprintf(debug_it
->err
,
963 "[error] %s in %s:%d\n", __func__
, __FILE__
,
968 ret
= add_clock_classes(debug_it
->err
, writer_trace
,
969 writer_stream_class
, trace
);
970 if (ret
!= BT_COMPONENT_STATUS_OK
) {
971 fprintf(debug_it
->err
,
972 "[error] %s in %s:%d\n", __func__
, __FILE__
,
976 BT_PUT(writer_trace
);
979 g_hash_table_insert(di_trace
->stream_class_map
,
980 (gpointer
) stream_class
, writer_stream_class
);
985 BT_PUT(writer_stream_class
);
988 bt_put(writer_trace
);
989 return writer_stream_class
;
993 struct bt_ctf_stream
*insert_new_stream(
994 struct debug_info_iterator
*debug_it
,
995 struct bt_ctf_stream
*stream
,
996 struct debug_info_trace
*di_trace
)
998 struct bt_ctf_stream
*writer_stream
= NULL
;
999 struct bt_ctf_stream_class
*stream_class
= NULL
;
1000 struct bt_ctf_stream_class
*writer_stream_class
= NULL
;
1002 stream_class
= bt_ctf_stream_get_class(stream
);
1003 if (!stream_class
) {
1004 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1005 __func__
, __FILE__
, __LINE__
);
1009 writer_stream_class
= g_hash_table_lookup(
1010 di_trace
->stream_class_map
,
1011 (gpointer
) stream_class
);
1013 if (!writer_stream_class
) {
1014 writer_stream_class
= insert_new_stream_class(debug_it
,
1016 if (!writer_stream_class
) {
1017 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1018 __func__
, __FILE__
, __LINE__
);
1022 bt_get(writer_stream_class
);
1024 writer_stream
= bt_ctf_stream_create(writer_stream_class
,
1025 bt_ctf_stream_get_name(stream
));
1026 if (!writer_stream
) {
1027 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1028 __func__
, __FILE__
, __LINE__
);
1032 g_hash_table_insert(di_trace
->stream_map
, (gpointer
) stream
,
1038 BT_PUT(writer_stream
);
1040 bt_put(stream_class
);
1041 bt_put(writer_stream_class
);
1042 return writer_stream
;
1046 struct bt_ctf_stream
*lookup_stream(struct debug_info_iterator
*debug_it
,
1047 struct bt_ctf_stream
*stream
,
1048 struct debug_info_trace
*di_trace
)
1050 return (struct bt_ctf_stream
*) g_hash_table_lookup(
1051 di_trace
->stream_map
, (gpointer
) stream
);
1055 struct bt_ctf_event_class
*get_event_class(struct debug_info_iterator
*debug_it
,
1056 struct bt_ctf_stream_class
*writer_stream_class
,
1057 struct bt_ctf_event_class
*event_class
)
1059 return bt_ctf_stream_class_get_event_class_by_id(writer_stream_class
,
1060 bt_ctf_event_class_get_id(event_class
));
1064 struct debug_info_trace
*lookup_di_trace_from_stream(
1065 struct debug_info_iterator
*debug_it
,
1066 struct bt_ctf_stream
*stream
)
1068 struct bt_ctf_stream_class
*stream_class
= NULL
;
1069 struct bt_ctf_trace
*trace
= NULL
;
1070 struct debug_info_trace
*di_trace
= NULL
;
1072 stream_class
= bt_ctf_stream_get_class(stream
);
1073 if (!stream_class
) {
1074 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1075 __func__
, __FILE__
, __LINE__
);
1079 trace
= bt_ctf_stream_class_get_trace(stream_class
);
1081 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1082 __func__
, __FILE__
, __LINE__
);
1086 di_trace
= (struct debug_info_trace
*) g_hash_table_lookup(
1087 debug_it
->trace_map
, (gpointer
) trace
);
1090 BT_PUT(stream_class
);
1096 struct bt_ctf_stream
*get_writer_stream(
1097 struct debug_info_iterator
*debug_it
,
1098 struct bt_ctf_packet
*packet
, struct bt_ctf_stream
*stream
)
1100 struct bt_ctf_stream_class
*stream_class
= NULL
;
1101 struct bt_ctf_stream
*writer_stream
= NULL
;
1102 struct debug_info_trace
*di_trace
= NULL
;
1104 stream_class
= bt_ctf_stream_get_class(stream
);
1105 if (!stream_class
) {
1106 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1107 __func__
, __FILE__
, __LINE__
);
1111 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1113 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1114 __func__
, __FILE__
, __LINE__
);
1118 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1119 if (!writer_stream
) {
1120 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1121 __func__
, __FILE__
, __LINE__
);
1124 bt_get(writer_stream
);
1129 BT_PUT(writer_stream
);
1131 bt_put(stream_class
);
1132 return writer_stream
;
1136 struct bt_ctf_packet
*debug_info_new_packet(
1137 struct debug_info_iterator
*debug_it
,
1138 struct bt_ctf_packet
*packet
)
1140 struct bt_ctf_stream
*stream
= NULL
, *writer_stream
= NULL
;
1141 struct bt_ctf_field
*writer_packet_context
= NULL
;
1142 struct bt_ctf_packet
*writer_packet
= NULL
;
1143 struct debug_info_trace
*di_trace
;
1146 stream
= bt_ctf_packet_get_stream(packet
);
1148 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1149 __func__
, __FILE__
, __LINE__
);
1153 writer_stream
= get_writer_stream(debug_it
, packet
, stream
);
1154 if (!writer_stream
) {
1155 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1156 __func__
, __FILE__
, __LINE__
);
1160 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1162 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1163 __FILE__
, __LINE__
);
1168 * If a packet was already opened, close it and remove it from
1171 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1172 if (writer_packet
) {
1173 g_hash_table_remove(di_trace
->packet_map
, packet
);
1174 BT_PUT(writer_packet
);
1177 writer_packet
= insert_new_packet(debug_it
, packet
, writer_stream
,
1179 if (!writer_packet
) {
1180 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1181 __func__
, __FILE__
, __LINE__
);
1185 writer_packet_context
= ctf_copy_packet_context(debug_it
->err
, packet
,
1187 if (!writer_packet_context
) {
1188 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1189 __func__
, __FILE__
, __LINE__
);
1193 int_ret
= bt_ctf_packet_set_context(writer_packet
, writer_packet_context
);
1195 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1196 __func__
, __FILE__
, __LINE__
);
1204 bt_put(writer_packet_context
);
1205 bt_put(writer_stream
);
1207 return writer_packet
;
1211 struct bt_ctf_packet
*debug_info_close_packet(
1212 struct debug_info_iterator
*debug_it
,
1213 struct bt_ctf_packet
*packet
)
1215 struct bt_ctf_packet
*writer_packet
= NULL
;
1216 struct bt_ctf_stream
*stream
= NULL
;
1217 struct debug_info_trace
*di_trace
;
1219 stream
= bt_ctf_packet_get_stream(packet
);
1221 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1222 __FILE__
, __LINE__
);
1226 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1228 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1229 __FILE__
, __LINE__
);
1233 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1234 if (!writer_packet
) {
1235 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1236 __func__
, __FILE__
, __LINE__
);
1239 g_hash_table_remove(di_trace
->packet_map
, packet
);
1243 return writer_packet
;
1247 struct bt_ctf_stream
*debug_info_stream_begin(
1248 struct debug_info_iterator
*debug_it
,
1249 struct bt_ctf_stream
*stream
)
1251 struct bt_ctf_stream
*writer_stream
;
1252 struct debug_info_trace
*di_trace
= NULL
;
1254 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1256 di_trace
= insert_new_trace(debug_it
, stream
);
1258 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1259 __func__
, __FILE__
, __LINE__
);
1264 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1265 if (writer_stream
) {
1266 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1267 __func__
, __FILE__
, __LINE__
);
1271 writer_stream
= insert_new_stream(debug_it
, stream
, di_trace
);
1274 return writer_stream
;
1278 struct bt_ctf_stream
*debug_info_stream_end(struct debug_info_iterator
*debug_it
,
1279 struct bt_ctf_stream
*stream
)
1281 struct bt_ctf_stream
*writer_stream
;
1282 struct debug_info_trace
*di_trace
= NULL
;
1284 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1286 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1287 __func__
, __FILE__
, __LINE__
);
1291 writer_stream
= lookup_stream(debug_it
, stream
, di_trace
);
1292 if (!writer_stream
) {
1293 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1294 __func__
, __FILE__
, __LINE__
);
1297 bt_get(writer_stream
);
1298 g_hash_table_remove(di_trace
->stream_map
, stream
);
1301 return writer_stream
;
1305 struct debug_info_source
*lookup_debug_info(FILE *err
,
1306 struct bt_ctf_event
*event
,
1307 struct debug_info
*debug_info
)
1311 struct debug_info_source
*dbg_info_src
= NULL
;
1314 ret
= get_stream_event_context_int_field_value(err
, event
,
1320 ret
= get_stream_event_context_unsigned_int_field_value(err
, event
,
1326 /* Get debug info for this context. */
1327 dbg_info_src
= debug_info_query(debug_info
, vpid
, ip
);
1330 return dbg_info_src
;
1334 int set_debug_info_field(FILE *err
, struct bt_ctf_field
*debug_field
,
1335 struct debug_info_source
*dbg_info_src
,
1336 struct debug_info_component
*component
)
1338 int i
, nr_fields
, ret
= 0;
1339 struct bt_ctf_field_type
*debug_field_type
= NULL
;
1340 struct bt_ctf_field
*field
= NULL
;
1341 struct bt_ctf_field_type
*field_type
= NULL
;
1343 debug_field_type
= bt_ctf_field_get_type(debug_field
);
1344 if (!debug_field_type
) {
1345 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1346 __FILE__
, __LINE__
);
1350 nr_fields
= bt_ctf_field_type_structure_get_field_count(debug_field_type
);
1351 for (i
= 0; i
< nr_fields
; i
++) {
1352 const char *field_name
;
1354 if (bt_ctf_field_type_structure_get_field(debug_field_type
,
1355 &field_name
, &field_type
, i
) < 0) {
1356 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1357 __FILE__
, __LINE__
);
1362 field
= bt_ctf_field_structure_get_field_by_index(debug_field
, i
);
1363 if (!strcmp(field_name
, "bin")) {
1364 if (dbg_info_src
&& dbg_info_src
->bin_path
) {
1365 GString
*tmp
= g_string_new(NULL
);
1367 if (component
->arg_full_path
) {
1368 g_string_printf(tmp
, "%s%s",
1369 dbg_info_src
->bin_path
,
1370 dbg_info_src
->bin_loc
);
1372 g_string_printf(tmp
, "%s%s",
1373 dbg_info_src
->short_bin_path
,
1374 dbg_info_src
->bin_loc
);
1376 ret
= bt_ctf_field_string_set_value(field
, tmp
->str
);
1377 g_string_free(tmp
, true);
1379 ret
= bt_ctf_field_string_set_value(field
, "");
1381 } else if (!strcmp(field_name
, "func")) {
1382 if (dbg_info_src
&& dbg_info_src
->func
) {
1383 ret
= bt_ctf_field_string_set_value(field
,
1384 dbg_info_src
->func
);
1386 ret
= bt_ctf_field_string_set_value(field
, "");
1388 } else if (!strcmp(field_name
, "src")) {
1389 if (dbg_info_src
&& dbg_info_src
->src_path
) {
1390 GString
*tmp
= g_string_new(NULL
);
1392 if (component
->arg_full_path
) {
1393 g_string_printf(tmp
, "%s:%" PRId64
,
1394 dbg_info_src
->src_path
,
1395 dbg_info_src
->line_no
);
1397 g_string_printf(tmp
, "%s:%" PRId64
,
1398 dbg_info_src
->short_src_path
,
1399 dbg_info_src
->line_no
);
1401 ret
= bt_ctf_field_string_set_value(field
, tmp
->str
);
1402 g_string_free(tmp
, true);
1404 ret
= bt_ctf_field_string_set_value(field
, "");
1409 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1410 __FILE__
, __LINE__
);
1422 bt_put(debug_field_type
);
1427 int copy_set_debug_info_stream_event_context(FILE *err
,
1428 struct bt_ctf_field
*event_context
,
1429 struct bt_ctf_event
*event
,
1430 struct bt_ctf_event
*writer_event
,
1431 struct debug_info
*debug_info
,
1432 struct debug_info_component
*component
)
1434 struct bt_ctf_field_type
*writer_event_context_type
= NULL
,
1435 *event_context_type
= NULL
;
1436 struct bt_ctf_field
*writer_event_context
= NULL
;
1437 struct bt_ctf_field
*field
= NULL
, *copy_field
= NULL
, *debug_field
= NULL
;
1438 struct bt_ctf_field_type
*field_type
= NULL
;
1439 struct debug_info_source
*dbg_info_src
;
1440 int ret
, nr_fields
, i
;
1442 writer_event_context
= bt_ctf_event_get_stream_event_context(writer_event
);
1443 if (!writer_event_context
) {
1444 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
, __LINE__
);
1448 writer_event_context_type
= bt_ctf_field_get_type(writer_event_context
);
1449 if (!writer_event_context_type
) {
1450 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1451 __FILE__
, __LINE__
);
1455 event_context_type
= bt_ctf_field_get_type(event_context
);
1456 if (!event_context_type
) {
1457 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1458 __FILE__
, __LINE__
);
1463 * If it is not a structure, we did not modify it to add the debug info
1464 * fields, so just assign it as is.
1466 if (bt_ctf_field_type_get_type_id(writer_event_context_type
) != BT_CTF_FIELD_TYPE_ID_STRUCT
) {
1467 ret
= bt_ctf_event_set_event_context(writer_event
, event_context
);
1471 dbg_info_src
= lookup_debug_info(err
, event
, debug_info
);
1473 nr_fields
= bt_ctf_field_type_structure_get_field_count(writer_event_context_type
);
1474 for (i
= 0; i
< nr_fields
; i
++) {
1475 const char *field_name
;
1477 if (bt_ctf_field_type_structure_get_field(writer_event_context_type
,
1478 &field_name
, &field_type
, i
) < 0) {
1479 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1480 __FILE__
, __LINE__
);
1485 * Prevent illegal access in the event_context.
1487 if (i
< bt_ctf_field_type_structure_get_field_count(event_context_type
)) {
1488 field
= bt_ctf_field_structure_get_field_by_index(event_context
, i
);
1491 * The debug_info field, only exists in the writer event or
1492 * if it was set by a earlier pass of the debug_info plugin.
1494 if (!strcmp(field_name
, component
->arg_debug_info_field_name
) &&
1496 debug_field
= bt_ctf_field_structure_get_field_by_index(
1497 writer_event_context
, i
);
1499 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1500 __FILE__
, __LINE__
);
1503 ret
= set_debug_info_field(err
, debug_field
,
1504 dbg_info_src
, component
);
1506 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1507 __FILE__
, __LINE__
);
1510 BT_PUT(debug_field
);
1512 copy_field
= bt_ctf_field_copy(field
);
1514 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1515 __FILE__
, __LINE__
);
1519 ret
= bt_ctf_field_structure_set_field(writer_event_context
,
1520 field_name
, copy_field
);
1522 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1523 __FILE__
, __LINE__
);
1538 bt_put(event_context_type
);
1539 bt_put(writer_event_context_type
);
1540 bt_put(writer_event_context
);
1543 bt_put(debug_field
);
1549 struct bt_ctf_clock_class
*stream_class_get_clock_class(FILE *err
,
1550 struct bt_ctf_stream_class
*stream_class
)
1552 struct bt_ctf_trace
*trace
= NULL
;
1553 struct bt_ctf_clock_class
*clock_class
= NULL
;
1555 trace
= bt_ctf_stream_class_get_trace(stream_class
);
1557 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1562 /* FIXME multi-clock? */
1563 clock_class
= bt_ctf_trace_get_clock_class_by_index(trace
, 0);
1572 struct bt_ctf_clock_class
*event_get_clock_class(FILE *err
, struct bt_ctf_event
*event
)
1574 struct bt_ctf_event_class
*event_class
= NULL
;
1575 struct bt_ctf_stream_class
*stream_class
= NULL
;
1576 struct bt_ctf_clock_class
*clock_class
= NULL
;
1578 event_class
= bt_ctf_event_get_class(event
);
1580 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1585 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
1586 if (!stream_class
) {
1587 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1592 clock_class
= stream_class_get_clock_class(err
, stream_class
);
1596 BT_PUT(clock_class
);
1598 bt_put(stream_class
);
1599 bt_put(event_class
);
1604 int set_event_clock_value(FILE *err
, struct bt_ctf_event
*event
,
1605 struct bt_ctf_event
*writer_event
)
1607 struct bt_ctf_clock_class
*clock_class
= NULL
;
1608 struct bt_ctf_clock_value
*clock_value
= NULL
;
1611 clock_class
= event_get_clock_class(err
, event
);
1613 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1618 clock_value
= bt_ctf_event_get_clock_value(event
, clock_class
);
1620 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1626 * We share the same clocks, so we can assign the clock value to the
1629 ret
= bt_ctf_event_set_clock_value(writer_event
, clock_value
);
1631 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1642 bt_put(clock_class
);
1643 bt_put(clock_value
);
1648 struct bt_ctf_event
*debug_info_copy_event(FILE *err
, struct bt_ctf_event
*event
,
1649 struct bt_ctf_event_class
*writer_event_class
,
1650 struct debug_info
*debug_info
,
1651 struct debug_info_component
*component
)
1653 struct bt_ctf_event
*writer_event
= NULL
;
1654 struct bt_ctf_field
*field
= NULL
, *copy_field
= NULL
;
1657 writer_event
= bt_ctf_event_create(writer_event_class
);
1658 if (!writer_event
) {
1659 fprintf(err
, "[error] %s in %s:%d\n", __func__
, __FILE__
,
1664 ret
= set_event_clock_value(err
, event
, writer_event
);
1666 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1667 __FILE__
, __LINE__
);
1671 /* Optional field, so it can fail silently. */
1672 field
= bt_ctf_event_get_header(event
);
1674 ret
= ctf_copy_event_header(err
, event
, writer_event_class
,
1675 writer_event
, field
);
1677 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1678 __FILE__
, __LINE__
);
1684 /* Optional field, so it can fail silently. */
1685 field
= bt_ctf_event_get_stream_event_context(event
);
1687 ret
= copy_set_debug_info_stream_event_context(err
,
1688 field
, event
, writer_event
, debug_info
,
1691 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1692 __FILE__
, __LINE__
);
1698 /* Optional field, so it can fail silently. */
1699 field
= bt_ctf_event_get_event_context(event
);
1701 copy_field
= bt_ctf_field_copy(field
);
1703 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1704 __FILE__
, __LINE__
);
1707 ret
= bt_ctf_event_set_event_context(writer_event
, copy_field
);
1709 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1710 __FILE__
, __LINE__
);
1717 field
= bt_ctf_event_get_event_payload(event
);
1719 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1720 __FILE__
, __LINE__
);
1723 copy_field
= bt_ctf_field_copy(field
);
1725 ret
= bt_ctf_event_set_event_payload(writer_event
, copy_field
);
1727 fprintf(err
, "[error] %s in %s:%d\n", __func__
,
1728 __FILE__
, __LINE__
);
1738 BT_PUT(writer_event
);
1742 return writer_event
;
1746 struct bt_ctf_event
*debug_info_output_event(
1747 struct debug_info_iterator
*debug_it
,
1748 struct bt_ctf_event
*event
)
1750 struct bt_ctf_event_class
*event_class
= NULL
, *writer_event_class
= NULL
;
1751 struct bt_ctf_stream_class
*stream_class
= NULL
, *writer_stream_class
= NULL
;
1752 struct bt_ctf_event
*writer_event
= NULL
;
1753 struct bt_ctf_packet
*packet
= NULL
, *writer_packet
= NULL
;
1754 struct bt_ctf_trace
*writer_trace
= NULL
;
1755 struct bt_ctf_stream
*stream
= NULL
;
1756 struct debug_info_trace
*di_trace
;
1757 struct debug_info
*debug_info
;
1758 const char *event_name
;
1761 event_class
= bt_ctf_event_get_class(event
);
1763 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1764 __FILE__
, __LINE__
);
1768 event_name
= bt_ctf_event_class_get_name(event_class
);
1770 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1771 __FILE__
, __LINE__
);
1775 stream_class
= bt_ctf_event_class_get_stream_class(event_class
);
1776 if (!stream_class
) {
1777 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1778 __FILE__
, __LINE__
);
1781 stream
= bt_ctf_event_get_stream(event
);
1783 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1784 __FILE__
, __LINE__
);
1787 di_trace
= lookup_di_trace_from_stream(debug_it
, stream
);
1789 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1790 __FILE__
, __LINE__
);
1794 writer_stream_class
= g_hash_table_lookup(
1795 di_trace
->stream_class_map
,
1796 (gpointer
) stream_class
);
1797 if (!writer_stream_class
) {
1798 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1799 __FILE__
, __LINE__
);
1802 bt_get(writer_stream_class
);
1804 writer_event_class
= get_event_class(debug_it
,
1805 writer_stream_class
, event_class
);
1806 if (!writer_event_class
) {
1807 writer_event_class
= ctf_copy_event_class(debug_it
->err
,
1809 if (!writer_event_class
) {
1810 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1811 __func__
, __FILE__
, __LINE__
);
1814 int_ret
= bt_ctf_stream_class_add_event_class(
1815 writer_stream_class
, writer_event_class
);
1817 fprintf(debug_it
->err
, "[error] %s in %s:%d\n",
1818 __func__
, __FILE__
, __LINE__
);
1823 writer_trace
= bt_ctf_stream_class_get_trace(writer_stream_class
);
1824 if (!writer_trace
) {
1825 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1826 __FILE__
, __LINE__
);
1830 debug_info
= get_trace_debug_info(debug_it
, writer_trace
, di_trace
);
1832 debug_info_handle_event(debug_it
->err
, event
, debug_info
);
1835 writer_event
= debug_info_copy_event(debug_it
->err
, event
,
1836 writer_event_class
, debug_info
,
1837 debug_it
->debug_info_component
);
1838 if (!writer_event
) {
1839 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1840 __FILE__
, __LINE__
);
1841 fprintf(debug_it
->err
, "[error] Failed to copy event %s\n",
1842 bt_ctf_event_class_get_name(writer_event_class
));
1846 packet
= bt_ctf_event_get_packet(event
);
1848 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1849 __FILE__
, __LINE__
);
1853 writer_packet
= lookup_packet(debug_it
, packet
, di_trace
);
1854 if (!writer_packet
) {
1855 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1856 __FILE__
, __LINE__
);
1859 bt_get(writer_packet
);
1861 int_ret
= bt_ctf_event_set_packet(writer_event
, writer_packet
);
1863 fprintf(debug_it
->err
, "[error] %s in %s:%d\n", __func__
,
1864 __FILE__
, __LINE__
);
1865 fprintf(debug_it
->err
, "[error] Failed to append event %s\n",
1866 bt_ctf_event_class_get_name(writer_event_class
));
1870 /* Keep the reference on the writer event */
1874 BT_PUT(writer_event
);
1878 bt_put(writer_trace
);
1879 bt_put(writer_packet
);
1881 bt_put(writer_event_class
);
1882 bt_put(writer_stream_class
);
1883 bt_put(stream_class
);
1884 bt_put(event_class
);
1885 return writer_event
;