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
&& node
->u
.unary_expression
.type
!= UNARY_SIGNED_CONSTANT
)
223 || node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
226 switch (node
->u
.unary_expression
.type
) {
227 case UNARY_UNSIGNED_CONSTANT
:
228 *value
= (int64_t) node
->u
.unary_expression
.u
.unsigned_constant
;
230 case UNARY_SIGNED_CONSTANT
:
231 *value
= node
->u
.unary_expression
.u
.signed_constant
;
242 int get_unary_uuid(struct bt_list_head
*head
, unsigned char *uuid
)
244 struct ctf_node
*node
;
248 bt_list_for_each_entry(node
, head
, siblings
) {
249 const char *src_string
;
251 if (node
->type
!= NODE_UNARY_EXPRESSION
252 || node
->u
.unary_expression
.type
!= UNARY_STRING
253 || node
->u
.unary_expression
.link
!= UNARY_LINK_UNKNOWN
256 src_string
= node
->u
.unary_expression
.u
.string
;
257 ret
= bt_uuid_parse(src_string
, uuid
);
263 struct ctf_stream_declaration
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
265 if (trace
->streams
->len
<= stream_id
)
267 return g_ptr_array_index(trace
->streams
, stream_id
);
271 struct ctf_event_declaration
*stream_event_lookup(struct ctf_stream_declaration
*stream
, uint64_t event_id
)
273 if (stream
->events_by_id
->len
<= event_id
)
275 return g_ptr_array_index(stream
->events_by_id
, event_id
);
279 struct ctf_clock
*trace_clock_lookup(struct ctf_trace
*trace
, GQuark clock_name
)
281 return g_hash_table_lookup(trace
->parent
.clocks
, (gpointer
) (unsigned long) clock_name
);
285 int visit_type_specifier(FILE *fd
, struct ctf_node
*type_specifier
, GString
*str
)
287 if (type_specifier
->type
!= NODE_TYPE_SPECIFIER
)
290 switch (type_specifier
->u
.type_specifier
.type
) {
292 g_string_append(str
, "void");
295 g_string_append(str
, "char");
298 g_string_append(str
, "short");
301 g_string_append(str
, "int");
304 g_string_append(str
, "long");
307 g_string_append(str
, "float");
309 case TYPESPEC_DOUBLE
:
310 g_string_append(str
, "double");
312 case TYPESPEC_SIGNED
:
313 g_string_append(str
, "signed");
315 case TYPESPEC_UNSIGNED
:
316 g_string_append(str
, "unsigned");
319 g_string_append(str
, "bool");
321 case TYPESPEC_COMPLEX
:
322 g_string_append(str
, "_Complex");
324 case TYPESPEC_IMAGINARY
:
325 g_string_append(str
, "_Imaginary");
328 g_string_append(str
, "const");
330 case TYPESPEC_ID_TYPE
:
331 if (type_specifier
->u
.type_specifier
.id_type
)
332 g_string_append(str
, type_specifier
->u
.type_specifier
.id_type
);
334 case TYPESPEC_STRUCT
:
336 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
338 if (!node
->u
._struct
.name
) {
339 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
342 g_string_append(str
, "struct ");
343 g_string_append(str
, node
->u
._struct
.name
);
346 case TYPESPEC_VARIANT
:
348 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
350 if (!node
->u
.variant
.name
) {
351 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
354 g_string_append(str
, "variant ");
355 g_string_append(str
, node
->u
.variant
.name
);
360 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
362 if (!node
->u
._enum
.enum_id
) {
363 fprintf(fd
, "[error] %s: unexpected empty enum ID\n", __func__
);
366 g_string_append(str
, "enum ");
367 g_string_append(str
, node
->u
._enum
.enum_id
);
370 case TYPESPEC_FLOATING_POINT
:
371 case TYPESPEC_INTEGER
:
372 case TYPESPEC_STRING
:
374 fprintf(fd
, "[error] %s: unknown specifier\n", __func__
);
381 int visit_type_specifier_list(FILE *fd
, struct ctf_node
*type_specifier_list
, GString
*str
)
383 struct ctf_node
*iter
;
384 int alias_item_nr
= 0;
387 bt_list_for_each_entry(iter
, &type_specifier_list
->u
.type_specifier_list
.head
, siblings
) {
388 if (alias_item_nr
!= 0)
389 g_string_append(str
, " ");
391 ret
= visit_type_specifier(fd
, iter
, str
);
399 GQuark
create_typealias_identifier(FILE *fd
, int depth
,
400 struct ctf_node
*type_specifier_list
,
401 struct ctf_node
*node_type_declarator
)
403 struct ctf_node
*iter
;
409 str
= g_string_new("");
410 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
412 g_string_free(str
, TRUE
);
415 bt_list_for_each_entry(iter
, &node_type_declarator
->u
.type_declarator
.pointers
, siblings
) {
416 g_string_append(str
, " *");
417 if (iter
->u
.pointer
.const_qualifier
)
418 g_string_append(str
, " const");
420 str_c
= g_string_free(str
, FALSE
);
421 alias_q
= g_quark_from_string(str_c
);
427 struct bt_declaration
*ctf_type_declarator_visit(FILE *fd
, int depth
,
428 struct ctf_node
*type_specifier_list
,
430 struct ctf_node
*node_type_declarator
,
431 struct declaration_scope
*declaration_scope
,
432 struct bt_declaration
*nested_declaration
,
433 struct ctf_trace
*trace
)
436 * Visit type declarator by first taking care of sequence/array
437 * (recursively). Then, when we get to the identifier, take care
441 if (node_type_declarator
) {
442 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_UNKNOWN
) {
446 /* TODO: gcc bitfields not supported yet. */
447 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!= NULL
) {
448 fprintf(fd
, "[error] %s: gcc bitfields are not supported yet.\n", __func__
);
453 if (!nested_declaration
) {
454 if (node_type_declarator
&& !bt_list_empty(&node_type_declarator
->u
.type_declarator
.pointers
)) {
458 * If we have a pointer declarator, it _has_ to be present in
459 * the typealiases (else fail).
461 alias_q
= create_typealias_identifier(fd
, depth
,
462 type_specifier_list
, node_type_declarator
);
463 nested_declaration
= bt_lookup_declaration(alias_q
, declaration_scope
);
464 if (!nested_declaration
) {
465 fprintf(fd
, "[error] %s: cannot find typealias \"%s\".\n", __func__
, g_quark_to_string(alias_q
));
468 if (nested_declaration
->id
== CTF_TYPE_INTEGER
) {
469 struct declaration_integer
*integer_declaration
=
470 container_of(nested_declaration
, struct declaration_integer
, p
);
471 /* For base to 16 for pointers (expected pretty-print) */
472 if (!integer_declaration
->base
) {
474 * We need to do a copy of the
475 * integer declaration to modify it. There could be other references to
478 integer_declaration
= bt_integer_declaration_new(integer_declaration
->len
,
479 integer_declaration
->byte_order
, integer_declaration
->signedness
,
480 integer_declaration
->p
.alignment
, 16, integer_declaration
->encoding
,
481 integer_declaration
->clock
);
482 nested_declaration
= &integer_declaration
->p
;
486 nested_declaration
= ctf_type_specifier_list_visit(fd
, depth
,
487 type_specifier_list
, declaration_scope
, trace
);
491 if (!node_type_declarator
)
492 return nested_declaration
;
494 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
495 if (node_type_declarator
->u
.type_declarator
.u
.id
)
496 *field_name
= g_quark_from_string(node_type_declarator
->u
.type_declarator
.u
.id
);
499 return nested_declaration
;
501 struct bt_declaration
*declaration
;
502 struct ctf_node
*first
;
506 if (!nested_declaration
) {
507 fprintf(fd
, "[error] %s: nested type is unknown.\n", __func__
);
511 /* create array/sequence, pass nested_declaration as child. */
512 if (bt_list_empty(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
)) {
513 fprintf(fd
, "[error] %s: expecting length field reference or value.\n", __func__
);
516 first
= _bt_list_first_entry(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
,
517 struct ctf_node
, siblings
);
518 if (first
->type
!= NODE_UNARY_EXPRESSION
) {
522 switch (first
->u
.unary_expression
.type
) {
523 case UNARY_UNSIGNED_CONSTANT
:
525 struct declaration_array
*array_declaration
;
528 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
529 array_declaration
= bt_array_declaration_new(len
, nested_declaration
,
532 if (!array_declaration
) {
533 fprintf(fd
, "[error] %s: cannot create array declaration.\n", __func__
);
536 bt_declaration_unref(nested_declaration
);
537 declaration
= &array_declaration
->p
;
542 /* Lookup unsigned integer definition, create sequence */
543 char *length_name
= concatenate_unary_strings(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
);
544 struct declaration_sequence
*sequence_declaration
;
548 sequence_declaration
= bt_sequence_declaration_new(length_name
, nested_declaration
, declaration_scope
);
549 if (!sequence_declaration
) {
550 fprintf(fd
, "[error] %s: cannot create sequence declaration.\n", __func__
);
554 bt_declaration_unref(nested_declaration
);
555 declaration
= &sequence_declaration
->p
;
563 /* Pass it as content of outer container */
564 declaration
= ctf_type_declarator_visit(fd
, depth
,
565 type_specifier_list
, field_name
,
566 node_type_declarator
->u
.type_declarator
.u
.nested
.type_declarator
,
567 declaration_scope
, declaration
, trace
);
573 int ctf_struct_type_declarators_visit(FILE *fd
, int depth
,
574 struct declaration_struct
*struct_declaration
,
575 struct ctf_node
*type_specifier_list
,
576 struct bt_list_head
*type_declarators
,
577 struct declaration_scope
*declaration_scope
,
578 struct ctf_trace
*trace
)
580 struct ctf_node
*iter
;
583 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
584 struct bt_declaration
*field_declaration
;
586 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
589 struct_declaration
->scope
,
591 if (!field_declaration
) {
592 fprintf(fd
, "[error] %s: unable to find struct field declaration type\n", __func__
);
596 /* Check if field with same name already exists */
597 if (bt_struct_declaration_lookup_field_index(struct_declaration
, field_name
) >= 0) {
598 fprintf(fd
, "[error] %s: duplicate field %s in struct\n", __func__
, g_quark_to_string(field_name
));
602 bt_struct_declaration_add_field(struct_declaration
,
603 g_quark_to_string(field_name
),
605 bt_declaration_unref(field_declaration
);
611 int ctf_variant_type_declarators_visit(FILE *fd
, int depth
,
612 struct declaration_untagged_variant
*untagged_variant_declaration
,
613 struct ctf_node
*type_specifier_list
,
614 struct bt_list_head
*type_declarators
,
615 struct declaration_scope
*declaration_scope
,
616 struct ctf_trace
*trace
)
618 struct ctf_node
*iter
;
621 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
622 struct bt_declaration
*field_declaration
;
624 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
627 untagged_variant_declaration
->scope
,
629 if (!field_declaration
) {
630 fprintf(fd
, "[error] %s: unable to find variant field declaration type\n", __func__
);
634 if (bt_untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration
, field_name
) != NULL
) {
635 fprintf(fd
, "[error] %s: duplicate field %s in variant\n", __func__
, g_quark_to_string(field_name
));
639 bt_untagged_variant_declaration_add_field(untagged_variant_declaration
,
640 g_quark_to_string(field_name
),
642 bt_declaration_unref(field_declaration
);
648 int ctf_typedef_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
649 struct ctf_node
*type_specifier_list
,
650 struct bt_list_head
*type_declarators
,
651 struct ctf_trace
*trace
)
653 struct ctf_node
*iter
;
656 bt_list_for_each_entry(iter
, type_declarators
, siblings
) {
657 struct bt_declaration
*type_declaration
;
660 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
664 if (!type_declaration
) {
665 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
669 * Don't allow typedef and typealias of untagged
672 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
673 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
674 bt_declaration_unref(type_declaration
);
677 ret
= bt_register_declaration(identifier
, type_declaration
, scope
);
679 type_declaration
->declaration_free(type_declaration
);
682 bt_declaration_unref(type_declaration
);
688 int ctf_typealias_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
689 struct ctf_node
*target
, struct ctf_node
*alias
,
690 struct ctf_trace
*trace
)
692 struct bt_declaration
*type_declaration
;
693 struct ctf_node
*node
;
698 /* See ctf_visitor_type_declarator() in the semantic validator. */
701 * Create target type declaration.
704 if (bt_list_empty(&target
->u
.typealias_target
.type_declarators
))
707 node
= _bt_list_first_entry(&target
->u
.typealias_target
.type_declarators
,
708 struct ctf_node
, siblings
);
709 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
710 target
->u
.typealias_target
.type_specifier_list
,
713 if (!type_declaration
) {
714 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
719 * Don't allow typedef and typealias of untagged
722 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
723 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
724 bt_declaration_unref(type_declaration
);
728 * The semantic validator does not check whether the target is
729 * abstract or not (if it has an identifier). Check it here.
732 fprintf(fd
, "[error] %s: expecting empty identifier\n", __func__
);
737 * Create alias identifier.
740 node
= _bt_list_first_entry(&alias
->u
.typealias_alias
.type_declarators
,
741 struct ctf_node
, siblings
);
742 alias_q
= create_typealias_identifier(fd
, depth
,
743 alias
->u
.typealias_alias
.type_specifier_list
, node
);
744 err
= bt_register_declaration(alias_q
, type_declaration
, scope
);
747 bt_declaration_unref(type_declaration
);
751 if (type_declaration
) {
752 type_declaration
->declaration_free(type_declaration
);
758 int ctf_struct_declaration_list_visit(FILE *fd
, int depth
,
759 struct ctf_node
*iter
, struct declaration_struct
*struct_declaration
,
760 struct ctf_trace
*trace
)
764 switch (iter
->type
) {
766 /* For each declarator, declare type and add type to struct bt_declaration scope */
767 ret
= ctf_typedef_visit(fd
, depth
,
768 struct_declaration
->scope
,
769 iter
->u
._typedef
.type_specifier_list
,
770 &iter
->u
._typedef
.type_declarators
, trace
);
775 /* Declare type with declarator and add type to struct bt_declaration scope */
776 ret
= ctf_typealias_visit(fd
, depth
,
777 struct_declaration
->scope
,
778 iter
->u
.typealias
.target
,
779 iter
->u
.typealias
.alias
, trace
);
783 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
784 /* Add field to structure declaration */
785 ret
= ctf_struct_type_declarators_visit(fd
, depth
,
787 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
788 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
789 struct_declaration
->scope
, trace
);
794 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
801 int ctf_variant_declaration_list_visit(FILE *fd
, int depth
,
802 struct ctf_node
*iter
,
803 struct declaration_untagged_variant
*untagged_variant_declaration
,
804 struct ctf_trace
*trace
)
808 switch (iter
->type
) {
810 /* For each declarator, declare type and add type to variant declaration scope */
811 ret
= ctf_typedef_visit(fd
, depth
,
812 untagged_variant_declaration
->scope
,
813 iter
->u
._typedef
.type_specifier_list
,
814 &iter
->u
._typedef
.type_declarators
, trace
);
819 /* Declare type with declarator and add type to variant declaration scope */
820 ret
= ctf_typealias_visit(fd
, depth
,
821 untagged_variant_declaration
->scope
,
822 iter
->u
.typealias
.target
,
823 iter
->u
.typealias
.alias
, trace
);
827 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
828 /* Add field to structure declaration */
829 ret
= ctf_variant_type_declarators_visit(fd
, depth
,
830 untagged_variant_declaration
,
831 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
832 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
833 untagged_variant_declaration
->scope
, trace
);
838 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
845 struct bt_declaration
*ctf_declaration_struct_visit(FILE *fd
,
846 int depth
, const char *name
, struct bt_list_head
*declaration_list
,
847 int has_body
, struct bt_list_head
*min_align
,
848 struct declaration_scope
*declaration_scope
,
849 struct ctf_trace
*trace
)
851 struct declaration_struct
*struct_declaration
;
852 struct ctf_node
*iter
;
855 * For named struct (without body), lookup in
856 * declaration scope. Don't take reference on struct
857 * declaration: ref is only taken upon definition.
863 bt_lookup_struct_declaration(g_quark_from_string(name
),
865 bt_declaration_ref(&struct_declaration
->p
);
866 return &struct_declaration
->p
;
868 uint64_t min_align_value
= 0;
870 /* For unnamed struct, create type */
871 /* For named struct (with body), create type and add to declaration scope */
873 if (bt_lookup_struct_declaration(g_quark_from_string(name
),
874 declaration_scope
)) {
875 fprintf(fd
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
879 if (!bt_list_empty(min_align
)) {
882 ret
= get_unary_unsigned(min_align
, &min_align_value
);
884 fprintf(fd
, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__
);
888 struct_declaration
= bt_struct_declaration_new(declaration_scope
,
890 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
893 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
894 struct_declaration
, trace
);
896 goto error_free_declaration
;
901 ret
= bt_register_struct_declaration(g_quark_from_string(name
),
907 return &struct_declaration
->p
;
909 error_free_declaration
:
910 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
916 struct bt_declaration
*ctf_declaration_variant_visit(FILE *fd
,
917 int depth
, const char *name
, const char *choice
,
918 struct bt_list_head
*declaration_list
,
919 int has_body
, struct declaration_scope
*declaration_scope
,
920 struct ctf_trace
*trace
)
922 struct declaration_untagged_variant
*untagged_variant_declaration
;
923 struct declaration_variant
*variant_declaration
;
924 struct ctf_node
*iter
;
927 * For named variant (without body), lookup in
928 * declaration scope. Don't take reference on variant
929 * declaration: ref is only taken upon definition.
934 untagged_variant_declaration
=
935 bt_lookup_variant_declaration(g_quark_from_string(name
),
937 bt_declaration_ref(&untagged_variant_declaration
->p
);
939 /* For unnamed variant, create type */
940 /* For named variant (with body), create type and add to declaration scope */
942 if (bt_lookup_variant_declaration(g_quark_from_string(name
),
943 declaration_scope
)) {
944 fprintf(fd
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
948 untagged_variant_declaration
= bt_untagged_bt_variant_declaration_new(declaration_scope
);
949 bt_list_for_each_entry(iter
, declaration_list
, siblings
) {
952 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
953 untagged_variant_declaration
, trace
);
960 ret
= bt_register_variant_declaration(g_quark_from_string(name
),
961 untagged_variant_declaration
,
968 * if tagged, create tagged variant and return. else return
972 return &untagged_variant_declaration
->p
;
974 variant_declaration
= bt_variant_declaration_new(untagged_variant_declaration
, choice
);
975 if (!variant_declaration
)
977 bt_declaration_unref(&untagged_variant_declaration
->p
);
978 return &variant_declaration
->p
;
981 untagged_variant_declaration
->p
.declaration_free(&untagged_variant_declaration
->p
);
986 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
987 struct ctf_node
*enumerator
,
988 struct declaration_enum
*enum_declaration
,
989 struct last_enum_value
*last
)
992 struct ctf_node
*iter
;
994 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
995 if (enum_declaration
->integer_declaration
->signedness
) {
996 int64_t start
= 0, end
= 0;
999 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
1002 if (iter
->type
!= NODE_UNARY_EXPRESSION
)
1009 switch (iter
->u
.unary_expression
.type
) {
1010 case UNARY_SIGNED_CONSTANT
:
1011 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
1013 case UNARY_UNSIGNED_CONSTANT
:
1014 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1017 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1021 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1030 last
->u
.s
= end
+ 1;
1031 bt_enum_signed_insert(enum_declaration
, start
, end
, q
);
1033 uint64_t start
= 0, end
= 0;
1036 bt_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
1039 if (iter
->type
!= NODE_UNARY_EXPRESSION
)
1046 switch (iter
->u
.unary_expression
.type
) {
1047 case UNARY_UNSIGNED_CONSTANT
:
1048 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
1050 case UNARY_SIGNED_CONSTANT
:
1052 * We don't accept signed constants for enums with unsigned
1055 fprintf(fd
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
1058 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1062 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
1071 last
->u
.u
= end
+ 1;
1072 bt_enum_unsigned_insert(enum_declaration
, start
, end
, q
);
1078 struct bt_declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
1080 struct ctf_node
*container_type
,
1081 struct bt_list_head
*enumerator_list
,
1083 struct declaration_scope
*declaration_scope
,
1084 struct ctf_trace
*trace
)
1086 struct bt_declaration
*declaration
;
1087 struct declaration_enum
*enum_declaration
;
1088 struct declaration_integer
*integer_declaration
;
1089 struct last_enum_value last_value
;
1090 struct ctf_node
*iter
;
1094 * For named enum (without body), lookup in
1095 * declaration scope. Don't take reference on enum
1096 * declaration: ref is only taken upon definition.
1102 bt_lookup_enum_declaration(g_quark_from_string(name
),
1104 bt_declaration_ref(&enum_declaration
->p
);
1105 return &enum_declaration
->p
;
1107 /* For unnamed enum, create type */
1108 /* For named enum (with body), create type and add to declaration scope */
1110 if (bt_lookup_enum_declaration(g_quark_from_string(name
),
1111 declaration_scope
)) {
1112 fprintf(fd
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
1116 if (!container_type
) {
1117 declaration
= bt_lookup_declaration(g_quark_from_static_string("int"),
1120 fprintf(fd
, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__
);
1124 declaration
= ctf_type_declarator_visit(fd
, depth
,
1131 fprintf(fd
, "[error] %s: unable to create container type for enumeration\n", __func__
);
1134 if (declaration
->id
!= CTF_TYPE_INTEGER
) {
1135 fprintf(fd
, "[error] %s: container type for enumeration is not integer\n", __func__
);
1138 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
1139 enum_declaration
= bt_enum_declaration_new(integer_declaration
);
1140 bt_declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
1141 if (enum_declaration
->integer_declaration
->signedness
) {
1146 bt_list_for_each_entry(iter
, enumerator_list
, siblings
) {
1149 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
,
1157 ret
= bt_register_enum_declaration(g_quark_from_string(name
),
1162 bt_declaration_unref(&enum_declaration
->p
);
1164 return &enum_declaration
->p
;
1167 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
1172 struct bt_declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
1173 struct ctf_node
*type_specifier_list
,
1174 struct declaration_scope
*declaration_scope
)
1177 struct bt_declaration
*declaration
;
1182 str
= g_string_new("");
1183 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
1185 (void) g_string_free(str
, TRUE
);
1188 str_c
= g_string_free(str
, FALSE
);
1189 id_q
= g_quark_from_string(str_c
);
1191 declaration
= bt_lookup_declaration(id_q
, declaration_scope
);
1194 bt_declaration_ref(declaration
);
1199 * Returns 0/1 boolean, or < 0 on error.
1202 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1204 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1205 fprintf(fd
, "[error] %s: expecting unary expression\n",
1209 switch (unary_expression
->u
.unary_expression
.type
) {
1210 case UNARY_UNSIGNED_CONSTANT
:
1211 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1215 case UNARY_SIGNED_CONSTANT
:
1216 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1221 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1223 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1225 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1227 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1230 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1231 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1236 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1244 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1248 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1249 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1253 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1254 byte_order
= BIG_ENDIAN
;
1255 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1256 byte_order
= LITTLE_ENDIAN
;
1258 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"be\" or \"le\".\n",
1259 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1266 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1267 struct ctf_trace
*trace
)
1271 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1272 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1276 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1277 byte_order
= trace
->byte_order
;
1278 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1279 byte_order
= BIG_ENDIAN
;
1280 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1281 byte_order
= BIG_ENDIAN
;
1282 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1283 byte_order
= LITTLE_ENDIAN
;
1285 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1286 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1293 struct bt_declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1294 struct bt_list_head
*expressions
,
1295 struct ctf_trace
*trace
)
1297 struct ctf_node
*expression
;
1298 uint64_t alignment
= 1, size
= 0;
1299 int byte_order
= trace
->byte_order
;
1301 int has_alignment
= 0, has_size
= 0;
1303 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1304 struct ctf_clock
*clock
= NULL
;
1305 struct declaration_integer
*integer_declaration
;
1307 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1308 struct ctf_node
*left
, *right
;
1310 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1311 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1312 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1314 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1315 signedness
= get_boolean(fd
, depth
, right
);
1318 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1319 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1322 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1323 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1324 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1328 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1330 fprintf(fd
, "[error] %s: integer size: expecting non-zero constant\n",
1335 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1336 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1337 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1341 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1342 /* Make sure alignment is a power of two */
1343 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1344 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1349 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1350 switch (right
->u
.unary_expression
.type
) {
1351 case UNARY_UNSIGNED_CONSTANT
:
1352 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1357 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1360 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1361 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1367 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1369 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1373 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1374 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1376 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1377 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1378 || !strcmp(s_right
, "p")) {
1380 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1381 || !strcmp(s_right
, "o")) {
1383 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1386 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1395 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1399 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1402 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1403 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1407 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1409 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1413 if (!strcmp(s_right
, "UTF8")
1414 || !strcmp(s_right
, "utf8")
1415 || !strcmp(s_right
, "utf-8")
1416 || !strcmp(s_right
, "UTF-8"))
1417 encoding
= CTF_STRING_UTF8
;
1418 else if (!strcmp(s_right
, "ASCII")
1419 || !strcmp(s_right
, "ascii"))
1420 encoding
= CTF_STRING_ASCII
;
1421 else if (!strcmp(s_right
, "none"))
1422 encoding
= CTF_STRING_NONE
;
1424 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1429 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1432 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1433 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1437 /* currently only support clock.name.value */
1438 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1442 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1444 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1448 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1453 clock
= trace_clock_lookup(trace
, clock_name
);
1455 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1456 __func__
, g_quark_to_string(clock_name
));
1460 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1461 __func__
, left
->u
.unary_expression
.u
.string
);
1462 /* Fall-through after warning */
1466 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1469 if (!has_alignment
) {
1470 if (size
% CHAR_BIT
) {
1471 /* bit-packed alignment */
1474 /* byte-packed alignment */
1475 alignment
= CHAR_BIT
;
1478 integer_declaration
= bt_integer_declaration_new(size
,
1479 byte_order
, signedness
, alignment
,
1480 base
, encoding
, clock
);
1481 return &integer_declaration
->p
;
1485 struct bt_declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1486 struct bt_list_head
*expressions
,
1487 struct ctf_trace
*trace
)
1489 struct ctf_node
*expression
;
1490 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0;
1491 int byte_order
= trace
->byte_order
, has_alignment
= 0,
1492 has_exp_dig
= 0, has_mant_dig
= 0;
1493 struct declaration_float
*float_declaration
;
1495 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1496 struct ctf_node
*left
, *right
;
1498 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1499 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1500 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1502 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1503 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1506 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1507 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1508 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1512 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1514 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1515 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1516 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1520 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1522 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1523 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1524 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1528 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1529 /* Make sure alignment is a power of two */
1530 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1531 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1537 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1538 __func__
, left
->u
.unary_expression
.u
.string
);
1539 /* Fall-through after warning */
1542 if (!has_mant_dig
) {
1543 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1547 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1550 if (!has_alignment
) {
1551 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1552 /* bit-packed alignment */
1555 /* byte-packed alignment */
1556 alignment
= CHAR_BIT
;
1559 float_declaration
= bt_float_declaration_new(mant_dig
, exp_dig
,
1560 byte_order
, alignment
);
1561 return &float_declaration
->p
;
1565 struct bt_declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1566 struct bt_list_head
*expressions
,
1567 struct ctf_trace
*trace
)
1569 struct ctf_node
*expression
;
1570 const char *encoding_c
= NULL
;
1571 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1572 struct declaration_string
*string_declaration
;
1574 bt_list_for_each_entry(expression
, expressions
, siblings
) {
1575 struct ctf_node
*left
, *right
;
1577 left
= _bt_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1578 right
= _bt_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1579 if (left
->u
.unary_expression
.type
!= UNARY_STRING
)
1581 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1582 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1583 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1587 encoding_c
= right
->u
.unary_expression
.u
.string
;
1589 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1590 __func__
, left
->u
.unary_expression
.u
.string
);
1591 /* Fall-through after warning */
1594 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1595 encoding
= CTF_STRING_ASCII
;
1596 string_declaration
= bt_string_declaration_new(encoding
);
1597 return &string_declaration
->p
;
1602 struct bt_declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1603 int depth
, struct ctf_node
*type_specifier_list
,
1604 struct declaration_scope
*declaration_scope
,
1605 struct ctf_trace
*trace
)
1607 struct ctf_node
*first
;
1608 struct ctf_node
*node
;
1610 if (type_specifier_list
->type
!= NODE_TYPE_SPECIFIER_LIST
)
1613 first
= _bt_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1615 if (first
->type
!= NODE_TYPE_SPECIFIER
)
1618 node
= first
->u
.type_specifier
.node
;
1620 switch (first
->u
.type_specifier
.type
) {
1621 case TYPESPEC_FLOATING_POINT
:
1622 return ctf_declaration_floating_point_visit(fd
, depth
,
1623 &node
->u
.floating_point
.expressions
, trace
);
1624 case TYPESPEC_INTEGER
:
1625 return ctf_declaration_integer_visit(fd
, depth
,
1626 &node
->u
.integer
.expressions
, trace
);
1627 case TYPESPEC_STRING
:
1628 return ctf_declaration_string_visit(fd
, depth
,
1629 &node
->u
.string
.expressions
, trace
);
1630 case TYPESPEC_STRUCT
:
1631 return ctf_declaration_struct_visit(fd
, depth
,
1632 node
->u
._struct
.name
,
1633 &node
->u
._struct
.declaration_list
,
1634 node
->u
._struct
.has_body
,
1635 &node
->u
._struct
.min_align
,
1638 case TYPESPEC_VARIANT
:
1639 return ctf_declaration_variant_visit(fd
, depth
,
1640 node
->u
.variant
.name
,
1641 node
->u
.variant
.choice
,
1642 &node
->u
.variant
.declaration_list
,
1643 node
->u
.variant
.has_body
,
1647 return ctf_declaration_enum_visit(fd
, depth
,
1648 node
->u
._enum
.enum_id
,
1649 node
->u
._enum
.container_type
,
1650 &node
->u
._enum
.enumerator_list
,
1651 node
->u
._enum
.has_body
,
1657 case TYPESPEC_SHORT
:
1660 case TYPESPEC_FLOAT
:
1661 case TYPESPEC_DOUBLE
:
1662 case TYPESPEC_SIGNED
:
1663 case TYPESPEC_UNSIGNED
:
1665 case TYPESPEC_COMPLEX
:
1666 case TYPESPEC_IMAGINARY
:
1667 case TYPESPEC_CONST
:
1668 case TYPESPEC_ID_TYPE
:
1669 return ctf_declaration_type_specifier_visit(fd
, depth
,
1670 type_specifier_list
, declaration_scope
);
1672 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1678 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event_declaration
*event
, struct ctf_trace
*trace
)
1682 switch (node
->type
) {
1684 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1685 event
->declaration_scope
,
1686 node
->u
._typedef
.type_specifier_list
,
1687 &node
->u
._typedef
.type_declarators
,
1692 case NODE_TYPEALIAS
:
1693 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1694 event
->declaration_scope
,
1695 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1700 case NODE_CTF_EXPRESSION
:
1704 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1707 if (!strcmp(left
, "name")) {
1710 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1711 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1715 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1717 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1721 event
->name
= g_quark_from_string(right
);
1723 CTF_EVENT_SET_FIELD(event
, name
);
1724 } else if (!strcmp(left
, "id")) {
1725 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1726 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1730 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1732 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1736 CTF_EVENT_SET_FIELD(event
, id
);
1737 } else if (!strcmp(left
, "stream_id")) {
1738 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1739 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1743 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1745 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1749 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1750 if (!event
->stream
) {
1751 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1755 CTF_EVENT_SET_FIELD(event
, stream_id
);
1756 } else if (!strcmp(left
, "context")) {
1757 struct bt_declaration
*declaration
;
1759 if (event
->context_decl
) {
1760 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1764 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1765 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1766 struct ctf_node
, siblings
),
1767 event
->declaration_scope
, trace
);
1772 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1776 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1777 } else if (!strcmp(left
, "fields")) {
1778 struct bt_declaration
*declaration
;
1780 if (event
->fields_decl
) {
1781 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1785 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1786 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1787 struct ctf_node
, siblings
),
1788 event
->declaration_scope
, trace
);
1793 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1797 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1798 } else if (!strcmp(left
, "loglevel")) {
1799 int64_t loglevel
= -1;
1801 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel
)) {
1802 fprintf(fd
, "[error] %s: loglevel already declared in event declaration\n", __func__
);
1806 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &loglevel
);
1808 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel\n", __func__
);
1812 event
->loglevel
= (int) loglevel
;
1813 CTF_EVENT_SET_FIELD(event
, loglevel
);
1814 } else if (!strcmp(left
, "model.emf.uri")) {
1817 if (CTF_EVENT_FIELD_IS_SET(event
, model_emf_uri
)) {
1818 fprintf(fd
, "[error] %s: model.emf.uri already declared in event declaration\n", __func__
);
1822 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1824 fprintf(fd
, "[error] %s: unexpected unary expression for event model.emf.uri\n", __func__
);
1828 event
->model_emf_uri
= g_quark_from_string(right
);
1830 CTF_EVENT_SET_FIELD(event
, model_emf_uri
);
1832 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1833 /* Fall-through after warning */
1841 /* TODO: declaration specifier should be added. */
1848 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1849 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1852 struct ctf_node
*iter
;
1853 struct ctf_event_declaration
*event
;
1854 struct bt_ctf_event_decl
*event_decl
;
1860 event_decl
= g_new0(struct bt_ctf_event_decl
, 1);
1861 event
= &event_decl
->parent
;
1862 event
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
1863 event
->loglevel
= -1;
1864 bt_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1865 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1869 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1871 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1874 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1875 /* Allow missing stream_id if there is only a single stream */
1876 switch (trace
->streams
->len
) {
1877 case 0: /* Create stream if there was none. */
1878 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1883 event
->stream_id
= 0;
1884 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1888 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1892 /* Allow only one event without id per stream */
1893 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1894 && event
->stream
->events_by_id
->len
!= 0) {
1896 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1899 /* Disallow re-using the same event ID in the same stream */
1900 if (stream_event_lookup(event
->stream
, event
->id
)) {
1902 fprintf(fd
, "[error] %s: event ID %" PRIu64
" used more than once in stream %" PRIu64
"\n",
1903 __func__
, event
->id
, event
->stream_id
);
1906 if (event
->stream
->events_by_id
->len
<= event
->id
)
1907 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1908 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1909 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1910 (gpointer
) (unsigned long) event
->name
,
1912 g_ptr_array_add(trace
->event_declarations
, event_decl
);
1916 if (event
->fields_decl
)
1917 bt_declaration_unref(&event
->fields_decl
->p
);
1918 if (event
->context_decl
)
1919 bt_declaration_unref(&event
->context_decl
->p
);
1920 bt_free_declaration_scope(event
->declaration_scope
);
1927 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_declaration
*stream
, struct ctf_trace
*trace
)
1931 switch (node
->type
) {
1933 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1934 stream
->declaration_scope
,
1935 node
->u
._typedef
.type_specifier_list
,
1936 &node
->u
._typedef
.type_declarators
,
1941 case NODE_TYPEALIAS
:
1942 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1943 stream
->declaration_scope
,
1944 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1949 case NODE_CTF_EXPRESSION
:
1953 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1956 if (!strcmp(left
, "id")) {
1957 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1958 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1962 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1964 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1968 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1969 } else if (!strcmp(left
, "event.header")) {
1970 struct bt_declaration
*declaration
;
1972 if (stream
->event_header_decl
) {
1973 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1977 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1978 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
1979 struct ctf_node
, siblings
),
1980 stream
->declaration_scope
, trace
);
1985 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1989 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1990 } else if (!strcmp(left
, "event.context")) {
1991 struct bt_declaration
*declaration
;
1993 if (stream
->event_context_decl
) {
1994 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1998 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1999 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2000 struct ctf_node
, siblings
),
2001 stream
->declaration_scope
, trace
);
2006 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2010 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
2011 } else if (!strcmp(left
, "packet.context")) {
2012 struct bt_declaration
*declaration
;
2014 if (stream
->packet_context_decl
) {
2015 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
2019 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2020 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2021 struct ctf_node
, siblings
),
2022 stream
->declaration_scope
, trace
);
2027 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2031 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
2033 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
2034 /* Fall-through after warning */
2043 /* TODO: declaration specifier should be added. */
2050 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2051 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
2054 struct ctf_node
*iter
;
2055 struct ctf_stream_declaration
*stream
;
2063 stream
= g_new0(struct ctf_stream_declaration
, 1);
2064 stream
->declaration_scope
= bt_new_declaration_scope(parent_declaration_scope
);
2065 stream
->events_by_id
= g_ptr_array_new();
2066 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
2067 stream
->streams
= g_ptr_array_new();
2069 bt_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
2070 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
2075 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
2076 /* check that packet header has stream_id field. */
2077 if (!trace
->packet_header_decl
2078 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
2080 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
2084 /* Allow only one id-less stream */
2085 if (trace
->streams
->len
!= 0) {
2087 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
2090 stream
->stream_id
= 0;
2092 if (trace
->streams
->len
<= stream
->stream_id
)
2093 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
2094 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
2095 stream
->trace
= trace
;
2100 if (stream
->event_header_decl
)
2101 bt_declaration_unref(&stream
->event_header_decl
->p
);
2102 if (stream
->event_context_decl
)
2103 bt_declaration_unref(&stream
->event_context_decl
->p
);
2104 if (stream
->packet_context_decl
)
2105 bt_declaration_unref(&stream
->packet_context_decl
->p
);
2106 g_ptr_array_free(stream
->streams
, TRUE
);
2107 g_ptr_array_free(stream
->events_by_id
, TRUE
);
2108 g_hash_table_destroy(stream
->event_quark_to_id
);
2109 bt_free_declaration_scope(stream
->declaration_scope
);
2115 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2119 switch (node
->type
) {
2121 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2122 trace
->declaration_scope
,
2123 node
->u
._typedef
.type_specifier_list
,
2124 &node
->u
._typedef
.type_declarators
,
2129 case NODE_TYPEALIAS
:
2130 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2131 trace
->declaration_scope
,
2132 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2137 case NODE_CTF_EXPRESSION
:
2141 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2144 if (!strcmp(left
, "major")) {
2145 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2146 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
2150 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
2152 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
2156 CTF_TRACE_SET_FIELD(trace
, major
);
2157 } else if (!strcmp(left
, "minor")) {
2158 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2159 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
2163 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
2165 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
2169 CTF_TRACE_SET_FIELD(trace
, minor
);
2170 } else if (!strcmp(left
, "uuid")) {
2171 unsigned char uuid
[BABELTRACE_UUID_LEN
];
2173 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, uuid
);
2175 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2179 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2180 && bt_uuid_compare(uuid
, trace
->uuid
)) {
2181 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2185 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2187 CTF_TRACE_SET_FIELD(trace
, uuid
);
2188 } else if (!strcmp(left
, "byte_order")) {
2189 struct ctf_node
*right
;
2192 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2193 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2194 if (byte_order
< 0) {
2199 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2200 && byte_order
!= trace
->byte_order
) {
2201 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2205 if (byte_order
!= trace
->byte_order
) {
2206 trace
->byte_order
= byte_order
;
2208 * We need to restart
2209 * construction of the
2210 * intermediate representation.
2212 trace
->field_mask
= 0;
2213 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2218 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2219 } else if (!strcmp(left
, "packet.header")) {
2220 struct bt_declaration
*declaration
;
2222 if (trace
->packet_header_decl
) {
2223 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2227 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2228 _bt_list_first_entry(&node
->u
.ctf_expression
.right
,
2229 struct ctf_node
, siblings
),
2230 trace
->declaration_scope
, trace
);
2235 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2239 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2241 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2250 /* TODO: declaration specifier should be added. */
2257 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2260 struct ctf_node
*iter
;
2262 if (!trace
->restart_root_decl
&& node
->visited
)
2266 if (trace
->declaration_scope
)
2269 trace
->declaration_scope
= bt_new_declaration_scope(trace
->root_declaration_scope
);
2270 trace
->streams
= g_ptr_array_new();
2271 trace
->event_declarations
= g_ptr_array_new();
2272 bt_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2273 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2277 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2279 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2282 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2284 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2287 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2289 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2293 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2294 /* check that the packet header contains a "magic" field */
2295 if (!trace
->packet_header_decl
2296 || bt_struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2298 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2305 if (trace
->packet_header_decl
) {
2306 bt_declaration_unref(&trace
->packet_header_decl
->p
);
2307 trace
->packet_header_decl
= NULL
;
2309 g_ptr_array_free(trace
->streams
, TRUE
);
2310 g_ptr_array_free(trace
->event_declarations
, TRUE
);
2311 bt_free_declaration_scope(trace
->declaration_scope
);
2312 trace
->declaration_scope
= NULL
;
2317 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2318 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2322 switch (node
->type
) {
2323 case NODE_CTF_EXPRESSION
:
2327 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2330 if (!strcmp(left
, "name")) {
2333 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2334 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2338 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2340 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2344 clock
->name
= g_quark_from_string(right
);
2346 CTF_CLOCK_SET_FIELD(clock
, name
);
2347 } else if (!strcmp(left
, "uuid")) {
2351 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2355 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2357 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2361 clock
->uuid
= g_quark_from_string(right
);
2363 } else if (!strcmp(left
, "description")) {
2366 if (clock
->description
) {
2367 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2368 goto error
; /* ret is 0, so not an actual error, just warn. */
2370 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2372 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2373 goto error
; /* ret is 0, so not an actual error, just warn. */
2375 clock
->description
= right
;
2376 } else if (!strcmp(left
, "freq")) {
2377 if (CTF_CLOCK_FIELD_IS_SET(clock
, freq
)) {
2378 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2382 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2384 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2388 CTF_CLOCK_SET_FIELD(clock
, freq
);
2389 } else if (!strcmp(left
, "precision")) {
2390 if (clock
->precision
) {
2391 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2395 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2397 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2401 } else if (!strcmp(left
, "offset_s")) {
2402 if (clock
->offset_s
) {
2403 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2407 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2409 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2413 } else if (!strcmp(left
, "offset")) {
2414 if (clock
->offset
) {
2415 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2419 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2421 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2425 } else if (!strcmp(left
, "absolute")) {
2426 struct ctf_node
*right
;
2428 right
= _bt_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2429 ret
= get_boolean(fd
, depth
, right
);
2431 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2435 clock
->absolute
= ret
;
2438 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2447 /* TODO: declaration specifier should be added. */
2454 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2457 struct ctf_node
*iter
;
2458 struct ctf_clock
*clock
;
2464 clock
= g_new0(struct ctf_clock
, 1);
2465 /* Default clock frequency is set to 1000000000 */
2466 clock
->freq
= 1000000000ULL;
2467 bt_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2468 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2472 if (opt_clock_force_correlate
) {
2474 * User requested to forcibly correlate the clock
2475 * sources, even if we have no correlation
2478 if (!clock
->absolute
) {
2479 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2481 clock
->absolute
= 1;
2483 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2485 fprintf(fd
, "[error] %s: missing name field in clock declaration\n", __func__
);
2488 if (g_hash_table_size(trace
->parent
.clocks
) > 0) {
2489 fprintf(fd
, "[error] Only CTF traces with a single clock description are supported by this babeltrace version.\n");
2493 trace
->parent
.single_clock
= clock
;
2494 g_hash_table_insert(trace
->parent
.clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2498 g_free(clock
->description
);
2504 void ctf_clock_default(FILE *fd
, int depth
, struct ctf_trace
*trace
)
2506 struct ctf_clock
*clock
;
2508 clock
= g_new0(struct ctf_clock
, 1);
2509 clock
->name
= g_quark_from_string("monotonic");
2511 clock
->description
= g_strdup("Default clock");
2512 /* Default clock frequency is set to 1000000000 */
2513 clock
->freq
= 1000000000ULL;
2514 if (opt_clock_force_correlate
) {
2516 * User requested to forcibly correlate the clock
2517 * sources, even if we have no correlatation
2520 if (!clock
->absolute
) {
2521 fprintf(fd
, "[warning] Forcibly correlating trace clock sources (--clock-force-correlate).\n");
2523 clock
->absolute
= 1;
2525 clock
->absolute
= 0; /* Not an absolute reference across traces */
2528 trace
->parent
.single_clock
= clock
;
2529 g_hash_table_insert(trace
->parent
.clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2533 void clock_free(gpointer data
)
2535 struct ctf_clock
*clock
= data
;
2537 g_free(clock
->description
);
2542 int ctf_callsite_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2543 struct ctf_callsite
*callsite
, struct ctf_trace
*trace
)
2547 switch (node
->type
) {
2548 case NODE_CTF_EXPRESSION
:
2552 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2555 if (!strcmp(left
, "name")) {
2558 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2559 fprintf(fd
, "[error] %s: name already declared in callsite declaration\n", __func__
);
2563 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2565 fprintf(fd
, "[error] %s: unexpected unary expression for callsite name\n", __func__
);
2569 callsite
->name
= g_quark_from_string(right
);
2571 CTF_CALLSITE_SET_FIELD(callsite
, name
);
2572 } else if (!strcmp(left
, "func")) {
2575 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2576 fprintf(fd
, "[error] %s: func already declared in callsite declaration\n", __func__
);
2580 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2582 fprintf(fd
, "[error] %s: unexpected unary expression for callsite func\n", __func__
);
2586 callsite
->func
= right
;
2587 CTF_CALLSITE_SET_FIELD(callsite
, func
);
2588 } else if (!strcmp(left
, "file")) {
2591 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2592 fprintf(fd
, "[error] %s: file already declared in callsite declaration\n", __func__
);
2596 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2598 fprintf(fd
, "[error] %s: unexpected unary expression for callsite file\n", __func__
);
2602 callsite
->file
= right
;
2603 CTF_CALLSITE_SET_FIELD(callsite
, file
);
2604 } else if (!strcmp(left
, "line")) {
2605 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2606 fprintf(fd
, "[error] %s: line already declared in callsite declaration\n", __func__
);
2610 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->line
);
2612 fprintf(fd
, "[error] %s: unexpected unary expression for callsite line\n", __func__
);
2616 CTF_CALLSITE_SET_FIELD(callsite
, line
);
2617 } else if (!strcmp(left
, "ip")) {
2618 if (CTF_CALLSITE_FIELD_IS_SET(callsite
, ip
)) {
2619 fprintf(fd
, "[error] %s: ip already declared in callsite declaration\n", __func__
);
2623 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &callsite
->ip
);
2625 fprintf(fd
, "[error] %s: unexpected unary expression for callsite ip\n", __func__
);
2629 CTF_CALLSITE_SET_FIELD(callsite
, ip
);
2631 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in callsite declaration.\n", __func__
, left
);
2640 /* TODO: declaration specifier should be added. */
2647 int ctf_callsite_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2650 struct ctf_node
*iter
;
2651 struct ctf_callsite
*callsite
;
2652 struct ctf_callsite_dups
*cs_dups
;
2658 callsite
= g_new0(struct ctf_callsite
, 1);
2659 bt_list_for_each_entry(iter
, &node
->u
.callsite
.declaration_list
, siblings
) {
2660 ret
= ctf_callsite_declaration_visit(fd
, depth
+ 1, iter
, callsite
, trace
);
2664 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, name
)) {
2666 fprintf(fd
, "[error] %s: missing name field in callsite declaration\n", __func__
);
2669 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, func
)) {
2671 fprintf(fd
, "[error] %s: missing func field in callsite declaration\n", __func__
);
2674 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, file
)) {
2676 fprintf(fd
, "[error] %s: missing file field in callsite declaration\n", __func__
);
2679 if (!CTF_CALLSITE_FIELD_IS_SET(callsite
, line
)) {
2681 fprintf(fd
, "[error] %s: missing line field in callsite declaration\n", __func__
);
2685 cs_dups
= g_hash_table_lookup(trace
->callsites
,
2686 (gpointer
) (unsigned long) callsite
->name
);
2688 cs_dups
= g_new0(struct ctf_callsite_dups
, 1);
2689 BT_INIT_LIST_HEAD(&cs_dups
->head
);
2690 g_hash_table_insert(trace
->callsites
,
2691 (gpointer
) (unsigned long) callsite
->name
, cs_dups
);
2693 bt_list_add_tail(&callsite
->node
, &cs_dups
->head
);
2697 g_free(callsite
->func
);
2698 g_free(callsite
->file
);
2704 void callsite_free(gpointer data
)
2706 struct ctf_callsite_dups
*cs_dups
= data
;
2707 struct ctf_callsite
*callsite
, *cs_n
;
2709 bt_list_for_each_entry_safe(callsite
, cs_n
, &cs_dups
->head
, node
) {
2710 g_free(callsite
->func
);
2711 g_free(callsite
->file
);
2718 int ctf_env_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2719 struct ctf_trace
*trace
)
2722 struct ctf_tracer_env
*env
= &trace
->env
;
2724 switch (node
->type
) {
2725 case NODE_CTF_EXPRESSION
:
2729 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2732 if (!strcmp(left
, "vpid")) {
2735 if (env
->vpid
!= -1) {
2736 fprintf(fd
, "[error] %s: vpid already declared in env declaration\n", __func__
);
2737 goto error
; /* ret is 0, so not an actual error, just warn. */
2739 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2741 fprintf(fd
, "[error] %s: unexpected unary expression for env vpid\n", __func__
);
2742 goto error
; /* ret is 0, so not an actual error, just warn. */
2744 env
->vpid
= (int) v
;
2745 printf_verbose("env.vpid = %d\n", env
->vpid
);
2746 } else if (!strcmp(left
, "procname")) {
2749 if (env
->procname
[0]) {
2750 fprintf(fd
, "[warning] %s: duplicated env procname\n", __func__
);
2751 goto error
; /* ret is 0, so not an actual error, just warn. */
2753 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2755 fprintf(fd
, "[warning] %s: unexpected unary expression for env procname\n", __func__
);
2756 goto error
; /* ret is 0, so not an actual error, just warn. */
2758 strncpy(env
->procname
, right
, TRACER_ENV_LEN
);
2759 env
->procname
[TRACER_ENV_LEN
- 1] = '\0';
2760 printf_verbose("env.procname = \"%s\"\n", env
->procname
);
2762 } else if (!strcmp(left
, "hostname")) {
2765 if (env
->hostname
[0]) {
2766 fprintf(fd
, "[warning] %s: duplicated env hostname\n", __func__
);
2767 goto error
; /* ret is 0, so not an actual error, just warn. */
2769 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2771 fprintf(fd
, "[warning] %s: unexpected unary expression for env hostname\n", __func__
);
2772 goto error
; /* ret is 0, so not an actual error, just warn. */
2774 strncpy(env
->hostname
, right
, TRACER_ENV_LEN
);
2775 env
->hostname
[TRACER_ENV_LEN
- 1] = '\0';
2776 printf_verbose("env.hostname = \"%s\"\n", env
->hostname
);
2778 } else if (!strcmp(left
, "domain")) {
2781 if (env
->domain
[0]) {
2782 fprintf(fd
, "[warning] %s: duplicated env domain\n", __func__
);
2783 goto error
; /* ret is 0, so not an actual error, just warn. */
2785 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2787 fprintf(fd
, "[warning] %s: unexpected unary expression for env domain\n", __func__
);
2788 goto error
; /* ret is 0, so not an actual error, just warn. */
2790 strncpy(env
->domain
, right
, TRACER_ENV_LEN
);
2791 env
->domain
[TRACER_ENV_LEN
- 1] = '\0';
2792 printf_verbose("env.domain = \"%s\"\n", env
->domain
);
2794 } else if (!strcmp(left
, "sysname")) {
2797 if (env
->sysname
[0]) {
2798 fprintf(fd
, "[warning] %s: duplicated env sysname\n", __func__
);
2799 goto error
; /* ret is 0, so not an actual error, just warn. */
2801 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2803 fprintf(fd
, "[warning] %s: unexpected unary expression for env sysname\n", __func__
);
2804 goto error
; /* ret is 0, so not an actual error, just warn. */
2806 strncpy(env
->sysname
, right
, TRACER_ENV_LEN
);
2807 env
->sysname
[TRACER_ENV_LEN
- 1] = '\0';
2808 printf_verbose("env.sysname = \"%s\"\n", env
->sysname
);
2810 } else if (!strcmp(left
, "kernel_release")) {
2813 if (env
->release
[0]) {
2814 fprintf(fd
, "[warning] %s: duplicated env release\n", __func__
);
2815 goto error
; /* ret is 0, so not an actual error, just warn. */
2817 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2819 fprintf(fd
, "[warning] %s: unexpected unary expression for env release\n", __func__
);
2820 goto error
; /* ret is 0, so not an actual error, just warn. */
2822 strncpy(env
->release
, right
, TRACER_ENV_LEN
);
2823 env
->release
[TRACER_ENV_LEN
- 1] = '\0';
2824 printf_verbose("env.release = \"%s\"\n", env
->release
);
2826 } else if (!strcmp(left
, "kernel_version")) {
2829 if (env
->version
[0]) {
2830 fprintf(fd
, "[warning] %s: duplicated env version\n", __func__
);
2831 goto error
; /* ret is 0, so not an actual error, just warn. */
2833 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2835 fprintf(fd
, "[warning] %s: unexpected unary expression for env version\n", __func__
);
2836 goto error
; /* ret is 0, so not an actual error, just warn. */
2838 strncpy(env
->version
, right
, TRACER_ENV_LEN
);
2839 env
->version
[TRACER_ENV_LEN
- 1] = '\0';
2840 printf_verbose("env.version = \"%s\"\n", env
->version
);
2843 if (is_unary_string(&node
->u
.ctf_expression
.right
)) {
2846 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2848 fprintf(fd
, "[warning] %s: unexpected unary expression for env\n", __func__
);
2852 printf_verbose("env.%s = \"%s\"\n", left
, right
);
2854 } else if (is_unary_unsigned(&node
->u
.ctf_expression
.right
)) {
2858 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &v
);
2861 printf_verbose("env.%s = %" PRIu64
"\n", left
, v
);
2862 } else if (is_unary_signed(&node
->u
.ctf_expression
.right
)) {
2866 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &v
);
2869 printf_verbose("env.%s = %" PRId64
"\n", left
, v
);
2871 printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__
, left
);
2887 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2890 struct ctf_node
*iter
;
2896 trace
->env
.vpid
= -1;
2897 trace
->env
.procname
[0] = '\0';
2898 trace
->env
.hostname
[0] = '\0';
2899 trace
->env
.domain
[0] = '\0';
2900 trace
->env
.sysname
[0] = '\0';
2901 trace
->env
.release
[0] = '\0';
2902 trace
->env
.version
[0] = '\0';
2903 bt_list_for_each_entry(iter
, &node
->u
.env
.declaration_list
, siblings
) {
2904 ret
= ctf_env_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2913 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2917 if (!trace
->restart_root_decl
&& node
->visited
)
2921 switch (node
->type
) {
2923 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2924 trace
->root_declaration_scope
,
2925 node
->u
._typedef
.type_specifier_list
,
2926 &node
->u
._typedef
.type_declarators
,
2931 case NODE_TYPEALIAS
:
2932 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2933 trace
->root_declaration_scope
,
2934 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2939 case NODE_TYPE_SPECIFIER_LIST
:
2941 struct bt_declaration
*declaration
;
2944 * Just add the type specifier to the root scope
2945 * declaration scope. Release local reference.
2947 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2948 node
, trace
->root_declaration_scope
, trace
);
2951 bt_declaration_unref(declaration
);
2961 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2962 struct ctf_trace
*trace
, int byte_order
)
2965 struct ctf_node
*iter
;
2967 printf_verbose("CTF visitor: metadata construction...\n");
2968 trace
->byte_order
= byte_order
;
2969 trace
->parent
.clocks
= g_hash_table_new_full(g_direct_hash
,
2970 g_direct_equal
, NULL
, clock_free
);
2971 trace
->callsites
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2972 NULL
, callsite_free
);
2975 trace
->root_declaration_scope
= bt_new_declaration_scope(NULL
);
2977 switch (node
->type
) {
2980 * declarations need to query clock hash table,
2981 * so clock need to be treated first.
2983 if (bt_list_empty(&node
->u
.root
.clock
)) {
2984 ctf_clock_default(fd
, depth
+ 1, trace
);
2986 bt_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2987 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2990 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2995 bt_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2997 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2999 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
3003 bt_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
3004 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
3005 if (ret
== -EINTR
) {
3006 trace
->restart_root_decl
= 1;
3007 bt_free_declaration_scope(trace
->root_declaration_scope
);
3009 * Need to restart creation of type
3010 * definitions, aliases and
3011 * trace header declarations.
3016 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
3020 trace
->restart_root_decl
= 0;
3021 bt_list_for_each_entry(iter
, &node
->u
.root
.callsite
, siblings
) {
3022 ret
= ctf_callsite_visit(fd
, depth
+ 1, iter
,
3025 fprintf(fd
, "[error] %s: callsite declaration error\n", __func__
);
3029 if (!trace
->streams
) {
3030 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
3034 bt_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
3035 ret
= ctf_env_visit(fd
, depth
+ 1, iter
, trace
);
3037 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
3041 bt_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
3042 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
3043 trace
->root_declaration_scope
, trace
);
3045 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
3049 bt_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
3050 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
3051 trace
->root_declaration_scope
, trace
);
3053 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
3060 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
3065 printf_verbose("done.\n");
3069 bt_free_declaration_scope(trace
->root_declaration_scope
);
3070 g_hash_table_destroy(trace
->callsites
);
3071 g_hash_table_destroy(trace
->parent
.clocks
);
3075 int ctf_destroy_metadata(struct ctf_trace
*trace
)
3078 struct ctf_file_stream
*metadata_stream
;
3080 if (trace
->streams
) {
3081 for (i
= 0; i
< trace
->streams
->len
; i
++) {
3082 struct ctf_stream_declaration
*stream
;
3085 stream
= g_ptr_array_index(trace
->streams
, i
);
3088 for (j
= 0; j
< stream
->streams
->len
; j
++) {
3089 struct ctf_stream_definition
*stream_def
;
3092 stream_def
= g_ptr_array_index(stream
->streams
, j
);
3095 for (k
= 0; k
< stream_def
->events_by_id
->len
; k
++) {
3096 struct ctf_event_definition
*event
;
3098 event
= g_ptr_array_index(stream_def
->events_by_id
, k
);
3101 if (&event
->event_fields
->p
)
3102 bt_definition_unref(&event
->event_fields
->p
);
3103 if (&event
->event_context
->p
)
3104 bt_definition_unref(&event
->event_context
->p
);
3107 if (&stream_def
->trace_packet_header
->p
)
3108 bt_definition_unref(&stream_def
->trace_packet_header
->p
);
3109 if (&stream_def
->stream_event_header
->p
)
3110 bt_definition_unref(&stream_def
->stream_event_header
->p
);
3111 if (&stream_def
->stream_packet_context
->p
)
3112 bt_definition_unref(&stream_def
->stream_packet_context
->p
);
3113 if (&stream_def
->stream_event_context
->p
)
3114 bt_definition_unref(&stream_def
->stream_event_context
->p
);
3115 g_ptr_array_free(stream_def
->events_by_id
, TRUE
);
3118 if (stream
->event_header_decl
)
3119 bt_declaration_unref(&stream
->event_header_decl
->p
);
3120 if (stream
->event_context_decl
)
3121 bt_declaration_unref(&stream
->event_context_decl
->p
);
3122 if (stream
->packet_context_decl
)
3123 bt_declaration_unref(&stream
->packet_context_decl
->p
);
3124 g_ptr_array_free(stream
->streams
, TRUE
);
3125 g_ptr_array_free(stream
->events_by_id
, TRUE
);
3126 g_hash_table_destroy(stream
->event_quark_to_id
);
3127 bt_free_declaration_scope(stream
->declaration_scope
);
3130 g_ptr_array_free(trace
->streams
, TRUE
);
3133 if (trace
->event_declarations
) {
3134 for (i
= 0; i
< trace
->event_declarations
->len
; i
++) {
3135 struct bt_ctf_event_decl
*event_decl
;
3136 struct ctf_event_declaration
*event
;
3138 event_decl
= g_ptr_array_index(trace
->event_declarations
, i
);
3139 if (event_decl
->context_decl
)
3140 g_ptr_array_free(event_decl
->context_decl
, TRUE
);
3141 if (event_decl
->fields_decl
)
3142 g_ptr_array_free(event_decl
->fields_decl
, TRUE
);
3143 if (event_decl
->packet_header_decl
)
3144 g_ptr_array_free(event_decl
->packet_header_decl
, TRUE
);
3145 if (event_decl
->event_context_decl
)
3146 g_ptr_array_free(event_decl
->event_context_decl
, TRUE
);
3147 if (event_decl
->event_header_decl
)
3148 g_ptr_array_free(event_decl
->event_header_decl
, TRUE
);
3149 if (event_decl
->packet_context_decl
)
3150 g_ptr_array_free(event_decl
->packet_context_decl
, TRUE
);
3152 event
= &event_decl
->parent
;
3153 if (event
->fields_decl
)
3154 bt_declaration_unref(&event
->fields_decl
->p
);
3155 if (event
->context_decl
)
3156 bt_declaration_unref(&event
->context_decl
->p
);
3157 bt_free_declaration_scope(event
->declaration_scope
);
3161 g_ptr_array_free(trace
->event_declarations
, TRUE
);
3163 if (trace
->packet_header_decl
)
3164 bt_declaration_unref(&trace
->packet_header_decl
->p
);
3166 bt_free_declaration_scope(trace
->root_declaration_scope
);
3167 bt_free_declaration_scope(trace
->declaration_scope
);
3169 g_hash_table_destroy(trace
->callsites
);
3170 g_hash_table_destroy(trace
->parent
.clocks
);
3172 metadata_stream
= container_of(trace
->metadata
, struct ctf_file_stream
, parent
);
3173 g_free(metadata_stream
);