2 * ctf-visitor-generate-io-struct.c
4 * Common Trace Format Metadata Visitor (generate I/O structures).
6 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 #include <babeltrace/babeltrace-internal.h>
36 #include <babeltrace/list.h>
37 #include <babeltrace/types.h>
38 #include <babeltrace/ctf/metadata.h>
39 #include <babeltrace/uuid.h>
40 #include <babeltrace/endian.h>
41 #include <babeltrace/ctf/events-internal.h>
42 #include "ctf-scanner.h"
43 #include "ctf-parser.h"
46 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
48 #define _bt_list_first_entry(ptr, type, member) \
49 bt_list_entry((ptr)->next, type, member)
51 struct last_enum_value
{
58 int opt_clock_force_correlate
;
61 struct bt_declaration
*ctf_type_specifier_list_visit(FILE *fd
,
62 int depth
, struct ctf_node
*type_specifier_list
,
63 struct declaration_scope
*declaration_scope
,
64 struct ctf_trace
*trace
);
67 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
68 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
);
71 int is_unary_string(struct bt_list_head
*head
)
73 struct ctf_node
*node
;
75 bt_list_for_each_entry(node
, head
, siblings
) {
76 if (node
->type
!= NODE_UNARY_EXPRESSION
)
78 if (node
->u
.unary_expression
.type
!= UNARY_STRING
)
85 * String returned must be freed by the caller using g_free.
88 char *concatenate_unary_strings(struct bt_list_head
*head
)
90 struct ctf_node
*node
;
94 str
= g_string_new("");
95 bt_list_for_each_entry(node
, head
, siblings
) {
98 assert(node
->type
== NODE_UNARY_EXPRESSION
);
99 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
100 assert((node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
)
102 switch (node
->u
.unary_expression
.link
) {
104 g_string_append(str
, ".");
106 case UNARY_ARROWLINK
:
107 g_string_append(str
, "->");
109 case UNARY_DOTDOTDOT
:
110 g_string_append(str
, "...");
115 src_string
= node
->u
.unary_expression
.u
.string
;
116 g_string_append(str
, src_string
);
119 return g_string_free(str
, FALSE
);
123 GQuark
get_map_clock_name_value(struct bt_list_head
*head
)
125 struct ctf_node
*node
;
126 const char *name
= NULL
;
129 bt_list_for_each_entry(node
, head
, siblings
) {
132 assert(node
->type
== NODE_UNARY_EXPRESSION
);
133 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
134 assert((node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
)
136 /* needs to be chained with . */
137 switch (node
->u
.unary_expression
.link
) {
140 case UNARY_ARROWLINK
:
141 case UNARY_DOTDOTDOT
:
146 src_string
= node
->u
.unary_expression
.u
.string
;
148 case 0: if (strcmp("clock", src_string
) != 0) {
152 case 1: name
= src_string
;
154 case 2: if (strcmp("value", src_string
) != 0) {
159 return 0; /* extra identifier, unknown */
163 return g_quark_from_string(name
);
167 int is_unary_unsigned(struct bt_list_head
*head
)
169 struct ctf_node
*node
;
171 bt_list_for_each_entry(node
, head
, siblings
) {
172 if (node
->type
!= NODE_UNARY_EXPRESSION
)
174 if (node
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
)
181 int get_unary_unsigned(struct bt_list_head
*head
, uint64_t *value
)
183 struct ctf_node
*node
;
186 bt_list_for_each_entry(node
, head
, siblings
) {
187 assert(node
->type
== NODE_UNARY_EXPRESSION
);
188 assert(node
->u
.unary_expression
.type
== UNARY_UNSIGNED_CONSTANT
);
189 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
191 *value
= node
->u
.unary_expression
.u
.unsigned_constant
;
198 int is_unary_signed(struct bt_list_head
*head
)
200 struct ctf_node
*node
;
202 bt_list_for_each_entry(node
, head
, siblings
) {
203 if (node
->type
!= NODE_UNARY_EXPRESSION
)
205 if (node
->u
.unary_expression
.type
!= UNARY_SIGNED_CONSTANT
)
212 int get_unary_signed(struct bt_list_head
*head
, int64_t *value
)
214 struct ctf_node
*node
;
217 bt_list_for_each_entry(node
, head
, siblings
) {
218 assert(node
->type
== NODE_UNARY_EXPRESSION
);
219 assert(node
->u
.unary_expression
.type
== UNARY_UNSIGNED_CONSTANT
220 || node
->u
.unary_expression
.type
== UNARY_SIGNED_CONSTANT
);
221 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
223 switch (node
->u
.unary_expression
.type
) {
224 case UNARY_UNSIGNED_CONSTANT
:
225 *value
= (int64_t) node
->u
.unary_expression
.u
.unsigned_constant
;
227 case UNARY_SIGNED_CONSTANT
:
228 *value
= node
->u
.unary_expression
.u
.signed_constant
;
239 int get_unary_uuid(struct bt_list_head
*head
, unsigned char *uuid
)
241 struct ctf_node
*node
;
245 bt_list_for_each_entry(node
, head
, siblings
) {
246 const char *src_string
;
248 assert(node
->type
== NODE_UNARY_EXPRESSION
);
249 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
250 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
252 src_string
= node
->u
.unary_expression
.u
.string
;
253 ret
= babeltrace_uuid_parse(src_string
, uuid
);
259 struct ctf_stream_declaration
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
261 if (trace
->streams
->len
<= stream_id
)
263 return g_ptr_array_index(trace
->streams
, stream_id
);
267 struct ctf_clock
*trace_clock_lookup(struct ctf_trace
*trace
, GQuark clock_name
)
269 return g_hash_table_lookup(trace
->clocks
, (gpointer
) (unsigned long) clock_name
);
273 int visit_type_specifier(FILE *fd
, struct ctf_node
*type_specifier
, GString
*str
)
275 assert(type_specifier
->type
== NODE_TYPE_SPECIFIER
);
277 switch (type_specifier
->u
.type_specifier
.type
) {
279 g_string_append(str
, "void");
282 g_string_append(str
, "char");
285 g_string_append(str
, "short");
288 g_string_append(str
, "int");
291 g_string_append(str
, "long");
294 g_string_append(str
, "float");
296 case TYPESPEC_DOUBLE
:
297 g_string_append(str
, "double");
299 case TYPESPEC_SIGNED
:
300 g_string_append(str
, "signed");
302 case TYPESPEC_UNSIGNED
:
303 g_string_append(str
, "unsigned");
306 g_string_append(str
, "bool");
308 case TYPESPEC_COMPLEX
:
309 g_string_append(str
, "_Complex");
311 case TYPESPEC_IMAGINARY
:
312 g_string_append(str
, "_Imaginary");
315 g_string_append(str
, "const");
317 case TYPESPEC_ID_TYPE
:
318 if (type_specifier
->u
.type_specifier
.id_type
)
319 g_string_append(str
, type_specifier
->u
.type_specifier
.id_type
);
321 case TYPESPEC_STRUCT
:
323 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
325 if (!node
->u
._struct
.name
) {
326 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
329 g_string_append(str
, "struct ");
330 g_string_append(str
, node
->u
._struct
.name
);
333 case TYPESPEC_VARIANT
:
335 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
337 if (!node
->u
.variant
.name
) {
338 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
341 g_string_append(str
, "variant ");
342 g_string_append(str
, node
->u
.variant
.name
);
347 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
349 if (!node
->u
._enum
.enum_id
) {
350 fprintf(fd
, "[error] %s: unexpected empty enum ID\n", __func__
);
353 g_string_append(str
, "enum ");
354 g_string_append(str
, node
->u
._enum
.enum_id
);
357 case TYPESPEC_FLOATING_POINT
:
358 case TYPESPEC_INTEGER
:
359 case TYPESPEC_STRING
:
361 fprintf(fd
, "[error] %s: unknown specifier\n", __func__
);
368 int visit_type_specifier_list(FILE *fd
, struct ctf_node
*type_specifier_list
, GString
*str
)
370 struct ctf_node
*iter
;
371 int alias_item_nr
= 0;
374 bt_list_for_each_entry(iter
, &type_specifier_list
->u
.type_specifier_list
.head
, siblings
) {
375 if (alias_item_nr
!= 0)
376 g_string_append(str
, " ");
378 ret
= visit_type_specifier(fd
, iter
, str
);
386 GQuark
create_typealias_identifier(FILE *fd
, int depth
,
387 struct ctf_node
*type_specifier_list
,
388 struct ctf_node
*node_type_declarator
)
390 struct ctf_node
*iter
;
396 str
= g_string_new("");
397 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
399 g_string_free(str
, TRUE
);
402 bt_list_for_each_entry(iter
, &node_type_declarator
->u
.type_declarator
.pointers
, siblings
) {
403 g_string_append(str
, " *");
404 if (iter
->u
.pointer
.const_qualifier
)
405 g_string_append(str
, " const");
407 str_c
= g_string_free(str
, FALSE
);
408 alias_q
= g_quark_from_string(str_c
);
414 struct bt_declaration
*ctf_type_declarator_visit(FILE *fd
, int depth
,
415 struct ctf_node
*type_specifier_list
,
417 struct ctf_node
*node_type_declarator
,
418 struct declaration_scope
*declaration_scope
,
419 struct bt_declaration
*nested_declaration
,
420 struct ctf_trace
*trace
)
423 * Visit type declarator by first taking care of sequence/array
424 * (recursively). Then, when we get to the identifier, take care
428 if (node_type_declarator
) {
429 assert(node_type_declarator
->u
.type_declarator
.type
!= TYPEDEC_UNKNOWN
);
431 /* TODO: gcc bitfields not supported yet. */
432 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!= NULL
) {
433 fprintf(fd
, "[error] %s: gcc bitfields are not supported yet.\n", __func__
);
438 if (!nested_declaration
) {
439 if (node_type_declarator
&& !bt_list_empty(&node_type_declarator
->u
.type_declarator
.pointers
)) {
443 * If we have a pointer declarator, it _has_ to be present in
444 * the typealiases (else fail).
446 alias_q
= create_typealias_identifier(fd
, depth
,
447 type_specifier_list
, node_type_declarator
);
448 nested_declaration
= bt_lookup_declaration(alias_q
, declaration_scope
);
449 if (!nested_declaration
) {
450 fprintf(fd
, "[error] %s: cannot find typealias \"%s\".\n", __func__
, g_quark_to_string(alias_q
));
453 if (nested_declaration
->id
== CTF_TYPE_INTEGER
) {
454 struct declaration_integer
*integer_declaration
=
455 container_of(nested_declaration
, struct declaration_integer
, p
);
456 /* For base to 16 for pointers (expected pretty-print) */
457 if (!integer_declaration
->base
) {
459 * We need to do a copy of the
460 * integer declaration to modify it. There could be other references to
463 integer_declaration
= bt_integer_declaration_new(integer_declaration
->len
,
464 integer_declaration
->byte_order
, integer_declaration
->signedness
,
465 integer_declaration
->p
.alignment
, 16, integer_declaration
->encoding
,
466 integer_declaration
->clock
);
467 nested_declaration
= &integer_declaration
->p
;
471 nested_declaration
= ctf_type_specifier_list_visit(fd
, depth
,
472 type_specifier_list
, declaration_scope
, trace
);
476 if (!node_type_declarator
)
477 return nested_declaration
;
479 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
480 if (node_type_declarator
->u
.type_declarator
.u
.id
)
481 *field_name
= g_quark_from_string(node_type_declarator
->u
.type_declarator
.u
.id
);
484 return nested_declaration
;
486 struct bt_declaration
*declaration
;
487 struct ctf_node
*first
;
491 if (!nested_declaration
) {
492 fprintf(fd
, "[error] %s: nested type is unknown.\n", __func__
);
496 /* create array/sequence, pass nested_declaration as child. */
497 if (bt_list_empty(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
)) {
498 fprintf(fd
, "[error] %s: expecting length field reference or value.\n", __func__
);
501 first
= _bt_list_first_entry(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
,
502 struct ctf_node
, siblings
);
503 assert(first
->type
== NODE_UNARY_EXPRESSION
);
505 switch (first
->u
.unary_expression
.type
) {
506 case UNARY_UNSIGNED_CONSTANT
:
508 struct declaration_array
*array_declaration
;
511 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
512 array_declaration
= bt_array_declaration_new(len
, nested_declaration
,
515 if (!array_declaration
) {
516 fprintf(fd
, "[error] %s: cannot create array declaration.\n", __func__
);
519 bt_declaration_unref(nested_declaration
);
520 declaration
= &array_declaration
->p
;
525 /* Lookup unsigned integer definition, create sequence */
526 char *length_name
= concatenate_unary_strings(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
);
527 struct declaration_sequence
*sequence_declaration
;
529 sequence_declaration
= bt_sequence_declaration_new(length_name
, nested_declaration
, declaration_scope
);
530 if (!sequence_declaration
) {
531 fprintf(fd
, "[error] %s: cannot create sequence declaration.\n", __func__
);
535 bt_declaration_unref(nested_declaration
);
536 declaration
= &sequence_declaration
->p
;
544 /* Pass it as content of outer container */
545 declaration
= ctf_type_declarator_visit(fd
, depth
,
546 type_specifier_list
, field_name
,
547 node_type_declarator
->u
.type_declarator
.u
.nested
.type_declarator
,
548 declaration_scope
, declaration
, trace
);
554 int ctf_struct_type_declarators_visit(FILE *fd
, int depth
,
555 struct declaration_struct
*struct_declaration
,
556 struct ctf_node
*type_specifier_list
,
557 struct bt_list_head
*type_declarators
,
558 struct declaration_scope
*declaration_scope
,
559 struct ctf_trace
*trace
)
561 struct ctf_node
*iter
;
564 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
565 struct bt_declaration
*field_declaration
;
567 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
570 struct_declaration
->scope
,
572 if (!field_declaration
) {
573 fprintf(fd
, "[error] %s: unable to find struct field declaration type\n", __func__
);
577 /* Check if field with same name already exists */
578 if (bt_struct_declaration_lookup_field_index(struct_declaration
, field_name
) >= 0) {
579 fprintf(fd
, "[error] %s: duplicate field %s in struct\n", __func__
, g_quark_to_string(field_name
));
583 bt_struct_declaration_add_field(struct_declaration
,
584 g_quark_to_string(field_name
),
586 bt_declaration_unref(field_declaration
);
592 int ctf_variant_type_declarators_visit(FILE *fd
, int depth
,
593 struct declaration_untagged_variant
*untagged_variant_declaration
,
594 struct ctf_node
*type_specifier_list
,
595 struct bt_list_head
*type_declarators
,
596 struct declaration_scope
*declaration_scope
,
597 struct ctf_trace
*trace
)
599 struct ctf_node
*iter
;
602 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
603 struct bt_declaration
*field_declaration
;
605 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
608 untagged_variant_declaration
->scope
,
610 if (!field_declaration
) {
611 fprintf(fd
, "[error] %s: unable to find variant field declaration type\n", __func__
);
615 if (bt_untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration
, field_name
) != NULL
) {
616 fprintf(fd
, "[error] %s: duplicate field %s in variant\n", __func__
, g_quark_to_string(field_name
));
620 bt_untagged_variant_declaration_add_field(untagged_variant_declaration
,
621 g_quark_to_string(field_name
),
623 bt_declaration_unref(field_declaration
);
629 int ctf_typedef_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
630 struct ctf_node
*type_specifier_list
,
631 struct bt_list_head
*type_declarators
,
632 struct ctf_trace
*trace
)
634 struct ctf_node
*iter
;
637 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
638 struct bt_declaration
*type_declaration
;
641 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
645 if (!type_declaration
) {
646 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
650 * Don't allow typedef and typealias of untagged
653 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
654 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
655 bt_declaration_unref(type_declaration
);
658 ret
= bt_register_declaration(identifier
, type_declaration
, scope
);
660 type_declaration
->declaration_free(type_declaration
);
663 bt_declaration_unref(type_declaration
);
669 int ctf_typealias_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
670 struct ctf_node
*target
, struct ctf_node
*alias
,
671 struct ctf_trace
*trace
)
673 struct bt_declaration
*type_declaration
;
674 struct ctf_node
*node
;
679 /* See ctf_visitor_type_declarator() in the semantic validator. */
682 * Create target type declaration.
685 if (bt_list_empty(&target
->u
.typealias_target
.type_declarators
))
688 node
= _bt_list_first_entry(&target
->u
.typealias_target
.type_declarators
,
689 struct ctf_node
, siblings
);
690 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
691 target
->u
.typealias_target
.type_specifier_list
,
694 if (!type_declaration
) {
695 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
700 * Don't allow typedef and typealias of untagged
703 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
704 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
705 bt_declaration_unref(type_declaration
);
709 * The semantic validator does not check whether the target is
710 * abstract or not (if it has an identifier). Check it here.
713 fprintf(fd
, "[error] %s: expecting empty identifier\n", __func__
);
718 * Create alias identifier.
721 node
= _bt_list_first_entry(&alias
->u
.typealias_alias
.type_declarators
,
722 struct ctf_node
, siblings
);
723 alias_q
= create_typealias_identifier(fd
, depth
,
724 alias
->u
.typealias_alias
.type_specifier_list
, node
);
725 err
= bt_register_declaration(alias_q
, type_declaration
, scope
);
728 bt_declaration_unref(type_declaration
);
732 if (type_declaration
) {
733 type_declaration
->declaration_free(type_declaration
);
739 int ctf_struct_declaration_list_visit(FILE *fd
, int depth
,
740 struct ctf_node
*iter
, struct declaration_struct
*struct_declaration
,
741 struct ctf_trace
*trace
)
745 switch (iter
->type
) {
747 /* For each declarator, declare type and add type to struct bt_declaration scope */
748 ret
= ctf_typedef_visit(fd
, depth
,
749 struct_declaration
->scope
,
750 iter
->u
._typedef
.type_specifier_list
,
751 &iter
->u
._typedef
.type_declarators
, trace
);
756 /* Declare type with declarator and add type to struct bt_declaration scope */
757 ret
= ctf_typealias_visit(fd
, depth
,
758 struct_declaration
->scope
,
759 iter
->u
.typealias
.target
,
760 iter
->u
.typealias
.alias
, trace
);
764 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
765 /* Add field to structure declaration */
766 ret
= ctf_struct_type_declarators_visit(fd
, depth
,
768 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
769 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
770 struct_declaration
->scope
, trace
);
775 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
782 int ctf_variant_declaration_list_visit(FILE *fd
, int depth
,
783 struct ctf_node
*iter
,
784 struct declaration_untagged_variant
*untagged_variant_declaration
,
785 struct ctf_trace
*trace
)
789 switch (iter
->type
) {
791 /* For each declarator, declare type and add type to variant declaration scope */
792 ret
= ctf_typedef_visit(fd
, depth
,
793 untagged_variant_declaration
->scope
,
794 iter
->u
._typedef
.type_specifier_list
,
795 &iter
->u
._typedef
.type_declarators
, trace
);
800 /* Declare type with declarator and add type to variant declaration scope */
801 ret
= ctf_typealias_visit(fd
, depth
,
802 untagged_variant_declaration
->scope
,
803 iter
->u
.typealias
.target
,
804 iter
->u
.typealias
.alias
, trace
);
808 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
809 /* Add field to structure declaration */
810 ret
= ctf_variant_type_declarators_visit(fd
, depth
,
811 untagged_variant_declaration
,
812 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
813 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
814 untagged_variant_declaration
->scope
, trace
);
819 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
826 struct bt_declaration
*ctf_declaration_struct_visit(FILE *fd
,
827 int depth
, const char *name
, struct bt_list_head
*declaration_list
,
828 int has_body
, struct bt_list_head
*min_align
,
829 struct declaration_scope
*declaration_scope
,
830 struct ctf_trace
*trace
)
832 struct declaration_struct
*struct_declaration
;
833 struct ctf_node
*iter
;
836 * For named struct (without body), lookup in
837 * declaration scope. Don't take reference on struct
838 * declaration: ref is only taken upon definition.
843 bt_lookup_struct_declaration(g_quark_from_string(name
),
845 bt_declaration_ref(&struct_declaration
->p
);
846 return &struct_declaration
->p
;
848 uint64_t min_align_value
= 0;
850 /* For unnamed struct, create type */
851 /* For named struct (with body), create type and add to declaration scope */
853 if (bt_lookup_struct_declaration(g_quark_from_string(name
),
854 declaration_scope
)) {
856 fprintf(fd
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
860 if (!bt_list_empty(min_align
)) {
863 ret
= get_unary_unsigned(min_align
, &min_align_value
);
865 fprintf(fd
, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__
);
870 struct_declaration
= bt_struct_declaration_new(declaration_scope
,
872 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
875 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
876 struct_declaration
, trace
);
878 goto error_free_declaration
;
883 ret
= bt_register_struct_declaration(g_quark_from_string(name
),
888 return &struct_declaration
->p
;
890 error_free_declaration
:
891 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
897 struct bt_declaration
*ctf_declaration_variant_visit(FILE *fd
,
898 int depth
, const char *name
, const char *choice
,
899 struct bt_list_head
*declaration_list
,
900 int has_body
, struct declaration_scope
*declaration_scope
,
901 struct ctf_trace
*trace
)
903 struct declaration_untagged_variant
*untagged_variant_declaration
;
904 struct declaration_variant
*variant_declaration
;
905 struct ctf_node
*iter
;
908 * For named variant (without body), lookup in
909 * declaration scope. Don't take reference on variant
910 * declaration: ref is only taken upon definition.
914 untagged_variant_declaration
=
915 bt_lookup_variant_declaration(g_quark_from_string(name
),
917 bt_declaration_ref(&untagged_variant_declaration
->p
);
919 /* For unnamed variant, create type */
920 /* For named variant (with body), create type and add to declaration scope */
922 if (bt_lookup_variant_declaration(g_quark_from_string(name
),
923 declaration_scope
)) {
925 fprintf(fd
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
929 untagged_variant_declaration
= bt_untagged_bt_variant_declaration_new(declaration_scope
);
930 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
933 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
934 untagged_variant_declaration
, trace
);
941 ret
= bt_register_variant_declaration(g_quark_from_string(name
),
942 untagged_variant_declaration
,
948 * if tagged, create tagged variant and return. else return
952 return &untagged_variant_declaration
->p
;
954 variant_declaration
= bt_variant_declaration_new(untagged_variant_declaration
, choice
);
955 if (!variant_declaration
)
957 bt_declaration_unref(&untagged_variant_declaration
->p
);
958 return &variant_declaration
->p
;
961 untagged_variant_declaration
->p
.declaration_free(&untagged_variant_declaration
->p
);
966 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
967 struct ctf_node
*enumerator
,
968 struct declaration_enum
*enum_declaration
,
969 struct last_enum_value
*last
)
972 struct ctf_node
*iter
;
974 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
975 if (enum_declaration
->integer_declaration
->signedness
) {
979 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
982 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
988 switch (iter
->u
.unary_expression
.type
) {
989 case UNARY_SIGNED_CONSTANT
:
990 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
992 case UNARY_UNSIGNED_CONSTANT
:
993 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
996 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1000 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1009 last
->u
.s
= end
+ 1;
1010 bt_enum_signed_insert(enum_declaration
, start
, end
, q
);
1012 uint64_t start
, end
;
1015 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
1018 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
1024 switch (iter
->u
.unary_expression
.type
) {
1025 case UNARY_UNSIGNED_CONSTANT
:
1026 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1028 case UNARY_SIGNED_CONSTANT
:
1030 * We don't accept signed constants for enums with unsigned
1033 fprintf(fd
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
1036 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1040 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1049 last
->u
.u
= end
+ 1;
1050 bt_enum_unsigned_insert(enum_declaration
, start
, end
, q
);
1056 struct bt_declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
1058 struct ctf_node
*container_type
,
1059 struct bt_list_head
*enumerator_list
,
1061 struct declaration_scope
*declaration_scope
,
1062 struct ctf_trace
*trace
)
1064 struct bt_declaration
*declaration
;
1065 struct declaration_enum
*enum_declaration
;
1066 struct declaration_integer
*integer_declaration
;
1067 struct last_enum_value last_value
;
1068 struct ctf_node
*iter
;
1072 * For named enum (without body), lookup in
1073 * declaration scope. Don't take reference on enum
1074 * declaration: ref is only taken upon definition.
1079 bt_lookup_enum_declaration(g_quark_from_string(name
),
1081 bt_declaration_ref(&enum_declaration
->p
);
1082 return &enum_declaration
->p
;
1084 /* For unnamed enum, create type */
1085 /* For named enum (with body), create type and add to declaration scope */
1087 if (bt_lookup_enum_declaration(g_quark_from_string(name
),
1088 declaration_scope
)) {
1090 fprintf(fd
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
1094 if (!container_type
) {
1095 declaration
= bt_lookup_declaration(g_quark_from_static_string("int"),
1098 fprintf(fd
, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__
);
1102 declaration
= ctf_type_declarator_visit(fd
, depth
,
1109 fprintf(fd
, "[error] %s: unable to create container type for enumeration\n", __func__
);
1112 if (declaration
->id
!= CTF_TYPE_INTEGER
) {
1113 fprintf(fd
, "[error] %s: container type for enumeration is not integer\n", __func__
);
1116 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
1117 enum_declaration
= bt_enum_declaration_new(integer_declaration
);
1118 bt_declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
1119 if (enum_declaration
->integer_declaration
->signedness
) {
1124 bt_list_for_each_entry(iter
, enumerator_list
, siblings
) {
1127 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
,
1135 ret
= bt_register_enum_declaration(g_quark_from_string(name
),
1139 bt_declaration_unref(&enum_declaration
->p
);
1141 return &enum_declaration
->p
;
1144 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
1149 struct bt_declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
1150 struct ctf_node
*type_specifier_list
,
1151 struct declaration_scope
*declaration_scope
)
1154 struct bt_declaration
*declaration
;
1159 str
= g_string_new("");
1160 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
1163 str_c
= g_string_free(str
, FALSE
);
1164 id_q
= g_quark_from_string(str_c
);
1166 declaration
= bt_lookup_declaration(id_q
, declaration_scope
);
1169 bt_declaration_ref(declaration
);
1174 * Returns 0/1 boolean, or < 0 on error.
1177 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1179 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1180 fprintf(fd
, "[error] %s: expecting unary expression\n",
1184 switch (unary_expression
->u
.unary_expression
.type
) {
1185 case UNARY_UNSIGNED_CONSTANT
:
1186 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1190 case UNARY_SIGNED_CONSTANT
:
1191 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1196 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1198 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1200 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1202 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1205 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1206 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1211 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1219 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1223 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1224 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1228 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1229 byte_order
= BIG_ENDIAN
;
1230 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1231 byte_order
= LITTLE_ENDIAN
;
1233 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
1234 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1241 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1242 struct ctf_trace
*trace
)
1246 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1247 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1251 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1252 byte_order
= trace
->byte_order
;
1253 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1254 byte_order
= BIG_ENDIAN
;
1255 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1256 byte_order
= BIG_ENDIAN
;
1257 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1258 byte_order
= LITTLE_ENDIAN
;
1260 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1261 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1268 struct bt_declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1269 struct bt_list_head
*expressions
,
1270 struct ctf_trace
*trace
)
1272 struct ctf_node
*expression
;
1273 uint64_t alignment
= 1, size
= 0;
1274 int byte_order
= trace
->byte_order
;
1276 int has_alignment
= 0, has_size
= 0;
1278 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1279 struct ctf_clock
*clock
= NULL
;
1280 struct declaration_integer
*integer_declaration
;
1282 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1283 struct ctf_node
*left
, *right
;
1285 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1286 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1287 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1288 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1289 signedness
= get_boolean(fd
, depth
, right
);
1292 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1293 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1296 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1297 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1298 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1302 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1304 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1305 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1306 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1310 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1311 /* Make sure alignment is a power of two */
1312 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1313 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1318 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1319 switch (right
->u
.unary_expression
.type
) {
1320 case UNARY_UNSIGNED_CONSTANT
:
1321 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1326 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1329 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1330 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1336 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1338 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1342 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1343 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1345 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1346 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1347 || !strcmp(s_right
, "p")) {
1349 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1350 || !strcmp(s_right
, "o")) {
1352 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1355 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1364 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1368 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1371 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1372 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1376 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1378 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1382 if (!strcmp(s_right
, "UTF8")
1383 || !strcmp(s_right
, "utf8")
1384 || !strcmp(s_right
, "utf-8")
1385 || !strcmp(s_right
, "UTF-8"))
1386 encoding
= CTF_STRING_UTF8
;
1387 else if (!strcmp(s_right
, "ASCII")
1388 || !strcmp(s_right
, "ascii"))
1389 encoding
= CTF_STRING_ASCII
;
1390 else if (!strcmp(s_right
, "none"))
1391 encoding
= CTF_STRING_NONE
;
1393 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1398 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1401 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1402 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1406 /* currently only support clock.name.value */
1407 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1411 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1413 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1417 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1422 clock
= trace_clock_lookup(trace
, clock_name
);
1424 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1425 __func__
, g_quark_to_string(clock_name
));
1429 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1430 __func__
, left
->u
.unary_expression
.u
.string
);
1431 /* Fall-through after warning */
1435 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1438 if (!has_alignment
) {
1439 if (size
% CHAR_BIT
) {
1440 /* bit-packed alignment */
1443 /* byte-packed alignment */
1444 alignment
= CHAR_BIT
;
1447 integer_declaration
= bt_integer_declaration_new(size
,
1448 byte_order
, signedness
, alignment
,
1449 base
, encoding
, clock
);
1450 return &integer_declaration
->p
;
1454 struct bt_declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1455 struct bt_list_head
*expressions
,
1456 struct ctf_trace
*trace
)
1458 struct ctf_node
*expression
;
1459 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0,
1460 byte_order
= trace
->byte_order
;
1461 int has_alignment
= 0, has_exp_dig
= 0, has_mant_dig
= 0;
1462 struct declaration_float
*float_declaration
;
1464 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1465 struct ctf_node
*left
, *right
;
1467 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1468 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1469 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1470 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1471 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1474 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1475 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1476 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1480 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1482 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1483 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1484 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1488 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1490 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1491 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1492 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1496 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1497 /* Make sure alignment is a power of two */
1498 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1499 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1505 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1506 __func__
, left
->u
.unary_expression
.u
.string
);
1507 /* Fall-through after warning */
1510 if (!has_mant_dig
) {
1511 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1515 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1518 if (!has_alignment
) {
1519 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1520 /* bit-packed alignment */
1523 /* byte-packed alignment */
1524 alignment
= CHAR_BIT
;
1527 float_declaration
= bt_float_declaration_new(mant_dig
, exp_dig
,
1528 byte_order
, alignment
);
1529 return &float_declaration
->p
;
1533 struct bt_declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1534 struct bt_list_head
*expressions
,
1535 struct ctf_trace
*trace
)
1537 struct ctf_node
*expression
;
1538 const char *encoding_c
= NULL
;
1539 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1540 struct declaration_string
*string_declaration
;
1542 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1543 struct ctf_node
*left
, *right
;
1545 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1546 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1547 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1548 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1549 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1550 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1554 encoding_c
= right
->u
.unary_expression
.u
.string
;
1556 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1557 __func__
, left
->u
.unary_expression
.u
.string
);
1558 /* Fall-through after warning */
1561 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1562 encoding
= CTF_STRING_ASCII
;
1563 string_declaration
= bt_string_declaration_new(encoding
);
1564 return &string_declaration
->p
;
1569 struct bt_declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1570 int depth
, struct ctf_node
*type_specifier_list
,
1571 struct declaration_scope
*declaration_scope
,
1572 struct ctf_trace
*trace
)
1574 struct ctf_node
*first
;
1575 struct ctf_node
*node
;
1577 assert(type_specifier_list
->type
== NODE_TYPE_SPECIFIER_LIST
);
1579 first
= _bt_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1581 assert(first
->type
== NODE_TYPE_SPECIFIER
);
1583 node
= first
->u
.type_specifier
.node
;
1585 switch (first
->u
.type_specifier
.type
) {
1586 case TYPESPEC_FLOATING_POINT
:
1587 return ctf_declaration_floating_point_visit(fd
, depth
,
1588 &node
->u
.floating_point
.expressions
, trace
);
1589 case TYPESPEC_INTEGER
:
1590 return ctf_declaration_integer_visit(fd
, depth
,
1591 &node
->u
.integer
.expressions
, trace
);
1592 case TYPESPEC_STRING
:
1593 return ctf_declaration_string_visit(fd
, depth
,
1594 &node
->u
.string
.expressions
, trace
);
1595 case TYPESPEC_STRUCT
:
1596 return ctf_declaration_struct_visit(fd
, depth
,
1597 node
->u
._struct
.name
,
1598 &node
->u
._struct
.declaration_list
,
1599 node
->u
._struct
.has_body
,
1600 &node
->u
._struct
.min_align
,
1603 case TYPESPEC_VARIANT
:
1604 return ctf_declaration_variant_visit(fd
, depth
,
1605 node
->u
.variant
.name
,
1606 node
->u
.variant
.choice
,
1607 &node
->u
.variant
.declaration_list
,
1608 node
->u
.variant
.has_body
,
1612 return ctf_declaration_enum_visit(fd
, depth
,
1613 node
->u
._enum
.enum_id
,
1614 node
->u
._enum
.container_type
,
1615 &node
->u
._enum
.enumerator_list
,
1616 node
->u
._enum
.has_body
,
1622 case TYPESPEC_SHORT
:
1625 case TYPESPEC_FLOAT
:
1626 case TYPESPEC_DOUBLE
:
1627 case TYPESPEC_SIGNED
:
1628 case TYPESPEC_UNSIGNED
:
1630 case TYPESPEC_COMPLEX
:
1631 case TYPESPEC_IMAGINARY
:
1632 case TYPESPEC_CONST
:
1633 case TYPESPEC_ID_TYPE
:
1634 return ctf_declaration_type_specifier_visit(fd
, depth
,
1635 type_specifier_list
, declaration_scope
);
1637 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1643 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event_declaration
*event
, struct ctf_trace
*trace
)
1647 switch (node
->type
) {
1649 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1650 event
->declaration_scope
,
1651 node
->u
._typedef
.type_specifier_list
,
1652 &node
->u
._typedef
.type_declarators
,
1657 case NODE_TYPEALIAS
:
1658 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1659 event
->declaration_scope
,
1660 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1665 case NODE_CTF_EXPRESSION
:
1669 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1670 if (!strcmp(left
, "name")) {
1673 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1674 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1678 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1680 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1684 event
->name
= g_quark_from_string(right
);
1686 CTF_EVENT_SET_FIELD(event
, name
);
1687 } else if (!strcmp(left
, "id")) {
1688 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1689 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1693 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1695 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1699 CTF_EVENT_SET_FIELD(event
, id
);
1700 } else if (!strcmp(left
, "stream_id")) {
1701 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1702 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1706 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1708 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1712 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1713 if (!event
->stream
) {
1714 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1718 CTF_EVENT_SET_FIELD(event
, stream_id
);
1719 } else if (!strcmp(left
, "context")) {
1720 struct bt_declaration
*declaration
;
1722 if (event
->context_decl
) {
1723 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1727 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1728 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1729 struct ctf_node
, siblings
),
1730 event
->declaration_scope
, trace
);
1735 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1739 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1740 } else if (!strcmp(left
, "fields")) {
1741 struct bt_declaration
*declaration
;
1743 if (event
->fields_decl
) {
1744 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1748 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1749 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1750 struct ctf_node
, siblings
),
1751 event
->declaration_scope
, trace
);
1756 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1760 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1761 } else if (!strcmp(left
, "loglevel")) {
1762 int64_t loglevel
= -1;
1764 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel
)) {
1765 fprintf(fd
, "[error] %s: loglevel already declared in event declaration\n", __func__
);
1769 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &loglevel
);
1771 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel\n", __func__
);
1775 event
->loglevel
= (int) loglevel
;
1776 CTF_EVENT_SET_FIELD(event
, loglevel
);
1777 } else if (!strcmp(left
, "model.emf.uri")) {
1780 if (CTF_EVENT_FIELD_IS_SET(event
, model_emf_uri
)) {
1781 fprintf(fd
, "[error] %s: model.emf.uri already declared in event declaration\n", __func__
);
1785 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1787 fprintf(fd
, "[error] %s: unexpected unary expression for event model.emf.uri\n", __func__
);
1791 event
->model_emf_uri
= g_quark_from_string(right
);
1793 CTF_EVENT_SET_FIELD(event
, model_emf_uri
);
1795 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1796 /* Fall-through after warning */
1804 /* TODO: declaration specifier should be added. */
1811 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1812 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1815 struct ctf_node
*iter
;
1816 struct ctf_event_declaration
*event
;
1817 struct bt_ctf_event_decl
*event_decl
;
1819 event_decl
= g_new0(struct bt_ctf_event_decl
, 1);
1820 event
= &event_decl
->parent
;
1821 event
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
1822 event
->loglevel
= -1;
1823 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1824 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1828 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1830 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1833 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1834 /* Allow missing stream_id if there is only a single stream */
1835 switch (trace
->streams
->len
) {
1836 case 0: /* Create stream if there was none. */
1837 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1842 event
->stream_id
= 0;
1843 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1847 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1851 /* Allow only one event without id per stream */
1852 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1853 && event
->stream
->events_by_id
->len
!= 0) {
1855 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1858 if (event
->stream
->events_by_id
->len
<= event
->id
)
1859 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1860 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1861 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1862 (gpointer
) (unsigned long) event
->name
,
1864 g_ptr_array_add(trace
->event_declarations
, event_decl
);
1868 if (event
->fields_decl
)
1869 bt_declaration_unref(&event
->fields_decl
->p
);
1870 if (event
->context_decl
)
1871 bt_declaration_unref(&event
->context_decl
->p
);
1872 bt_free_declaration_scope(event
->declaration_scope
);
1879 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_declaration
*stream
, struct ctf_trace
*trace
)
1883 switch (node
->type
) {
1885 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1886 stream
->declaration_scope
,
1887 node
->u
._typedef
.type_specifier_list
,
1888 &node
->u
._typedef
.type_declarators
,
1893 case NODE_TYPEALIAS
:
1894 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1895 stream
->declaration_scope
,
1896 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1901 case NODE_CTF_EXPRESSION
:
1905 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1906 if (!strcmp(left
, "id")) {
1907 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1908 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1912 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1914 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1918 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1919 } else if (!strcmp(left
, "event.header")) {
1920 struct bt_declaration
*declaration
;
1922 if (stream
->event_header_decl
) {
1923 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1927 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1928 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1929 struct ctf_node
, siblings
),
1930 stream
->declaration_scope
, trace
);
1935 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1939 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1940 } else if (!strcmp(left
, "event.context")) {
1941 struct bt_declaration
*declaration
;
1943 if (stream
->event_context_decl
) {
1944 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1948 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1949 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1950 struct ctf_node
, siblings
),
1951 stream
->declaration_scope
, trace
);
1956 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1960 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1961 } else if (!strcmp(left
, "packet.context")) {
1962 struct bt_declaration
*declaration
;
1964 if (stream
->packet_context_decl
) {
1965 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
1969 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1970 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1971 struct ctf_node
, siblings
),
1972 stream
->declaration_scope
, trace
);
1977 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1981 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1983 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
1984 /* Fall-through after warning */
1993 /* TODO: declaration specifier should be added. */
2000 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2001 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
2004 struct ctf_node
*iter
;
2005 struct ctf_stream_declaration
*stream
;
2007 stream
= g_new0(struct ctf_stream_declaration
, 1);
2008 stream
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
2009 stream
->events_by_id
= g_ptr_array_new();
2010 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2011 stream
->streams
= g_ptr_array_new();
2013 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
2014 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
2019 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
2020 /* check that packet header has stream_id field. */
2021 if (!trace
->packet_header_decl
2022 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
2024 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
2028 /* Allow only one id-less stream */
2029 if (trace
->streams
->len
!= 0) {
2031 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
2034 stream
->stream_id
= 0;
2036 if (trace
->streams
->len
<= stream
->stream_id
)
2037 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
2038 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
2039 stream
->trace
= trace
;
2044 if (stream
->event_header_decl
)
2045 bt_declaration_unref(&stream
->event_header_decl
->p
);
2046 if (stream
->event_context_decl
)
2047 bt_declaration_unref(&stream
->event_context_decl
->p
);
2048 if (stream
->packet_context_decl
)
2049 bt_declaration_unref(&stream
->packet_context_decl
->p
);
2050 g_ptr_array_free(stream
->streams
, TRUE
);
2051 g_ptr_array_free(stream
->events_by_id
, TRUE
);
2052 g_hash_table_destroy(stream
->event_quark_to_id
);
2053 bt_free_declaration_scope(stream
->declaration_scope
);
2059 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2063 switch (node
->type
) {
2065 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2066 trace
->declaration_scope
,
2067 node
->u
._typedef
.type_specifier_list
,
2068 &node
->u
._typedef
.type_declarators
,
2073 case NODE_TYPEALIAS
:
2074 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2075 trace
->declaration_scope
,
2076 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2081 case NODE_CTF_EXPRESSION
:
2085 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2086 if (!strcmp(left
, "major")) {
2087 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2088 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
2092 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
2094 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
2098 CTF_TRACE_SET_FIELD(trace
, major
);
2099 } else if (!strcmp(left
, "minor")) {
2100 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2101 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
2105 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
2107 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
2111 CTF_TRACE_SET_FIELD(trace
, minor
);
2112 } else if (!strcmp(left
, "uuid")) {
2113 unsigned char uuid
[BABELTRACE_UUID_LEN
];
2115 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, uuid
);
2117 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2121 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2122 && babeltrace_uuid_compare(uuid
, trace
->uuid
)) {
2123 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2127 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2129 CTF_TRACE_SET_FIELD(trace
, uuid
);
2130 } else if (!strcmp(left
, "byte_order")) {
2131 struct ctf_node
*right
;
2134 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2135 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2139 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2140 && byte_order
!= trace
->byte_order
) {
2141 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2145 if (byte_order
!= trace
->byte_order
) {
2146 trace
->byte_order
= byte_order
;
2148 * We need to restart
2149 * construction of the
2150 * intermediate representation.
2152 trace
->field_mask
= 0;
2153 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2158 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2159 } else if (!strcmp(left
, "packet.header")) {
2160 struct bt_declaration
*declaration
;
2162 if (trace
->packet_header_decl
) {
2163 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2167 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2168 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2169 struct ctf_node
, siblings
),
2170 trace
->declaration_scope
, trace
);
2175 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2179 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2181 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2190 /* TODO: declaration specifier should be added. */
2197 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2200 struct ctf_node
*iter
;
2202 if (trace
->declaration_scope
)
2204 trace
->declaration_scope
= bt_new_declaration_scope(trace
->root_declaration_scope
);
2205 trace
->streams
= g_ptr_array_new();
2206 trace
->event_declarations
= g_ptr_array_new();
2207 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2208 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2212 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2214 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2217 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2219 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2222 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2224 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2228 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2229 /* check that the packet header contains a "magic" field */
2230 if (!trace
->packet_header_decl
2231 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2233 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2240 if (trace
->packet_header_decl
) {
2241 bt_declaration_unref(&trace
->packet_header_decl
->p
);
2242 trace
->packet_header_decl
= NULL
;
2244 g_ptr_array_free(trace
->streams
, TRUE
);
2245 g_ptr_array_free(trace
->event_declarations
, TRUE
);
2246 bt_free_declaration_scope(trace
->declaration_scope
);
2247 trace
->declaration_scope
= NULL
;
2252 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2253 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2257 switch (node
->type
) {
2258 case NODE_CTF_EXPRESSION
:
2262 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2263 if (!strcmp(left
, "name")) {
2266 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2267 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2271 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2273 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2277 clock
->name
= g_quark_from_string(right
);
2279 CTF_CLOCK_SET_FIELD(clock
, name
);
2280 } else if (!strcmp(left
, "uuid")) {
2284 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2288 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2290 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2294 clock
->uuid
= g_quark_from_string(right
);
2296 } else if (!strcmp(left
, "description")) {
2299 if (clock
->description
) {
2300 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2301 goto error
; /* ret is 0, so not an actual error, just warn. */
2303 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2305 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2306 goto error
; /* ret is 0, so not an actual error, just warn. */
2308 clock
->description
= right
;
2309 } else if (!strcmp(left
, "freq")) {
2310 if (CTF_CLOCK_FIELD_IS_SET(clock
, freq
)) {
2311 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2315 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2317 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2321 CTF_CLOCK_SET_FIELD(clock
, freq
);
2322 } else if (!strcmp(left
, "precision")) {
2323 if (clock
->precision
) {
2324 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2328 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2330 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2334 } else if (!strcmp(left
, "offset_s")) {
2335 if (clock
->offset_s
) {
2336 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2340 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2342 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2346 } else if (!strcmp(left
, "offset")) {
2347 if (clock
->offset
) {
2348 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2352 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2354 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2358 } else if (!strcmp(left
, "absolute")) {
2359 struct ctf_node
*right
;
2361 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2362 ret
= get_boolean(fd
, depth
, right
);
2364 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2368 clock
->absolute
= ret
;
2370 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2379 /* TODO: declaration specifier should be added. */
2386 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2389 struct ctf_node
*iter
;
2390 struct ctf_clock
*clock
;
2392 clock
= g_new0(struct ctf_clock
, 1);
2393 /* Default clock frequency is set to 1000000000 */
2394 clock
->freq
= 1000000000ULL;
2395 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2396 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2400 if (opt_clock_force_correlate
) {
2402 * User requested to forcibly correlate the clock
2403 * sources, even if we have no correlation
2406 if (!clock
->absolute
) {
2407 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2409 clock
->absolute
= 1;
2411 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2413 fprintf(fd
, "[error] %s: missing name field in clock declaration\n", __func__
);
2416 if (g_hash_table_size(trace
->clocks
) > 0) {
2417 fprintf(fd
, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
2421 trace
->single_clock
= clock
;
2422 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2426 g_free(clock
->description
);
2432 void ctf_clock_default(FILE *fd
, int depth
, struct ctf_trace
*trace
)
2434 struct ctf_clock
*clock
;
2436 clock
= g_new0(struct ctf_clock
, 1);
2437 clock
->name
= g_quark_from_string("monotonic");
2439 clock
->description
= g_strdup("Default clock");
2440 /* Default clock frequency is set to 1000000000 */
2441 clock
->freq
= 1000000000ULL;
2442 if (opt_clock_force_correlate
) {
2444 * User requested to forcibly correlate the clock
2445 * sources, even if we have no correlatation
2448 if (!clock
->absolute
) {
2449 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2451 clock
->absolute
= 1;
2453 clock
->absolute
= 0; /* Not an absolute reference across traces */
2456 trace
->single_clock
= clock
;
2457 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2461 void clock_free(gpointer data
)
2463 struct ctf_clock
*clock
= data
;
2465 g_free(clock
->description
);
2470 int ctf_callsite_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2471 struct ctf_callsite
*callsite
, struct ctf_trace
*trace
)
2475 switch (node
->type
) {
2476 case NODE_CTF_EXPRESSION
:
2480 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2481 if (!strcmp(left
, "name")) {
2484 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2485 fprintf(fd
, "[error] %s: name already declared in callsite declaration\n", __func__
);
2489 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2491 fprintf(fd
, "[error] %s: unexpected unary expression for callsite name\n", __func__
);
2495 callsite
->name
= g_quark_from_string(right
);
2497 CTF_CALLSITE_SET_FIELD(callsite
, name
);
2498 } else if (!strcmp(left
, "func")) {
2501 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2502 fprintf(fd
, "[error] %s: func already declared in callsite declaration\n", __func__
);
2506 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2508 fprintf(fd
, "[error] %s: unexpected unary expression for callsite func\n", __func__
);
2512 callsite
->func
= right
;
2513 CTF_CALLSITE_SET_FIELD(callsite
, func
);
2514 } else if (!strcmp(left
, "file")) {
2517 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2518 fprintf(fd
, "[error] %s: file already declared in callsite declaration\n", __func__
);
2522 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2524 fprintf(fd
, "[error] %s: unexpected unary expression for callsite file\n", __func__
);
2528 callsite
->file
= right
;
2529 CTF_CALLSITE_SET_FIELD(callsite
, file
);
2530 } else if (!strcmp(left
, "line")) {
2531 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2532 fprintf(fd
, "[error] %s: line already declared in callsite declaration\n", __func__
);
2536 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->line
);
2538 fprintf(fd
, "[error] %s: unexpected unary expression for callsite line\n", __func__
);
2542 CTF_CALLSITE_SET_FIELD(callsite
, line
);
2543 } else if (!strcmp(left
, "ip")) {
2544 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, ip
)) {
2545 fprintf(fd
, "[error] %s: ip already declared in callsite declaration\n", __func__
);
2549 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->ip
);
2551 fprintf(fd
, "[error] %s: unexpected unary expression for callsite ip\n", __func__
);
2555 CTF_CALLSITE_SET_FIELD(callsite
, ip
);
2557 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in callsite declaration.\n", __func__
, left
);
2566 /* TODO: declaration specifier should be added. */
2573 int ctf_callsite_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2576 struct ctf_node
*iter
;
2577 struct ctf_callsite
*callsite
;
2578 struct ctf_callsite_dups
*cs_dups
;
2580 callsite
= g_new0(struct ctf_callsite
, 1);
2581 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
2582 ret
= ctf_callsite_declaration_visit(fd
, depth
+ 1, iter
, callsite
, trace
);
2586 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2588 fprintf(fd
, "[error] %s: missing name field in callsite declaration\n", __func__
);
2591 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2593 fprintf(fd
, "[error] %s: missing func field in callsite declaration\n", __func__
);
2596 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2598 fprintf(fd
, "[error] %s: missing file field in callsite declaration\n", __func__
);
2601 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2603 fprintf(fd
, "[error] %s: missing line field in callsite declaration\n", __func__
);
2607 cs_dups
= g_hash_table_lookup(trace
->callsites
,
2608 (gpointer
) (unsigned long) callsite
->name
);
2610 cs_dups
= g_new0(struct ctf_callsite_dups
, 1);
2611 BT_INIT_LIST_HEAD(&cs_dups
->head
);
2612 g_hash_table_insert(trace
->callsites
,
2613 (gpointer
) (unsigned long) callsite
->name
, cs_dups
);
2615 bt_list_add_tail(&callsite
->node
, &cs_dups
->head
);
2619 g_free(callsite
->func
);
2620 g_free(callsite
->file
);
2626 void callsite_free(gpointer data
)
2628 struct ctf_callsite_dups
*cs_dups
= data
;
2629 struct ctf_callsite
*callsite
, *cs_n
;
2631 bt_list_for_each_entry_safe(callsite
, cs_n
, &cs_dups
->head
, node
) {
2632 g_free(callsite
->func
);
2633 g_free(callsite
->file
);
2640 int ctf_env_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2641 struct ctf_trace
*trace
)
2644 struct ctf_tracer_env
*env
= &trace
->env
;
2646 switch (node
->type
) {
2647 case NODE_CTF_EXPRESSION
:
2651 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2652 if (!strcmp(left
, "vpid")) {
2655 if (env
->vpid
!= -1) {
2656 fprintf(fd
, "[error] %s: vpid already declared in env declaration\n", __func__
);
2657 goto error
; /* ret is 0, so not an actual error, just warn. */
2659 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2661 fprintf(fd
, "[error] %s: unexpected unary expression for env vpid\n", __func__
);
2662 goto error
; /* ret is 0, so not an actual error, just warn. */
2664 env
->vpid
= (int) v
;
2665 printf_verbose("env.vpid = %d\n", env
->vpid
);
2666 } else if (!strcmp(left
, "procname")) {
2669 if (env
->procname
[0]) {
2670 fprintf(fd
, "[warning] %s: duplicated env procname\n", __func__
);
2671 goto error
; /* ret is 0, so not an actual error, just warn. */
2673 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2675 fprintf(fd
, "[warning] %s: unexpected unary expression for env procname\n", __func__
);
2676 goto error
; /* ret is 0, so not an actual error, just warn. */
2678 strncpy(env
->procname
, right
, TRACER_ENV_LEN
);
2679 env
->procname
[TRACER_ENV_LEN
- 1] = '\0';
2680 printf_verbose("env.procname = \"%s\"\n", env
->procname
);
2682 } else if (!strcmp(left
, "hostname")) {
2685 if (env
->hostname
[0]) {
2686 fprintf(fd
, "[warning] %s: duplicated env hostname\n", __func__
);
2687 goto error
; /* ret is 0, so not an actual error, just warn. */
2689 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2691 fprintf(fd
, "[warning] %s: unexpected unary expression for env hostname\n", __func__
);
2692 goto error
; /* ret is 0, so not an actual error, just warn. */
2694 strncpy(env
->hostname
, right
, TRACER_ENV_LEN
);
2695 env
->hostname
[TRACER_ENV_LEN
- 1] = '\0';
2696 printf_verbose("env.hostname = \"%s\"\n", env
->hostname
);
2698 } else if (!strcmp(left
, "domain")) {
2701 if (env
->domain
[0]) {
2702 fprintf(fd
, "[warning] %s: duplicated env domain\n", __func__
);
2703 goto error
; /* ret is 0, so not an actual error, just warn. */
2705 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2707 fprintf(fd
, "[warning] %s: unexpected unary expression for env domain\n", __func__
);
2708 goto error
; /* ret is 0, so not an actual error, just warn. */
2710 strncpy(env
->domain
, right
, TRACER_ENV_LEN
);
2711 env
->domain
[TRACER_ENV_LEN
- 1] = '\0';
2712 printf_verbose("env.domain = \"%s\"\n", env
->domain
);
2714 } else if (!strcmp(left
, "sysname")) {
2717 if (env
->sysname
[0]) {
2718 fprintf(fd
, "[warning] %s: duplicated env sysname\n", __func__
);
2719 goto error
; /* ret is 0, so not an actual error, just warn. */
2721 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2723 fprintf(fd
, "[warning] %s: unexpected unary expression for env sysname\n", __func__
);
2724 goto error
; /* ret is 0, so not an actual error, just warn. */
2726 strncpy(env
->sysname
, right
, TRACER_ENV_LEN
);
2727 env
->sysname
[TRACER_ENV_LEN
- 1] = '\0';
2728 printf_verbose("env.sysname = \"%s\"\n", env
->sysname
);
2730 } else if (!strcmp(left
, "kernel_release")) {
2733 if (env
->release
[0]) {
2734 fprintf(fd
, "[warning] %s: duplicated env release\n", __func__
);
2735 goto error
; /* ret is 0, so not an actual error, just warn. */
2737 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2739 fprintf(fd
, "[warning] %s: unexpected unary expression for env release\n", __func__
);
2740 goto error
; /* ret is 0, so not an actual error, just warn. */
2742 strncpy(env
->release
, right
, TRACER_ENV_LEN
);
2743 env
->release
[TRACER_ENV_LEN
- 1] = '\0';
2744 printf_verbose("env.release = \"%s\"\n", env
->release
);
2746 } else if (!strcmp(left
, "kernel_version")) {
2749 if (env
->version
[0]) {
2750 fprintf(fd
, "[warning] %s: duplicated env version\n", __func__
);
2751 goto error
; /* ret is 0, so not an actual error, just warn. */
2753 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2755 fprintf(fd
, "[warning] %s: unexpected unary expression for env version\n", __func__
);
2756 goto error
; /* ret is 0, so not an actual error, just warn. */
2758 strncpy(env
->version
, right
, TRACER_ENV_LEN
);
2759 env
->version
[TRACER_ENV_LEN
- 1] = '\0';
2760 printf_verbose("env.version = \"%s\"\n", env
->version
);
2763 if (is_unary_string(&node
->u
.ctf_expression
.right
)) {
2766 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2767 printf_verbose("env.%s = \"%s\"\n", left
, right
);
2769 } else if (is_unary_unsigned(&node
->u
.ctf_expression
.right
)) {
2773 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2775 printf_verbose("env.%s = %" PRIu64
"\n", left
, v
);
2776 } else if (is_unary_signed(&node
->u
.ctf_expression
.right
)) {
2780 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &v
);
2782 printf_verbose("env.%s = %" PRId64
"\n", left
, v
);
2784 printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__
, left
);
2800 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2803 struct ctf_node
*iter
;
2805 trace
->env
.vpid
= -1;
2806 trace
->env
.procname
[0] = '\0';
2807 trace
->env
.hostname
[0] = '\0';
2808 trace
->env
.domain
[0] = '\0';
2809 trace
->env
.sysname
[0] = '\0';
2810 trace
->env
.release
[0] = '\0';
2811 trace
->env
.version
[0] = '\0';
2812 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
2813 ret
= ctf_env_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2822 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2826 switch (node
->type
) {
2828 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2829 trace
->root_declaration_scope
,
2830 node
->u
._typedef
.type_specifier_list
,
2831 &node
->u
._typedef
.type_declarators
,
2836 case NODE_TYPEALIAS
:
2837 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2838 trace
->root_declaration_scope
,
2839 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2844 case NODE_TYPE_SPECIFIER_LIST
:
2846 struct bt_declaration
*declaration
;
2849 * Just add the type specifier to the root scope
2850 * declaration scope. Release local reference.
2852 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2853 node
, trace
->root_declaration_scope
, trace
);
2856 bt_declaration_unref(declaration
);
2866 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2867 struct ctf_trace
*trace
, int byte_order
)
2870 struct ctf_node
*iter
;
2871 int env_clock_done
= 0;
2873 printf_verbose("CTF visitor: metadata construction...\n");
2874 trace
->byte_order
= byte_order
;
2875 trace
->clocks
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2877 trace
->callsites
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2878 NULL
, callsite_free
);
2881 trace
->root_declaration_scope
= bt_new_declaration_scope(NULL
);
2883 switch (node
->type
) {
2885 if (!env_clock_done
) {
2887 * declarations need to query clock hash table,
2888 * so clock need to be treated first.
2890 if (bt_list_empty(&node
->u
.root
.clock
)) {
2891 ctf_clock_default(fd
, depth
+ 1, trace
);
2893 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2894 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2897 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2904 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2906 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2908 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
2912 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
2913 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
2914 if (ret
== -EINTR
) {
2915 bt_free_declaration_scope(trace
->root_declaration_scope
);
2917 * Need to restart creation of type
2918 * definitions, aliases and
2919 * trace header declarations.
2924 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
2928 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
2929 ret
= ctf_callsite_visit(fd
, depth
+ 1, iter
,
2932 fprintf(fd
, "[error] %s: callsite declaration error\n", __func__
);
2936 if (!trace
->streams
) {
2937 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
2941 bt_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
2942 ret
= ctf_env_visit(fd
, depth
+ 1, iter
, trace
);
2944 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
2948 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
2949 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
2950 trace
->root_declaration_scope
, trace
);
2952 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
2956 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
2957 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
2958 trace
->root_declaration_scope
, trace
);
2960 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
2967 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
2972 printf_verbose("done.\n");
2976 bt_free_declaration_scope(trace
->root_declaration_scope
);
2977 g_hash_table_destroy(trace
->callsites
);
2978 g_hash_table_destroy(trace
->clocks
);
2982 int ctf_destroy_metadata(struct ctf_trace
*trace
)
2985 struct ctf_file_stream
*metadata_stream
;
2987 if (trace
->streams
) {
2988 for (i
= 0; i
< trace
->streams
->len
; i
++) {
2989 struct ctf_stream_declaration
*stream
;
2992 stream
= g_ptr_array_index(trace
->streams
, i
);
2995 for (j
= 0; j
< stream
->streams
->len
; j
++) {
2996 struct ctf_stream_definition
*stream_def
;
2999 stream_def
= g_ptr_array_index(stream
->streams
, j
);
3002 for (k
= 0; k
< stream_def
->events_by_id
->len
; k
++) {
3003 struct ctf_event_definition
*event
;
3005 event
= g_ptr_array_index(stream_def
->events_by_id
, k
);
3008 if (&event
->event_fields
->p
)
3009 bt_definition_unref(&event
->event_fields
->p
);
3010 if (&event
->event_context
->p
)
3011 bt_definition_unref(&event
->event_context
->p
);
3014 if (&stream_def
->trace_packet_header
->p
)
3015 bt_definition_unref(&stream_def
->trace_packet_header
->p
);
3016 if (&stream_def
->stream_event_header
->p
)
3017 bt_definition_unref(&stream_def
->stream_event_header
->p
);
3018 if (&stream_def
->stream_packet_context
->p
)
3019 bt_definition_unref(&stream_def
->stream_packet_context
->p
);
3020 if (&stream_def
->stream_event_context
->p
)
3021 bt_definition_unref(&stream_def
->stream_event_context
->p
);
3022 g_ptr_array_free(stream_def
->events_by_id
, TRUE
);
3025 if (stream
->event_header_decl
)
3026 bt_declaration_unref(&stream
->event_header_decl
->p
);
3027 if (stream
->event_context_decl
)
3028 bt_declaration_unref(&stream
->event_context_decl
->p
);
3029 if (stream
->packet_context_decl
)
3030 bt_declaration_unref(&stream
->packet_context_decl
->p
);
3031 g_ptr_array_free(stream
->streams
, TRUE
);
3032 g_ptr_array_free(stream
->events_by_id
, TRUE
);
3033 g_hash_table_destroy(stream
->event_quark_to_id
);
3034 bt_free_declaration_scope(stream
->declaration_scope
);
3037 g_ptr_array_free(trace
->streams
, TRUE
);
3040 if (trace
->event_declarations
) {
3041 for (i
= 0; i
< trace
->event_declarations
->len
; i
++) {
3042 struct bt_ctf_event_decl
*event_decl
;
3043 struct ctf_event_declaration
*event
;
3045 event_decl
= g_ptr_array_index(trace
->event_declarations
, i
);
3046 if (event_decl
->context_decl
)
3047 g_ptr_array_free(event_decl
->context_decl
, TRUE
);
3048 if (event_decl
->fields_decl
)
3049 g_ptr_array_free(event_decl
->fields_decl
, TRUE
);
3050 if (event_decl
->packet_header_decl
)
3051 g_ptr_array_free(event_decl
->packet_header_decl
, TRUE
);
3052 if (event_decl
->event_context_decl
)
3053 g_ptr_array_free(event_decl
->event_context_decl
, TRUE
);
3054 if (event_decl
->event_header_decl
)
3055 g_ptr_array_free(event_decl
->event_header_decl
, TRUE
);
3056 if (event_decl
->packet_context_decl
)
3057 g_ptr_array_free(event_decl
->packet_context_decl
, TRUE
);
3059 event
= &event_decl
->parent
;
3060 if (event
->fields_decl
)
3061 bt_declaration_unref(&event
->fields_decl
->p
);
3062 if (event
->context_decl
)
3063 bt_declaration_unref(&event
->context_decl
->p
);
3064 bt_free_declaration_scope(event
->declaration_scope
);
3068 g_ptr_array_free(trace
->event_declarations
, TRUE
);
3070 if (trace
->packet_header_decl
)
3071 bt_declaration_unref(&trace
->packet_header_decl
->p
);
3073 bt_free_declaration_scope(trace
->root_declaration_scope
);
3074 bt_free_declaration_scope(trace
->declaration_scope
);
3076 g_hash_table_destroy(trace
->callsites
);
3077 g_hash_table_destroy(trace
->clocks
);
3079 metadata_stream
= container_of(trace
->metadata
, struct ctf_file_stream
, parent
);
3080 g_free(metadata_stream
);