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/compat/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 if (node
->type
!= NODE_UNARY_EXPRESSION
99 || node
->u
.unary_expression
.type
!= UNARY_STRING
100 || !((node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
)
103 switch (node
->u
.unary_expression
.link
) {
105 g_string_append(str
, ".");
107 case UNARY_ARROWLINK
:
108 g_string_append(str
, "->");
110 case UNARY_DOTDOTDOT
:
111 g_string_append(str
, "...");
116 src_string
= node
->u
.unary_expression
.u
.string
;
117 g_string_append(str
, src_string
);
120 return g_string_free(str
, FALSE
);
124 GQuark
get_map_clock_name_value(struct bt_list_head
*head
)
126 struct ctf_node
*node
;
127 const char *name
= NULL
;
130 bt_list_for_each_entry(node
, head
, siblings
) {
133 if (node
->type
!= NODE_UNARY_EXPRESSION
134 || node
->u
.unary_expression
.type
!= UNARY_STRING
135 || !((node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
)
138 /* needs to be chained with . */
139 switch (node
->u
.unary_expression
.link
) {
142 case UNARY_ARROWLINK
:
143 case UNARY_DOTDOTDOT
:
148 src_string
= node
->u
.unary_expression
.u
.string
;
150 case 0: if (strcmp("clock", src_string
) != 0) {
154 case 1: name
= src_string
;
156 case 2: if (strcmp("value", src_string
) != 0) {
161 return 0; /* extra identifier, unknown */
165 return g_quark_from_string(name
);
169 int is_unary_unsigned(struct bt_list_head
*head
)
171 struct ctf_node
*node
;
173 bt_list_for_each_entry(node
, head
, siblings
) {
174 if (node
->type
!= NODE_UNARY_EXPRESSION
)
176 if (node
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
)
183 int get_unary_unsigned(struct bt_list_head
*head
, uint64_t *value
)
185 struct ctf_node
*node
;
188 bt_list_for_each_entry(node
, head
, siblings
) {
189 if (node
->type
!= NODE_UNARY_EXPRESSION
190 || node
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
191 || node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
194 *value
= node
->u
.unary_expression
.u
.unsigned_constant
;
201 int is_unary_signed(struct bt_list_head
*head
)
203 struct ctf_node
*node
;
205 bt_list_for_each_entry(node
, head
, siblings
) {
206 if (node
->type
!= NODE_UNARY_EXPRESSION
)
208 if (node
->u
.unary_expression
.type
!= UNARY_SIGNED_CONSTANT
)
215 int get_unary_signed(struct bt_list_head
*head
, int64_t *value
)
217 struct ctf_node
*node
;
220 bt_list_for_each_entry(node
, head
, siblings
) {
221 if (node
->type
!= NODE_UNARY_EXPRESSION
222 || node
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
223 || (node
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
&& node
->u
.unary_expression
.type
!= UNARY_SIGNED_CONSTANT
)
224 || node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
227 switch (node
->u
.unary_expression
.type
) {
228 case UNARY_UNSIGNED_CONSTANT
:
229 *value
= (int64_t) node
->u
.unary_expression
.u
.unsigned_constant
;
231 case UNARY_SIGNED_CONSTANT
:
232 *value
= node
->u
.unary_expression
.u
.signed_constant
;
243 int get_unary_uuid(struct bt_list_head
*head
, unsigned char *uuid
)
245 struct ctf_node
*node
;
249 bt_list_for_each_entry(node
, head
, siblings
) {
250 const char *src_string
;
252 if (node
->type
!= NODE_UNARY_EXPRESSION
253 || node
->u
.unary_expression
.type
!= UNARY_STRING
254 || node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
257 src_string
= node
->u
.unary_expression
.u
.string
;
258 ret
= babeltrace_uuid_parse(src_string
, uuid
);
264 struct ctf_stream_declaration
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
266 if (trace
->streams
->len
<= stream_id
)
268 return g_ptr_array_index(trace
->streams
, stream_id
);
272 struct ctf_clock
*trace_clock_lookup(struct ctf_trace
*trace
, GQuark clock_name
)
274 return g_hash_table_lookup(trace
->parent
.clocks
, (gpointer
) (unsigned long) clock_name
);
278 int visit_type_specifier(FILE *fd
, struct ctf_node
*type_specifier
, GString
*str
)
280 if (type_specifier
->type
!= NODE_TYPE_SPECIFIER
)
283 switch (type_specifier
->u
.type_specifier
.type
) {
285 g_string_append(str
, "void");
288 g_string_append(str
, "char");
291 g_string_append(str
, "short");
294 g_string_append(str
, "int");
297 g_string_append(str
, "long");
300 g_string_append(str
, "float");
302 case TYPESPEC_DOUBLE
:
303 g_string_append(str
, "double");
305 case TYPESPEC_SIGNED
:
306 g_string_append(str
, "signed");
308 case TYPESPEC_UNSIGNED
:
309 g_string_append(str
, "unsigned");
312 g_string_append(str
, "bool");
314 case TYPESPEC_COMPLEX
:
315 g_string_append(str
, "_Complex");
317 case TYPESPEC_IMAGINARY
:
318 g_string_append(str
, "_Imaginary");
321 g_string_append(str
, "const");
323 case TYPESPEC_ID_TYPE
:
324 if (type_specifier
->u
.type_specifier
.id_type
)
325 g_string_append(str
, type_specifier
->u
.type_specifier
.id_type
);
327 case TYPESPEC_STRUCT
:
329 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
331 if (!node
->u
._struct
.name
) {
332 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
335 g_string_append(str
, "struct ");
336 g_string_append(str
, node
->u
._struct
.name
);
339 case TYPESPEC_VARIANT
:
341 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
343 if (!node
->u
.variant
.name
) {
344 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
347 g_string_append(str
, "variant ");
348 g_string_append(str
, node
->u
.variant
.name
);
353 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
355 if (!node
->u
._enum
.enum_id
) {
356 fprintf(fd
, "[error] %s: unexpected empty enum ID\n", __func__
);
359 g_string_append(str
, "enum ");
360 g_string_append(str
, node
->u
._enum
.enum_id
);
363 case TYPESPEC_FLOATING_POINT
:
364 case TYPESPEC_INTEGER
:
365 case TYPESPEC_STRING
:
367 fprintf(fd
, "[error] %s: unknown specifier\n", __func__
);
374 int visit_type_specifier_list(FILE *fd
, struct ctf_node
*type_specifier_list
, GString
*str
)
376 struct ctf_node
*iter
;
377 int alias_item_nr
= 0;
380 bt_list_for_each_entry(iter
, &type_specifier_list
->u
.type_specifier_list
.head
, siblings
) {
381 if (alias_item_nr
!= 0)
382 g_string_append(str
, " ");
384 ret
= visit_type_specifier(fd
, iter
, str
);
392 GQuark
create_typealias_identifier(FILE *fd
, int depth
,
393 struct ctf_node
*type_specifier_list
,
394 struct ctf_node
*node_type_declarator
)
396 struct ctf_node
*iter
;
402 str
= g_string_new("");
403 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
405 g_string_free(str
, TRUE
);
408 bt_list_for_each_entry(iter
, &node_type_declarator
->u
.type_declarator
.pointers
, siblings
) {
409 g_string_append(str
, " *");
410 if (iter
->u
.pointer
.const_qualifier
)
411 g_string_append(str
, " const");
413 str_c
= g_string_free(str
, FALSE
);
414 alias_q
= g_quark_from_string(str_c
);
420 struct bt_declaration
*ctf_type_declarator_visit(FILE *fd
, int depth
,
421 struct ctf_node
*type_specifier_list
,
423 struct ctf_node
*node_type_declarator
,
424 struct declaration_scope
*declaration_scope
,
425 struct bt_declaration
*nested_declaration
,
426 struct ctf_trace
*trace
)
429 * Visit type declarator by first taking care of sequence/array
430 * (recursively). Then, when we get to the identifier, take care
434 if (node_type_declarator
) {
435 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_UNKNOWN
) {
439 /* TODO: gcc bitfields not supported yet. */
440 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!= NULL
) {
441 fprintf(fd
, "[error] %s: gcc bitfields are not supported yet.\n", __func__
);
446 if (!nested_declaration
) {
447 if (node_type_declarator
&& !bt_list_empty(&node_type_declarator
->u
.type_declarator
.pointers
)) {
451 * If we have a pointer declarator, it _has_ to be present in
452 * the typealiases (else fail).
454 alias_q
= create_typealias_identifier(fd
, depth
,
455 type_specifier_list
, node_type_declarator
);
456 nested_declaration
= bt_lookup_declaration(alias_q
, declaration_scope
);
457 if (!nested_declaration
) {
458 fprintf(fd
, "[error] %s: cannot find typealias \"%s\".\n", __func__
, g_quark_to_string(alias_q
));
461 if (nested_declaration
->id
== CTF_TYPE_INTEGER
) {
462 struct declaration_integer
*integer_declaration
=
463 container_of(nested_declaration
, struct declaration_integer
, p
);
464 /* For base to 16 for pointers (expected pretty-print) */
465 if (!integer_declaration
->base
) {
467 * We need to do a copy of the
468 * integer declaration to modify it. There could be other references to
471 integer_declaration
= bt_integer_declaration_new(integer_declaration
->len
,
472 integer_declaration
->byte_order
, integer_declaration
->signedness
,
473 integer_declaration
->p
.alignment
, 16, integer_declaration
->encoding
,
474 integer_declaration
->clock
);
475 nested_declaration
= &integer_declaration
->p
;
479 nested_declaration
= ctf_type_specifier_list_visit(fd
, depth
,
480 type_specifier_list
, declaration_scope
, trace
);
484 if (!node_type_declarator
)
485 return nested_declaration
;
487 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
488 if (node_type_declarator
->u
.type_declarator
.u
.id
)
489 *field_name
= g_quark_from_string(node_type_declarator
->u
.type_declarator
.u
.id
);
492 return nested_declaration
;
494 struct bt_declaration
*declaration
;
495 struct ctf_node
*first
;
499 if (!nested_declaration
) {
500 fprintf(fd
, "[error] %s: nested type is unknown.\n", __func__
);
504 /* create array/sequence, pass nested_declaration as child. */
505 if (bt_list_empty(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
)) {
506 fprintf(fd
, "[error] %s: expecting length field reference or value.\n", __func__
);
509 first
= _bt_list_first_entry(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
,
510 struct ctf_node
, siblings
);
511 if (first
->type
!= NODE_UNARY_EXPRESSION
) {
515 switch (first
->u
.unary_expression
.type
) {
516 case UNARY_UNSIGNED_CONSTANT
:
518 struct declaration_array
*array_declaration
;
521 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
522 array_declaration
= bt_array_declaration_new(len
, nested_declaration
,
525 if (!array_declaration
) {
526 fprintf(fd
, "[error] %s: cannot create array declaration.\n", __func__
);
529 bt_declaration_unref(nested_declaration
);
530 declaration
= &array_declaration
->p
;
535 /* Lookup unsigned integer definition, create sequence */
536 char *length_name
= concatenate_unary_strings(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
);
537 struct declaration_sequence
*sequence_declaration
;
541 sequence_declaration
= bt_sequence_declaration_new(length_name
, nested_declaration
, declaration_scope
);
542 if (!sequence_declaration
) {
543 fprintf(fd
, "[error] %s: cannot create sequence declaration.\n", __func__
);
547 bt_declaration_unref(nested_declaration
);
548 declaration
= &sequence_declaration
->p
;
556 /* Pass it as content of outer container */
557 declaration
= ctf_type_declarator_visit(fd
, depth
,
558 type_specifier_list
, field_name
,
559 node_type_declarator
->u
.type_declarator
.u
.nested
.type_declarator
,
560 declaration_scope
, declaration
, trace
);
566 int ctf_struct_type_declarators_visit(FILE *fd
, int depth
,
567 struct declaration_struct
*struct_declaration
,
568 struct ctf_node
*type_specifier_list
,
569 struct bt_list_head
*type_declarators
,
570 struct declaration_scope
*declaration_scope
,
571 struct ctf_trace
*trace
)
573 struct ctf_node
*iter
;
576 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
577 struct bt_declaration
*field_declaration
;
579 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
582 struct_declaration
->scope
,
584 if (!field_declaration
) {
585 fprintf(fd
, "[error] %s: unable to find struct field declaration type\n", __func__
);
589 /* Check if field with same name already exists */
590 if (bt_struct_declaration_lookup_field_index(struct_declaration
, field_name
) >= 0) {
591 fprintf(fd
, "[error] %s: duplicate field %s in struct\n", __func__
, g_quark_to_string(field_name
));
595 bt_struct_declaration_add_field(struct_declaration
,
596 g_quark_to_string(field_name
),
598 bt_declaration_unref(field_declaration
);
604 int ctf_variant_type_declarators_visit(FILE *fd
, int depth
,
605 struct declaration_untagged_variant
*untagged_variant_declaration
,
606 struct ctf_node
*type_specifier_list
,
607 struct bt_list_head
*type_declarators
,
608 struct declaration_scope
*declaration_scope
,
609 struct ctf_trace
*trace
)
611 struct ctf_node
*iter
;
614 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
615 struct bt_declaration
*field_declaration
;
617 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
620 untagged_variant_declaration
->scope
,
622 if (!field_declaration
) {
623 fprintf(fd
, "[error] %s: unable to find variant field declaration type\n", __func__
);
627 if (bt_untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration
, field_name
) != NULL
) {
628 fprintf(fd
, "[error] %s: duplicate field %s in variant\n", __func__
, g_quark_to_string(field_name
));
632 bt_untagged_variant_declaration_add_field(untagged_variant_declaration
,
633 g_quark_to_string(field_name
),
635 bt_declaration_unref(field_declaration
);
641 int ctf_typedef_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
642 struct ctf_node
*type_specifier_list
,
643 struct bt_list_head
*type_declarators
,
644 struct ctf_trace
*trace
)
646 struct ctf_node
*iter
;
649 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
650 struct bt_declaration
*type_declaration
;
653 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
657 if (!type_declaration
) {
658 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
662 * Don't allow typedef and typealias of untagged
665 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
666 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
667 bt_declaration_unref(type_declaration
);
670 ret
= bt_register_declaration(identifier
, type_declaration
, scope
);
672 type_declaration
->declaration_free(type_declaration
);
675 bt_declaration_unref(type_declaration
);
681 int ctf_typealias_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
682 struct ctf_node
*target
, struct ctf_node
*alias
,
683 struct ctf_trace
*trace
)
685 struct bt_declaration
*type_declaration
;
686 struct ctf_node
*node
;
691 /* See ctf_visitor_type_declarator() in the semantic validator. */
694 * Create target type declaration.
697 if (bt_list_empty(&target
->u
.typealias_target
.type_declarators
))
700 node
= _bt_list_first_entry(&target
->u
.typealias_target
.type_declarators
,
701 struct ctf_node
, siblings
);
702 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
703 target
->u
.typealias_target
.type_specifier_list
,
706 if (!type_declaration
) {
707 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
712 * Don't allow typedef and typealias of untagged
715 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
716 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
717 bt_declaration_unref(type_declaration
);
721 * The semantic validator does not check whether the target is
722 * abstract or not (if it has an identifier). Check it here.
725 fprintf(fd
, "[error] %s: expecting empty identifier\n", __func__
);
730 * Create alias identifier.
733 node
= _bt_list_first_entry(&alias
->u
.typealias_alias
.type_declarators
,
734 struct ctf_node
, siblings
);
735 alias_q
= create_typealias_identifier(fd
, depth
,
736 alias
->u
.typealias_alias
.type_specifier_list
, node
);
737 err
= bt_register_declaration(alias_q
, type_declaration
, scope
);
740 bt_declaration_unref(type_declaration
);
744 if (type_declaration
) {
745 type_declaration
->declaration_free(type_declaration
);
751 int ctf_struct_declaration_list_visit(FILE *fd
, int depth
,
752 struct ctf_node
*iter
, struct declaration_struct
*struct_declaration
,
753 struct ctf_trace
*trace
)
757 switch (iter
->type
) {
759 /* For each declarator, declare type and add type to struct bt_declaration scope */
760 ret
= ctf_typedef_visit(fd
, depth
,
761 struct_declaration
->scope
,
762 iter
->u
._typedef
.type_specifier_list
,
763 &iter
->u
._typedef
.type_declarators
, trace
);
768 /* Declare type with declarator and add type to struct bt_declaration scope */
769 ret
= ctf_typealias_visit(fd
, depth
,
770 struct_declaration
->scope
,
771 iter
->u
.typealias
.target
,
772 iter
->u
.typealias
.alias
, trace
);
776 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
777 /* Add field to structure declaration */
778 ret
= ctf_struct_type_declarators_visit(fd
, depth
,
780 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
781 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
782 struct_declaration
->scope
, trace
);
787 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
794 int ctf_variant_declaration_list_visit(FILE *fd
, int depth
,
795 struct ctf_node
*iter
,
796 struct declaration_untagged_variant
*untagged_variant_declaration
,
797 struct ctf_trace
*trace
)
801 switch (iter
->type
) {
803 /* For each declarator, declare type and add type to variant declaration scope */
804 ret
= ctf_typedef_visit(fd
, depth
,
805 untagged_variant_declaration
->scope
,
806 iter
->u
._typedef
.type_specifier_list
,
807 &iter
->u
._typedef
.type_declarators
, trace
);
812 /* Declare type with declarator and add type to variant declaration scope */
813 ret
= ctf_typealias_visit(fd
, depth
,
814 untagged_variant_declaration
->scope
,
815 iter
->u
.typealias
.target
,
816 iter
->u
.typealias
.alias
, trace
);
820 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
821 /* Add field to structure declaration */
822 ret
= ctf_variant_type_declarators_visit(fd
, depth
,
823 untagged_variant_declaration
,
824 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
825 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
826 untagged_variant_declaration
->scope
, trace
);
831 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
838 struct bt_declaration
*ctf_declaration_struct_visit(FILE *fd
,
839 int depth
, const char *name
, struct bt_list_head
*declaration_list
,
840 int has_body
, struct bt_list_head
*min_align
,
841 struct declaration_scope
*declaration_scope
,
842 struct ctf_trace
*trace
)
844 struct declaration_struct
*struct_declaration
;
845 struct ctf_node
*iter
;
848 * For named struct (without body), lookup in
849 * declaration scope. Don't take reference on struct
850 * declaration: ref is only taken upon definition.
856 bt_lookup_struct_declaration(g_quark_from_string(name
),
858 bt_declaration_ref(&struct_declaration
->p
);
859 return &struct_declaration
->p
;
861 uint64_t min_align_value
= 0;
863 /* For unnamed struct, create type */
864 /* For named struct (with body), create type and add to declaration scope */
866 if (bt_lookup_struct_declaration(g_quark_from_string(name
),
867 declaration_scope
)) {
868 fprintf(fd
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
872 if (!bt_list_empty(min_align
)) {
875 ret
= get_unary_unsigned(min_align
, &min_align_value
);
877 fprintf(fd
, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__
);
882 struct_declaration
= bt_struct_declaration_new(declaration_scope
,
884 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
887 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
888 struct_declaration
, trace
);
890 goto error_free_declaration
;
895 ret
= bt_register_struct_declaration(g_quark_from_string(name
),
901 return &struct_declaration
->p
;
903 error_free_declaration
:
904 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
910 struct bt_declaration
*ctf_declaration_variant_visit(FILE *fd
,
911 int depth
, const char *name
, const char *choice
,
912 struct bt_list_head
*declaration_list
,
913 int has_body
, struct declaration_scope
*declaration_scope
,
914 struct ctf_trace
*trace
)
916 struct declaration_untagged_variant
*untagged_variant_declaration
;
917 struct declaration_variant
*variant_declaration
;
918 struct ctf_node
*iter
;
921 * For named variant (without body), lookup in
922 * declaration scope. Don't take reference on variant
923 * declaration: ref is only taken upon definition.
928 untagged_variant_declaration
=
929 bt_lookup_variant_declaration(g_quark_from_string(name
),
931 bt_declaration_ref(&untagged_variant_declaration
->p
);
933 /* For unnamed variant, create type */
934 /* For named variant (with body), create type and add to declaration scope */
936 if (bt_lookup_variant_declaration(g_quark_from_string(name
),
937 declaration_scope
)) {
938 fprintf(fd
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
942 untagged_variant_declaration
= bt_untagged_bt_variant_declaration_new(declaration_scope
);
943 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
946 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
947 untagged_variant_declaration
, trace
);
954 ret
= bt_register_variant_declaration(g_quark_from_string(name
),
955 untagged_variant_declaration
,
962 * if tagged, create tagged variant and return. else return
966 return &untagged_variant_declaration
->p
;
968 variant_declaration
= bt_variant_declaration_new(untagged_variant_declaration
, choice
);
969 if (!variant_declaration
)
971 bt_declaration_unref(&untagged_variant_declaration
->p
);
972 return &variant_declaration
->p
;
975 untagged_variant_declaration
->p
.declaration_free(&untagged_variant_declaration
->p
);
980 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
981 struct ctf_node
*enumerator
,
982 struct declaration_enum
*enum_declaration
,
983 struct last_enum_value
*last
)
986 struct ctf_node
*iter
;
988 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
989 if (enum_declaration
->integer_declaration
->signedness
) {
993 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
996 if (iter
->type
!= NODE_UNARY_EXPRESSION
)
1003 switch (iter
->u
.unary_expression
.type
) {
1004 case UNARY_SIGNED_CONSTANT
:
1005 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
1007 case UNARY_UNSIGNED_CONSTANT
:
1008 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1011 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1015 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1024 last
->u
.s
= end
+ 1;
1025 bt_enum_signed_insert(enum_declaration
, start
, end
, q
);
1027 uint64_t start
, end
;
1030 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
1033 if (iter
->type
!= NODE_UNARY_EXPRESSION
)
1040 switch (iter
->u
.unary_expression
.type
) {
1041 case UNARY_UNSIGNED_CONSTANT
:
1042 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1044 case UNARY_SIGNED_CONSTANT
:
1046 * We don't accept signed constants for enums with unsigned
1049 fprintf(fd
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
1052 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1056 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1065 last
->u
.u
= end
+ 1;
1066 bt_enum_unsigned_insert(enum_declaration
, start
, end
, q
);
1072 struct bt_declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
1074 struct ctf_node
*container_type
,
1075 struct bt_list_head
*enumerator_list
,
1077 struct declaration_scope
*declaration_scope
,
1078 struct ctf_trace
*trace
)
1080 struct bt_declaration
*declaration
;
1081 struct declaration_enum
*enum_declaration
;
1082 struct declaration_integer
*integer_declaration
;
1083 struct last_enum_value last_value
;
1084 struct ctf_node
*iter
;
1088 * For named enum (without body), lookup in
1089 * declaration scope. Don't take reference on enum
1090 * declaration: ref is only taken upon definition.
1096 bt_lookup_enum_declaration(g_quark_from_string(name
),
1098 bt_declaration_ref(&enum_declaration
->p
);
1099 return &enum_declaration
->p
;
1101 /* For unnamed enum, create type */
1102 /* For named enum (with body), create type and add to declaration scope */
1104 if (bt_lookup_enum_declaration(g_quark_from_string(name
),
1105 declaration_scope
)) {
1106 fprintf(fd
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
1110 if (!container_type
) {
1111 declaration
= bt_lookup_declaration(g_quark_from_static_string("int"),
1114 fprintf(fd
, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__
);
1118 declaration
= ctf_type_declarator_visit(fd
, depth
,
1125 fprintf(fd
, "[error] %s: unable to create container type for enumeration\n", __func__
);
1128 if (declaration
->id
!= CTF_TYPE_INTEGER
) {
1129 fprintf(fd
, "[error] %s: container type for enumeration is not integer\n", __func__
);
1132 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
1133 enum_declaration
= bt_enum_declaration_new(integer_declaration
);
1134 bt_declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
1135 if (enum_declaration
->integer_declaration
->signedness
) {
1140 bt_list_for_each_entry(iter
, enumerator_list
, siblings
) {
1143 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
,
1151 ret
= bt_register_enum_declaration(g_quark_from_string(name
),
1156 bt_declaration_unref(&enum_declaration
->p
);
1158 return &enum_declaration
->p
;
1161 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
1166 struct bt_declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
1167 struct ctf_node
*type_specifier_list
,
1168 struct declaration_scope
*declaration_scope
)
1171 struct bt_declaration
*declaration
;
1176 str
= g_string_new("");
1177 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
1179 (void) g_string_free(str
, TRUE
);
1182 str_c
= g_string_free(str
, FALSE
);
1183 id_q
= g_quark_from_string(str_c
);
1185 declaration
= bt_lookup_declaration(id_q
, declaration_scope
);
1188 bt_declaration_ref(declaration
);
1193 * Returns 0/1 boolean, or < 0 on error.
1196 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1198 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1199 fprintf(fd
, "[error] %s: expecting unary expression\n",
1203 switch (unary_expression
->u
.unary_expression
.type
) {
1204 case UNARY_UNSIGNED_CONSTANT
:
1205 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1209 case UNARY_SIGNED_CONSTANT
:
1210 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1215 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1217 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1219 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1221 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1224 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1225 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1230 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1238 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1242 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1243 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1247 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1248 byte_order
= BIG_ENDIAN
;
1249 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1250 byte_order
= LITTLE_ENDIAN
;
1252 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
1253 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1260 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1261 struct ctf_trace
*trace
)
1265 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1266 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1270 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1271 byte_order
= trace
->byte_order
;
1272 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1273 byte_order
= BIG_ENDIAN
;
1274 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1275 byte_order
= BIG_ENDIAN
;
1276 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1277 byte_order
= LITTLE_ENDIAN
;
1279 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1280 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1287 struct bt_declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1288 struct bt_list_head
*expressions
,
1289 struct ctf_trace
*trace
)
1291 struct ctf_node
*expression
;
1292 uint64_t alignment
= 1, size
= 0;
1293 int byte_order
= trace
->byte_order
;
1295 int has_alignment
= 0, has_size
= 0;
1297 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1298 struct ctf_clock
*clock
= NULL
;
1299 struct declaration_integer
*integer_declaration
;
1301 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1302 struct ctf_node
*left
, *right
;
1304 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1305 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1306 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1308 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1309 signedness
= get_boolean(fd
, depth
, right
);
1312 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1313 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1316 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1317 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1318 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1322 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1324 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1325 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1326 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1330 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1331 /* Make sure alignment is a power of two */
1332 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1333 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1338 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1339 switch (right
->u
.unary_expression
.type
) {
1340 case UNARY_UNSIGNED_CONSTANT
:
1341 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1346 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1349 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1350 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1356 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1358 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1362 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1363 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1365 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1366 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1367 || !strcmp(s_right
, "p")) {
1369 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1370 || !strcmp(s_right
, "o")) {
1372 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1375 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1384 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1388 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1391 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1392 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1396 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1398 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1402 if (!strcmp(s_right
, "UTF8")
1403 || !strcmp(s_right
, "utf8")
1404 || !strcmp(s_right
, "utf-8")
1405 || !strcmp(s_right
, "UTF-8"))
1406 encoding
= CTF_STRING_UTF8
;
1407 else if (!strcmp(s_right
, "ASCII")
1408 || !strcmp(s_right
, "ascii"))
1409 encoding
= CTF_STRING_ASCII
;
1410 else if (!strcmp(s_right
, "none"))
1411 encoding
= CTF_STRING_NONE
;
1413 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1418 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1421 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1422 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1426 /* currently only support clock.name.value */
1427 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1431 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1433 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1437 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1442 clock
= trace_clock_lookup(trace
, clock_name
);
1444 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1445 __func__
, g_quark_to_string(clock_name
));
1449 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1450 __func__
, left
->u
.unary_expression
.u
.string
);
1451 /* Fall-through after warning */
1455 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1458 if (!has_alignment
) {
1459 if (size
% CHAR_BIT
) {
1460 /* bit-packed alignment */
1463 /* byte-packed alignment */
1464 alignment
= CHAR_BIT
;
1467 integer_declaration
= bt_integer_declaration_new(size
,
1468 byte_order
, signedness
, alignment
,
1469 base
, encoding
, clock
);
1470 return &integer_declaration
->p
;
1474 struct bt_declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1475 struct bt_list_head
*expressions
,
1476 struct ctf_trace
*trace
)
1478 struct ctf_node
*expression
;
1479 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0;
1480 int byte_order
= trace
->byte_order
, has_alignment
= 0,
1481 has_exp_dig
= 0, has_mant_dig
= 0;
1482 struct declaration_float
*float_declaration
;
1484 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1485 struct ctf_node
*left
, *right
;
1487 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1488 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1489 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1491 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1492 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1495 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1496 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1497 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1501 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1503 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1504 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1505 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1509 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1511 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1512 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1513 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1517 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1518 /* Make sure alignment is a power of two */
1519 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1520 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1526 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1527 __func__
, left
->u
.unary_expression
.u
.string
);
1528 /* Fall-through after warning */
1531 if (!has_mant_dig
) {
1532 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1536 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1539 if (!has_alignment
) {
1540 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1541 /* bit-packed alignment */
1544 /* byte-packed alignment */
1545 alignment
= CHAR_BIT
;
1548 float_declaration
= bt_float_declaration_new(mant_dig
, exp_dig
,
1549 byte_order
, alignment
);
1550 return &float_declaration
->p
;
1554 struct bt_declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1555 struct bt_list_head
*expressions
,
1556 struct ctf_trace
*trace
)
1558 struct ctf_node
*expression
;
1559 const char *encoding_c
= NULL
;
1560 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1561 struct declaration_string
*string_declaration
;
1563 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1564 struct ctf_node
*left
, *right
;
1566 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1567 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1568 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1570 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1571 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1572 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1576 encoding_c
= right
->u
.unary_expression
.u
.string
;
1578 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1579 __func__
, left
->u
.unary_expression
.u
.string
);
1580 /* Fall-through after warning */
1583 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1584 encoding
= CTF_STRING_ASCII
;
1585 string_declaration
= bt_string_declaration_new(encoding
);
1586 return &string_declaration
->p
;
1591 struct bt_declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1592 int depth
, struct ctf_node
*type_specifier_list
,
1593 struct declaration_scope
*declaration_scope
,
1594 struct ctf_trace
*trace
)
1596 struct ctf_node
*first
;
1597 struct ctf_node
*node
;
1599 if (type_specifier_list
->type
!= NODE_TYPE_SPECIFIER_LIST
)
1602 first
= _bt_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1604 if (first
->type
!= NODE_TYPE_SPECIFIER
)
1607 node
= first
->u
.type_specifier
.node
;
1609 switch (first
->u
.type_specifier
.type
) {
1610 case TYPESPEC_FLOATING_POINT
:
1611 return ctf_declaration_floating_point_visit(fd
, depth
,
1612 &node
->u
.floating_point
.expressions
, trace
);
1613 case TYPESPEC_INTEGER
:
1614 return ctf_declaration_integer_visit(fd
, depth
,
1615 &node
->u
.integer
.expressions
, trace
);
1616 case TYPESPEC_STRING
:
1617 return ctf_declaration_string_visit(fd
, depth
,
1618 &node
->u
.string
.expressions
, trace
);
1619 case TYPESPEC_STRUCT
:
1620 return ctf_declaration_struct_visit(fd
, depth
,
1621 node
->u
._struct
.name
,
1622 &node
->u
._struct
.declaration_list
,
1623 node
->u
._struct
.has_body
,
1624 &node
->u
._struct
.min_align
,
1627 case TYPESPEC_VARIANT
:
1628 return ctf_declaration_variant_visit(fd
, depth
,
1629 node
->u
.variant
.name
,
1630 node
->u
.variant
.choice
,
1631 &node
->u
.variant
.declaration_list
,
1632 node
->u
.variant
.has_body
,
1636 return ctf_declaration_enum_visit(fd
, depth
,
1637 node
->u
._enum
.enum_id
,
1638 node
->u
._enum
.container_type
,
1639 &node
->u
._enum
.enumerator_list
,
1640 node
->u
._enum
.has_body
,
1646 case TYPESPEC_SHORT
:
1649 case TYPESPEC_FLOAT
:
1650 case TYPESPEC_DOUBLE
:
1651 case TYPESPEC_SIGNED
:
1652 case TYPESPEC_UNSIGNED
:
1654 case TYPESPEC_COMPLEX
:
1655 case TYPESPEC_IMAGINARY
:
1656 case TYPESPEC_CONST
:
1657 case TYPESPEC_ID_TYPE
:
1658 return ctf_declaration_type_specifier_visit(fd
, depth
,
1659 type_specifier_list
, declaration_scope
);
1661 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1667 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event_declaration
*event
, struct ctf_trace
*trace
)
1671 switch (node
->type
) {
1673 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1674 event
->declaration_scope
,
1675 node
->u
._typedef
.type_specifier_list
,
1676 &node
->u
._typedef
.type_declarators
,
1681 case NODE_TYPEALIAS
:
1682 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1683 event
->declaration_scope
,
1684 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1689 case NODE_CTF_EXPRESSION
:
1693 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1696 if (!strcmp(left
, "name")) {
1699 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1700 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1704 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1706 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1710 event
->name
= g_quark_from_string(right
);
1712 CTF_EVENT_SET_FIELD(event
, name
);
1713 } else if (!strcmp(left
, "id")) {
1714 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1715 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1719 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1721 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1725 CTF_EVENT_SET_FIELD(event
, id
);
1726 } else if (!strcmp(left
, "stream_id")) {
1727 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1728 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1732 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1734 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1738 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1739 if (!event
->stream
) {
1740 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1744 CTF_EVENT_SET_FIELD(event
, stream_id
);
1745 } else if (!strcmp(left
, "context")) {
1746 struct bt_declaration
*declaration
;
1748 if (event
->context_decl
) {
1749 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1753 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1754 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1755 struct ctf_node
, siblings
),
1756 event
->declaration_scope
, trace
);
1761 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1765 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1766 } else if (!strcmp(left
, "fields")) {
1767 struct bt_declaration
*declaration
;
1769 if (event
->fields_decl
) {
1770 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1774 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1775 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1776 struct ctf_node
, siblings
),
1777 event
->declaration_scope
, trace
);
1782 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1786 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1787 } else if (!strcmp(left
, "loglevel")) {
1788 int64_t loglevel
= -1;
1790 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel
)) {
1791 fprintf(fd
, "[error] %s: loglevel already declared in event declaration\n", __func__
);
1795 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &loglevel
);
1797 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel\n", __func__
);
1801 event
->loglevel
= (int) loglevel
;
1802 CTF_EVENT_SET_FIELD(event
, loglevel
);
1803 } else if (!strcmp(left
, "model.emf.uri")) {
1806 if (CTF_EVENT_FIELD_IS_SET(event
, model_emf_uri
)) {
1807 fprintf(fd
, "[error] %s: model.emf.uri already declared in event declaration\n", __func__
);
1811 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1813 fprintf(fd
, "[error] %s: unexpected unary expression for event model.emf.uri\n", __func__
);
1817 event
->model_emf_uri
= g_quark_from_string(right
);
1819 CTF_EVENT_SET_FIELD(event
, model_emf_uri
);
1821 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1822 /* Fall-through after warning */
1830 /* TODO: declaration specifier should be added. */
1837 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1838 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1841 struct ctf_node
*iter
;
1842 struct ctf_event_declaration
*event
;
1843 struct bt_ctf_event_decl
*event_decl
;
1845 event_decl
= g_new0(struct bt_ctf_event_decl
, 1);
1846 event
= &event_decl
->parent
;
1847 event
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
1848 event
->loglevel
= -1;
1849 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1850 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1854 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1856 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1859 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1860 /* Allow missing stream_id if there is only a single stream */
1861 switch (trace
->streams
->len
) {
1862 case 0: /* Create stream if there was none. */
1863 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1868 event
->stream_id
= 0;
1869 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1873 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1877 /* Allow only one event without id per stream */
1878 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1879 && event
->stream
->events_by_id
->len
!= 0) {
1881 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1884 if (event
->stream
->events_by_id
->len
<= event
->id
)
1885 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1886 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1887 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1888 (gpointer
) (unsigned long) event
->name
,
1890 g_ptr_array_add(trace
->event_declarations
, event_decl
);
1894 if (event
->fields_decl
)
1895 bt_declaration_unref(&event
->fields_decl
->p
);
1896 if (event
->context_decl
)
1897 bt_declaration_unref(&event
->context_decl
->p
);
1898 bt_free_declaration_scope(event
->declaration_scope
);
1905 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_declaration
*stream
, struct ctf_trace
*trace
)
1909 switch (node
->type
) {
1911 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1912 stream
->declaration_scope
,
1913 node
->u
._typedef
.type_specifier_list
,
1914 &node
->u
._typedef
.type_declarators
,
1919 case NODE_TYPEALIAS
:
1920 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1921 stream
->declaration_scope
,
1922 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1927 case NODE_CTF_EXPRESSION
:
1931 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1934 if (!strcmp(left
, "id")) {
1935 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1936 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1940 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1942 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1946 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1947 } else if (!strcmp(left
, "event.header")) {
1948 struct bt_declaration
*declaration
;
1950 if (stream
->event_header_decl
) {
1951 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1955 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1956 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1957 struct ctf_node
, siblings
),
1958 stream
->declaration_scope
, trace
);
1963 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1967 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1968 } else if (!strcmp(left
, "event.context")) {
1969 struct bt_declaration
*declaration
;
1971 if (stream
->event_context_decl
) {
1972 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1976 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1977 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1978 struct ctf_node
, siblings
),
1979 stream
->declaration_scope
, trace
);
1984 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1988 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1989 } else if (!strcmp(left
, "packet.context")) {
1990 struct bt_declaration
*declaration
;
1992 if (stream
->packet_context_decl
) {
1993 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
1997 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1998 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1999 struct ctf_node
, siblings
),
2000 stream
->declaration_scope
, trace
);
2005 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2009 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
2011 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
2012 /* Fall-through after warning */
2021 /* TODO: declaration specifier should be added. */
2028 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2029 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
2032 struct ctf_node
*iter
;
2033 struct ctf_stream_declaration
*stream
;
2035 stream
= g_new0(struct ctf_stream_declaration
, 1);
2036 stream
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
2037 stream
->events_by_id
= g_ptr_array_new();
2038 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2039 stream
->streams
= g_ptr_array_new();
2041 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
2042 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
2047 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
2048 /* check that packet header has stream_id field. */
2049 if (!trace
->packet_header_decl
2050 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
2052 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
2056 /* Allow only one id-less stream */
2057 if (trace
->streams
->len
!= 0) {
2059 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
2062 stream
->stream_id
= 0;
2064 if (trace
->streams
->len
<= stream
->stream_id
)
2065 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
2066 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
2067 stream
->trace
= trace
;
2072 if (stream
->event_header_decl
)
2073 bt_declaration_unref(&stream
->event_header_decl
->p
);
2074 if (stream
->event_context_decl
)
2075 bt_declaration_unref(&stream
->event_context_decl
->p
);
2076 if (stream
->packet_context_decl
)
2077 bt_declaration_unref(&stream
->packet_context_decl
->p
);
2078 g_ptr_array_free(stream
->streams
, TRUE
);
2079 g_ptr_array_free(stream
->events_by_id
, TRUE
);
2080 g_hash_table_destroy(stream
->event_quark_to_id
);
2081 bt_free_declaration_scope(stream
->declaration_scope
);
2087 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2091 switch (node
->type
) {
2093 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2094 trace
->declaration_scope
,
2095 node
->u
._typedef
.type_specifier_list
,
2096 &node
->u
._typedef
.type_declarators
,
2101 case NODE_TYPEALIAS
:
2102 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2103 trace
->declaration_scope
,
2104 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2109 case NODE_CTF_EXPRESSION
:
2113 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2116 if (!strcmp(left
, "major")) {
2117 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2118 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
2122 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
2124 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
2128 CTF_TRACE_SET_FIELD(trace
, major
);
2129 } else if (!strcmp(left
, "minor")) {
2130 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2131 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
2135 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
2137 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
2141 CTF_TRACE_SET_FIELD(trace
, minor
);
2142 } else if (!strcmp(left
, "uuid")) {
2143 unsigned char uuid
[BABELTRACE_UUID_LEN
];
2145 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, uuid
);
2147 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2151 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2152 && babeltrace_uuid_compare(uuid
, trace
->uuid
)) {
2153 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2157 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2159 CTF_TRACE_SET_FIELD(trace
, uuid
);
2160 } else if (!strcmp(left
, "byte_order")) {
2161 struct ctf_node
*right
;
2164 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2165 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2166 if (byte_order
< 0) {
2171 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2172 && byte_order
!= trace
->byte_order
) {
2173 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2177 if (byte_order
!= trace
->byte_order
) {
2178 trace
->byte_order
= byte_order
;
2180 * We need to restart
2181 * construction of the
2182 * intermediate representation.
2184 trace
->field_mask
= 0;
2185 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2190 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2191 } else if (!strcmp(left
, "packet.header")) {
2192 struct bt_declaration
*declaration
;
2194 if (trace
->packet_header_decl
) {
2195 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2199 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2200 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2201 struct ctf_node
, siblings
),
2202 trace
->declaration_scope
, trace
);
2207 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2211 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2213 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2222 /* TODO: declaration specifier should be added. */
2229 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2232 struct ctf_node
*iter
;
2234 if (trace
->declaration_scope
)
2236 trace
->declaration_scope
= bt_new_declaration_scope(trace
->root_declaration_scope
);
2237 trace
->streams
= g_ptr_array_new();
2238 trace
->event_declarations
= g_ptr_array_new();
2239 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2240 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2244 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2246 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2249 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2251 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2254 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2256 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2260 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2261 /* check that the packet header contains a "magic" field */
2262 if (!trace
->packet_header_decl
2263 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2265 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2272 if (trace
->packet_header_decl
) {
2273 bt_declaration_unref(&trace
->packet_header_decl
->p
);
2274 trace
->packet_header_decl
= NULL
;
2276 g_ptr_array_free(trace
->streams
, TRUE
);
2277 g_ptr_array_free(trace
->event_declarations
, TRUE
);
2278 bt_free_declaration_scope(trace
->declaration_scope
);
2279 trace
->declaration_scope
= NULL
;
2284 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2285 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2289 switch (node
->type
) {
2290 case NODE_CTF_EXPRESSION
:
2294 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2297 if (!strcmp(left
, "name")) {
2300 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2301 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2305 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2307 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2311 clock
->name
= g_quark_from_string(right
);
2313 CTF_CLOCK_SET_FIELD(clock
, name
);
2314 } else if (!strcmp(left
, "uuid")) {
2318 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2322 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2324 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2328 clock
->uuid
= g_quark_from_string(right
);
2330 } else if (!strcmp(left
, "description")) {
2333 if (clock
->description
) {
2334 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2335 goto error
; /* ret is 0, so not an actual error, just warn. */
2337 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2339 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2340 goto error
; /* ret is 0, so not an actual error, just warn. */
2342 clock
->description
= right
;
2343 } else if (!strcmp(left
, "freq")) {
2344 if (CTF_CLOCK_FIELD_IS_SET(clock
, freq
)) {
2345 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2349 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2351 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2355 CTF_CLOCK_SET_FIELD(clock
, freq
);
2356 } else if (!strcmp(left
, "precision")) {
2357 if (clock
->precision
) {
2358 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2362 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2364 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2368 } else if (!strcmp(left
, "offset_s")) {
2369 if (clock
->offset_s
) {
2370 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2374 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2376 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2380 } else if (!strcmp(left
, "offset")) {
2381 if (clock
->offset
) {
2382 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2386 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2388 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2392 } else if (!strcmp(left
, "absolute")) {
2393 struct ctf_node
*right
;
2395 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2396 ret
= get_boolean(fd
, depth
, right
);
2398 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2402 clock
->absolute
= ret
;
2404 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2413 /* TODO: declaration specifier should be added. */
2420 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2423 struct ctf_node
*iter
;
2424 struct ctf_clock
*clock
;
2426 clock
= g_new0(struct ctf_clock
, 1);
2427 /* Default clock frequency is set to 1000000000 */
2428 clock
->freq
= 1000000000ULL;
2429 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2430 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2434 if (opt_clock_force_correlate
) {
2436 * User requested to forcibly correlate the clock
2437 * sources, even if we have no correlation
2440 if (!clock
->absolute
) {
2441 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2443 clock
->absolute
= 1;
2445 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2447 fprintf(fd
, "[error] %s: missing name field in clock declaration\n", __func__
);
2450 if (g_hash_table_size(trace
->parent
.clocks
) > 0) {
2451 fprintf(fd
, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
2455 trace
->parent
.single_clock
= clock
;
2456 g_hash_table_insert(trace
->parent
.clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2460 g_free(clock
->description
);
2466 void ctf_clock_default(FILE *fd
, int depth
, struct ctf_trace
*trace
)
2468 struct ctf_clock
*clock
;
2470 clock
= g_new0(struct ctf_clock
, 1);
2471 clock
->name
= g_quark_from_string("monotonic");
2473 clock
->description
= g_strdup("Default clock");
2474 /* Default clock frequency is set to 1000000000 */
2475 clock
->freq
= 1000000000ULL;
2476 if (opt_clock_force_correlate
) {
2478 * User requested to forcibly correlate the clock
2479 * sources, even if we have no correlatation
2482 if (!clock
->absolute
) {
2483 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2485 clock
->absolute
= 1;
2487 clock
->absolute
= 0; /* Not an absolute reference across traces */
2490 trace
->parent
.single_clock
= clock
;
2491 g_hash_table_insert(trace
->parent
.clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2495 void clock_free(gpointer data
)
2497 struct ctf_clock
*clock
= data
;
2499 g_free(clock
->description
);
2504 int ctf_callsite_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2505 struct ctf_callsite
*callsite
, struct ctf_trace
*trace
)
2509 switch (node
->type
) {
2510 case NODE_CTF_EXPRESSION
:
2514 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2517 if (!strcmp(left
, "name")) {
2520 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2521 fprintf(fd
, "[error] %s: name already declared in callsite declaration\n", __func__
);
2525 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2527 fprintf(fd
, "[error] %s: unexpected unary expression for callsite name\n", __func__
);
2531 callsite
->name
= g_quark_from_string(right
);
2533 CTF_CALLSITE_SET_FIELD(callsite
, name
);
2534 } else if (!strcmp(left
, "func")) {
2537 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2538 fprintf(fd
, "[error] %s: func already declared in callsite declaration\n", __func__
);
2542 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2544 fprintf(fd
, "[error] %s: unexpected unary expression for callsite func\n", __func__
);
2548 callsite
->func
= right
;
2549 CTF_CALLSITE_SET_FIELD(callsite
, func
);
2550 } else if (!strcmp(left
, "file")) {
2553 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2554 fprintf(fd
, "[error] %s: file already declared in callsite declaration\n", __func__
);
2558 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2560 fprintf(fd
, "[error] %s: unexpected unary expression for callsite file\n", __func__
);
2564 callsite
->file
= right
;
2565 CTF_CALLSITE_SET_FIELD(callsite
, file
);
2566 } else if (!strcmp(left
, "line")) {
2567 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2568 fprintf(fd
, "[error] %s: line already declared in callsite declaration\n", __func__
);
2572 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->line
);
2574 fprintf(fd
, "[error] %s: unexpected unary expression for callsite line\n", __func__
);
2578 CTF_CALLSITE_SET_FIELD(callsite
, line
);
2579 } else if (!strcmp(left
, "ip")) {
2580 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, ip
)) {
2581 fprintf(fd
, "[error] %s: ip already declared in callsite declaration\n", __func__
);
2585 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->ip
);
2587 fprintf(fd
, "[error] %s: unexpected unary expression for callsite ip\n", __func__
);
2591 CTF_CALLSITE_SET_FIELD(callsite
, ip
);
2593 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in callsite declaration.\n", __func__
, left
);
2602 /* TODO: declaration specifier should be added. */
2609 int ctf_callsite_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2612 struct ctf_node
*iter
;
2613 struct ctf_callsite
*callsite
;
2614 struct ctf_callsite_dups
*cs_dups
;
2616 callsite
= g_new0(struct ctf_callsite
, 1);
2617 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
2618 ret
= ctf_callsite_declaration_visit(fd
, depth
+ 1, iter
, callsite
, trace
);
2622 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2624 fprintf(fd
, "[error] %s: missing name field in callsite declaration\n", __func__
);
2627 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2629 fprintf(fd
, "[error] %s: missing func field in callsite declaration\n", __func__
);
2632 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2634 fprintf(fd
, "[error] %s: missing file field in callsite declaration\n", __func__
);
2637 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2639 fprintf(fd
, "[error] %s: missing line field in callsite declaration\n", __func__
);
2643 cs_dups
= g_hash_table_lookup(trace
->callsites
,
2644 (gpointer
) (unsigned long) callsite
->name
);
2646 cs_dups
= g_new0(struct ctf_callsite_dups
, 1);
2647 BT_INIT_LIST_HEAD(&cs_dups
->head
);
2648 g_hash_table_insert(trace
->callsites
,
2649 (gpointer
) (unsigned long) callsite
->name
, cs_dups
);
2651 bt_list_add_tail(&callsite
->node
, &cs_dups
->head
);
2655 g_free(callsite
->func
);
2656 g_free(callsite
->file
);
2662 void callsite_free(gpointer data
)
2664 struct ctf_callsite_dups
*cs_dups
= data
;
2665 struct ctf_callsite
*callsite
, *cs_n
;
2667 bt_list_for_each_entry_safe(callsite
, cs_n
, &cs_dups
->head
, node
) {
2668 g_free(callsite
->func
);
2669 g_free(callsite
->file
);
2676 int ctf_env_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2677 struct ctf_trace
*trace
)
2680 struct ctf_tracer_env
*env
= &trace
->env
;
2682 switch (node
->type
) {
2683 case NODE_CTF_EXPRESSION
:
2687 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2690 if (!strcmp(left
, "vpid")) {
2693 if (env
->vpid
!= -1) {
2694 fprintf(fd
, "[error] %s: vpid already declared in env declaration\n", __func__
);
2695 goto error
; /* ret is 0, so not an actual error, just warn. */
2697 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2699 fprintf(fd
, "[error] %s: unexpected unary expression for env vpid\n", __func__
);
2700 goto error
; /* ret is 0, so not an actual error, just warn. */
2702 env
->vpid
= (int) v
;
2703 printf_verbose("env.vpid = %d\n", env
->vpid
);
2704 } else if (!strcmp(left
, "procname")) {
2707 if (env
->procname
[0]) {
2708 fprintf(fd
, "[warning] %s: duplicated env procname\n", __func__
);
2709 goto error
; /* ret is 0, so not an actual error, just warn. */
2711 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2713 fprintf(fd
, "[warning] %s: unexpected unary expression for env procname\n", __func__
);
2714 goto error
; /* ret is 0, so not an actual error, just warn. */
2716 strncpy(env
->procname
, right
, TRACER_ENV_LEN
);
2717 env
->procname
[TRACER_ENV_LEN
- 1] = '\0';
2718 printf_verbose("env.procname = \"%s\"\n", env
->procname
);
2720 } else if (!strcmp(left
, "hostname")) {
2723 if (env
->hostname
[0]) {
2724 fprintf(fd
, "[warning] %s: duplicated env hostname\n", __func__
);
2725 goto error
; /* ret is 0, so not an actual error, just warn. */
2727 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2729 fprintf(fd
, "[warning] %s: unexpected unary expression for env hostname\n", __func__
);
2730 goto error
; /* ret is 0, so not an actual error, just warn. */
2732 strncpy(env
->hostname
, right
, TRACER_ENV_LEN
);
2733 env
->hostname
[TRACER_ENV_LEN
- 1] = '\0';
2734 printf_verbose("env.hostname = \"%s\"\n", env
->hostname
);
2736 } else if (!strcmp(left
, "domain")) {
2739 if (env
->domain
[0]) {
2740 fprintf(fd
, "[warning] %s: duplicated env domain\n", __func__
);
2741 goto error
; /* ret is 0, so not an actual error, just warn. */
2743 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2745 fprintf(fd
, "[warning] %s: unexpected unary expression for env domain\n", __func__
);
2746 goto error
; /* ret is 0, so not an actual error, just warn. */
2748 strncpy(env
->domain
, right
, TRACER_ENV_LEN
);
2749 env
->domain
[TRACER_ENV_LEN
- 1] = '\0';
2750 printf_verbose("env.domain = \"%s\"\n", env
->domain
);
2752 } else if (!strcmp(left
, "sysname")) {
2755 if (env
->sysname
[0]) {
2756 fprintf(fd
, "[warning] %s: duplicated env sysname\n", __func__
);
2757 goto error
; /* ret is 0, so not an actual error, just warn. */
2759 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2761 fprintf(fd
, "[warning] %s: unexpected unary expression for env sysname\n", __func__
);
2762 goto error
; /* ret is 0, so not an actual error, just warn. */
2764 strncpy(env
->sysname
, right
, TRACER_ENV_LEN
);
2765 env
->sysname
[TRACER_ENV_LEN
- 1] = '\0';
2766 printf_verbose("env.sysname = \"%s\"\n", env
->sysname
);
2768 } else if (!strcmp(left
, "kernel_release")) {
2771 if (env
->release
[0]) {
2772 fprintf(fd
, "[warning] %s: duplicated env release\n", __func__
);
2773 goto error
; /* ret is 0, so not an actual error, just warn. */
2775 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2777 fprintf(fd
, "[warning] %s: unexpected unary expression for env release\n", __func__
);
2778 goto error
; /* ret is 0, so not an actual error, just warn. */
2780 strncpy(env
->release
, right
, TRACER_ENV_LEN
);
2781 env
->release
[TRACER_ENV_LEN
- 1] = '\0';
2782 printf_verbose("env.release = \"%s\"\n", env
->release
);
2784 } else if (!strcmp(left
, "kernel_version")) {
2787 if (env
->version
[0]) {
2788 fprintf(fd
, "[warning] %s: duplicated env version\n", __func__
);
2789 goto error
; /* ret is 0, so not an actual error, just warn. */
2791 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2793 fprintf(fd
, "[warning] %s: unexpected unary expression for env version\n", __func__
);
2794 goto error
; /* ret is 0, so not an actual error, just warn. */
2796 strncpy(env
->version
, right
, TRACER_ENV_LEN
);
2797 env
->version
[TRACER_ENV_LEN
- 1] = '\0';
2798 printf_verbose("env.version = \"%s\"\n", env
->version
);
2801 if (is_unary_string(&node
->u
.ctf_expression
.right
)) {
2804 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2806 fprintf(fd
, "[warning] %s: unexpected unary expression for env\n", __func__
);
2810 printf_verbose("env.%s = \"%s\"\n", left
, right
);
2812 } else if (is_unary_unsigned(&node
->u
.ctf_expression
.right
)) {
2816 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2819 printf_verbose("env.%s = %" PRIu64
"\n", left
, v
);
2820 } else if (is_unary_signed(&node
->u
.ctf_expression
.right
)) {
2824 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &v
);
2827 printf_verbose("env.%s = %" PRId64
"\n", left
, v
);
2829 printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__
, left
);
2845 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2848 struct ctf_node
*iter
;
2850 trace
->env
.vpid
= -1;
2851 trace
->env
.procname
[0] = '\0';
2852 trace
->env
.hostname
[0] = '\0';
2853 trace
->env
.domain
[0] = '\0';
2854 trace
->env
.sysname
[0] = '\0';
2855 trace
->env
.release
[0] = '\0';
2856 trace
->env
.version
[0] = '\0';
2857 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
2858 ret
= ctf_env_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2867 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2871 switch (node
->type
) {
2873 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2874 trace
->root_declaration_scope
,
2875 node
->u
._typedef
.type_specifier_list
,
2876 &node
->u
._typedef
.type_declarators
,
2881 case NODE_TYPEALIAS
:
2882 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2883 trace
->root_declaration_scope
,
2884 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2889 case NODE_TYPE_SPECIFIER_LIST
:
2891 struct bt_declaration
*declaration
;
2894 * Just add the type specifier to the root scope
2895 * declaration scope. Release local reference.
2897 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2898 node
, trace
->root_declaration_scope
, trace
);
2901 bt_declaration_unref(declaration
);
2911 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2912 struct ctf_trace
*trace
, int byte_order
)
2915 struct ctf_node
*iter
;
2916 int env_clock_done
= 0;
2918 printf_verbose("CTF visitor: metadata construction...\n");
2919 trace
->byte_order
= byte_order
;
2920 trace
->parent
.clocks
= g_hash_table_new_full(g_direct_hash
,
2921 g_direct_equal
, NULL
, clock_free
);
2922 trace
->callsites
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2923 NULL
, callsite_free
);
2926 trace
->root_declaration_scope
= bt_new_declaration_scope(NULL
);
2928 switch (node
->type
) {
2930 if (!env_clock_done
) {
2932 * declarations need to query clock hash table,
2933 * so clock need to be treated first.
2935 if (bt_list_empty(&node
->u
.root
.clock
)) {
2936 ctf_clock_default(fd
, depth
+ 1, trace
);
2938 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2939 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2942 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2949 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2951 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2953 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
2957 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
2958 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
2959 if (ret
== -EINTR
) {
2960 bt_free_declaration_scope(trace
->root_declaration_scope
);
2962 * Need to restart creation of type
2963 * definitions, aliases and
2964 * trace header declarations.
2969 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
2973 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
2974 ret
= ctf_callsite_visit(fd
, depth
+ 1, iter
,
2977 fprintf(fd
, "[error] %s: callsite declaration error\n", __func__
);
2981 if (!trace
->streams
) {
2982 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
2986 bt_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
2987 ret
= ctf_env_visit(fd
, depth
+ 1, iter
, trace
);
2989 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
2993 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
2994 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
2995 trace
->root_declaration_scope
, trace
);
2997 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
3001 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
3002 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
3003 trace
->root_declaration_scope
, trace
);
3005 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
3012 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
3017 printf_verbose("done.\n");
3021 bt_free_declaration_scope(trace
->root_declaration_scope
);
3022 g_hash_table_destroy(trace
->callsites
);
3023 g_hash_table_destroy(trace
->parent
.clocks
);
3027 int ctf_destroy_metadata(struct ctf_trace
*trace
)
3030 struct ctf_file_stream
*metadata_stream
;
3032 if (trace
->streams
) {
3033 for (i
= 0; i
< trace
->streams
->len
; i
++) {
3034 struct ctf_stream_declaration
*stream
;
3037 stream
= g_ptr_array_index(trace
->streams
, i
);
3040 for (j
= 0; j
< stream
->streams
->len
; j
++) {
3041 struct ctf_stream_definition
*stream_def
;
3044 stream_def
= g_ptr_array_index(stream
->streams
, j
);
3047 for (k
= 0; k
< stream_def
->events_by_id
->len
; k
++) {
3048 struct ctf_event_definition
*event
;
3050 event
= g_ptr_array_index(stream_def
->events_by_id
, k
);
3053 if (&event
->event_fields
->p
)
3054 bt_definition_unref(&event
->event_fields
->p
);
3055 if (&event
->event_context
->p
)
3056 bt_definition_unref(&event
->event_context
->p
);
3059 if (&stream_def
->trace_packet_header
->p
)
3060 bt_definition_unref(&stream_def
->trace_packet_header
->p
);
3061 if (&stream_def
->stream_event_header
->p
)
3062 bt_definition_unref(&stream_def
->stream_event_header
->p
);
3063 if (&stream_def
->stream_packet_context
->p
)
3064 bt_definition_unref(&stream_def
->stream_packet_context
->p
);
3065 if (&stream_def
->stream_event_context
->p
)
3066 bt_definition_unref(&stream_def
->stream_event_context
->p
);
3067 g_ptr_array_free(stream_def
->events_by_id
, TRUE
);
3070 if (stream
->event_header_decl
)
3071 bt_declaration_unref(&stream
->event_header_decl
->p
);
3072 if (stream
->event_context_decl
)
3073 bt_declaration_unref(&stream
->event_context_decl
->p
);
3074 if (stream
->packet_context_decl
)
3075 bt_declaration_unref(&stream
->packet_context_decl
->p
);
3076 g_ptr_array_free(stream
->streams
, TRUE
);
3077 g_ptr_array_free(stream
->events_by_id
, TRUE
);
3078 g_hash_table_destroy(stream
->event_quark_to_id
);
3079 bt_free_declaration_scope(stream
->declaration_scope
);
3082 g_ptr_array_free(trace
->streams
, TRUE
);
3085 if (trace
->event_declarations
) {
3086 for (i
= 0; i
< trace
->event_declarations
->len
; i
++) {
3087 struct bt_ctf_event_decl
*event_decl
;
3088 struct ctf_event_declaration
*event
;
3090 event_decl
= g_ptr_array_index(trace
->event_declarations
, i
);
3091 if (event_decl
->context_decl
)
3092 g_ptr_array_free(event_decl
->context_decl
, TRUE
);
3093 if (event_decl
->fields_decl
)
3094 g_ptr_array_free(event_decl
->fields_decl
, TRUE
);
3095 if (event_decl
->packet_header_decl
)
3096 g_ptr_array_free(event_decl
->packet_header_decl
, TRUE
);
3097 if (event_decl
->event_context_decl
)
3098 g_ptr_array_free(event_decl
->event_context_decl
, TRUE
);
3099 if (event_decl
->event_header_decl
)
3100 g_ptr_array_free(event_decl
->event_header_decl
, TRUE
);
3101 if (event_decl
->packet_context_decl
)
3102 g_ptr_array_free(event_decl
->packet_context_decl
, TRUE
);
3104 event
= &event_decl
->parent
;
3105 if (event
->fields_decl
)
3106 bt_declaration_unref(&event
->fields_decl
->p
);
3107 if (event
->context_decl
)
3108 bt_declaration_unref(&event
->context_decl
->p
);
3109 bt_free_declaration_scope(event
->declaration_scope
);
3113 g_ptr_array_free(trace
->event_declarations
, TRUE
);
3115 if (trace
->packet_header_decl
)
3116 bt_declaration_unref(&trace
->packet_header_decl
->p
);
3118 bt_free_declaration_scope(trace
->root_declaration_scope
);
3119 bt_free_declaration_scope(trace
->declaration_scope
);
3121 g_hash_table_destroy(trace
->callsites
);
3122 g_hash_table_destroy(trace
->parent
.clocks
);
3124 metadata_stream
= container_of(trace
->metadata
, struct ctf_file_stream
, parent
);
3125 g_free(metadata_stream
);