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
);
1162 (void) g_string_free(str
, TRUE
);
1165 str_c
= g_string_free(str
, FALSE
);
1166 id_q
= g_quark_from_string(str_c
);
1168 declaration
= bt_lookup_declaration(id_q
, declaration_scope
);
1171 bt_declaration_ref(declaration
);
1176 * Returns 0/1 boolean, or < 0 on error.
1179 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1181 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1182 fprintf(fd
, "[error] %s: expecting unary expression\n",
1186 switch (unary_expression
->u
.unary_expression
.type
) {
1187 case UNARY_UNSIGNED_CONSTANT
:
1188 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1192 case UNARY_SIGNED_CONSTANT
:
1193 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1198 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1200 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1202 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1204 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1207 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1208 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1213 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1221 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1225 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1226 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1230 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1231 byte_order
= BIG_ENDIAN
;
1232 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1233 byte_order
= LITTLE_ENDIAN
;
1235 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
1236 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1243 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1244 struct ctf_trace
*trace
)
1248 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1249 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1253 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1254 byte_order
= trace
->byte_order
;
1255 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1256 byte_order
= BIG_ENDIAN
;
1257 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1258 byte_order
= BIG_ENDIAN
;
1259 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1260 byte_order
= LITTLE_ENDIAN
;
1262 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1263 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1270 struct bt_declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1271 struct bt_list_head
*expressions
,
1272 struct ctf_trace
*trace
)
1274 struct ctf_node
*expression
;
1275 uint64_t alignment
= 1, size
= 0;
1276 int byte_order
= trace
->byte_order
;
1278 int has_alignment
= 0, has_size
= 0;
1280 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1281 struct ctf_clock
*clock
= NULL
;
1282 struct declaration_integer
*integer_declaration
;
1284 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1285 struct ctf_node
*left
, *right
;
1287 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1288 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1289 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1290 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1291 signedness
= get_boolean(fd
, depth
, right
);
1294 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1295 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1298 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1299 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1300 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1304 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1306 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1307 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1308 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1312 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1313 /* Make sure alignment is a power of two */
1314 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1315 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1320 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1321 switch (right
->u
.unary_expression
.type
) {
1322 case UNARY_UNSIGNED_CONSTANT
:
1323 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1328 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1331 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1332 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1338 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1340 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1344 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1345 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1347 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1348 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1349 || !strcmp(s_right
, "p")) {
1351 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1352 || !strcmp(s_right
, "o")) {
1354 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1357 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1366 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1370 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1373 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1374 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1378 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1380 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1384 if (!strcmp(s_right
, "UTF8")
1385 || !strcmp(s_right
, "utf8")
1386 || !strcmp(s_right
, "utf-8")
1387 || !strcmp(s_right
, "UTF-8"))
1388 encoding
= CTF_STRING_UTF8
;
1389 else if (!strcmp(s_right
, "ASCII")
1390 || !strcmp(s_right
, "ascii"))
1391 encoding
= CTF_STRING_ASCII
;
1392 else if (!strcmp(s_right
, "none"))
1393 encoding
= CTF_STRING_NONE
;
1395 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1400 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1403 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1404 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1408 /* currently only support clock.name.value */
1409 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1413 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1415 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1419 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1424 clock
= trace_clock_lookup(trace
, clock_name
);
1426 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1427 __func__
, g_quark_to_string(clock_name
));
1431 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1432 __func__
, left
->u
.unary_expression
.u
.string
);
1433 /* Fall-through after warning */
1437 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1440 if (!has_alignment
) {
1441 if (size
% CHAR_BIT
) {
1442 /* bit-packed alignment */
1445 /* byte-packed alignment */
1446 alignment
= CHAR_BIT
;
1449 integer_declaration
= bt_integer_declaration_new(size
,
1450 byte_order
, signedness
, alignment
,
1451 base
, encoding
, clock
);
1452 return &integer_declaration
->p
;
1456 struct bt_declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1457 struct bt_list_head
*expressions
,
1458 struct ctf_trace
*trace
)
1460 struct ctf_node
*expression
;
1461 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0,
1462 byte_order
= trace
->byte_order
;
1463 int has_alignment
= 0, has_exp_dig
= 0, has_mant_dig
= 0;
1464 struct declaration_float
*float_declaration
;
1466 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1467 struct ctf_node
*left
, *right
;
1469 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1470 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1471 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1472 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1473 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1476 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1477 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1478 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1482 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1484 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1485 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1486 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1490 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1492 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1493 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1494 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1498 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1499 /* Make sure alignment is a power of two */
1500 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1501 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1507 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1508 __func__
, left
->u
.unary_expression
.u
.string
);
1509 /* Fall-through after warning */
1512 if (!has_mant_dig
) {
1513 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1517 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1520 if (!has_alignment
) {
1521 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1522 /* bit-packed alignment */
1525 /* byte-packed alignment */
1526 alignment
= CHAR_BIT
;
1529 float_declaration
= bt_float_declaration_new(mant_dig
, exp_dig
,
1530 byte_order
, alignment
);
1531 return &float_declaration
->p
;
1535 struct bt_declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1536 struct bt_list_head
*expressions
,
1537 struct ctf_trace
*trace
)
1539 struct ctf_node
*expression
;
1540 const char *encoding_c
= NULL
;
1541 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1542 struct declaration_string
*string_declaration
;
1544 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1545 struct ctf_node
*left
, *right
;
1547 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1548 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1549 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1550 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1551 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1552 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1556 encoding_c
= right
->u
.unary_expression
.u
.string
;
1558 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1559 __func__
, left
->u
.unary_expression
.u
.string
);
1560 /* Fall-through after warning */
1563 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1564 encoding
= CTF_STRING_ASCII
;
1565 string_declaration
= bt_string_declaration_new(encoding
);
1566 return &string_declaration
->p
;
1571 struct bt_declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1572 int depth
, struct ctf_node
*type_specifier_list
,
1573 struct declaration_scope
*declaration_scope
,
1574 struct ctf_trace
*trace
)
1576 struct ctf_node
*first
;
1577 struct ctf_node
*node
;
1579 assert(type_specifier_list
->type
== NODE_TYPE_SPECIFIER_LIST
);
1581 first
= _bt_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1583 assert(first
->type
== NODE_TYPE_SPECIFIER
);
1585 node
= first
->u
.type_specifier
.node
;
1587 switch (first
->u
.type_specifier
.type
) {
1588 case TYPESPEC_FLOATING_POINT
:
1589 return ctf_declaration_floating_point_visit(fd
, depth
,
1590 &node
->u
.floating_point
.expressions
, trace
);
1591 case TYPESPEC_INTEGER
:
1592 return ctf_declaration_integer_visit(fd
, depth
,
1593 &node
->u
.integer
.expressions
, trace
);
1594 case TYPESPEC_STRING
:
1595 return ctf_declaration_string_visit(fd
, depth
,
1596 &node
->u
.string
.expressions
, trace
);
1597 case TYPESPEC_STRUCT
:
1598 return ctf_declaration_struct_visit(fd
, depth
,
1599 node
->u
._struct
.name
,
1600 &node
->u
._struct
.declaration_list
,
1601 node
->u
._struct
.has_body
,
1602 &node
->u
._struct
.min_align
,
1605 case TYPESPEC_VARIANT
:
1606 return ctf_declaration_variant_visit(fd
, depth
,
1607 node
->u
.variant
.name
,
1608 node
->u
.variant
.choice
,
1609 &node
->u
.variant
.declaration_list
,
1610 node
->u
.variant
.has_body
,
1614 return ctf_declaration_enum_visit(fd
, depth
,
1615 node
->u
._enum
.enum_id
,
1616 node
->u
._enum
.container_type
,
1617 &node
->u
._enum
.enumerator_list
,
1618 node
->u
._enum
.has_body
,
1624 case TYPESPEC_SHORT
:
1627 case TYPESPEC_FLOAT
:
1628 case TYPESPEC_DOUBLE
:
1629 case TYPESPEC_SIGNED
:
1630 case TYPESPEC_UNSIGNED
:
1632 case TYPESPEC_COMPLEX
:
1633 case TYPESPEC_IMAGINARY
:
1634 case TYPESPEC_CONST
:
1635 case TYPESPEC_ID_TYPE
:
1636 return ctf_declaration_type_specifier_visit(fd
, depth
,
1637 type_specifier_list
, declaration_scope
);
1639 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1645 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event_declaration
*event
, struct ctf_trace
*trace
)
1649 switch (node
->type
) {
1651 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1652 event
->declaration_scope
,
1653 node
->u
._typedef
.type_specifier_list
,
1654 &node
->u
._typedef
.type_declarators
,
1659 case NODE_TYPEALIAS
:
1660 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1661 event
->declaration_scope
,
1662 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1667 case NODE_CTF_EXPRESSION
:
1671 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1672 if (!strcmp(left
, "name")) {
1675 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1676 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1680 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1682 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1686 event
->name
= g_quark_from_string(right
);
1688 CTF_EVENT_SET_FIELD(event
, name
);
1689 } else if (!strcmp(left
, "id")) {
1690 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1691 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1695 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1697 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1701 CTF_EVENT_SET_FIELD(event
, id
);
1702 } else if (!strcmp(left
, "stream_id")) {
1703 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1704 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1708 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1710 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1714 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1715 if (!event
->stream
) {
1716 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1720 CTF_EVENT_SET_FIELD(event
, stream_id
);
1721 } else if (!strcmp(left
, "context")) {
1722 struct bt_declaration
*declaration
;
1724 if (event
->context_decl
) {
1725 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1729 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1730 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1731 struct ctf_node
, siblings
),
1732 event
->declaration_scope
, trace
);
1737 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1741 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1742 } else if (!strcmp(left
, "fields")) {
1743 struct bt_declaration
*declaration
;
1745 if (event
->fields_decl
) {
1746 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1750 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1751 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1752 struct ctf_node
, siblings
),
1753 event
->declaration_scope
, trace
);
1758 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1762 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1763 } else if (!strcmp(left
, "loglevel")) {
1764 int64_t loglevel
= -1;
1766 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel
)) {
1767 fprintf(fd
, "[error] %s: loglevel already declared in event declaration\n", __func__
);
1771 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &loglevel
);
1773 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel\n", __func__
);
1777 event
->loglevel
= (int) loglevel
;
1778 CTF_EVENT_SET_FIELD(event
, loglevel
);
1779 } else if (!strcmp(left
, "model.emf.uri")) {
1782 if (CTF_EVENT_FIELD_IS_SET(event
, model_emf_uri
)) {
1783 fprintf(fd
, "[error] %s: model.emf.uri already declared in event declaration\n", __func__
);
1787 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1789 fprintf(fd
, "[error] %s: unexpected unary expression for event model.emf.uri\n", __func__
);
1793 event
->model_emf_uri
= g_quark_from_string(right
);
1795 CTF_EVENT_SET_FIELD(event
, model_emf_uri
);
1797 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1798 /* Fall-through after warning */
1806 /* TODO: declaration specifier should be added. */
1813 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1814 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1817 struct ctf_node
*iter
;
1818 struct ctf_event_declaration
*event
;
1819 struct bt_ctf_event_decl
*event_decl
;
1821 event_decl
= g_new0(struct bt_ctf_event_decl
, 1);
1822 event
= &event_decl
->parent
;
1823 event
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
1824 event
->loglevel
= -1;
1825 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1826 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1830 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1832 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1835 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1836 /* Allow missing stream_id if there is only a single stream */
1837 switch (trace
->streams
->len
) {
1838 case 0: /* Create stream if there was none. */
1839 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1844 event
->stream_id
= 0;
1845 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1849 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1853 /* Allow only one event without id per stream */
1854 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1855 && event
->stream
->events_by_id
->len
!= 0) {
1857 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1860 if (event
->stream
->events_by_id
->len
<= event
->id
)
1861 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1862 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1863 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1864 (gpointer
) (unsigned long) event
->name
,
1866 g_ptr_array_add(trace
->event_declarations
, event_decl
);
1870 if (event
->fields_decl
)
1871 bt_declaration_unref(&event
->fields_decl
->p
);
1872 if (event
->context_decl
)
1873 bt_declaration_unref(&event
->context_decl
->p
);
1874 bt_free_declaration_scope(event
->declaration_scope
);
1881 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_declaration
*stream
, struct ctf_trace
*trace
)
1885 switch (node
->type
) {
1887 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1888 stream
->declaration_scope
,
1889 node
->u
._typedef
.type_specifier_list
,
1890 &node
->u
._typedef
.type_declarators
,
1895 case NODE_TYPEALIAS
:
1896 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1897 stream
->declaration_scope
,
1898 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1903 case NODE_CTF_EXPRESSION
:
1907 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1908 if (!strcmp(left
, "id")) {
1909 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1910 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1914 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1916 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1920 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1921 } else if (!strcmp(left
, "event.header")) {
1922 struct bt_declaration
*declaration
;
1924 if (stream
->event_header_decl
) {
1925 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1929 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1930 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1931 struct ctf_node
, siblings
),
1932 stream
->declaration_scope
, trace
);
1937 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1941 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1942 } else if (!strcmp(left
, "event.context")) {
1943 struct bt_declaration
*declaration
;
1945 if (stream
->event_context_decl
) {
1946 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1950 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1951 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1952 struct ctf_node
, siblings
),
1953 stream
->declaration_scope
, trace
);
1958 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1962 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1963 } else if (!strcmp(left
, "packet.context")) {
1964 struct bt_declaration
*declaration
;
1966 if (stream
->packet_context_decl
) {
1967 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
1971 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1972 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1973 struct ctf_node
, siblings
),
1974 stream
->declaration_scope
, trace
);
1979 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1983 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1985 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
1986 /* Fall-through after warning */
1995 /* TODO: declaration specifier should be added. */
2002 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2003 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
2006 struct ctf_node
*iter
;
2007 struct ctf_stream_declaration
*stream
;
2009 stream
= g_new0(struct ctf_stream_declaration
, 1);
2010 stream
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
2011 stream
->events_by_id
= g_ptr_array_new();
2012 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2013 stream
->streams
= g_ptr_array_new();
2015 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
2016 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
2021 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
2022 /* check that packet header has stream_id field. */
2023 if (!trace
->packet_header_decl
2024 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
2026 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
2030 /* Allow only one id-less stream */
2031 if (trace
->streams
->len
!= 0) {
2033 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
2036 stream
->stream_id
= 0;
2038 if (trace
->streams
->len
<= stream
->stream_id
)
2039 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
2040 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
2041 stream
->trace
= trace
;
2046 if (stream
->event_header_decl
)
2047 bt_declaration_unref(&stream
->event_header_decl
->p
);
2048 if (stream
->event_context_decl
)
2049 bt_declaration_unref(&stream
->event_context_decl
->p
);
2050 if (stream
->packet_context_decl
)
2051 bt_declaration_unref(&stream
->packet_context_decl
->p
);
2052 g_ptr_array_free(stream
->streams
, TRUE
);
2053 g_ptr_array_free(stream
->events_by_id
, TRUE
);
2054 g_hash_table_destroy(stream
->event_quark_to_id
);
2055 bt_free_declaration_scope(stream
->declaration_scope
);
2061 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2065 switch (node
->type
) {
2067 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2068 trace
->declaration_scope
,
2069 node
->u
._typedef
.type_specifier_list
,
2070 &node
->u
._typedef
.type_declarators
,
2075 case NODE_TYPEALIAS
:
2076 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2077 trace
->declaration_scope
,
2078 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2083 case NODE_CTF_EXPRESSION
:
2087 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2088 if (!strcmp(left
, "major")) {
2089 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2090 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
2094 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
2096 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
2100 CTF_TRACE_SET_FIELD(trace
, major
);
2101 } else if (!strcmp(left
, "minor")) {
2102 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2103 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
2107 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
2109 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
2113 CTF_TRACE_SET_FIELD(trace
, minor
);
2114 } else if (!strcmp(left
, "uuid")) {
2115 unsigned char uuid
[BABELTRACE_UUID_LEN
];
2117 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, uuid
);
2119 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2123 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2124 && babeltrace_uuid_compare(uuid
, trace
->uuid
)) {
2125 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2129 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2131 CTF_TRACE_SET_FIELD(trace
, uuid
);
2132 } else if (!strcmp(left
, "byte_order")) {
2133 struct ctf_node
*right
;
2136 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2137 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2141 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2142 && byte_order
!= trace
->byte_order
) {
2143 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2147 if (byte_order
!= trace
->byte_order
) {
2148 trace
->byte_order
= byte_order
;
2150 * We need to restart
2151 * construction of the
2152 * intermediate representation.
2154 trace
->field_mask
= 0;
2155 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2160 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2161 } else if (!strcmp(left
, "packet.header")) {
2162 struct bt_declaration
*declaration
;
2164 if (trace
->packet_header_decl
) {
2165 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2169 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2170 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2171 struct ctf_node
, siblings
),
2172 trace
->declaration_scope
, trace
);
2177 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2181 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2183 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2192 /* TODO: declaration specifier should be added. */
2199 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2202 struct ctf_node
*iter
;
2204 if (trace
->declaration_scope
)
2206 trace
->declaration_scope
= bt_new_declaration_scope(trace
->root_declaration_scope
);
2207 trace
->streams
= g_ptr_array_new();
2208 trace
->event_declarations
= g_ptr_array_new();
2209 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2210 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2214 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2216 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2219 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2221 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2224 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2226 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2230 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2231 /* check that the packet header contains a "magic" field */
2232 if (!trace
->packet_header_decl
2233 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2235 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2242 if (trace
->packet_header_decl
) {
2243 bt_declaration_unref(&trace
->packet_header_decl
->p
);
2244 trace
->packet_header_decl
= NULL
;
2246 g_ptr_array_free(trace
->streams
, TRUE
);
2247 g_ptr_array_free(trace
->event_declarations
, TRUE
);
2248 bt_free_declaration_scope(trace
->declaration_scope
);
2249 trace
->declaration_scope
= NULL
;
2254 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2255 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2259 switch (node
->type
) {
2260 case NODE_CTF_EXPRESSION
:
2264 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2265 if (!strcmp(left
, "name")) {
2268 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2269 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2273 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2275 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2279 clock
->name
= g_quark_from_string(right
);
2281 CTF_CLOCK_SET_FIELD(clock
, name
);
2282 } else if (!strcmp(left
, "uuid")) {
2286 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2290 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2292 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2296 clock
->uuid
= g_quark_from_string(right
);
2298 } else if (!strcmp(left
, "description")) {
2301 if (clock
->description
) {
2302 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2303 goto error
; /* ret is 0, so not an actual error, just warn. */
2305 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2307 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2308 goto error
; /* ret is 0, so not an actual error, just warn. */
2310 clock
->description
= right
;
2311 } else if (!strcmp(left
, "freq")) {
2312 if (CTF_CLOCK_FIELD_IS_SET(clock
, freq
)) {
2313 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2317 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2319 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2323 CTF_CLOCK_SET_FIELD(clock
, freq
);
2324 } else if (!strcmp(left
, "precision")) {
2325 if (clock
->precision
) {
2326 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2330 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2332 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2336 } else if (!strcmp(left
, "offset_s")) {
2337 if (clock
->offset_s
) {
2338 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2342 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2344 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2348 } else if (!strcmp(left
, "offset")) {
2349 if (clock
->offset
) {
2350 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2354 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2356 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2360 } else if (!strcmp(left
, "absolute")) {
2361 struct ctf_node
*right
;
2363 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2364 ret
= get_boolean(fd
, depth
, right
);
2366 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2370 clock
->absolute
= ret
;
2372 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2381 /* TODO: declaration specifier should be added. */
2388 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2391 struct ctf_node
*iter
;
2392 struct ctf_clock
*clock
;
2394 clock
= g_new0(struct ctf_clock
, 1);
2395 /* Default clock frequency is set to 1000000000 */
2396 clock
->freq
= 1000000000ULL;
2397 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2398 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2402 if (opt_clock_force_correlate
) {
2404 * User requested to forcibly correlate the clock
2405 * sources, even if we have no correlation
2408 if (!clock
->absolute
) {
2409 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2411 clock
->absolute
= 1;
2413 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2415 fprintf(fd
, "[error] %s: missing name field in clock declaration\n", __func__
);
2418 if (g_hash_table_size(trace
->clocks
) > 0) {
2419 fprintf(fd
, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
2423 trace
->single_clock
= clock
;
2424 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2428 g_free(clock
->description
);
2434 void ctf_clock_default(FILE *fd
, int depth
, struct ctf_trace
*trace
)
2436 struct ctf_clock
*clock
;
2438 clock
= g_new0(struct ctf_clock
, 1);
2439 clock
->name
= g_quark_from_string("monotonic");
2441 clock
->description
= g_strdup("Default clock");
2442 /* Default clock frequency is set to 1000000000 */
2443 clock
->freq
= 1000000000ULL;
2444 if (opt_clock_force_correlate
) {
2446 * User requested to forcibly correlate the clock
2447 * sources, even if we have no correlatation
2450 if (!clock
->absolute
) {
2451 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2453 clock
->absolute
= 1;
2455 clock
->absolute
= 0; /* Not an absolute reference across traces */
2458 trace
->single_clock
= clock
;
2459 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2463 void clock_free(gpointer data
)
2465 struct ctf_clock
*clock
= data
;
2467 g_free(clock
->description
);
2472 int ctf_callsite_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2473 struct ctf_callsite
*callsite
, struct ctf_trace
*trace
)
2477 switch (node
->type
) {
2478 case NODE_CTF_EXPRESSION
:
2482 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2483 if (!strcmp(left
, "name")) {
2486 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2487 fprintf(fd
, "[error] %s: name already declared in callsite declaration\n", __func__
);
2491 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2493 fprintf(fd
, "[error] %s: unexpected unary expression for callsite name\n", __func__
);
2497 callsite
->name
= g_quark_from_string(right
);
2499 CTF_CALLSITE_SET_FIELD(callsite
, name
);
2500 } else if (!strcmp(left
, "func")) {
2503 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2504 fprintf(fd
, "[error] %s: func already declared in callsite declaration\n", __func__
);
2508 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2510 fprintf(fd
, "[error] %s: unexpected unary expression for callsite func\n", __func__
);
2514 callsite
->func
= right
;
2515 CTF_CALLSITE_SET_FIELD(callsite
, func
);
2516 } else if (!strcmp(left
, "file")) {
2519 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2520 fprintf(fd
, "[error] %s: file already declared in callsite declaration\n", __func__
);
2524 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2526 fprintf(fd
, "[error] %s: unexpected unary expression for callsite file\n", __func__
);
2530 callsite
->file
= right
;
2531 CTF_CALLSITE_SET_FIELD(callsite
, file
);
2532 } else if (!strcmp(left
, "line")) {
2533 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2534 fprintf(fd
, "[error] %s: line already declared in callsite declaration\n", __func__
);
2538 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->line
);
2540 fprintf(fd
, "[error] %s: unexpected unary expression for callsite line\n", __func__
);
2544 CTF_CALLSITE_SET_FIELD(callsite
, line
);
2545 } else if (!strcmp(left
, "ip")) {
2546 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, ip
)) {
2547 fprintf(fd
, "[error] %s: ip already declared in callsite declaration\n", __func__
);
2551 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->ip
);
2553 fprintf(fd
, "[error] %s: unexpected unary expression for callsite ip\n", __func__
);
2557 CTF_CALLSITE_SET_FIELD(callsite
, ip
);
2559 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in callsite declaration.\n", __func__
, left
);
2568 /* TODO: declaration specifier should be added. */
2575 int ctf_callsite_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2578 struct ctf_node
*iter
;
2579 struct ctf_callsite
*callsite
;
2580 struct ctf_callsite_dups
*cs_dups
;
2582 callsite
= g_new0(struct ctf_callsite
, 1);
2583 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
2584 ret
= ctf_callsite_declaration_visit(fd
, depth
+ 1, iter
, callsite
, trace
);
2588 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2590 fprintf(fd
, "[error] %s: missing name field in callsite declaration\n", __func__
);
2593 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2595 fprintf(fd
, "[error] %s: missing func field in callsite declaration\n", __func__
);
2598 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2600 fprintf(fd
, "[error] %s: missing file field in callsite declaration\n", __func__
);
2603 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2605 fprintf(fd
, "[error] %s: missing line field in callsite declaration\n", __func__
);
2609 cs_dups
= g_hash_table_lookup(trace
->callsites
,
2610 (gpointer
) (unsigned long) callsite
->name
);
2612 cs_dups
= g_new0(struct ctf_callsite_dups
, 1);
2613 BT_INIT_LIST_HEAD(&cs_dups
->head
);
2614 g_hash_table_insert(trace
->callsites
,
2615 (gpointer
) (unsigned long) callsite
->name
, cs_dups
);
2617 bt_list_add_tail(&callsite
->node
, &cs_dups
->head
);
2621 g_free(callsite
->func
);
2622 g_free(callsite
->file
);
2628 void callsite_free(gpointer data
)
2630 struct ctf_callsite_dups
*cs_dups
= data
;
2631 struct ctf_callsite
*callsite
, *cs_n
;
2633 bt_list_for_each_entry_safe(callsite
, cs_n
, &cs_dups
->head
, node
) {
2634 g_free(callsite
->func
);
2635 g_free(callsite
->file
);
2642 int ctf_env_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2643 struct ctf_trace
*trace
)
2646 struct ctf_tracer_env
*env
= &trace
->env
;
2648 switch (node
->type
) {
2649 case NODE_CTF_EXPRESSION
:
2653 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2654 if (!strcmp(left
, "vpid")) {
2657 if (env
->vpid
!= -1) {
2658 fprintf(fd
, "[error] %s: vpid already declared in env declaration\n", __func__
);
2659 goto error
; /* ret is 0, so not an actual error, just warn. */
2661 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2663 fprintf(fd
, "[error] %s: unexpected unary expression for env vpid\n", __func__
);
2664 goto error
; /* ret is 0, so not an actual error, just warn. */
2666 env
->vpid
= (int) v
;
2667 printf_verbose("env.vpid = %d\n", env
->vpid
);
2668 } else if (!strcmp(left
, "procname")) {
2671 if (env
->procname
[0]) {
2672 fprintf(fd
, "[warning] %s: duplicated env procname\n", __func__
);
2673 goto error
; /* ret is 0, so not an actual error, just warn. */
2675 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2677 fprintf(fd
, "[warning] %s: unexpected unary expression for env procname\n", __func__
);
2678 goto error
; /* ret is 0, so not an actual error, just warn. */
2680 strncpy(env
->procname
, right
, TRACER_ENV_LEN
);
2681 env
->procname
[TRACER_ENV_LEN
- 1] = '\0';
2682 printf_verbose("env.procname = \"%s\"\n", env
->procname
);
2684 } else if (!strcmp(left
, "hostname")) {
2687 if (env
->hostname
[0]) {
2688 fprintf(fd
, "[warning] %s: duplicated env hostname\n", __func__
);
2689 goto error
; /* ret is 0, so not an actual error, just warn. */
2691 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2693 fprintf(fd
, "[warning] %s: unexpected unary expression for env hostname\n", __func__
);
2694 goto error
; /* ret is 0, so not an actual error, just warn. */
2696 strncpy(env
->hostname
, right
, TRACER_ENV_LEN
);
2697 env
->hostname
[TRACER_ENV_LEN
- 1] = '\0';
2698 printf_verbose("env.hostname = \"%s\"\n", env
->hostname
);
2700 } else if (!strcmp(left
, "domain")) {
2703 if (env
->domain
[0]) {
2704 fprintf(fd
, "[warning] %s: duplicated env domain\n", __func__
);
2705 goto error
; /* ret is 0, so not an actual error, just warn. */
2707 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2709 fprintf(fd
, "[warning] %s: unexpected unary expression for env domain\n", __func__
);
2710 goto error
; /* ret is 0, so not an actual error, just warn. */
2712 strncpy(env
->domain
, right
, TRACER_ENV_LEN
);
2713 env
->domain
[TRACER_ENV_LEN
- 1] = '\0';
2714 printf_verbose("env.domain = \"%s\"\n", env
->domain
);
2716 } else if (!strcmp(left
, "sysname")) {
2719 if (env
->sysname
[0]) {
2720 fprintf(fd
, "[warning] %s: duplicated env sysname\n", __func__
);
2721 goto error
; /* ret is 0, so not an actual error, just warn. */
2723 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2725 fprintf(fd
, "[warning] %s: unexpected unary expression for env sysname\n", __func__
);
2726 goto error
; /* ret is 0, so not an actual error, just warn. */
2728 strncpy(env
->sysname
, right
, TRACER_ENV_LEN
);
2729 env
->sysname
[TRACER_ENV_LEN
- 1] = '\0';
2730 printf_verbose("env.sysname = \"%s\"\n", env
->sysname
);
2732 } else if (!strcmp(left
, "kernel_release")) {
2735 if (env
->release
[0]) {
2736 fprintf(fd
, "[warning] %s: duplicated env release\n", __func__
);
2737 goto error
; /* ret is 0, so not an actual error, just warn. */
2739 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2741 fprintf(fd
, "[warning] %s: unexpected unary expression for env release\n", __func__
);
2742 goto error
; /* ret is 0, so not an actual error, just warn. */
2744 strncpy(env
->release
, right
, TRACER_ENV_LEN
);
2745 env
->release
[TRACER_ENV_LEN
- 1] = '\0';
2746 printf_verbose("env.release = \"%s\"\n", env
->release
);
2748 } else if (!strcmp(left
, "kernel_version")) {
2751 if (env
->version
[0]) {
2752 fprintf(fd
, "[warning] %s: duplicated env version\n", __func__
);
2753 goto error
; /* ret is 0, so not an actual error, just warn. */
2755 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2757 fprintf(fd
, "[warning] %s: unexpected unary expression for env version\n", __func__
);
2758 goto error
; /* ret is 0, so not an actual error, just warn. */
2760 strncpy(env
->version
, right
, TRACER_ENV_LEN
);
2761 env
->version
[TRACER_ENV_LEN
- 1] = '\0';
2762 printf_verbose("env.version = \"%s\"\n", env
->version
);
2765 if (is_unary_string(&node
->u
.ctf_expression
.right
)) {
2768 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2769 printf_verbose("env.%s = \"%s\"\n", left
, right
);
2771 } else if (is_unary_unsigned(&node
->u
.ctf_expression
.right
)) {
2775 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2777 printf_verbose("env.%s = %" PRIu64
"\n", left
, v
);
2778 } else if (is_unary_signed(&node
->u
.ctf_expression
.right
)) {
2782 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &v
);
2784 printf_verbose("env.%s = %" PRId64
"\n", left
, v
);
2786 printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__
, left
);
2802 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2805 struct ctf_node
*iter
;
2807 trace
->env
.vpid
= -1;
2808 trace
->env
.procname
[0] = '\0';
2809 trace
->env
.hostname
[0] = '\0';
2810 trace
->env
.domain
[0] = '\0';
2811 trace
->env
.sysname
[0] = '\0';
2812 trace
->env
.release
[0] = '\0';
2813 trace
->env
.version
[0] = '\0';
2814 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
2815 ret
= ctf_env_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2824 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2828 switch (node
->type
) {
2830 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2831 trace
->root_declaration_scope
,
2832 node
->u
._typedef
.type_specifier_list
,
2833 &node
->u
._typedef
.type_declarators
,
2838 case NODE_TYPEALIAS
:
2839 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2840 trace
->root_declaration_scope
,
2841 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2846 case NODE_TYPE_SPECIFIER_LIST
:
2848 struct bt_declaration
*declaration
;
2851 * Just add the type specifier to the root scope
2852 * declaration scope. Release local reference.
2854 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2855 node
, trace
->root_declaration_scope
, trace
);
2858 bt_declaration_unref(declaration
);
2868 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2869 struct ctf_trace
*trace
, int byte_order
)
2872 struct ctf_node
*iter
;
2873 int env_clock_done
= 0;
2875 printf_verbose("CTF visitor: metadata construction...\n");
2876 trace
->byte_order
= byte_order
;
2877 trace
->clocks
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2879 trace
->callsites
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2880 NULL
, callsite_free
);
2883 trace
->root_declaration_scope
= bt_new_declaration_scope(NULL
);
2885 switch (node
->type
) {
2887 if (!env_clock_done
) {
2889 * declarations need to query clock hash table,
2890 * so clock need to be treated first.
2892 if (bt_list_empty(&node
->u
.root
.clock
)) {
2893 ctf_clock_default(fd
, depth
+ 1, trace
);
2895 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2896 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2899 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2906 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2908 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2910 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
2914 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
2915 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
2916 if (ret
== -EINTR
) {
2917 bt_free_declaration_scope(trace
->root_declaration_scope
);
2919 * Need to restart creation of type
2920 * definitions, aliases and
2921 * trace header declarations.
2926 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
2930 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
2931 ret
= ctf_callsite_visit(fd
, depth
+ 1, iter
,
2934 fprintf(fd
, "[error] %s: callsite declaration error\n", __func__
);
2938 if (!trace
->streams
) {
2939 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
2943 bt_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
2944 ret
= ctf_env_visit(fd
, depth
+ 1, iter
, trace
);
2946 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
2950 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
2951 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
2952 trace
->root_declaration_scope
, trace
);
2954 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
2958 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
2959 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
2960 trace
->root_declaration_scope
, trace
);
2962 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
2969 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
2974 printf_verbose("done.\n");
2978 bt_free_declaration_scope(trace
->root_declaration_scope
);
2979 g_hash_table_destroy(trace
->callsites
);
2980 g_hash_table_destroy(trace
->clocks
);
2984 int ctf_destroy_metadata(struct ctf_trace
*trace
)
2987 struct ctf_file_stream
*metadata_stream
;
2989 if (trace
->streams
) {
2990 for (i
= 0; i
< trace
->streams
->len
; i
++) {
2991 struct ctf_stream_declaration
*stream
;
2994 stream
= g_ptr_array_index(trace
->streams
, i
);
2997 for (j
= 0; j
< stream
->streams
->len
; j
++) {
2998 struct ctf_stream_definition
*stream_def
;
3001 stream_def
= g_ptr_array_index(stream
->streams
, j
);
3004 for (k
= 0; k
< stream_def
->events_by_id
->len
; k
++) {
3005 struct ctf_event_definition
*event
;
3007 event
= g_ptr_array_index(stream_def
->events_by_id
, k
);
3010 if (&event
->event_fields
->p
)
3011 bt_definition_unref(&event
->event_fields
->p
);
3012 if (&event
->event_context
->p
)
3013 bt_definition_unref(&event
->event_context
->p
);
3016 if (&stream_def
->trace_packet_header
->p
)
3017 bt_definition_unref(&stream_def
->trace_packet_header
->p
);
3018 if (&stream_def
->stream_event_header
->p
)
3019 bt_definition_unref(&stream_def
->stream_event_header
->p
);
3020 if (&stream_def
->stream_packet_context
->p
)
3021 bt_definition_unref(&stream_def
->stream_packet_context
->p
);
3022 if (&stream_def
->stream_event_context
->p
)
3023 bt_definition_unref(&stream_def
->stream_event_context
->p
);
3024 g_ptr_array_free(stream_def
->events_by_id
, TRUE
);
3027 if (stream
->event_header_decl
)
3028 bt_declaration_unref(&stream
->event_header_decl
->p
);
3029 if (stream
->event_context_decl
)
3030 bt_declaration_unref(&stream
->event_context_decl
->p
);
3031 if (stream
->packet_context_decl
)
3032 bt_declaration_unref(&stream
->packet_context_decl
->p
);
3033 g_ptr_array_free(stream
->streams
, TRUE
);
3034 g_ptr_array_free(stream
->events_by_id
, TRUE
);
3035 g_hash_table_destroy(stream
->event_quark_to_id
);
3036 bt_free_declaration_scope(stream
->declaration_scope
);
3039 g_ptr_array_free(trace
->streams
, TRUE
);
3042 if (trace
->event_declarations
) {
3043 for (i
= 0; i
< trace
->event_declarations
->len
; i
++) {
3044 struct bt_ctf_event_decl
*event_decl
;
3045 struct ctf_event_declaration
*event
;
3047 event_decl
= g_ptr_array_index(trace
->event_declarations
, i
);
3048 if (event_decl
->context_decl
)
3049 g_ptr_array_free(event_decl
->context_decl
, TRUE
);
3050 if (event_decl
->fields_decl
)
3051 g_ptr_array_free(event_decl
->fields_decl
, TRUE
);
3052 if (event_decl
->packet_header_decl
)
3053 g_ptr_array_free(event_decl
->packet_header_decl
, TRUE
);
3054 if (event_decl
->event_context_decl
)
3055 g_ptr_array_free(event_decl
->event_context_decl
, TRUE
);
3056 if (event_decl
->event_header_decl
)
3057 g_ptr_array_free(event_decl
->event_header_decl
, TRUE
);
3058 if (event_decl
->packet_context_decl
)
3059 g_ptr_array_free(event_decl
->packet_context_decl
, TRUE
);
3061 event
= &event_decl
->parent
;
3062 if (event
->fields_decl
)
3063 bt_declaration_unref(&event
->fields_decl
->p
);
3064 if (event
->context_decl
)
3065 bt_declaration_unref(&event
->context_decl
->p
);
3066 bt_free_declaration_scope(event
->declaration_scope
);
3070 g_ptr_array_free(trace
->event_declarations
, TRUE
);
3072 if (trace
->packet_header_decl
)
3073 bt_declaration_unref(&trace
->packet_header_decl
->p
);
3075 bt_free_declaration_scope(trace
->root_declaration_scope
);
3076 bt_free_declaration_scope(trace
->declaration_scope
);
3078 g_hash_table_destroy(trace
->callsites
);
3079 g_hash_table_destroy(trace
->clocks
);
3081 metadata_stream
= container_of(trace
->metadata
, struct ctf_file_stream
, parent
);
3082 g_free(metadata_stream
);