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.
28 #include <babeltrace/babeltrace-internal.h>
29 #include <babeltrace/list.h>
30 #include <babeltrace/types.h>
31 #include <babeltrace/ctf/metadata.h>
32 #include <uuid/uuid.h>
33 #include "ctf-scanner.h"
34 #include "ctf-parser.h"
37 #define fprintf_dbg(fd, fmt, args...) fprintf(fd, "%s: " fmt, __func__, ## args)
39 #define _cds_list_first_entry(ptr, type, member) \
40 cds_list_entry((ptr)->next, type, member)
43 struct declaration
*ctf_type_specifier_list_visit(FILE *fd
,
44 int depth
, struct ctf_node
*type_specifier_list
,
45 struct declaration_scope
*declaration_scope
,
46 struct ctf_trace
*trace
);
49 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
50 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
);
53 * String returned must be freed by the caller using g_free.
56 char *concatenate_unary_strings(struct cds_list_head
*head
)
58 struct ctf_node
*node
;
62 str
= g_string_new("");
63 cds_list_for_each_entry(node
, head
, siblings
) {
66 assert(node
->type
== NODE_UNARY_EXPRESSION
);
67 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
68 assert((node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
)
70 switch (node
->u
.unary_expression
.link
) {
72 g_string_append(str
, ".");
75 g_string_append(str
, "->");
78 g_string_append(str
, "...");
83 src_string
= node
->u
.unary_expression
.u
.string
;
84 g_string_append(str
, src_string
);
87 return g_string_free(str
, FALSE
);
91 GQuark
get_map_clock_name_value(struct cds_list_head
*head
)
93 struct ctf_node
*node
;
94 const char *name
= NULL
;
97 cds_list_for_each_entry(node
, head
, siblings
) {
100 assert(node
->type
== NODE_UNARY_EXPRESSION
);
101 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
102 assert((node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
)
104 /* needs to be chained with . */
105 switch (node
->u
.unary_expression
.link
) {
108 case UNARY_ARROWLINK
:
109 case UNARY_DOTDOTDOT
:
114 src_string
= node
->u
.unary_expression
.u
.string
;
116 case 0: if (strcmp("clock", src_string
) != 0) {
120 case 1: name
= src_string
;
122 case 2: if (strcmp("value", src_string
) != 0) {
127 return 0; /* extra identifier, unknown */
131 return g_quark_from_string(name
);
135 int get_unary_unsigned(struct cds_list_head
*head
, uint64_t *value
)
137 struct ctf_node
*node
;
140 cds_list_for_each_entry(node
, head
, siblings
) {
141 assert(node
->type
== NODE_UNARY_EXPRESSION
);
142 assert(node
->u
.unary_expression
.type
== UNARY_UNSIGNED_CONSTANT
);
143 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
145 *value
= node
->u
.unary_expression
.u
.unsigned_constant
;
152 int get_unary_signed(struct cds_list_head
*head
, int64_t *value
)
154 struct ctf_node
*node
;
157 cds_list_for_each_entry(node
, head
, siblings
) {
158 assert(node
->type
== NODE_UNARY_EXPRESSION
);
159 assert(node
->u
.unary_expression
.type
== UNARY_UNSIGNED_CONSTANT
160 || node
->u
.unary_expression
.type
== UNARY_SIGNED_CONSTANT
);
161 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
163 switch (node
->u
.unary_expression
.type
) {
164 case UNARY_UNSIGNED_CONSTANT
:
165 *value
= (int64_t) node
->u
.unary_expression
.u
.unsigned_constant
;
167 case UNARY_SIGNED_CONSTANT
:
168 *value
= node
->u
.unary_expression
.u
.signed_constant
;
179 int get_unary_uuid(struct cds_list_head
*head
, uuid_t
*uuid
)
181 struct ctf_node
*node
;
185 cds_list_for_each_entry(node
, head
, siblings
) {
186 const char *src_string
;
188 assert(node
->type
== NODE_UNARY_EXPRESSION
);
189 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
190 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
192 src_string
= node
->u
.unary_expression
.u
.string
;
193 ret
= uuid_parse(src_string
, *uuid
);
199 struct ctf_stream_class
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
201 if (trace
->streams
->len
<= stream_id
)
203 return g_ptr_array_index(trace
->streams
, stream_id
);
207 struct ctf_clock
*trace_clock_lookup(struct ctf_trace
*trace
, GQuark clock_name
)
209 return g_hash_table_lookup(trace
->clocks
, (gpointer
) (unsigned long) clock_name
);
213 int visit_type_specifier(FILE *fd
, struct ctf_node
*type_specifier
, GString
*str
)
215 assert(type_specifier
->type
== NODE_TYPE_SPECIFIER
);
217 switch (type_specifier
->u
.type_specifier
.type
) {
219 g_string_append(str
, "void");
222 g_string_append(str
, "char");
225 g_string_append(str
, "short");
228 g_string_append(str
, "int");
231 g_string_append(str
, "long");
234 g_string_append(str
, "float");
236 case TYPESPEC_DOUBLE
:
237 g_string_append(str
, "double");
239 case TYPESPEC_SIGNED
:
240 g_string_append(str
, "signed");
242 case TYPESPEC_UNSIGNED
:
243 g_string_append(str
, "unsigned");
246 g_string_append(str
, "bool");
248 case TYPESPEC_COMPLEX
:
249 g_string_append(str
, "_Complex");
251 case TYPESPEC_IMAGINARY
:
252 g_string_append(str
, "_Imaginary");
255 g_string_append(str
, "const");
257 case TYPESPEC_ID_TYPE
:
258 if (type_specifier
->u
.type_specifier
.id_type
)
259 g_string_append(str
, type_specifier
->u
.type_specifier
.id_type
);
261 case TYPESPEC_STRUCT
:
263 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
265 if (!node
->u
._struct
.name
) {
266 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
269 g_string_append(str
, "struct ");
270 g_string_append(str
, node
->u
._struct
.name
);
273 case TYPESPEC_VARIANT
:
275 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
277 if (!node
->u
.variant
.name
) {
278 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
281 g_string_append(str
, "variant ");
282 g_string_append(str
, node
->u
.variant
.name
);
287 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
289 if (!node
->u
._enum
.enum_id
) {
290 fprintf(fd
, "[error] %s: unexpected empty enum ID\n", __func__
);
293 g_string_append(str
, "enum ");
294 g_string_append(str
, node
->u
._enum
.enum_id
);
297 case TYPESPEC_FLOATING_POINT
:
298 case TYPESPEC_INTEGER
:
299 case TYPESPEC_STRING
:
301 fprintf(fd
, "[error] %s: unknown specifier\n", __func__
);
308 int visit_type_specifier_list(FILE *fd
, struct ctf_node
*type_specifier_list
, GString
*str
)
310 struct ctf_node
*iter
;
311 int alias_item_nr
= 0;
314 cds_list_for_each_entry(iter
, &type_specifier_list
->u
.type_specifier_list
.head
, siblings
) {
315 if (alias_item_nr
!= 0)
316 g_string_append(str
, " ");
318 ret
= visit_type_specifier(fd
, iter
, str
);
326 GQuark
create_typealias_identifier(FILE *fd
, int depth
,
327 struct ctf_node
*type_specifier_list
,
328 struct ctf_node
*node_type_declarator
)
330 struct ctf_node
*iter
;
336 str
= g_string_new("");
337 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
339 g_string_free(str
, TRUE
);
342 cds_list_for_each_entry(iter
, &node_type_declarator
->u
.type_declarator
.pointers
, siblings
) {
343 g_string_append(str
, " *");
344 if (iter
->u
.pointer
.const_qualifier
)
345 g_string_append(str
, " const");
347 str_c
= g_string_free(str
, FALSE
);
348 alias_q
= g_quark_from_string(str_c
);
354 struct declaration
*ctf_type_declarator_visit(FILE *fd
, int depth
,
355 struct ctf_node
*type_specifier_list
,
357 struct ctf_node
*node_type_declarator
,
358 struct declaration_scope
*declaration_scope
,
359 struct declaration
*nested_declaration
,
360 struct ctf_trace
*trace
)
363 * Visit type declarator by first taking care of sequence/array
364 * (recursively). Then, when we get to the identifier, take care
368 if (node_type_declarator
) {
369 assert(node_type_declarator
->u
.type_declarator
.type
!= TYPEDEC_UNKNOWN
);
371 /* TODO: gcc bitfields not supported yet. */
372 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!= NULL
) {
373 fprintf(fd
, "[error] %s: gcc bitfields are not supported yet.\n", __func__
);
378 if (!nested_declaration
) {
379 if (node_type_declarator
&& !cds_list_empty(&node_type_declarator
->u
.type_declarator
.pointers
)) {
383 * If we have a pointer declarator, it _has_ to be present in
384 * the typealiases (else fail).
386 alias_q
= create_typealias_identifier(fd
, depth
,
387 type_specifier_list
, node_type_declarator
);
388 nested_declaration
= lookup_declaration(alias_q
, declaration_scope
);
389 if (!nested_declaration
) {
390 fprintf(fd
, "[error] %s: cannot find typealias \"%s\".\n", __func__
, g_quark_to_string(alias_q
));
393 if (nested_declaration
->id
== CTF_TYPE_INTEGER
) {
394 struct declaration_integer
*integer_declaration
=
395 container_of(nested_declaration
, struct declaration_integer
, p
);
396 /* For base to 16 for pointers (expected pretty-print) */
397 if (!integer_declaration
->base
) {
399 * We need to do a copy of the
400 * integer declaration to modify it. There could be other references to
403 integer_declaration
= integer_declaration_new(integer_declaration
->len
,
404 integer_declaration
->byte_order
, integer_declaration
->signedness
,
405 integer_declaration
->p
.alignment
, 16, integer_declaration
->encoding
,
406 integer_declaration
->clock
);
407 nested_declaration
= &integer_declaration
->p
;
411 nested_declaration
= ctf_type_specifier_list_visit(fd
, depth
,
412 type_specifier_list
, declaration_scope
, trace
);
416 if (!node_type_declarator
)
417 return nested_declaration
;
419 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
420 if (node_type_declarator
->u
.type_declarator
.u
.id
)
421 *field_name
= g_quark_from_string(node_type_declarator
->u
.type_declarator
.u
.id
);
424 return nested_declaration
;
426 struct declaration
*declaration
;
427 struct ctf_node
*first
;
431 if (!nested_declaration
) {
432 fprintf(fd
, "[error] %s: nested type is unknown.\n", __func__
);
436 /* create array/sequence, pass nested_declaration as child. */
437 if (cds_list_empty(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
)) {
438 fprintf(fd
, "[error] %s: expecting length field reference or value.\n", __func__
);
441 first
= _cds_list_first_entry(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
,
442 struct ctf_node
, siblings
);
443 assert(first
->type
== NODE_UNARY_EXPRESSION
);
445 switch (first
->u
.unary_expression
.type
) {
446 case UNARY_UNSIGNED_CONSTANT
:
448 struct declaration_array
*array_declaration
;
451 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
452 array_declaration
= array_declaration_new(len
, nested_declaration
,
455 if (!array_declaration
) {
456 fprintf(fd
, "[error] %s: cannot create array declaration.\n", __func__
);
459 declaration
= &array_declaration
->p
;
464 /* Lookup unsigned integer definition, create sequence */
465 char *length_name
= concatenate_unary_strings(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
);
466 struct declaration_sequence
*sequence_declaration
;
468 sequence_declaration
= sequence_declaration_new(length_name
, nested_declaration
, declaration_scope
);
469 if (!sequence_declaration
) {
470 fprintf(fd
, "[error] %s: cannot create sequence declaration.\n", __func__
);
473 declaration
= &sequence_declaration
->p
;
480 /* Pass it as content of outer container */
481 declaration
= ctf_type_declarator_visit(fd
, depth
,
482 type_specifier_list
, field_name
,
483 node_type_declarator
->u
.type_declarator
.u
.nested
.type_declarator
,
484 declaration_scope
, declaration
, trace
);
490 int ctf_struct_type_declarators_visit(FILE *fd
, int depth
,
491 struct declaration_struct
*struct_declaration
,
492 struct ctf_node
*type_specifier_list
,
493 struct cds_list_head
*type_declarators
,
494 struct declaration_scope
*declaration_scope
,
495 struct ctf_trace
*trace
)
497 struct ctf_node
*iter
;
500 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
501 struct declaration
*field_declaration
;
503 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
506 struct_declaration
->scope
,
508 if (!field_declaration
) {
509 fprintf(fd
, "[error] %s: unable to find struct field declaration type\n", __func__
);
513 /* Check if field with same name already exists */
514 if (struct_declaration_lookup_field_index(struct_declaration
, field_name
) >= 0) {
515 fprintf(fd
, "[error] %s: duplicate field %s in struct\n", __func__
, g_quark_to_string(field_name
));
519 struct_declaration_add_field(struct_declaration
,
520 g_quark_to_string(field_name
),
527 int ctf_variant_type_declarators_visit(FILE *fd
, int depth
,
528 struct declaration_untagged_variant
*untagged_variant_declaration
,
529 struct ctf_node
*type_specifier_list
,
530 struct cds_list_head
*type_declarators
,
531 struct declaration_scope
*declaration_scope
,
532 struct ctf_trace
*trace
)
534 struct ctf_node
*iter
;
537 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
538 struct declaration
*field_declaration
;
540 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
543 untagged_variant_declaration
->scope
,
545 if (!field_declaration
) {
546 fprintf(fd
, "[error] %s: unable to find variant field declaration type\n", __func__
);
550 if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration
, field_name
) != NULL
) {
551 fprintf(fd
, "[error] %s: duplicate field %s in variant\n", __func__
, g_quark_to_string(field_name
));
556 untagged_variant_declaration_add_field(untagged_variant_declaration
,
557 g_quark_to_string(field_name
),
564 int ctf_typedef_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
565 struct ctf_node
*type_specifier_list
,
566 struct cds_list_head
*type_declarators
,
567 struct ctf_trace
*trace
)
569 struct ctf_node
*iter
;
572 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
573 struct declaration
*type_declaration
;
576 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
580 if (!type_declaration
) {
581 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
585 * Don't allow typedef and typealias of untagged
588 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
589 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
590 declaration_unref(type_declaration
);
593 ret
= register_declaration(identifier
, type_declaration
, scope
);
595 type_declaration
->declaration_free(type_declaration
);
603 int ctf_typealias_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
604 struct ctf_node
*target
, struct ctf_node
*alias
,
605 struct ctf_trace
*trace
)
607 struct declaration
*type_declaration
;
608 struct ctf_node
*node
;
613 /* See ctf_visitor_type_declarator() in the semantic validator. */
616 * Create target type declaration.
619 if (cds_list_empty(&target
->u
.typealias_target
.type_declarators
))
622 node
= _cds_list_first_entry(&target
->u
.typealias_target
.type_declarators
,
623 struct ctf_node
, siblings
);
624 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
625 target
->u
.typealias_target
.type_specifier_list
,
628 if (!type_declaration
) {
629 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
634 * Don't allow typedef and typealias of untagged
637 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
638 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
639 declaration_unref(type_declaration
);
643 * The semantic validator does not check whether the target is
644 * abstract or not (if it has an identifier). Check it here.
647 fprintf(fd
, "[error] %s: expecting empty identifier\n", __func__
);
652 * Create alias identifier.
655 node
= _cds_list_first_entry(&alias
->u
.typealias_alias
.type_declarators
,
656 struct ctf_node
, siblings
);
657 alias_q
= create_typealias_identifier(fd
, depth
,
658 alias
->u
.typealias_alias
.type_specifier_list
, node
);
659 err
= register_declaration(alias_q
, type_declaration
, scope
);
665 if (type_declaration
) {
666 type_declaration
->declaration_free(type_declaration
);
672 int ctf_struct_declaration_list_visit(FILE *fd
, int depth
,
673 struct ctf_node
*iter
, struct declaration_struct
*struct_declaration
,
674 struct ctf_trace
*trace
)
678 switch (iter
->type
) {
680 /* For each declarator, declare type and add type to struct declaration scope */
681 ret
= ctf_typedef_visit(fd
, depth
,
682 struct_declaration
->scope
,
683 iter
->u
._typedef
.type_specifier_list
,
684 &iter
->u
._typedef
.type_declarators
, trace
);
689 /* Declare type with declarator and add type to struct declaration scope */
690 ret
= ctf_typealias_visit(fd
, depth
,
691 struct_declaration
->scope
,
692 iter
->u
.typealias
.target
,
693 iter
->u
.typealias
.alias
, trace
);
697 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
698 /* Add field to structure declaration */
699 ret
= ctf_struct_type_declarators_visit(fd
, depth
,
701 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
702 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
703 struct_declaration
->scope
, trace
);
708 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
715 int ctf_variant_declaration_list_visit(FILE *fd
, int depth
,
716 struct ctf_node
*iter
,
717 struct declaration_untagged_variant
*untagged_variant_declaration
,
718 struct ctf_trace
*trace
)
722 switch (iter
->type
) {
724 /* For each declarator, declare type and add type to variant declaration scope */
725 ret
= ctf_typedef_visit(fd
, depth
,
726 untagged_variant_declaration
->scope
,
727 iter
->u
._typedef
.type_specifier_list
,
728 &iter
->u
._typedef
.type_declarators
, trace
);
733 /* Declare type with declarator and add type to variant declaration scope */
734 ret
= ctf_typealias_visit(fd
, depth
,
735 untagged_variant_declaration
->scope
,
736 iter
->u
.typealias
.target
,
737 iter
->u
.typealias
.alias
, trace
);
741 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
742 /* Add field to structure declaration */
743 ret
= ctf_variant_type_declarators_visit(fd
, depth
,
744 untagged_variant_declaration
,
745 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
746 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
747 untagged_variant_declaration
->scope
, trace
);
752 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
759 struct declaration
*ctf_declaration_struct_visit(FILE *fd
,
760 int depth
, const char *name
, struct cds_list_head
*declaration_list
,
761 int has_body
, struct cds_list_head
*min_align
,
762 struct declaration_scope
*declaration_scope
,
763 struct ctf_trace
*trace
)
765 struct declaration_struct
*struct_declaration
;
766 struct ctf_node
*iter
;
770 * For named struct (without body), lookup in
771 * declaration scope. Don't take reference on struct
772 * declaration: ref is only taken upon definition.
777 lookup_struct_declaration(g_quark_from_string(name
),
779 return &struct_declaration
->p
;
781 uint64_t min_align_value
= 0;
783 /* For unnamed struct, create type */
784 /* For named struct (with body), create type and add to declaration scope */
786 if (lookup_struct_declaration(g_quark_from_string(name
),
787 declaration_scope
)) {
789 fprintf(fd
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
793 if (!cds_list_empty(min_align
)) {
794 ret
= get_unary_unsigned(min_align
, &min_align_value
);
796 fprintf(fd
, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__
);
801 struct_declaration
= struct_declaration_new(declaration_scope
,
803 cds_list_for_each_entry(iter
, declaration_list
, siblings
) {
804 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
805 struct_declaration
, trace
);
807 goto error_free_declaration
;
810 ret
= register_struct_declaration(g_quark_from_string(name
),
815 return &struct_declaration
->p
;
817 error_free_declaration
:
818 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
824 struct declaration
*ctf_declaration_variant_visit(FILE *fd
,
825 int depth
, const char *name
, const char *choice
,
826 struct cds_list_head
*declaration_list
,
827 int has_body
, struct declaration_scope
*declaration_scope
,
828 struct ctf_trace
*trace
)
830 struct declaration_untagged_variant
*untagged_variant_declaration
;
831 struct declaration_variant
*variant_declaration
;
832 struct ctf_node
*iter
;
836 * For named variant (without body), lookup in
837 * declaration scope. Don't take reference on variant
838 * declaration: ref is only taken upon definition.
842 untagged_variant_declaration
=
843 lookup_variant_declaration(g_quark_from_string(name
),
846 /* For unnamed variant, create type */
847 /* For named variant (with body), create type and add to declaration scope */
849 if (lookup_variant_declaration(g_quark_from_string(name
),
850 declaration_scope
)) {
852 fprintf(fd
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
856 untagged_variant_declaration
= untagged_variant_declaration_new(declaration_scope
);
857 cds_list_for_each_entry(iter
, declaration_list
, siblings
) {
858 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
859 untagged_variant_declaration
, trace
);
864 ret
= register_variant_declaration(g_quark_from_string(name
),
865 untagged_variant_declaration
,
871 * if tagged, create tagged variant and return. else return
875 return &untagged_variant_declaration
->p
;
877 variant_declaration
= variant_declaration_new(untagged_variant_declaration
, choice
);
878 if (!variant_declaration
)
880 declaration_unref(&untagged_variant_declaration
->p
);
881 return &variant_declaration
->p
;
884 untagged_variant_declaration
->p
.declaration_free(&untagged_variant_declaration
->p
);
889 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
890 struct ctf_node
*enumerator
,
891 struct declaration_enum
*enum_declaration
)
894 struct ctf_node
*iter
;
896 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
897 if (enum_declaration
->integer_declaration
->signedness
) {
901 cds_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
904 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
910 switch (iter
->u
.unary_expression
.type
) {
911 case UNARY_SIGNED_CONSTANT
:
912 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
914 case UNARY_UNSIGNED_CONSTANT
:
915 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
918 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
922 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
929 enum_signed_insert(enum_declaration
, start
, end
, q
);
934 cds_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
937 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
943 switch (iter
->u
.unary_expression
.type
) {
944 case UNARY_UNSIGNED_CONSTANT
:
945 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
947 case UNARY_SIGNED_CONSTANT
:
949 * We don't accept signed constants for enums with unsigned
952 fprintf(fd
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
955 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
959 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
966 enum_unsigned_insert(enum_declaration
, start
, end
, q
);
972 struct declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
974 struct ctf_node
*container_type
,
975 struct cds_list_head
*enumerator_list
,
977 struct declaration_scope
*declaration_scope
,
978 struct ctf_trace
*trace
)
980 struct declaration
*declaration
;
981 struct declaration_enum
*enum_declaration
;
982 struct declaration_integer
*integer_declaration
;
983 struct ctf_node
*iter
;
988 * For named enum (without body), lookup in
989 * declaration scope. Don't take reference on enum
990 * declaration: ref is only taken upon definition.
995 lookup_enum_declaration(g_quark_from_string(name
),
997 return &enum_declaration
->p
;
999 /* For unnamed enum, create type */
1000 /* For named enum (with body), create type and add to declaration scope */
1002 if (lookup_enum_declaration(g_quark_from_string(name
),
1003 declaration_scope
)) {
1005 fprintf(fd
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
1009 if (!container_type
) {
1010 declaration
= lookup_declaration(g_quark_from_static_string("int"),
1013 fprintf(fd
, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__
);
1017 declaration
= ctf_type_declarator_visit(fd
, depth
,
1024 fprintf(fd
, "[error] %s: unable to create container type for enumeration\n", __func__
);
1027 if (declaration
->id
!= CTF_TYPE_INTEGER
) {
1028 fprintf(fd
, "[error] %s: container type for enumeration is not integer\n", __func__
);
1031 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
1032 enum_declaration
= enum_declaration_new(integer_declaration
);
1033 declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
1034 cds_list_for_each_entry(iter
, enumerator_list
, siblings
) {
1035 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
);
1040 ret
= register_enum_declaration(g_quark_from_string(name
),
1045 return &enum_declaration
->p
;
1048 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
1053 struct declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
1054 struct ctf_node
*type_specifier_list
,
1055 struct declaration_scope
*declaration_scope
)
1058 struct declaration
*declaration
;
1063 str
= g_string_new("");
1064 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
1067 str_c
= g_string_free(str
, FALSE
);
1068 id_q
= g_quark_from_string(str_c
);
1070 declaration
= lookup_declaration(id_q
, declaration_scope
);
1075 * Returns 0/1 boolean, or < 0 on error.
1078 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1080 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1081 fprintf(fd
, "[error] %s: expecting unary expression\n",
1085 switch (unary_expression
->u
.unary_expression
.type
) {
1086 case UNARY_UNSIGNED_CONSTANT
:
1087 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1091 case UNARY_SIGNED_CONSTANT
:
1092 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1097 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1099 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1101 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1103 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1106 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1107 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1112 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1120 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1124 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1125 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1129 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1130 byte_order
= BIG_ENDIAN
;
1131 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1132 byte_order
= LITTLE_ENDIAN
;
1134 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1135 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1142 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1143 struct ctf_trace
*trace
)
1147 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1148 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1152 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1153 byte_order
= trace
->byte_order
;
1154 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1155 byte_order
= BIG_ENDIAN
;
1156 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1157 byte_order
= BIG_ENDIAN
;
1158 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1159 byte_order
= LITTLE_ENDIAN
;
1161 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1162 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1169 struct declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1170 struct cds_list_head
*expressions
,
1171 struct ctf_trace
*trace
)
1173 struct ctf_node
*expression
;
1174 uint64_t alignment
= 1, size
= 0;
1175 int byte_order
= trace
->byte_order
;
1177 int has_alignment
= 0, has_size
= 0;
1179 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1180 struct ctf_clock
*clock
= NULL
;
1181 struct declaration_integer
*integer_declaration
;
1183 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1184 struct ctf_node
*left
, *right
;
1186 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1187 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1188 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1189 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1190 signedness
= get_boolean(fd
, depth
, right
);
1193 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1194 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1197 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1198 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1199 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1203 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1205 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1206 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1207 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1211 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1212 /* Make sure alignment is a power of two */
1213 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1214 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1219 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1220 switch (right
->u
.unary_expression
.type
) {
1221 case UNARY_UNSIGNED_CONSTANT
:
1222 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1227 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1230 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1231 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1237 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1239 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1243 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1244 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1246 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1247 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1248 || !strcmp(s_right
, "p")) {
1250 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1251 || !strcmp(s_right
, "o")) {
1253 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1256 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1265 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1269 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1272 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1273 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1277 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1279 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1283 if (!strcmp(s_right
, "UTF8")
1284 || !strcmp(s_right
, "utf8")
1285 || !strcmp(s_right
, "utf-8")
1286 || !strcmp(s_right
, "UTF-8"))
1287 encoding
= CTF_STRING_UTF8
;
1288 else if (!strcmp(s_right
, "ASCII")
1289 || !strcmp(s_right
, "ascii"))
1290 encoding
= CTF_STRING_ASCII
;
1291 else if (!strcmp(s_right
, "none"))
1292 encoding
= CTF_STRING_NONE
;
1294 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1299 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1302 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1303 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1307 /* currently only support clock.name.value */
1308 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1312 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1314 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1318 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1323 clock
= trace_clock_lookup(trace
, clock_name
);
1325 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1326 __func__
, g_quark_to_string(clock_name
));
1330 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1331 __func__
, left
->u
.unary_expression
.u
.string
);
1332 /* Fall-through after warning */
1336 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1339 if (!has_alignment
) {
1340 if (size
% CHAR_BIT
) {
1341 /* bit-packed alignment */
1344 /* byte-packed alignment */
1345 alignment
= CHAR_BIT
;
1348 integer_declaration
= integer_declaration_new(size
,
1349 byte_order
, signedness
, alignment
,
1350 base
, encoding
, clock
);
1351 return &integer_declaration
->p
;
1355 struct declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1356 struct cds_list_head
*expressions
,
1357 struct ctf_trace
*trace
)
1359 struct ctf_node
*expression
;
1360 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0,
1361 byte_order
= trace
->byte_order
;
1362 int has_alignment
= 0, has_exp_dig
= 0, has_mant_dig
= 0;
1363 struct declaration_float
*float_declaration
;
1365 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1366 struct ctf_node
*left
, *right
;
1368 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1369 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1370 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1371 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1372 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1375 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1376 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1377 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1381 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1383 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1384 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1385 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1389 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1391 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1392 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1393 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1397 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1398 /* Make sure alignment is a power of two */
1399 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1400 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1406 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1407 __func__
, left
->u
.unary_expression
.u
.string
);
1408 /* Fall-through after warning */
1411 if (!has_mant_dig
) {
1412 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1416 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1419 if (!has_alignment
) {
1420 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1421 /* bit-packed alignment */
1424 /* byte-packed alignment */
1425 alignment
= CHAR_BIT
;
1428 float_declaration
= float_declaration_new(mant_dig
, exp_dig
,
1429 byte_order
, alignment
);
1430 return &float_declaration
->p
;
1434 struct declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1435 struct cds_list_head
*expressions
,
1436 struct ctf_trace
*trace
)
1438 struct ctf_node
*expression
;
1439 const char *encoding_c
= NULL
;
1440 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1441 struct declaration_string
*string_declaration
;
1443 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1444 struct ctf_node
*left
, *right
;
1446 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1447 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1448 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1449 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1450 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1451 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1455 encoding_c
= right
->u
.unary_expression
.u
.string
;
1457 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1458 __func__
, left
->u
.unary_expression
.u
.string
);
1459 /* Fall-through after warning */
1462 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1463 encoding
= CTF_STRING_ASCII
;
1464 string_declaration
= string_declaration_new(encoding
);
1465 return &string_declaration
->p
;
1470 struct declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1471 int depth
, struct ctf_node
*type_specifier_list
,
1472 struct declaration_scope
*declaration_scope
,
1473 struct ctf_trace
*trace
)
1475 struct ctf_node
*first
;
1476 struct ctf_node
*node
;
1478 assert(type_specifier_list
->type
== NODE_TYPE_SPECIFIER_LIST
);
1480 first
= _cds_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1482 assert(first
->type
== NODE_TYPE_SPECIFIER
);
1484 node
= first
->u
.type_specifier
.node
;
1486 switch (first
->u
.type_specifier
.type
) {
1487 case TYPESPEC_FLOATING_POINT
:
1488 return ctf_declaration_floating_point_visit(fd
, depth
,
1489 &node
->u
.floating_point
.expressions
, trace
);
1490 case TYPESPEC_INTEGER
:
1491 return ctf_declaration_integer_visit(fd
, depth
,
1492 &node
->u
.integer
.expressions
, trace
);
1493 case TYPESPEC_STRING
:
1494 return ctf_declaration_string_visit(fd
, depth
,
1495 &node
->u
.string
.expressions
, trace
);
1496 case TYPESPEC_STRUCT
:
1497 return ctf_declaration_struct_visit(fd
, depth
,
1498 node
->u
._struct
.name
,
1499 &node
->u
._struct
.declaration_list
,
1500 node
->u
._struct
.has_body
,
1501 &node
->u
._struct
.min_align
,
1504 case TYPESPEC_VARIANT
:
1505 return ctf_declaration_variant_visit(fd
, depth
,
1506 node
->u
.variant
.name
,
1507 node
->u
.variant
.choice
,
1508 &node
->u
.variant
.declaration_list
,
1509 node
->u
.variant
.has_body
,
1513 return ctf_declaration_enum_visit(fd
, depth
,
1514 node
->u
._enum
.enum_id
,
1515 node
->u
._enum
.container_type
,
1516 &node
->u
._enum
.enumerator_list
,
1517 node
->u
._enum
.has_body
,
1523 case TYPESPEC_SHORT
:
1526 case TYPESPEC_FLOAT
:
1527 case TYPESPEC_DOUBLE
:
1528 case TYPESPEC_SIGNED
:
1529 case TYPESPEC_UNSIGNED
:
1531 case TYPESPEC_COMPLEX
:
1532 case TYPESPEC_IMAGINARY
:
1533 case TYPESPEC_CONST
:
1534 case TYPESPEC_ID_TYPE
:
1535 return ctf_declaration_type_specifier_visit(fd
, depth
,
1536 type_specifier_list
, declaration_scope
);
1538 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1544 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event
*event
, struct ctf_trace
*trace
)
1548 switch (node
->type
) {
1550 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1551 event
->declaration_scope
,
1552 node
->u
._typedef
.type_specifier_list
,
1553 &node
->u
._typedef
.type_declarators
,
1558 case NODE_TYPEALIAS
:
1559 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1560 event
->declaration_scope
,
1561 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1566 case NODE_CTF_EXPRESSION
:
1570 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1571 if (!strcmp(left
, "name")) {
1574 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1575 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1579 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1581 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1585 event
->name
= g_quark_from_string(right
);
1587 CTF_EVENT_SET_FIELD(event
, name
);
1588 } else if (!strcmp(left
, "id")) {
1589 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1590 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1594 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1596 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1600 CTF_EVENT_SET_FIELD(event
, id
);
1601 } else if (!strcmp(left
, "stream_id")) {
1602 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1603 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1607 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1609 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1613 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1614 if (!event
->stream
) {
1615 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1619 CTF_EVENT_SET_FIELD(event
, stream_id
);
1620 } else if (!strcmp(left
, "context")) {
1621 struct declaration
*declaration
;
1623 if (event
->context_decl
) {
1624 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1628 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1629 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1630 struct ctf_node
, siblings
),
1631 event
->declaration_scope
, trace
);
1636 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1640 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1641 } else if (!strcmp(left
, "fields")) {
1642 struct declaration
*declaration
;
1644 if (event
->fields_decl
) {
1645 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1649 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1650 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1651 struct ctf_node
, siblings
),
1652 event
->declaration_scope
, trace
);
1657 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1661 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1662 } else if (!strcmp(left
, "loglevel")) {
1663 int64_t loglevel
= -1;
1665 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel
)) {
1666 fprintf(fd
, "[error] %s: loglevel already declared in event declaration\n", __func__
);
1670 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &loglevel
);
1672 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel\n", __func__
);
1676 event
->loglevel
= (int) loglevel
;
1677 CTF_EVENT_SET_FIELD(event
, loglevel
);
1679 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1680 /* Fall-through after warning */
1688 /* TODO: declaration specifier should be added. */
1695 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1696 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1699 struct ctf_node
*iter
;
1700 struct ctf_event
*event
;
1702 event
= g_new0(struct ctf_event
, 1);
1703 event
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
1704 event
->loglevel
= -1;
1705 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1706 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1710 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1712 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1715 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1716 /* Allow missing stream_id if there is only a single stream */
1717 switch (trace
->streams
->len
) {
1718 case 0: /* Create stream if there was none. */
1719 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1724 event
->stream_id
= 0;
1725 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1729 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1733 /* Allow only one event without id per stream */
1734 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1735 && event
->stream
->events_by_id
->len
!= 0) {
1737 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1740 if (event
->stream
->events_by_id
->len
<= event
->id
)
1741 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1742 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1743 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1744 (gpointer
) (unsigned long) event
->name
,
1749 if (event
->fields_decl
)
1750 declaration_unref(&event
->fields_decl
->p
);
1751 if (event
->context_decl
)
1752 declaration_unref(&event
->context_decl
->p
);
1753 free_declaration_scope(event
->declaration_scope
);
1760 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_class
*stream
, struct ctf_trace
*trace
)
1764 switch (node
->type
) {
1766 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1767 stream
->declaration_scope
,
1768 node
->u
._typedef
.type_specifier_list
,
1769 &node
->u
._typedef
.type_declarators
,
1774 case NODE_TYPEALIAS
:
1775 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1776 stream
->declaration_scope
,
1777 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1782 case NODE_CTF_EXPRESSION
:
1786 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1787 if (!strcmp(left
, "id")) {
1788 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1789 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1793 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1795 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1799 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1800 } else if (!strcmp(left
, "event.header")) {
1801 struct declaration
*declaration
;
1803 if (stream
->event_header_decl
) {
1804 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1808 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1809 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1810 struct ctf_node
, siblings
),
1811 stream
->declaration_scope
, trace
);
1816 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1820 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1821 } else if (!strcmp(left
, "event.context")) {
1822 struct declaration
*declaration
;
1824 if (stream
->event_context_decl
) {
1825 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1829 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1830 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1831 struct ctf_node
, siblings
),
1832 stream
->declaration_scope
, trace
);
1837 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1841 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1842 } else if (!strcmp(left
, "packet.context")) {
1843 struct declaration
*declaration
;
1845 if (stream
->packet_context_decl
) {
1846 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
1850 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1851 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1852 struct ctf_node
, siblings
),
1853 stream
->declaration_scope
, trace
);
1858 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1862 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1864 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
1865 /* Fall-through after warning */
1874 /* TODO: declaration specifier should be added. */
1881 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1882 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1885 struct ctf_node
*iter
;
1886 struct ctf_stream_class
*stream
;
1888 stream
= g_new0(struct ctf_stream_class
, 1);
1889 stream
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
1890 stream
->events_by_id
= g_ptr_array_new();
1891 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
1892 stream
->streams
= g_ptr_array_new();
1894 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
1895 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
1900 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1901 /* check that packet header has stream_id field. */
1902 if (!trace
->packet_header_decl
1903 || struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
1905 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
1909 /* Allow only one id-less stream */
1910 if (trace
->streams
->len
!= 0) {
1912 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
1915 stream
->stream_id
= 0;
1917 if (trace
->streams
->len
<= stream
->stream_id
)
1918 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
1919 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
1920 stream
->trace
= trace
;
1925 if (stream
->event_header_decl
)
1926 declaration_unref(&stream
->event_header_decl
->p
);
1927 if (stream
->event_context_decl
)
1928 declaration_unref(&stream
->event_context_decl
->p
);
1929 if (stream
->packet_context_decl
)
1930 declaration_unref(&stream
->packet_context_decl
->p
);
1931 g_ptr_array_free(stream
->streams
, TRUE
);
1932 g_ptr_array_free(stream
->events_by_id
, TRUE
);
1933 g_hash_table_destroy(stream
->event_quark_to_id
);
1934 free_declaration_scope(stream
->declaration_scope
);
1940 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
1944 switch (node
->type
) {
1946 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1947 trace
->declaration_scope
,
1948 node
->u
._typedef
.type_specifier_list
,
1949 &node
->u
._typedef
.type_declarators
,
1954 case NODE_TYPEALIAS
:
1955 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1956 trace
->declaration_scope
,
1957 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1962 case NODE_CTF_EXPRESSION
:
1966 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1967 if (!strcmp(left
, "major")) {
1968 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
1969 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
1973 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
1975 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
1979 CTF_TRACE_SET_FIELD(trace
, major
);
1980 } else if (!strcmp(left
, "minor")) {
1981 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
1982 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
1986 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
1988 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
1992 CTF_TRACE_SET_FIELD(trace
, minor
);
1993 } else if (!strcmp(left
, "uuid")) {
1996 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &uuid
);
1998 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2002 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2003 && uuid_compare(uuid
, trace
->uuid
)) {
2004 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2008 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2010 CTF_TRACE_SET_FIELD(trace
, uuid
);
2011 } else if (!strcmp(left
, "byte_order")) {
2012 struct ctf_node
*right
;
2015 right
= _cds_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2016 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2020 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2021 && byte_order
!= trace
->byte_order
) {
2022 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2026 if (byte_order
!= trace
->byte_order
) {
2027 trace
->byte_order
= byte_order
;
2029 * We need to restart
2030 * construction of the
2031 * intermediate representation.
2033 trace
->field_mask
= 0;
2034 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2039 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2040 } else if (!strcmp(left
, "packet.header")) {
2041 struct declaration
*declaration
;
2043 if (trace
->packet_header_decl
) {
2044 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2048 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2049 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
2050 struct ctf_node
, siblings
),
2051 trace
->declaration_scope
, trace
);
2056 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2060 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2062 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2071 /* TODO: declaration specifier should be added. */
2078 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2081 struct ctf_node
*iter
;
2083 if (trace
->declaration_scope
)
2085 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
2086 trace
->streams
= g_ptr_array_new();
2087 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2088 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2092 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2094 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2097 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2099 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2102 if (!CTF_TRACE_FIELD_IS_SET(trace
, uuid
)) {
2104 fprintf(fd
, "[error] %s: missing uuid field in trace declaration\n", __func__
);
2107 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2109 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2113 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2114 /* check that the packet header contains a "magic" field */
2115 if (!trace
->packet_header_decl
2116 || struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2118 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2125 if (trace
->packet_header_decl
) {
2126 declaration_unref(&trace
->packet_header_decl
->p
);
2127 trace
->packet_header_decl
= NULL
;
2129 g_ptr_array_free(trace
->streams
, TRUE
);
2130 free_declaration_scope(trace
->declaration_scope
);
2131 trace
->declaration_scope
= NULL
;
2136 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2137 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2141 switch (node
->type
) {
2142 case NODE_CTF_EXPRESSION
:
2146 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2147 if (!strcmp(left
, "name")) {
2150 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2151 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2155 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2157 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2161 clock
->name
= g_quark_from_string(right
);
2163 CTF_EVENT_SET_FIELD(clock
, name
);
2164 } else if (!strcmp(left
, "uuid")) {
2168 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2172 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2174 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2178 clock
->uuid
= g_quark_from_string(right
);
2180 } else if (!strcmp(left
, "description")) {
2183 if (clock
->description
) {
2184 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2185 goto error
; /* ret is 0, so not an actual error, just warn. */
2187 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2189 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2190 goto error
; /* ret is 0, so not an actual error, just warn. */
2192 clock
->description
= right
;
2193 } else if (!strcmp(left
, "freq")) {
2195 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2199 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2201 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2205 } else if (!strcmp(left
, "precision")) {
2206 if (clock
->precision
) {
2207 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2211 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2213 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2217 } else if (!strcmp(left
, "offset_s")) {
2218 if (clock
->offset_s
) {
2219 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2223 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2225 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2229 } else if (!strcmp(left
, "offset")) {
2230 if (clock
->offset
) {
2231 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2235 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2237 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2241 } else if (!strcmp(left
, "absolute")) {
2242 struct ctf_node
*right
;
2244 right
= _cds_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2245 ret
= get_boolean(fd
, depth
, right
);
2247 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2251 clock
->absolute
= ret
;
2253 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2262 /* TODO: declaration specifier should be added. */
2269 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2272 struct ctf_node
*iter
;
2273 struct ctf_clock
*clock
;
2275 clock
= g_new0(struct ctf_clock
, 1);
2276 cds_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2277 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2281 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2283 fprintf(fd
, "[error] %s: missing namefield in clock declaration\n", __func__
);
2286 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2290 g_free(clock
->description
);
2296 void clock_free(gpointer data
)
2298 struct ctf_clock
*clock
= data
;
2300 g_free(clock
->description
);
2305 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2307 fprintf(fd
, "[warning] %s: environment declaration support not implement yet.\n", __func__
);
2308 return 0; /* continue */
2312 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2316 switch (node
->type
) {
2318 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2319 trace
->root_declaration_scope
,
2320 node
->u
._typedef
.type_specifier_list
,
2321 &node
->u
._typedef
.type_declarators
,
2326 case NODE_TYPEALIAS
:
2327 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2328 trace
->root_declaration_scope
,
2329 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2334 case NODE_TYPE_SPECIFIER_LIST
:
2336 struct declaration
*declaration
;
2339 * Just add the type specifier to the root scope
2340 * declaration scope. Release local reference.
2342 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2343 node
, trace
->root_declaration_scope
, trace
);
2346 declaration_unref(declaration
);
2356 /* TODO: missing metadata "destroy" (memory leak) */
2357 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2358 struct ctf_trace
*trace
, int byte_order
)
2361 struct ctf_node
*iter
;
2362 int env_clock_done
= 0;
2364 printf_verbose("CTF visitor: metadata construction... ");
2365 trace
->byte_order
= byte_order
;
2366 trace
->clocks
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2370 trace
->root_declaration_scope
= new_declaration_scope(NULL
);
2372 switch (node
->type
) {
2374 if (!env_clock_done
) {
2375 cds_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
2376 ret
= ctf_env_visit(fd
, depth
+ 1, iter
,
2379 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
2385 * declarations need to query clock hash table,
2386 * so clock need to be treated first.
2388 cds_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2389 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2392 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2398 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2400 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2402 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
2406 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
2407 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
2408 if (ret
== -EINTR
) {
2409 free_declaration_scope(trace
->root_declaration_scope
);
2411 * Need to restart creation of type
2412 * definitions, aliases and
2413 * trace header declarations.
2418 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
2422 if (!trace
->streams
) {
2423 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
2427 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
2428 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
2429 trace
->root_declaration_scope
, trace
);
2431 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
2435 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
2436 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
2437 trace
->root_declaration_scope
, trace
);
2439 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
2446 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
2451 printf_verbose("done.\n");
2455 free_declaration_scope(trace
->root_declaration_scope
);
2456 g_hash_table_destroy(trace
->clocks
);