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 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
->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
)) {
869 fprintf(fd
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
873 if (!bt_list_empty(min_align
)) {
876 ret
= get_unary_unsigned(min_align
, &min_align_value
);
878 fprintf(fd
, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__
);
883 struct_declaration
= bt_struct_declaration_new(declaration_scope
,
885 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
888 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
889 struct_declaration
, trace
);
891 goto error_free_declaration
;
896 ret
= bt_register_struct_declaration(g_quark_from_string(name
),
902 return &struct_declaration
->p
;
904 error_free_declaration
:
905 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
911 struct bt_declaration
*ctf_declaration_variant_visit(FILE *fd
,
912 int depth
, const char *name
, const char *choice
,
913 struct bt_list_head
*declaration_list
,
914 int has_body
, struct declaration_scope
*declaration_scope
,
915 struct ctf_trace
*trace
)
917 struct declaration_untagged_variant
*untagged_variant_declaration
;
918 struct declaration_variant
*variant_declaration
;
919 struct ctf_node
*iter
;
922 * For named variant (without body), lookup in
923 * declaration scope. Don't take reference on variant
924 * declaration: ref is only taken upon definition.
929 untagged_variant_declaration
=
930 bt_lookup_variant_declaration(g_quark_from_string(name
),
932 bt_declaration_ref(&untagged_variant_declaration
->p
);
934 /* For unnamed variant, create type */
935 /* For named variant (with body), create type and add to declaration scope */
937 if (bt_lookup_variant_declaration(g_quark_from_string(name
),
938 declaration_scope
)) {
940 fprintf(fd
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
944 untagged_variant_declaration
= bt_untagged_bt_variant_declaration_new(declaration_scope
);
945 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
948 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
949 untagged_variant_declaration
, trace
);
956 ret
= bt_register_variant_declaration(g_quark_from_string(name
),
957 untagged_variant_declaration
,
964 * if tagged, create tagged variant and return. else return
968 return &untagged_variant_declaration
->p
;
970 variant_declaration
= bt_variant_declaration_new(untagged_variant_declaration
, choice
);
971 if (!variant_declaration
)
973 bt_declaration_unref(&untagged_variant_declaration
->p
);
974 return &variant_declaration
->p
;
977 untagged_variant_declaration
->p
.declaration_free(&untagged_variant_declaration
->p
);
982 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
983 struct ctf_node
*enumerator
,
984 struct declaration_enum
*enum_declaration
,
985 struct last_enum_value
*last
)
988 struct ctf_node
*iter
;
990 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
991 if (enum_declaration
->integer_declaration
->signedness
) {
995 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
998 if (iter
->type
!= NODE_UNARY_EXPRESSION
)
1005 switch (iter
->u
.unary_expression
.type
) {
1006 case UNARY_SIGNED_CONSTANT
:
1007 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
1009 case UNARY_UNSIGNED_CONSTANT
:
1010 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1013 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1017 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1026 last
->u
.s
= end
+ 1;
1027 bt_enum_signed_insert(enum_declaration
, start
, end
, q
);
1029 uint64_t start
, end
;
1032 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
1035 if (iter
->type
!= NODE_UNARY_EXPRESSION
)
1042 switch (iter
->u
.unary_expression
.type
) {
1043 case UNARY_UNSIGNED_CONSTANT
:
1044 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1046 case UNARY_SIGNED_CONSTANT
:
1048 * We don't accept signed constants for enums with unsigned
1051 fprintf(fd
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
1054 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1058 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1067 last
->u
.u
= end
+ 1;
1068 bt_enum_unsigned_insert(enum_declaration
, start
, end
, q
);
1074 struct bt_declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
1076 struct ctf_node
*container_type
,
1077 struct bt_list_head
*enumerator_list
,
1079 struct declaration_scope
*declaration_scope
,
1080 struct ctf_trace
*trace
)
1082 struct bt_declaration
*declaration
;
1083 struct declaration_enum
*enum_declaration
;
1084 struct declaration_integer
*integer_declaration
;
1085 struct last_enum_value last_value
;
1086 struct ctf_node
*iter
;
1090 * For named enum (without body), lookup in
1091 * declaration scope. Don't take reference on enum
1092 * declaration: ref is only taken upon definition.
1098 bt_lookup_enum_declaration(g_quark_from_string(name
),
1100 bt_declaration_ref(&enum_declaration
->p
);
1101 return &enum_declaration
->p
;
1103 /* For unnamed enum, create type */
1104 /* For named enum (with body), create type and add to declaration scope */
1106 if (bt_lookup_enum_declaration(g_quark_from_string(name
),
1107 declaration_scope
)) {
1109 fprintf(fd
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
1113 if (!container_type
) {
1114 declaration
= bt_lookup_declaration(g_quark_from_static_string("int"),
1117 fprintf(fd
, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__
);
1121 declaration
= ctf_type_declarator_visit(fd
, depth
,
1128 fprintf(fd
, "[error] %s: unable to create container type for enumeration\n", __func__
);
1131 if (declaration
->id
!= CTF_TYPE_INTEGER
) {
1132 fprintf(fd
, "[error] %s: container type for enumeration is not integer\n", __func__
);
1135 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
1136 enum_declaration
= bt_enum_declaration_new(integer_declaration
);
1137 bt_declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
1138 if (enum_declaration
->integer_declaration
->signedness
) {
1143 bt_list_for_each_entry(iter
, enumerator_list
, siblings
) {
1146 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
,
1154 ret
= bt_register_enum_declaration(g_quark_from_string(name
),
1159 bt_declaration_unref(&enum_declaration
->p
);
1161 return &enum_declaration
->p
;
1164 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
1169 struct bt_declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
1170 struct ctf_node
*type_specifier_list
,
1171 struct declaration_scope
*declaration_scope
)
1174 struct bt_declaration
*declaration
;
1179 str
= g_string_new("");
1180 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
1182 (void) g_string_free(str
, TRUE
);
1185 str_c
= g_string_free(str
, FALSE
);
1186 id_q
= g_quark_from_string(str_c
);
1188 declaration
= bt_lookup_declaration(id_q
, declaration_scope
);
1191 bt_declaration_ref(declaration
);
1196 * Returns 0/1 boolean, or < 0 on error.
1199 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1201 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1202 fprintf(fd
, "[error] %s: expecting unary expression\n",
1206 switch (unary_expression
->u
.unary_expression
.type
) {
1207 case UNARY_UNSIGNED_CONSTANT
:
1208 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1212 case UNARY_SIGNED_CONSTANT
:
1213 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1218 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1220 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1222 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1224 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1227 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1228 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1233 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1241 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1245 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1246 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1250 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1251 byte_order
= BIG_ENDIAN
;
1252 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1253 byte_order
= LITTLE_ENDIAN
;
1255 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
1256 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1263 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1264 struct ctf_trace
*trace
)
1268 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1269 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1273 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1274 byte_order
= trace
->byte_order
;
1275 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1276 byte_order
= BIG_ENDIAN
;
1277 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1278 byte_order
= BIG_ENDIAN
;
1279 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1280 byte_order
= LITTLE_ENDIAN
;
1282 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1283 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1290 struct bt_declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1291 struct bt_list_head
*expressions
,
1292 struct ctf_trace
*trace
)
1294 struct ctf_node
*expression
;
1295 uint64_t alignment
= 1, size
= 0;
1296 int byte_order
= trace
->byte_order
;
1298 int has_alignment
= 0, has_size
= 0;
1300 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1301 struct ctf_clock
*clock
= NULL
;
1302 struct declaration_integer
*integer_declaration
;
1304 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1305 struct ctf_node
*left
, *right
;
1307 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1308 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1309 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1311 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1312 signedness
= get_boolean(fd
, depth
, right
);
1315 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1316 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1319 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1320 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1321 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1325 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1327 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1328 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1329 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1333 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1334 /* Make sure alignment is a power of two */
1335 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1336 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1341 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1342 switch (right
->u
.unary_expression
.type
) {
1343 case UNARY_UNSIGNED_CONSTANT
:
1344 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1349 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1352 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1353 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1359 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1361 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1365 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1366 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1368 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1369 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1370 || !strcmp(s_right
, "p")) {
1372 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1373 || !strcmp(s_right
, "o")) {
1375 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1378 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1387 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1391 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1394 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1395 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1399 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1401 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1405 if (!strcmp(s_right
, "UTF8")
1406 || !strcmp(s_right
, "utf8")
1407 || !strcmp(s_right
, "utf-8")
1408 || !strcmp(s_right
, "UTF-8"))
1409 encoding
= CTF_STRING_UTF8
;
1410 else if (!strcmp(s_right
, "ASCII")
1411 || !strcmp(s_right
, "ascii"))
1412 encoding
= CTF_STRING_ASCII
;
1413 else if (!strcmp(s_right
, "none"))
1414 encoding
= CTF_STRING_NONE
;
1416 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1421 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1424 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1425 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1429 /* currently only support clock.name.value */
1430 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1434 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1436 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1440 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1445 clock
= trace_clock_lookup(trace
, clock_name
);
1447 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1448 __func__
, g_quark_to_string(clock_name
));
1452 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1453 __func__
, left
->u
.unary_expression
.u
.string
);
1454 /* Fall-through after warning */
1458 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1461 if (!has_alignment
) {
1462 if (size
% CHAR_BIT
) {
1463 /* bit-packed alignment */
1466 /* byte-packed alignment */
1467 alignment
= CHAR_BIT
;
1470 integer_declaration
= bt_integer_declaration_new(size
,
1471 byte_order
, signedness
, alignment
,
1472 base
, encoding
, clock
);
1473 return &integer_declaration
->p
;
1477 struct bt_declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1478 struct bt_list_head
*expressions
,
1479 struct ctf_trace
*trace
)
1481 struct ctf_node
*expression
;
1482 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0,
1483 byte_order
= trace
->byte_order
;
1484 int has_alignment
= 0, has_exp_dig
= 0, has_mant_dig
= 0;
1485 struct declaration_float
*float_declaration
;
1487 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1488 struct ctf_node
*left
, *right
;
1490 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1491 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1492 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1494 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1495 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1498 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1499 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1500 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1504 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1506 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1507 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1508 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1512 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1514 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1515 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1516 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1520 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1521 /* Make sure alignment is a power of two */
1522 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1523 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1529 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1530 __func__
, left
->u
.unary_expression
.u
.string
);
1531 /* Fall-through after warning */
1534 if (!has_mant_dig
) {
1535 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1539 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1542 if (!has_alignment
) {
1543 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1544 /* bit-packed alignment */
1547 /* byte-packed alignment */
1548 alignment
= CHAR_BIT
;
1551 float_declaration
= bt_float_declaration_new(mant_dig
, exp_dig
,
1552 byte_order
, alignment
);
1553 return &float_declaration
->p
;
1557 struct bt_declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1558 struct bt_list_head
*expressions
,
1559 struct ctf_trace
*trace
)
1561 struct ctf_node
*expression
;
1562 const char *encoding_c
= NULL
;
1563 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1564 struct declaration_string
*string_declaration
;
1566 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1567 struct ctf_node
*left
, *right
;
1569 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1570 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1571 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1573 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1574 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1575 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1579 encoding_c
= right
->u
.unary_expression
.u
.string
;
1581 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1582 __func__
, left
->u
.unary_expression
.u
.string
);
1583 /* Fall-through after warning */
1586 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1587 encoding
= CTF_STRING_ASCII
;
1588 string_declaration
= bt_string_declaration_new(encoding
);
1589 return &string_declaration
->p
;
1594 struct bt_declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1595 int depth
, struct ctf_node
*type_specifier_list
,
1596 struct declaration_scope
*declaration_scope
,
1597 struct ctf_trace
*trace
)
1599 struct ctf_node
*first
;
1600 struct ctf_node
*node
;
1602 if (type_specifier_list
->type
!= NODE_TYPE_SPECIFIER_LIST
)
1605 first
= _bt_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1607 if (first
->type
!= NODE_TYPE_SPECIFIER
)
1610 node
= first
->u
.type_specifier
.node
;
1612 switch (first
->u
.type_specifier
.type
) {
1613 case TYPESPEC_FLOATING_POINT
:
1614 return ctf_declaration_floating_point_visit(fd
, depth
,
1615 &node
->u
.floating_point
.expressions
, trace
);
1616 case TYPESPEC_INTEGER
:
1617 return ctf_declaration_integer_visit(fd
, depth
,
1618 &node
->u
.integer
.expressions
, trace
);
1619 case TYPESPEC_STRING
:
1620 return ctf_declaration_string_visit(fd
, depth
,
1621 &node
->u
.string
.expressions
, trace
);
1622 case TYPESPEC_STRUCT
:
1623 return ctf_declaration_struct_visit(fd
, depth
,
1624 node
->u
._struct
.name
,
1625 &node
->u
._struct
.declaration_list
,
1626 node
->u
._struct
.has_body
,
1627 &node
->u
._struct
.min_align
,
1630 case TYPESPEC_VARIANT
:
1631 return ctf_declaration_variant_visit(fd
, depth
,
1632 node
->u
.variant
.name
,
1633 node
->u
.variant
.choice
,
1634 &node
->u
.variant
.declaration_list
,
1635 node
->u
.variant
.has_body
,
1639 return ctf_declaration_enum_visit(fd
, depth
,
1640 node
->u
._enum
.enum_id
,
1641 node
->u
._enum
.container_type
,
1642 &node
->u
._enum
.enumerator_list
,
1643 node
->u
._enum
.has_body
,
1649 case TYPESPEC_SHORT
:
1652 case TYPESPEC_FLOAT
:
1653 case TYPESPEC_DOUBLE
:
1654 case TYPESPEC_SIGNED
:
1655 case TYPESPEC_UNSIGNED
:
1657 case TYPESPEC_COMPLEX
:
1658 case TYPESPEC_IMAGINARY
:
1659 case TYPESPEC_CONST
:
1660 case TYPESPEC_ID_TYPE
:
1661 return ctf_declaration_type_specifier_visit(fd
, depth
,
1662 type_specifier_list
, declaration_scope
);
1664 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1670 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event_declaration
*event
, struct ctf_trace
*trace
)
1674 switch (node
->type
) {
1676 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1677 event
->declaration_scope
,
1678 node
->u
._typedef
.type_specifier_list
,
1679 &node
->u
._typedef
.type_declarators
,
1684 case NODE_TYPEALIAS
:
1685 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1686 event
->declaration_scope
,
1687 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1692 case NODE_CTF_EXPRESSION
:
1696 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1699 if (!strcmp(left
, "name")) {
1702 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1703 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1707 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1709 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1713 event
->name
= g_quark_from_string(right
);
1715 CTF_EVENT_SET_FIELD(event
, name
);
1716 } else if (!strcmp(left
, "id")) {
1717 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1718 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1722 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1724 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1728 CTF_EVENT_SET_FIELD(event
, id
);
1729 } else if (!strcmp(left
, "stream_id")) {
1730 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1731 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1735 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1737 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1741 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1742 if (!event
->stream
) {
1743 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1747 CTF_EVENT_SET_FIELD(event
, stream_id
);
1748 } else if (!strcmp(left
, "context")) {
1749 struct bt_declaration
*declaration
;
1751 if (event
->context_decl
) {
1752 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1756 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1757 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1758 struct ctf_node
, siblings
),
1759 event
->declaration_scope
, trace
);
1764 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1768 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1769 } else if (!strcmp(left
, "fields")) {
1770 struct bt_declaration
*declaration
;
1772 if (event
->fields_decl
) {
1773 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1777 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1778 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1779 struct ctf_node
, siblings
),
1780 event
->declaration_scope
, trace
);
1785 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1789 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1790 } else if (!strcmp(left
, "loglevel")) {
1791 int64_t loglevel
= -1;
1793 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel
)) {
1794 fprintf(fd
, "[error] %s: loglevel already declared in event declaration\n", __func__
);
1798 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &loglevel
);
1800 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel\n", __func__
);
1804 event
->loglevel
= (int) loglevel
;
1805 CTF_EVENT_SET_FIELD(event
, loglevel
);
1806 } else if (!strcmp(left
, "model.emf.uri")) {
1809 if (CTF_EVENT_FIELD_IS_SET(event
, model_emf_uri
)) {
1810 fprintf(fd
, "[error] %s: model.emf.uri already declared in event declaration\n", __func__
);
1814 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1816 fprintf(fd
, "[error] %s: unexpected unary expression for event model.emf.uri\n", __func__
);
1820 event
->model_emf_uri
= g_quark_from_string(right
);
1822 CTF_EVENT_SET_FIELD(event
, model_emf_uri
);
1824 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1825 /* Fall-through after warning */
1833 /* TODO: declaration specifier should be added. */
1840 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1841 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1844 struct ctf_node
*iter
;
1845 struct ctf_event_declaration
*event
;
1846 struct bt_ctf_event_decl
*event_decl
;
1848 event_decl
= g_new0(struct bt_ctf_event_decl
, 1);
1849 event
= &event_decl
->parent
;
1850 event
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
1851 event
->loglevel
= -1;
1852 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1853 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1857 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1859 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1862 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1863 /* Allow missing stream_id if there is only a single stream */
1864 switch (trace
->streams
->len
) {
1865 case 0: /* Create stream if there was none. */
1866 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1871 event
->stream_id
= 0;
1872 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1876 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1880 /* Allow only one event without id per stream */
1881 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1882 && event
->stream
->events_by_id
->len
!= 0) {
1884 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1887 if (event
->stream
->events_by_id
->len
<= event
->id
)
1888 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1889 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1890 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1891 (gpointer
) (unsigned long) event
->name
,
1893 g_ptr_array_add(trace
->event_declarations
, event_decl
);
1897 if (event
->fields_decl
)
1898 bt_declaration_unref(&event
->fields_decl
->p
);
1899 if (event
->context_decl
)
1900 bt_declaration_unref(&event
->context_decl
->p
);
1901 bt_free_declaration_scope(event
->declaration_scope
);
1908 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_declaration
*stream
, struct ctf_trace
*trace
)
1912 switch (node
->type
) {
1914 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1915 stream
->declaration_scope
,
1916 node
->u
._typedef
.type_specifier_list
,
1917 &node
->u
._typedef
.type_declarators
,
1922 case NODE_TYPEALIAS
:
1923 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1924 stream
->declaration_scope
,
1925 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1930 case NODE_CTF_EXPRESSION
:
1934 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1937 if (!strcmp(left
, "id")) {
1938 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1939 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1943 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1945 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1949 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1950 } else if (!strcmp(left
, "event.header")) {
1951 struct bt_declaration
*declaration
;
1953 if (stream
->event_header_decl
) {
1954 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1958 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1959 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1960 struct ctf_node
, siblings
),
1961 stream
->declaration_scope
, trace
);
1966 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1970 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1971 } else if (!strcmp(left
, "event.context")) {
1972 struct bt_declaration
*declaration
;
1974 if (stream
->event_context_decl
) {
1975 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1979 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1980 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1981 struct ctf_node
, siblings
),
1982 stream
->declaration_scope
, trace
);
1987 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1991 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1992 } else if (!strcmp(left
, "packet.context")) {
1993 struct bt_declaration
*declaration
;
1995 if (stream
->packet_context_decl
) {
1996 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
2000 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2001 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2002 struct ctf_node
, siblings
),
2003 stream
->declaration_scope
, trace
);
2008 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2012 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
2014 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
2015 /* Fall-through after warning */
2024 /* TODO: declaration specifier should be added. */
2031 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2032 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
2035 struct ctf_node
*iter
;
2036 struct ctf_stream_declaration
*stream
;
2038 stream
= g_new0(struct ctf_stream_declaration
, 1);
2039 stream
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
2040 stream
->events_by_id
= g_ptr_array_new();
2041 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2042 stream
->streams
= g_ptr_array_new();
2044 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
2045 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
2050 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
2051 /* check that packet header has stream_id field. */
2052 if (!trace
->packet_header_decl
2053 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
2055 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
2059 /* Allow only one id-less stream */
2060 if (trace
->streams
->len
!= 0) {
2062 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
2065 stream
->stream_id
= 0;
2067 if (trace
->streams
->len
<= stream
->stream_id
)
2068 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
2069 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
2070 stream
->trace
= trace
;
2075 if (stream
->event_header_decl
)
2076 bt_declaration_unref(&stream
->event_header_decl
->p
);
2077 if (stream
->event_context_decl
)
2078 bt_declaration_unref(&stream
->event_context_decl
->p
);
2079 if (stream
->packet_context_decl
)
2080 bt_declaration_unref(&stream
->packet_context_decl
->p
);
2081 g_ptr_array_free(stream
->streams
, TRUE
);
2082 g_ptr_array_free(stream
->events_by_id
, TRUE
);
2083 g_hash_table_destroy(stream
->event_quark_to_id
);
2084 bt_free_declaration_scope(stream
->declaration_scope
);
2090 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2094 switch (node
->type
) {
2096 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2097 trace
->declaration_scope
,
2098 node
->u
._typedef
.type_specifier_list
,
2099 &node
->u
._typedef
.type_declarators
,
2104 case NODE_TYPEALIAS
:
2105 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2106 trace
->declaration_scope
,
2107 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2112 case NODE_CTF_EXPRESSION
:
2116 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2119 if (!strcmp(left
, "major")) {
2120 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2121 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
2125 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
2127 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
2131 CTF_TRACE_SET_FIELD(trace
, major
);
2132 } else if (!strcmp(left
, "minor")) {
2133 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2134 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
2138 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
2140 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
2144 CTF_TRACE_SET_FIELD(trace
, minor
);
2145 } else if (!strcmp(left
, "uuid")) {
2146 unsigned char uuid
[BABELTRACE_UUID_LEN
];
2148 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, uuid
);
2150 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2154 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2155 && babeltrace_uuid_compare(uuid
, trace
->uuid
)) {
2156 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2160 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2162 CTF_TRACE_SET_FIELD(trace
, uuid
);
2163 } else if (!strcmp(left
, "byte_order")) {
2164 struct ctf_node
*right
;
2167 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2168 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2169 if (byte_order
< 0) {
2174 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2175 && byte_order
!= trace
->byte_order
) {
2176 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2180 if (byte_order
!= trace
->byte_order
) {
2181 trace
->byte_order
= byte_order
;
2183 * We need to restart
2184 * construction of the
2185 * intermediate representation.
2187 trace
->field_mask
= 0;
2188 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2193 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2194 } else if (!strcmp(left
, "packet.header")) {
2195 struct bt_declaration
*declaration
;
2197 if (trace
->packet_header_decl
) {
2198 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2202 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2203 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2204 struct ctf_node
, siblings
),
2205 trace
->declaration_scope
, trace
);
2210 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2214 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2216 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2225 /* TODO: declaration specifier should be added. */
2232 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2235 struct ctf_node
*iter
;
2237 if (trace
->declaration_scope
)
2239 trace
->declaration_scope
= bt_new_declaration_scope(trace
->root_declaration_scope
);
2240 trace
->streams
= g_ptr_array_new();
2241 trace
->event_declarations
= g_ptr_array_new();
2242 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2243 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2247 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2249 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2252 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2254 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2257 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2259 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2263 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2264 /* check that the packet header contains a "magic" field */
2265 if (!trace
->packet_header_decl
2266 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2268 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2275 if (trace
->packet_header_decl
) {
2276 bt_declaration_unref(&trace
->packet_header_decl
->p
);
2277 trace
->packet_header_decl
= NULL
;
2279 g_ptr_array_free(trace
->streams
, TRUE
);
2280 g_ptr_array_free(trace
->event_declarations
, TRUE
);
2281 bt_free_declaration_scope(trace
->declaration_scope
);
2282 trace
->declaration_scope
= NULL
;
2287 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2288 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2292 switch (node
->type
) {
2293 case NODE_CTF_EXPRESSION
:
2297 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2300 if (!strcmp(left
, "name")) {
2303 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2304 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2308 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2310 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2314 clock
->name
= g_quark_from_string(right
);
2316 CTF_CLOCK_SET_FIELD(clock
, name
);
2317 } else if (!strcmp(left
, "uuid")) {
2321 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2325 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2327 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2331 clock
->uuid
= g_quark_from_string(right
);
2333 } else if (!strcmp(left
, "description")) {
2336 if (clock
->description
) {
2337 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2338 goto error
; /* ret is 0, so not an actual error, just warn. */
2340 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2342 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2343 goto error
; /* ret is 0, so not an actual error, just warn. */
2345 clock
->description
= right
;
2346 } else if (!strcmp(left
, "freq")) {
2347 if (CTF_CLOCK_FIELD_IS_SET(clock
, freq
)) {
2348 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2352 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2354 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2358 CTF_CLOCK_SET_FIELD(clock
, freq
);
2359 } else if (!strcmp(left
, "precision")) {
2360 if (clock
->precision
) {
2361 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2365 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2367 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2371 } else if (!strcmp(left
, "offset_s")) {
2372 if (clock
->offset_s
) {
2373 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2377 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2379 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2383 } else if (!strcmp(left
, "offset")) {
2384 if (clock
->offset
) {
2385 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2389 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2391 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2395 } else if (!strcmp(left
, "absolute")) {
2396 struct ctf_node
*right
;
2398 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2399 ret
= get_boolean(fd
, depth
, right
);
2401 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2405 clock
->absolute
= ret
;
2407 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2416 /* TODO: declaration specifier should be added. */
2423 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2426 struct ctf_node
*iter
;
2427 struct ctf_clock
*clock
;
2429 clock
= g_new0(struct ctf_clock
, 1);
2430 /* Default clock frequency is set to 1000000000 */
2431 clock
->freq
= 1000000000ULL;
2432 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2433 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2437 if (opt_clock_force_correlate
) {
2439 * User requested to forcibly correlate the clock
2440 * sources, even if we have no correlation
2443 if (!clock
->absolute
) {
2444 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2446 clock
->absolute
= 1;
2448 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2450 fprintf(fd
, "[error] %s: missing name field in clock declaration\n", __func__
);
2453 if (g_hash_table_size(trace
->clocks
) > 0) {
2454 fprintf(fd
, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
2458 trace
->single_clock
= clock
;
2459 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2463 g_free(clock
->description
);
2469 void ctf_clock_default(FILE *fd
, int depth
, struct ctf_trace
*trace
)
2471 struct ctf_clock
*clock
;
2473 clock
= g_new0(struct ctf_clock
, 1);
2474 clock
->name
= g_quark_from_string("monotonic");
2476 clock
->description
= g_strdup("Default clock");
2477 /* Default clock frequency is set to 1000000000 */
2478 clock
->freq
= 1000000000ULL;
2479 if (opt_clock_force_correlate
) {
2481 * User requested to forcibly correlate the clock
2482 * sources, even if we have no correlatation
2485 if (!clock
->absolute
) {
2486 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2488 clock
->absolute
= 1;
2490 clock
->absolute
= 0; /* Not an absolute reference across traces */
2493 trace
->single_clock
= clock
;
2494 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2498 void clock_free(gpointer data
)
2500 struct ctf_clock
*clock
= data
;
2502 g_free(clock
->description
);
2507 int ctf_callsite_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2508 struct ctf_callsite
*callsite
, struct ctf_trace
*trace
)
2512 switch (node
->type
) {
2513 case NODE_CTF_EXPRESSION
:
2517 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2520 if (!strcmp(left
, "name")) {
2523 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2524 fprintf(fd
, "[error] %s: name already declared in callsite declaration\n", __func__
);
2528 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2530 fprintf(fd
, "[error] %s: unexpected unary expression for callsite name\n", __func__
);
2534 callsite
->name
= g_quark_from_string(right
);
2536 CTF_CALLSITE_SET_FIELD(callsite
, name
);
2537 } else if (!strcmp(left
, "func")) {
2540 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2541 fprintf(fd
, "[error] %s: func already declared in callsite declaration\n", __func__
);
2545 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2547 fprintf(fd
, "[error] %s: unexpected unary expression for callsite func\n", __func__
);
2551 callsite
->func
= right
;
2552 CTF_CALLSITE_SET_FIELD(callsite
, func
);
2553 } else if (!strcmp(left
, "file")) {
2556 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2557 fprintf(fd
, "[error] %s: file already declared in callsite declaration\n", __func__
);
2561 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2563 fprintf(fd
, "[error] %s: unexpected unary expression for callsite file\n", __func__
);
2567 callsite
->file
= right
;
2568 CTF_CALLSITE_SET_FIELD(callsite
, file
);
2569 } else if (!strcmp(left
, "line")) {
2570 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2571 fprintf(fd
, "[error] %s: line already declared in callsite declaration\n", __func__
);
2575 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->line
);
2577 fprintf(fd
, "[error] %s: unexpected unary expression for callsite line\n", __func__
);
2581 CTF_CALLSITE_SET_FIELD(callsite
, line
);
2582 } else if (!strcmp(left
, "ip")) {
2583 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, ip
)) {
2584 fprintf(fd
, "[error] %s: ip already declared in callsite declaration\n", __func__
);
2588 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->ip
);
2590 fprintf(fd
, "[error] %s: unexpected unary expression for callsite ip\n", __func__
);
2594 CTF_CALLSITE_SET_FIELD(callsite
, ip
);
2596 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in callsite declaration.\n", __func__
, left
);
2605 /* TODO: declaration specifier should be added. */
2612 int ctf_callsite_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2615 struct ctf_node
*iter
;
2616 struct ctf_callsite
*callsite
;
2617 struct ctf_callsite_dups
*cs_dups
;
2619 callsite
= g_new0(struct ctf_callsite
, 1);
2620 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
2621 ret
= ctf_callsite_declaration_visit(fd
, depth
+ 1, iter
, callsite
, trace
);
2625 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2627 fprintf(fd
, "[error] %s: missing name field in callsite declaration\n", __func__
);
2630 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2632 fprintf(fd
, "[error] %s: missing func field in callsite declaration\n", __func__
);
2635 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2637 fprintf(fd
, "[error] %s: missing file field in callsite declaration\n", __func__
);
2640 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2642 fprintf(fd
, "[error] %s: missing line field in callsite declaration\n", __func__
);
2646 cs_dups
= g_hash_table_lookup(trace
->callsites
,
2647 (gpointer
) (unsigned long) callsite
->name
);
2649 cs_dups
= g_new0(struct ctf_callsite_dups
, 1);
2650 BT_INIT_LIST_HEAD(&cs_dups
->head
);
2651 g_hash_table_insert(trace
->callsites
,
2652 (gpointer
) (unsigned long) callsite
->name
, cs_dups
);
2654 bt_list_add_tail(&callsite
->node
, &cs_dups
->head
);
2658 g_free(callsite
->func
);
2659 g_free(callsite
->file
);
2665 void callsite_free(gpointer data
)
2667 struct ctf_callsite_dups
*cs_dups
= data
;
2668 struct ctf_callsite
*callsite
, *cs_n
;
2670 bt_list_for_each_entry_safe(callsite
, cs_n
, &cs_dups
->head
, node
) {
2671 g_free(callsite
->func
);
2672 g_free(callsite
->file
);
2679 int ctf_env_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2680 struct ctf_trace
*trace
)
2683 struct ctf_tracer_env
*env
= &trace
->env
;
2685 switch (node
->type
) {
2686 case NODE_CTF_EXPRESSION
:
2690 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2693 if (!strcmp(left
, "vpid")) {
2696 if (env
->vpid
!= -1) {
2697 fprintf(fd
, "[error] %s: vpid already declared in env declaration\n", __func__
);
2698 goto error
; /* ret is 0, so not an actual error, just warn. */
2700 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2702 fprintf(fd
, "[error] %s: unexpected unary expression for env vpid\n", __func__
);
2703 goto error
; /* ret is 0, so not an actual error, just warn. */
2705 env
->vpid
= (int) v
;
2706 printf_verbose("env.vpid = %d\n", env
->vpid
);
2707 } else if (!strcmp(left
, "procname")) {
2710 if (env
->procname
[0]) {
2711 fprintf(fd
, "[warning] %s: duplicated env procname\n", __func__
);
2712 goto error
; /* ret is 0, so not an actual error, just warn. */
2714 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2716 fprintf(fd
, "[warning] %s: unexpected unary expression for env procname\n", __func__
);
2717 goto error
; /* ret is 0, so not an actual error, just warn. */
2719 strncpy(env
->procname
, right
, TRACER_ENV_LEN
);
2720 env
->procname
[TRACER_ENV_LEN
- 1] = '\0';
2721 printf_verbose("env.procname = \"%s\"\n", env
->procname
);
2723 } else if (!strcmp(left
, "hostname")) {
2726 if (env
->hostname
[0]) {
2727 fprintf(fd
, "[warning] %s: duplicated env hostname\n", __func__
);
2728 goto error
; /* ret is 0, so not an actual error, just warn. */
2730 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2732 fprintf(fd
, "[warning] %s: unexpected unary expression for env hostname\n", __func__
);
2733 goto error
; /* ret is 0, so not an actual error, just warn. */
2735 strncpy(env
->hostname
, right
, TRACER_ENV_LEN
);
2736 env
->hostname
[TRACER_ENV_LEN
- 1] = '\0';
2737 printf_verbose("env.hostname = \"%s\"\n", env
->hostname
);
2739 } else if (!strcmp(left
, "domain")) {
2742 if (env
->domain
[0]) {
2743 fprintf(fd
, "[warning] %s: duplicated env domain\n", __func__
);
2744 goto error
; /* ret is 0, so not an actual error, just warn. */
2746 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2748 fprintf(fd
, "[warning] %s: unexpected unary expression for env domain\n", __func__
);
2749 goto error
; /* ret is 0, so not an actual error, just warn. */
2751 strncpy(env
->domain
, right
, TRACER_ENV_LEN
);
2752 env
->domain
[TRACER_ENV_LEN
- 1] = '\0';
2753 printf_verbose("env.domain = \"%s\"\n", env
->domain
);
2755 } else if (!strcmp(left
, "sysname")) {
2758 if (env
->sysname
[0]) {
2759 fprintf(fd
, "[warning] %s: duplicated env sysname\n", __func__
);
2760 goto error
; /* ret is 0, so not an actual error, just warn. */
2762 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2764 fprintf(fd
, "[warning] %s: unexpected unary expression for env sysname\n", __func__
);
2765 goto error
; /* ret is 0, so not an actual error, just warn. */
2767 strncpy(env
->sysname
, right
, TRACER_ENV_LEN
);
2768 env
->sysname
[TRACER_ENV_LEN
- 1] = '\0';
2769 printf_verbose("env.sysname = \"%s\"\n", env
->sysname
);
2771 } else if (!strcmp(left
, "kernel_release")) {
2774 if (env
->release
[0]) {
2775 fprintf(fd
, "[warning] %s: duplicated env release\n", __func__
);
2776 goto error
; /* ret is 0, so not an actual error, just warn. */
2778 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2780 fprintf(fd
, "[warning] %s: unexpected unary expression for env release\n", __func__
);
2781 goto error
; /* ret is 0, so not an actual error, just warn. */
2783 strncpy(env
->release
, right
, TRACER_ENV_LEN
);
2784 env
->release
[TRACER_ENV_LEN
- 1] = '\0';
2785 printf_verbose("env.release = \"%s\"\n", env
->release
);
2787 } else if (!strcmp(left
, "kernel_version")) {
2790 if (env
->version
[0]) {
2791 fprintf(fd
, "[warning] %s: duplicated env version\n", __func__
);
2792 goto error
; /* ret is 0, so not an actual error, just warn. */
2794 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2796 fprintf(fd
, "[warning] %s: unexpected unary expression for env version\n", __func__
);
2797 goto error
; /* ret is 0, so not an actual error, just warn. */
2799 strncpy(env
->version
, right
, TRACER_ENV_LEN
);
2800 env
->version
[TRACER_ENV_LEN
- 1] = '\0';
2801 printf_verbose("env.version = \"%s\"\n", env
->version
);
2804 if (is_unary_string(&node
->u
.ctf_expression
.right
)) {
2807 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2809 fprintf(fd
, "[warning] %s: unexpected unary expression for env\n", __func__
);
2813 printf_verbose("env.%s = \"%s\"\n", left
, right
);
2815 } else if (is_unary_unsigned(&node
->u
.ctf_expression
.right
)) {
2819 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2822 printf_verbose("env.%s = %" PRIu64
"\n", left
, v
);
2823 } else if (is_unary_signed(&node
->u
.ctf_expression
.right
)) {
2827 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &v
);
2830 printf_verbose("env.%s = %" PRId64
"\n", left
, v
);
2832 printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__
, left
);
2848 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2851 struct ctf_node
*iter
;
2853 trace
->env
.vpid
= -1;
2854 trace
->env
.procname
[0] = '\0';
2855 trace
->env
.hostname
[0] = '\0';
2856 trace
->env
.domain
[0] = '\0';
2857 trace
->env
.sysname
[0] = '\0';
2858 trace
->env
.release
[0] = '\0';
2859 trace
->env
.version
[0] = '\0';
2860 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
2861 ret
= ctf_env_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2870 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2874 switch (node
->type
) {
2876 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2877 trace
->root_declaration_scope
,
2878 node
->u
._typedef
.type_specifier_list
,
2879 &node
->u
._typedef
.type_declarators
,
2884 case NODE_TYPEALIAS
:
2885 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2886 trace
->root_declaration_scope
,
2887 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2892 case NODE_TYPE_SPECIFIER_LIST
:
2894 struct bt_declaration
*declaration
;
2897 * Just add the type specifier to the root scope
2898 * declaration scope. Release local reference.
2900 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2901 node
, trace
->root_declaration_scope
, trace
);
2904 bt_declaration_unref(declaration
);
2914 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2915 struct ctf_trace
*trace
, int byte_order
)
2918 struct ctf_node
*iter
;
2919 int env_clock_done
= 0;
2921 printf_verbose("CTF visitor: metadata construction...\n");
2922 trace
->byte_order
= byte_order
;
2923 trace
->clocks
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2925 trace
->callsites
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2926 NULL
, callsite_free
);
2929 trace
->root_declaration_scope
= bt_new_declaration_scope(NULL
);
2931 switch (node
->type
) {
2933 if (!env_clock_done
) {
2935 * declarations need to query clock hash table,
2936 * so clock need to be treated first.
2938 if (bt_list_empty(&node
->u
.root
.clock
)) {
2939 ctf_clock_default(fd
, depth
+ 1, trace
);
2941 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2942 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2945 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2952 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2954 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2956 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
2960 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
2961 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
2962 if (ret
== -EINTR
) {
2963 bt_free_declaration_scope(trace
->root_declaration_scope
);
2965 * Need to restart creation of type
2966 * definitions, aliases and
2967 * trace header declarations.
2972 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
2976 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
2977 ret
= ctf_callsite_visit(fd
, depth
+ 1, iter
,
2980 fprintf(fd
, "[error] %s: callsite declaration error\n", __func__
);
2984 if (!trace
->streams
) {
2985 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
2989 bt_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
2990 ret
= ctf_env_visit(fd
, depth
+ 1, iter
, trace
);
2992 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
2996 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
2997 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
2998 trace
->root_declaration_scope
, trace
);
3000 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
3004 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
3005 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
3006 trace
->root_declaration_scope
, trace
);
3008 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
3015 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
3020 printf_verbose("done.\n");
3024 bt_free_declaration_scope(trace
->root_declaration_scope
);
3025 g_hash_table_destroy(trace
->callsites
);
3026 g_hash_table_destroy(trace
->clocks
);
3030 int ctf_destroy_metadata(struct ctf_trace
*trace
)
3033 struct ctf_file_stream
*metadata_stream
;
3035 if (trace
->streams
) {
3036 for (i
= 0; i
< trace
->streams
->len
; i
++) {
3037 struct ctf_stream_declaration
*stream
;
3040 stream
= g_ptr_array_index(trace
->streams
, i
);
3043 for (j
= 0; j
< stream
->streams
->len
; j
++) {
3044 struct ctf_stream_definition
*stream_def
;
3047 stream_def
= g_ptr_array_index(stream
->streams
, j
);
3050 for (k
= 0; k
< stream_def
->events_by_id
->len
; k
++) {
3051 struct ctf_event_definition
*event
;
3053 event
= g_ptr_array_index(stream_def
->events_by_id
, k
);
3056 if (&event
->event_fields
->p
)
3057 bt_definition_unref(&event
->event_fields
->p
);
3058 if (&event
->event_context
->p
)
3059 bt_definition_unref(&event
->event_context
->p
);
3062 if (&stream_def
->trace_packet_header
->p
)
3063 bt_definition_unref(&stream_def
->trace_packet_header
->p
);
3064 if (&stream_def
->stream_event_header
->p
)
3065 bt_definition_unref(&stream_def
->stream_event_header
->p
);
3066 if (&stream_def
->stream_packet_context
->p
)
3067 bt_definition_unref(&stream_def
->stream_packet_context
->p
);
3068 if (&stream_def
->stream_event_context
->p
)
3069 bt_definition_unref(&stream_def
->stream_event_context
->p
);
3070 g_ptr_array_free(stream_def
->events_by_id
, TRUE
);
3073 if (stream
->event_header_decl
)
3074 bt_declaration_unref(&stream
->event_header_decl
->p
);
3075 if (stream
->event_context_decl
)
3076 bt_declaration_unref(&stream
->event_context_decl
->p
);
3077 if (stream
->packet_context_decl
)
3078 bt_declaration_unref(&stream
->packet_context_decl
->p
);
3079 g_ptr_array_free(stream
->streams
, TRUE
);
3080 g_ptr_array_free(stream
->events_by_id
, TRUE
);
3081 g_hash_table_destroy(stream
->event_quark_to_id
);
3082 bt_free_declaration_scope(stream
->declaration_scope
);
3085 g_ptr_array_free(trace
->streams
, TRUE
);
3088 if (trace
->event_declarations
) {
3089 for (i
= 0; i
< trace
->event_declarations
->len
; i
++) {
3090 struct bt_ctf_event_decl
*event_decl
;
3091 struct ctf_event_declaration
*event
;
3093 event_decl
= g_ptr_array_index(trace
->event_declarations
, i
);
3094 if (event_decl
->context_decl
)
3095 g_ptr_array_free(event_decl
->context_decl
, TRUE
);
3096 if (event_decl
->fields_decl
)
3097 g_ptr_array_free(event_decl
->fields_decl
, TRUE
);
3098 if (event_decl
->packet_header_decl
)
3099 g_ptr_array_free(event_decl
->packet_header_decl
, TRUE
);
3100 if (event_decl
->event_context_decl
)
3101 g_ptr_array_free(event_decl
->event_context_decl
, TRUE
);
3102 if (event_decl
->event_header_decl
)
3103 g_ptr_array_free(event_decl
->event_header_decl
, TRUE
);
3104 if (event_decl
->packet_context_decl
)
3105 g_ptr_array_free(event_decl
->packet_context_decl
, TRUE
);
3107 event
= &event_decl
->parent
;
3108 if (event
->fields_decl
)
3109 bt_declaration_unref(&event
->fields_decl
->p
);
3110 if (event
->context_decl
)
3111 bt_declaration_unref(&event
->context_decl
->p
);
3112 bt_free_declaration_scope(event
->declaration_scope
);
3116 g_ptr_array_free(trace
->event_declarations
, TRUE
);
3118 if (trace
->packet_header_decl
)
3119 bt_declaration_unref(&trace
->packet_header_decl
->p
);
3121 bt_free_declaration_scope(trace
->root_declaration_scope
);
3122 bt_free_declaration_scope(trace
->declaration_scope
);
3124 g_hash_table_destroy(trace
->callsites
);
3125 g_hash_table_destroy(trace
->clocks
);
3127 metadata_stream
= container_of(trace
->metadata
, struct ctf_file_stream
, parent
);
3128 g_free(metadata_stream
);