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 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
162 *value
= node
->u
.unary_expression
.u
.signed_constant
;
169 int get_unary_uuid(struct cds_list_head
*head
, uuid_t
*uuid
)
171 struct ctf_node
*node
;
175 cds_list_for_each_entry(node
, head
, siblings
) {
176 const char *src_string
;
178 assert(node
->type
== NODE_UNARY_EXPRESSION
);
179 assert(node
->u
.unary_expression
.type
== UNARY_STRING
);
180 assert(node
->u
.unary_expression
.link
== UNARY_LINK_UNKNOWN
);
182 src_string
= node
->u
.unary_expression
.u
.string
;
183 ret
= uuid_parse(src_string
, *uuid
);
189 struct ctf_stream_class
*trace_stream_lookup(struct ctf_trace
*trace
, uint64_t stream_id
)
191 if (trace
->streams
->len
<= stream_id
)
193 return g_ptr_array_index(trace
->streams
, stream_id
);
197 struct ctf_clock
*trace_clock_lookup(struct ctf_trace
*trace
, GQuark clock_name
)
199 return g_hash_table_lookup(trace
->clocks
, (gpointer
) (unsigned long) clock_name
);
203 int visit_type_specifier(FILE *fd
, struct ctf_node
*type_specifier
, GString
*str
)
205 assert(type_specifier
->type
== NODE_TYPE_SPECIFIER
);
207 switch (type_specifier
->u
.type_specifier
.type
) {
209 g_string_append(str
, "void");
212 g_string_append(str
, "char");
215 g_string_append(str
, "short");
218 g_string_append(str
, "int");
221 g_string_append(str
, "long");
224 g_string_append(str
, "float");
226 case TYPESPEC_DOUBLE
:
227 g_string_append(str
, "double");
229 case TYPESPEC_SIGNED
:
230 g_string_append(str
, "signed");
232 case TYPESPEC_UNSIGNED
:
233 g_string_append(str
, "unsigned");
236 g_string_append(str
, "bool");
238 case TYPESPEC_COMPLEX
:
239 g_string_append(str
, "_Complex");
241 case TYPESPEC_IMAGINARY
:
242 g_string_append(str
, "_Imaginary");
245 g_string_append(str
, "const");
247 case TYPESPEC_ID_TYPE
:
248 if (type_specifier
->u
.type_specifier
.id_type
)
249 g_string_append(str
, type_specifier
->u
.type_specifier
.id_type
);
251 case TYPESPEC_STRUCT
:
253 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
255 if (!node
->u
._struct
.name
) {
256 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
259 g_string_append(str
, "struct ");
260 g_string_append(str
, node
->u
._struct
.name
);
263 case TYPESPEC_VARIANT
:
265 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
267 if (!node
->u
.variant
.name
) {
268 fprintf(fd
, "[error] %s: unexpected empty variant name\n", __func__
);
271 g_string_append(str
, "variant ");
272 g_string_append(str
, node
->u
.variant
.name
);
277 struct ctf_node
*node
= type_specifier
->u
.type_specifier
.node
;
279 if (!node
->u
._enum
.enum_id
) {
280 fprintf(fd
, "[error] %s: unexpected empty enum ID\n", __func__
);
283 g_string_append(str
, "enum ");
284 g_string_append(str
, node
->u
._enum
.enum_id
);
287 case TYPESPEC_FLOATING_POINT
:
288 case TYPESPEC_INTEGER
:
289 case TYPESPEC_STRING
:
291 fprintf(fd
, "[error] %s: unknown specifier\n", __func__
);
298 int visit_type_specifier_list(FILE *fd
, struct ctf_node
*type_specifier_list
, GString
*str
)
300 struct ctf_node
*iter
;
301 int alias_item_nr
= 0;
304 cds_list_for_each_entry(iter
, &type_specifier_list
->u
.type_specifier_list
.head
, siblings
) {
305 if (alias_item_nr
!= 0)
306 g_string_append(str
, " ");
308 ret
= visit_type_specifier(fd
, iter
, str
);
316 GQuark
create_typealias_identifier(FILE *fd
, int depth
,
317 struct ctf_node
*type_specifier_list
,
318 struct ctf_node
*node_type_declarator
)
320 struct ctf_node
*iter
;
326 str
= g_string_new("");
327 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
329 g_string_free(str
, TRUE
);
332 cds_list_for_each_entry(iter
, &node_type_declarator
->u
.type_declarator
.pointers
, siblings
) {
333 g_string_append(str
, " *");
334 if (iter
->u
.pointer
.const_qualifier
)
335 g_string_append(str
, " const");
337 str_c
= g_string_free(str
, FALSE
);
338 alias_q
= g_quark_from_string(str_c
);
344 struct declaration
*ctf_type_declarator_visit(FILE *fd
, int depth
,
345 struct ctf_node
*type_specifier_list
,
347 struct ctf_node
*node_type_declarator
,
348 struct declaration_scope
*declaration_scope
,
349 struct declaration
*nested_declaration
,
350 struct ctf_trace
*trace
)
353 * Visit type declarator by first taking care of sequence/array
354 * (recursively). Then, when we get to the identifier, take care
358 if (node_type_declarator
) {
359 assert(node_type_declarator
->u
.type_declarator
.type
!= TYPEDEC_UNKNOWN
);
361 /* TODO: gcc bitfields not supported yet. */
362 if (node_type_declarator
->u
.type_declarator
.bitfield_len
!= NULL
) {
363 fprintf(fd
, "[error] %s: gcc bitfields are not supported yet.\n", __func__
);
368 if (!nested_declaration
) {
369 if (node_type_declarator
&& !cds_list_empty(&node_type_declarator
->u
.type_declarator
.pointers
)) {
373 * If we have a pointer declarator, it _has_ to be present in
374 * the typealiases (else fail).
376 alias_q
= create_typealias_identifier(fd
, depth
,
377 type_specifier_list
, node_type_declarator
);
378 nested_declaration
= lookup_declaration(alias_q
, declaration_scope
);
379 if (!nested_declaration
) {
380 fprintf(fd
, "[error] %s: cannot find typealias \"%s\".\n", __func__
, g_quark_to_string(alias_q
));
383 if (nested_declaration
->id
== CTF_TYPE_INTEGER
) {
384 struct declaration_integer
*integer_declaration
=
385 container_of(nested_declaration
, struct declaration_integer
, p
);
386 /* For base to 16 for pointers (expected pretty-print) */
387 if (!integer_declaration
->base
) {
389 * We need to do a copy of the
390 * integer declaration to modify it. There could be other references to
393 integer_declaration
= integer_declaration_new(integer_declaration
->len
,
394 integer_declaration
->byte_order
, integer_declaration
->signedness
,
395 integer_declaration
->p
.alignment
, 16, integer_declaration
->encoding
,
396 integer_declaration
->clock
);
397 nested_declaration
= &integer_declaration
->p
;
401 nested_declaration
= ctf_type_specifier_list_visit(fd
, depth
,
402 type_specifier_list
, declaration_scope
, trace
);
406 if (!node_type_declarator
)
407 return nested_declaration
;
409 if (node_type_declarator
->u
.type_declarator
.type
== TYPEDEC_ID
) {
410 if (node_type_declarator
->u
.type_declarator
.u
.id
)
411 *field_name
= g_quark_from_string(node_type_declarator
->u
.type_declarator
.u
.id
);
414 return nested_declaration
;
416 struct declaration
*declaration
;
417 struct ctf_node
*first
;
421 if (!nested_declaration
) {
422 fprintf(fd
, "[error] %s: nested type is unknown.\n", __func__
);
426 /* create array/sequence, pass nested_declaration as child. */
427 if (cds_list_empty(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
)) {
428 fprintf(fd
, "[error] %s: expecting length field reference or value.\n", __func__
);
431 first
= _cds_list_first_entry(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
,
432 struct ctf_node
, siblings
);
433 assert(first
->type
== NODE_UNARY_EXPRESSION
);
435 switch (first
->u
.unary_expression
.type
) {
436 case UNARY_UNSIGNED_CONSTANT
:
438 struct declaration_array
*array_declaration
;
441 len
= first
->u
.unary_expression
.u
.unsigned_constant
;
442 array_declaration
= array_declaration_new(len
, nested_declaration
,
445 if (!array_declaration
) {
446 fprintf(fd
, "[error] %s: cannot create array declaration.\n", __func__
);
449 declaration
= &array_declaration
->p
;
454 /* Lookup unsigned integer definition, create sequence */
455 char *length_name
= concatenate_unary_strings(&node_type_declarator
->u
.type_declarator
.u
.nested
.length
);
456 struct declaration_sequence
*sequence_declaration
;
458 sequence_declaration
= sequence_declaration_new(length_name
, nested_declaration
, declaration_scope
);
459 if (!sequence_declaration
) {
460 fprintf(fd
, "[error] %s: cannot create sequence declaration.\n", __func__
);
463 declaration
= &sequence_declaration
->p
;
470 /* Pass it as content of outer container */
471 declaration
= ctf_type_declarator_visit(fd
, depth
,
472 type_specifier_list
, field_name
,
473 node_type_declarator
->u
.type_declarator
.u
.nested
.type_declarator
,
474 declaration_scope
, declaration
, trace
);
480 int ctf_struct_type_declarators_visit(FILE *fd
, int depth
,
481 struct declaration_struct
*struct_declaration
,
482 struct ctf_node
*type_specifier_list
,
483 struct cds_list_head
*type_declarators
,
484 struct declaration_scope
*declaration_scope
,
485 struct ctf_trace
*trace
)
487 struct ctf_node
*iter
;
490 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
491 struct declaration
*field_declaration
;
493 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
496 struct_declaration
->scope
,
498 if (!field_declaration
) {
499 fprintf(fd
, "[error] %s: unable to find struct field declaration type\n", __func__
);
503 /* Check if field with same name already exists */
504 if (struct_declaration_lookup_field_index(struct_declaration
, field_name
) >= 0) {
505 fprintf(fd
, "[error] %s: duplicate field %s in struct\n", __func__
, g_quark_to_string(field_name
));
509 struct_declaration_add_field(struct_declaration
,
510 g_quark_to_string(field_name
),
517 int ctf_variant_type_declarators_visit(FILE *fd
, int depth
,
518 struct declaration_untagged_variant
*untagged_variant_declaration
,
519 struct ctf_node
*type_specifier_list
,
520 struct cds_list_head
*type_declarators
,
521 struct declaration_scope
*declaration_scope
,
522 struct ctf_trace
*trace
)
524 struct ctf_node
*iter
;
527 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
528 struct declaration
*field_declaration
;
530 field_declaration
= ctf_type_declarator_visit(fd
, depth
,
533 untagged_variant_declaration
->scope
,
535 if (!field_declaration
) {
536 fprintf(fd
, "[error] %s: unable to find variant field declaration type\n", __func__
);
540 if (untagged_variant_declaration_get_field_from_tag(untagged_variant_declaration
, field_name
) != NULL
) {
541 fprintf(fd
, "[error] %s: duplicate field %s in variant\n", __func__
, g_quark_to_string(field_name
));
546 untagged_variant_declaration_add_field(untagged_variant_declaration
,
547 g_quark_to_string(field_name
),
554 int ctf_typedef_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
555 struct ctf_node
*type_specifier_list
,
556 struct cds_list_head
*type_declarators
,
557 struct ctf_trace
*trace
)
559 struct ctf_node
*iter
;
562 cds_list_for_each_entry(iter
, type_declarators
, siblings
) {
563 struct declaration
*type_declaration
;
566 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
570 if (!type_declaration
) {
571 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
575 * Don't allow typedef and typealias of untagged
578 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
579 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
580 declaration_unref(type_declaration
);
583 ret
= register_declaration(identifier
, type_declaration
, scope
);
585 type_declaration
->declaration_free(type_declaration
);
593 int ctf_typealias_visit(FILE *fd
, int depth
, struct declaration_scope
*scope
,
594 struct ctf_node
*target
, struct ctf_node
*alias
,
595 struct ctf_trace
*trace
)
597 struct declaration
*type_declaration
;
598 struct ctf_node
*node
;
603 /* See ctf_visitor_type_declarator() in the semantic validator. */
606 * Create target type declaration.
609 if (cds_list_empty(&target
->u
.typealias_target
.type_declarators
))
612 node
= _cds_list_first_entry(&target
->u
.typealias_target
.type_declarators
,
613 struct ctf_node
, siblings
);
614 type_declaration
= ctf_type_declarator_visit(fd
, depth
,
615 target
->u
.typealias_target
.type_specifier_list
,
618 if (!type_declaration
) {
619 fprintf(fd
, "[error] %s: problem creating type declaration\n", __func__
);
624 * Don't allow typedef and typealias of untagged
627 if (type_declaration
->id
== CTF_TYPE_UNTAGGED_VARIANT
) {
628 fprintf(fd
, "[error] %s: typedef of untagged variant is not permitted.\n", __func__
);
629 declaration_unref(type_declaration
);
633 * The semantic validator does not check whether the target is
634 * abstract or not (if it has an identifier). Check it here.
637 fprintf(fd
, "[error] %s: expecting empty identifier\n", __func__
);
642 * Create alias identifier.
645 node
= _cds_list_first_entry(&alias
->u
.typealias_alias
.type_declarators
,
646 struct ctf_node
, siblings
);
647 alias_q
= create_typealias_identifier(fd
, depth
,
648 alias
->u
.typealias_alias
.type_specifier_list
, node
);
649 err
= register_declaration(alias_q
, type_declaration
, scope
);
655 if (type_declaration
) {
656 type_declaration
->declaration_free(type_declaration
);
662 int ctf_struct_declaration_list_visit(FILE *fd
, int depth
,
663 struct ctf_node
*iter
, struct declaration_struct
*struct_declaration
,
664 struct ctf_trace
*trace
)
668 switch (iter
->type
) {
670 /* For each declarator, declare type and add type to struct declaration scope */
671 ret
= ctf_typedef_visit(fd
, depth
,
672 struct_declaration
->scope
,
673 iter
->u
._typedef
.type_specifier_list
,
674 &iter
->u
._typedef
.type_declarators
, trace
);
679 /* Declare type with declarator and add type to struct declaration scope */
680 ret
= ctf_typealias_visit(fd
, depth
,
681 struct_declaration
->scope
,
682 iter
->u
.typealias
.target
,
683 iter
->u
.typealias
.alias
, trace
);
687 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
688 /* Add field to structure declaration */
689 ret
= ctf_struct_type_declarators_visit(fd
, depth
,
691 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
692 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
693 struct_declaration
->scope
, trace
);
698 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
705 int ctf_variant_declaration_list_visit(FILE *fd
, int depth
,
706 struct ctf_node
*iter
,
707 struct declaration_untagged_variant
*untagged_variant_declaration
,
708 struct ctf_trace
*trace
)
712 switch (iter
->type
) {
714 /* For each declarator, declare type and add type to variant declaration scope */
715 ret
= ctf_typedef_visit(fd
, depth
,
716 untagged_variant_declaration
->scope
,
717 iter
->u
._typedef
.type_specifier_list
,
718 &iter
->u
._typedef
.type_declarators
, trace
);
723 /* Declare type with declarator and add type to variant declaration scope */
724 ret
= ctf_typealias_visit(fd
, depth
,
725 untagged_variant_declaration
->scope
,
726 iter
->u
.typealias
.target
,
727 iter
->u
.typealias
.alias
, trace
);
731 case NODE_STRUCT_OR_VARIANT_DECLARATION
:
732 /* Add field to structure declaration */
733 ret
= ctf_variant_type_declarators_visit(fd
, depth
,
734 untagged_variant_declaration
,
735 iter
->u
.struct_or_variant_declaration
.type_specifier_list
,
736 &iter
->u
.struct_or_variant_declaration
.type_declarators
,
737 untagged_variant_declaration
->scope
, trace
);
742 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) iter
->type
);
749 struct declaration
*ctf_declaration_struct_visit(FILE *fd
,
750 int depth
, const char *name
, struct cds_list_head
*declaration_list
,
751 int has_body
, struct cds_list_head
*min_align
,
752 struct declaration_scope
*declaration_scope
,
753 struct ctf_trace
*trace
)
755 struct declaration_struct
*struct_declaration
;
756 struct ctf_node
*iter
;
760 * For named struct (without body), lookup in
761 * declaration scope. Don't take reference on struct
762 * declaration: ref is only taken upon definition.
767 lookup_struct_declaration(g_quark_from_string(name
),
769 return &struct_declaration
->p
;
771 uint64_t min_align_value
= 0;
773 /* For unnamed struct, create type */
774 /* For named struct (with body), create type and add to declaration scope */
776 if (lookup_struct_declaration(g_quark_from_string(name
),
777 declaration_scope
)) {
779 fprintf(fd
, "[error] %s: struct %s already declared in scope\n", __func__
, name
);
783 if (!cds_list_empty(min_align
)) {
784 ret
= get_unary_unsigned(min_align
, &min_align_value
);
786 fprintf(fd
, "[error] %s: unexpected unary expression for structure \"align\" attribute\n", __func__
);
791 struct_declaration
= struct_declaration_new(declaration_scope
,
793 cds_list_for_each_entry(iter
, declaration_list
, siblings
) {
794 ret
= ctf_struct_declaration_list_visit(fd
, depth
+ 1, iter
,
795 struct_declaration
, trace
);
797 goto error_free_declaration
;
800 ret
= register_struct_declaration(g_quark_from_string(name
),
805 return &struct_declaration
->p
;
807 error_free_declaration
:
808 struct_declaration
->p
.declaration_free(&struct_declaration
->p
);
814 struct declaration
*ctf_declaration_variant_visit(FILE *fd
,
815 int depth
, const char *name
, const char *choice
,
816 struct cds_list_head
*declaration_list
,
817 int has_body
, struct declaration_scope
*declaration_scope
,
818 struct ctf_trace
*trace
)
820 struct declaration_untagged_variant
*untagged_variant_declaration
;
821 struct declaration_variant
*variant_declaration
;
822 struct ctf_node
*iter
;
826 * For named variant (without body), lookup in
827 * declaration scope. Don't take reference on variant
828 * declaration: ref is only taken upon definition.
832 untagged_variant_declaration
=
833 lookup_variant_declaration(g_quark_from_string(name
),
836 /* For unnamed variant, create type */
837 /* For named variant (with body), create type and add to declaration scope */
839 if (lookup_variant_declaration(g_quark_from_string(name
),
840 declaration_scope
)) {
842 fprintf(fd
, "[error] %s: variant %s already declared in scope\n", __func__
, name
);
846 untagged_variant_declaration
= untagged_variant_declaration_new(declaration_scope
);
847 cds_list_for_each_entry(iter
, declaration_list
, siblings
) {
848 ret
= ctf_variant_declaration_list_visit(fd
, depth
+ 1, iter
,
849 untagged_variant_declaration
, trace
);
854 ret
= register_variant_declaration(g_quark_from_string(name
),
855 untagged_variant_declaration
,
861 * if tagged, create tagged variant and return. else return
865 return &untagged_variant_declaration
->p
;
867 variant_declaration
= variant_declaration_new(untagged_variant_declaration
, choice
);
868 if (!variant_declaration
)
870 declaration_unref(&untagged_variant_declaration
->p
);
871 return &variant_declaration
->p
;
874 untagged_variant_declaration
->p
.declaration_free(&untagged_variant_declaration
->p
);
879 int ctf_enumerator_list_visit(FILE *fd
, int depth
,
880 struct ctf_node
*enumerator
,
881 struct declaration_enum
*enum_declaration
)
884 struct ctf_node
*iter
;
886 q
= g_quark_from_string(enumerator
->u
.enumerator
.id
);
887 if (enum_declaration
->integer_declaration
->signedness
) {
891 cds_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
894 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
900 switch (iter
->u
.unary_expression
.type
) {
901 case UNARY_SIGNED_CONSTANT
:
902 *target
= iter
->u
.unary_expression
.u
.signed_constant
;
904 case UNARY_UNSIGNED_CONSTANT
:
905 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
908 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
912 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
919 enum_signed_insert(enum_declaration
, start
, end
, q
);
924 cds_list_for_each_entry(iter
, &enumerator
->u
.enumerator
.values
, siblings
) {
927 assert(iter
->type
== NODE_UNARY_EXPRESSION
);
933 switch (iter
->u
.unary_expression
.type
) {
934 case UNARY_UNSIGNED_CONSTANT
:
935 *target
= iter
->u
.unary_expression
.u
.unsigned_constant
;
937 case UNARY_SIGNED_CONSTANT
:
939 * We don't accept signed constants for enums with unsigned
942 fprintf(fd
, "[error] %s: invalid enumerator (signed constant encountered, but enum container type is unsigned)\n", __func__
);
945 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
949 fprintf(fd
, "[error] %s: invalid enumerator\n", __func__
);
956 enum_unsigned_insert(enum_declaration
, start
, end
, q
);
962 struct declaration
*ctf_declaration_enum_visit(FILE *fd
, int depth
,
964 struct ctf_node
*container_type
,
965 struct cds_list_head
*enumerator_list
,
967 struct declaration_scope
*declaration_scope
,
968 struct ctf_trace
*trace
)
970 struct declaration
*declaration
;
971 struct declaration_enum
*enum_declaration
;
972 struct declaration_integer
*integer_declaration
;
973 struct ctf_node
*iter
;
978 * For named enum (without body), lookup in
979 * declaration scope. Don't take reference on enum
980 * declaration: ref is only taken upon definition.
985 lookup_enum_declaration(g_quark_from_string(name
),
987 return &enum_declaration
->p
;
989 /* For unnamed enum, create type */
990 /* For named enum (with body), create type and add to declaration scope */
992 if (lookup_enum_declaration(g_quark_from_string(name
),
993 declaration_scope
)) {
995 fprintf(fd
, "[error] %s: enum %s already declared in scope\n", __func__
, name
);
999 if (!container_type
) {
1000 declaration
= lookup_declaration(g_quark_from_static_string("int"),
1003 fprintf(fd
, "[error] %s: \"int\" type declaration missing for enumeration\n", __func__
);
1007 declaration
= ctf_type_declarator_visit(fd
, depth
,
1014 fprintf(fd
, "[error] %s: unable to create container type for enumeration\n", __func__
);
1017 if (declaration
->id
!= CTF_TYPE_INTEGER
) {
1018 fprintf(fd
, "[error] %s: container type for enumeration is not integer\n", __func__
);
1021 integer_declaration
= container_of(declaration
, struct declaration_integer
, p
);
1022 enum_declaration
= enum_declaration_new(integer_declaration
);
1023 declaration_unref(&integer_declaration
->p
); /* leave ref to enum */
1024 cds_list_for_each_entry(iter
, enumerator_list
, siblings
) {
1025 ret
= ctf_enumerator_list_visit(fd
, depth
+ 1, iter
, enum_declaration
);
1030 ret
= register_enum_declaration(g_quark_from_string(name
),
1035 return &enum_declaration
->p
;
1038 enum_declaration
->p
.declaration_free(&enum_declaration
->p
);
1043 struct declaration
*ctf_declaration_type_specifier_visit(FILE *fd
, int depth
,
1044 struct ctf_node
*type_specifier_list
,
1045 struct declaration_scope
*declaration_scope
)
1048 struct declaration
*declaration
;
1053 str
= g_string_new("");
1054 ret
= visit_type_specifier_list(fd
, type_specifier_list
, str
);
1057 str_c
= g_string_free(str
, FALSE
);
1058 id_q
= g_quark_from_string(str_c
);
1060 declaration
= lookup_declaration(id_q
, declaration_scope
);
1065 * Returns 0/1 boolean, or < 0 on error.
1068 int get_boolean(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1070 if (unary_expression
->type
!= NODE_UNARY_EXPRESSION
) {
1071 fprintf(fd
, "[error] %s: expecting unary expression\n",
1075 switch (unary_expression
->u
.unary_expression
.type
) {
1076 case UNARY_UNSIGNED_CONSTANT
:
1077 if (unary_expression
->u
.unary_expression
.u
.unsigned_constant
== 0)
1081 case UNARY_SIGNED_CONSTANT
:
1082 if (unary_expression
->u
.unary_expression
.u
.signed_constant
== 0)
1087 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "true"))
1089 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "TRUE"))
1091 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "false"))
1093 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "FALSE"))
1096 fprintf(fd
, "[error] %s: unexpected string \"%s\"\n",
1097 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1102 fprintf(fd
, "[error] %s: unexpected unary expression type\n",
1110 int get_trace_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
)
1114 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1115 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1119 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1120 byte_order
= BIG_ENDIAN
;
1121 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1122 byte_order
= LITTLE_ENDIAN
;
1124 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1125 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1132 int get_byte_order(FILE *fd
, int depth
, struct ctf_node
*unary_expression
,
1133 struct ctf_trace
*trace
)
1137 if (unary_expression
->u
.unary_expression
.type
!= UNARY_STRING
) {
1138 fprintf(fd
, "[error] %s: byte_order: expecting string\n",
1142 if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "native"))
1143 byte_order
= trace
->byte_order
;
1144 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "network"))
1145 byte_order
= BIG_ENDIAN
;
1146 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "be"))
1147 byte_order
= BIG_ENDIAN
;
1148 else if (!strcmp(unary_expression
->u
.unary_expression
.u
.string
, "le"))
1149 byte_order
= LITTLE_ENDIAN
;
1151 fprintf(fd
, "[error] %s: unexpected string \"%s\". Should be \"native\", \"network\", \"be\" or \"le\".\n",
1152 __func__
, unary_expression
->u
.unary_expression
.u
.string
);
1159 struct declaration
*ctf_declaration_integer_visit(FILE *fd
, int depth
,
1160 struct cds_list_head
*expressions
,
1161 struct ctf_trace
*trace
)
1163 struct ctf_node
*expression
;
1164 uint64_t alignment
= 1, size
= 0;
1165 int byte_order
= trace
->byte_order
;
1167 int has_alignment
= 0, has_size
= 0;
1169 enum ctf_string_encoding encoding
= CTF_STRING_NONE
;
1170 struct ctf_clock
*clock
= NULL
;
1171 struct declaration_integer
*integer_declaration
;
1173 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1174 struct ctf_node
*left
, *right
;
1176 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1177 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1178 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1179 if (!strcmp(left
->u
.unary_expression
.u
.string
, "signed")) {
1180 signedness
= get_boolean(fd
, depth
, right
);
1183 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1184 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1187 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "size")) {
1188 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1189 fprintf(fd
, "[error] %s: size: expecting unsigned constant\n",
1193 size
= right
->u
.unary_expression
.u
.unsigned_constant
;
1195 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1196 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1197 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1201 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1202 /* Make sure alignment is a power of two */
1203 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1204 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1209 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "base")) {
1210 switch (right
->u
.unary_expression
.type
) {
1211 case UNARY_UNSIGNED_CONSTANT
:
1212 switch (right
->u
.unary_expression
.u
.unsigned_constant
) {
1217 base
= right
->u
.unary_expression
.u
.unsigned_constant
;
1220 fprintf(fd
, "[error] %s: base not supported (%" PRIu64
")\n",
1221 __func__
, right
->u
.unary_expression
.u
.unsigned_constant
);
1227 char *s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1229 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1233 if (!strcmp(s_right
, "decimal") || !strcmp(s_right
, "dec") || !strcmp(s_right
, "d")
1234 || !strcmp(s_right
, "i") || !strcmp(s_right
, "u")) {
1236 } else if (!strcmp(s_right
, "hexadecimal") || !strcmp(s_right
, "hex")
1237 || !strcmp(s_right
, "x") || !strcmp(s_right
, "X")
1238 || !strcmp(s_right
, "p")) {
1240 } else if (!strcmp(s_right
, "octal") || !strcmp(s_right
, "oct")
1241 || !strcmp(s_right
, "o")) {
1243 } else if (!strcmp(s_right
, "binary") || !strcmp(s_right
, "b")) {
1246 fprintf(fd
, "[error] %s: unexpected expression for integer base (%s)\n", __func__
, s_right
);
1255 fprintf(fd
, "[error] %s: base: expecting unsigned constant or unary string\n",
1259 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1262 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1263 fprintf(fd
, "[error] %s: encoding: expecting unary string\n",
1267 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1269 fprintf(fd
, "[error] %s: unexpected unary expression for integer base\n", __func__
);
1273 if (!strcmp(s_right
, "UTF8")
1274 || !strcmp(s_right
, "utf8")
1275 || !strcmp(s_right
, "utf-8")
1276 || !strcmp(s_right
, "UTF-8"))
1277 encoding
= CTF_STRING_UTF8
;
1278 else if (!strcmp(s_right
, "ASCII")
1279 || !strcmp(s_right
, "ascii"))
1280 encoding
= CTF_STRING_ASCII
;
1281 else if (!strcmp(s_right
, "none"))
1282 encoding
= CTF_STRING_NONE
;
1284 fprintf(fd
, "[error] %s: unknown string encoding \"%s\"\n", __func__
, s_right
);
1289 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "map")) {
1292 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1293 fprintf(fd
, "[error] %s: map: expecting identifier\n",
1297 /* currently only support clock.name.value */
1298 clock_name
= get_map_clock_name_value(&expression
->u
.ctf_expression
.right
);
1302 s_right
= concatenate_unary_strings(&expression
->u
.ctf_expression
.right
);
1304 fprintf(fd
, "[error] %s: unexpected unary expression for integer map\n", __func__
);
1308 fprintf(fd
, "[warning] %s: unknown map %s in integer declaration\n", __func__
,
1313 clock
= trace_clock_lookup(trace
, clock_name
);
1315 fprintf(fd
, "[error] %s: map: unable to find clock %s declaration\n",
1316 __func__
, g_quark_to_string(clock_name
));
1320 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1321 __func__
, left
->u
.unary_expression
.u
.string
);
1322 /* Fall-through after warning */
1326 fprintf(fd
, "[error] %s: missing size attribute\n", __func__
);
1329 if (!has_alignment
) {
1330 if (size
% CHAR_BIT
) {
1331 /* bit-packed alignment */
1334 /* byte-packed alignment */
1335 alignment
= CHAR_BIT
;
1338 integer_declaration
= integer_declaration_new(size
,
1339 byte_order
, signedness
, alignment
,
1340 base
, encoding
, clock
);
1341 return &integer_declaration
->p
;
1345 struct declaration
*ctf_declaration_floating_point_visit(FILE *fd
, int depth
,
1346 struct cds_list_head
*expressions
,
1347 struct ctf_trace
*trace
)
1349 struct ctf_node
*expression
;
1350 uint64_t alignment
= 1, exp_dig
= 0, mant_dig
= 0,
1351 byte_order
= trace
->byte_order
;
1352 int has_alignment
= 0, has_exp_dig
= 0, has_mant_dig
= 0;
1353 struct declaration_float
*float_declaration
;
1355 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1356 struct ctf_node
*left
, *right
;
1358 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1359 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1360 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1361 if (!strcmp(left
->u
.unary_expression
.u
.string
, "byte_order")) {
1362 byte_order
= get_byte_order(fd
, depth
, right
, trace
);
1365 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "exp_dig")) {
1366 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1367 fprintf(fd
, "[error] %s: exp_dig: expecting unsigned constant\n",
1371 exp_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1373 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "mant_dig")) {
1374 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1375 fprintf(fd
, "[error] %s: mant_dig: expecting unsigned constant\n",
1379 mant_dig
= right
->u
.unary_expression
.u
.unsigned_constant
;
1381 } else if (!strcmp(left
->u
.unary_expression
.u
.string
, "align")) {
1382 if (right
->u
.unary_expression
.type
!= UNARY_UNSIGNED_CONSTANT
) {
1383 fprintf(fd
, "[error] %s: align: expecting unsigned constant\n",
1387 alignment
= right
->u
.unary_expression
.u
.unsigned_constant
;
1388 /* Make sure alignment is a power of two */
1389 if (alignment
== 0 || (alignment
& (alignment
- 1)) != 0) {
1390 fprintf(fd
, "[error] %s: align: expecting power of two\n",
1396 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1397 __func__
, left
->u
.unary_expression
.u
.string
);
1398 /* Fall-through after warning */
1401 if (!has_mant_dig
) {
1402 fprintf(fd
, "[error] %s: missing mant_dig attribute\n", __func__
);
1406 fprintf(fd
, "[error] %s: missing exp_dig attribute\n", __func__
);
1409 if (!has_alignment
) {
1410 if ((mant_dig
+ exp_dig
) % CHAR_BIT
) {
1411 /* bit-packed alignment */
1414 /* byte-packed alignment */
1415 alignment
= CHAR_BIT
;
1418 float_declaration
= float_declaration_new(mant_dig
, exp_dig
,
1419 byte_order
, alignment
);
1420 return &float_declaration
->p
;
1424 struct declaration
*ctf_declaration_string_visit(FILE *fd
, int depth
,
1425 struct cds_list_head
*expressions
,
1426 struct ctf_trace
*trace
)
1428 struct ctf_node
*expression
;
1429 const char *encoding_c
= NULL
;
1430 enum ctf_string_encoding encoding
= CTF_STRING_UTF8
;
1431 struct declaration_string
*string_declaration
;
1433 cds_list_for_each_entry(expression
, expressions
, siblings
) {
1434 struct ctf_node
*left
, *right
;
1436 left
= _cds_list_first_entry(&expression
->u
.ctf_expression
.left
, struct ctf_node
, siblings
);
1437 right
= _cds_list_first_entry(&expression
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
1438 assert(left
->u
.unary_expression
.type
== UNARY_STRING
);
1439 if (!strcmp(left
->u
.unary_expression
.u
.string
, "encoding")) {
1440 if (right
->u
.unary_expression
.type
!= UNARY_STRING
) {
1441 fprintf(fd
, "[error] %s: encoding: expecting string\n",
1445 encoding_c
= right
->u
.unary_expression
.u
.string
;
1447 fprintf(fd
, "[warning] %s: unknown attribute name %s\n",
1448 __func__
, left
->u
.unary_expression
.u
.string
);
1449 /* Fall-through after warning */
1452 if (encoding_c
&& !strcmp(encoding_c
, "ASCII"))
1453 encoding
= CTF_STRING_ASCII
;
1454 string_declaration
= string_declaration_new(encoding
);
1455 return &string_declaration
->p
;
1460 struct declaration
*ctf_type_specifier_list_visit(FILE *fd
,
1461 int depth
, struct ctf_node
*type_specifier_list
,
1462 struct declaration_scope
*declaration_scope
,
1463 struct ctf_trace
*trace
)
1465 struct ctf_node
*first
;
1466 struct ctf_node
*node
;
1468 assert(type_specifier_list
->type
== NODE_TYPE_SPECIFIER_LIST
);
1470 first
= _cds_list_first_entry(&type_specifier_list
->u
.type_specifier_list
.head
, struct ctf_node
, siblings
);
1472 assert(first
->type
== NODE_TYPE_SPECIFIER
);
1474 node
= first
->u
.type_specifier
.node
;
1476 switch (first
->u
.type_specifier
.type
) {
1477 case TYPESPEC_FLOATING_POINT
:
1478 return ctf_declaration_floating_point_visit(fd
, depth
,
1479 &node
->u
.floating_point
.expressions
, trace
);
1480 case TYPESPEC_INTEGER
:
1481 return ctf_declaration_integer_visit(fd
, depth
,
1482 &node
->u
.integer
.expressions
, trace
);
1483 case TYPESPEC_STRING
:
1484 return ctf_declaration_string_visit(fd
, depth
,
1485 &node
->u
.string
.expressions
, trace
);
1486 case TYPESPEC_STRUCT
:
1487 return ctf_declaration_struct_visit(fd
, depth
,
1488 node
->u
._struct
.name
,
1489 &node
->u
._struct
.declaration_list
,
1490 node
->u
._struct
.has_body
,
1491 &node
->u
._struct
.min_align
,
1494 case TYPESPEC_VARIANT
:
1495 return ctf_declaration_variant_visit(fd
, depth
,
1496 node
->u
.variant
.name
,
1497 node
->u
.variant
.choice
,
1498 &node
->u
.variant
.declaration_list
,
1499 node
->u
.variant
.has_body
,
1503 return ctf_declaration_enum_visit(fd
, depth
,
1504 node
->u
._enum
.enum_id
,
1505 node
->u
._enum
.container_type
,
1506 &node
->u
._enum
.enumerator_list
,
1507 node
->u
._enum
.has_body
,
1513 case TYPESPEC_SHORT
:
1516 case TYPESPEC_FLOAT
:
1517 case TYPESPEC_DOUBLE
:
1518 case TYPESPEC_SIGNED
:
1519 case TYPESPEC_UNSIGNED
:
1521 case TYPESPEC_COMPLEX
:
1522 case TYPESPEC_IMAGINARY
:
1523 case TYPESPEC_CONST
:
1524 case TYPESPEC_ID_TYPE
:
1525 return ctf_declaration_type_specifier_visit(fd
, depth
,
1526 type_specifier_list
, declaration_scope
);
1528 fprintf(fd
, "[error] %s: unexpected node type %d\n", __func__
, (int) first
->u
.type_specifier
.type
);
1534 int ctf_event_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_event
*event
, struct ctf_trace
*trace
)
1538 switch (node
->type
) {
1540 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1541 event
->declaration_scope
,
1542 node
->u
._typedef
.type_specifier_list
,
1543 &node
->u
._typedef
.type_declarators
,
1548 case NODE_TYPEALIAS
:
1549 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1550 event
->declaration_scope
,
1551 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1556 case NODE_CTF_EXPRESSION
:
1560 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1561 if (!strcmp(left
, "name")) {
1564 if (CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1565 fprintf(fd
, "[error] %s: name already declared in event declaration\n", __func__
);
1569 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1571 fprintf(fd
, "[error] %s: unexpected unary expression for event name\n", __func__
);
1575 event
->name
= g_quark_from_string(right
);
1577 CTF_EVENT_SET_FIELD(event
, name
);
1578 } else if (!strcmp(left
, "id")) {
1579 if (CTF_EVENT_FIELD_IS_SET(event
, id
)) {
1580 fprintf(fd
, "[error] %s: id already declared in event declaration\n", __func__
);
1584 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->id
);
1586 fprintf(fd
, "[error] %s: unexpected unary expression for event id\n", __func__
);
1590 CTF_EVENT_SET_FIELD(event
, id
);
1591 } else if (!strcmp(left
, "stream_id")) {
1592 if (CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1593 fprintf(fd
, "[error] %s: stream_id already declared in event declaration\n", __func__
);
1597 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &event
->stream_id
);
1599 fprintf(fd
, "[error] %s: unexpected unary expression for event stream_id\n", __func__
);
1603 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1604 if (!event
->stream
) {
1605 fprintf(fd
, "[error] %s: stream id %" PRIu64
" cannot be found\n", __func__
, event
->stream_id
);
1609 CTF_EVENT_SET_FIELD(event
, stream_id
);
1610 } else if (!strcmp(left
, "context")) {
1611 struct declaration
*declaration
;
1613 if (event
->context_decl
) {
1614 fprintf(fd
, "[error] %s: context already declared in event declaration\n", __func__
);
1618 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1619 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1620 struct ctf_node
, siblings
),
1621 event
->declaration_scope
, trace
);
1626 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1630 event
->context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1631 } else if (!strcmp(left
, "fields")) {
1632 struct declaration
*declaration
;
1634 if (event
->fields_decl
) {
1635 fprintf(fd
, "[error] %s: fields already declared in event declaration\n", __func__
);
1639 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1640 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1641 struct ctf_node
, siblings
),
1642 event
->declaration_scope
, trace
);
1647 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1651 event
->fields_decl
= container_of(declaration
, struct declaration_struct
, p
);
1652 } else if (!strcmp(left
, "loglevel.identifier")) {
1655 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel_identifier
)) {
1656 fprintf(fd
, "[error] %s: identifier already declared in event declaration\n", __func__
);
1660 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
1662 fprintf(fd
, "[error] %s: unexpected unary expression for event identifier\n", __func__
);
1666 event
->loglevel_identifier
= g_quark_from_string(right
);
1668 CTF_EVENT_SET_FIELD(event
, loglevel_identifier
);
1669 } else if (!strcmp(left
, "loglevel.value")) {
1670 if (CTF_EVENT_FIELD_IS_SET(event
, loglevel_value
)) {
1671 fprintf(fd
, "[error] %s: loglevel value already declared in event declaration\n", __func__
);
1675 ret
= get_unary_signed(&node
->u
.ctf_expression
.right
, &event
->loglevel_value
);
1677 fprintf(fd
, "[error] %s: unexpected unary expression for event loglevel value\n", __func__
);
1681 CTF_EVENT_SET_FIELD(event
, loglevel_value
);
1683 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__
, left
);
1684 /* Fall-through after warning */
1692 /* TODO: declaration specifier should be added. */
1699 int ctf_event_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1700 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1703 struct ctf_node
*iter
;
1704 struct ctf_event
*event
;
1706 event
= g_new0(struct ctf_event
, 1);
1707 event
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
1708 cds_list_for_each_entry(iter
, &node
->u
.event
.declaration_list
, siblings
) {
1709 ret
= ctf_event_declaration_visit(fd
, depth
+ 1, iter
, event
, trace
);
1713 if (!CTF_EVENT_FIELD_IS_SET(event
, name
)) {
1715 fprintf(fd
, "[error] %s: missing name field in event declaration\n", __func__
);
1718 if (!CTF_EVENT_FIELD_IS_SET(event
, stream_id
)) {
1719 /* Allow missing stream_id if there is only a single stream */
1720 switch (trace
->streams
->len
) {
1721 case 0: /* Create stream if there was none. */
1722 ret
= ctf_stream_visit(fd
, depth
, NULL
, trace
->root_declaration_scope
, trace
);
1727 event
->stream_id
= 0;
1728 event
->stream
= trace_stream_lookup(trace
, event
->stream_id
);
1732 fprintf(fd
, "[error] %s: missing stream_id field in event declaration\n", __func__
);
1736 /* Allow only one event without id per stream */
1737 if (!CTF_EVENT_FIELD_IS_SET(event
, id
)
1738 && event
->stream
->events_by_id
->len
!= 0) {
1740 fprintf(fd
, "[error] %s: missing id field in event declaration\n", __func__
);
1743 if (event
->stream
->events_by_id
->len
<= event
->id
)
1744 g_ptr_array_set_size(event
->stream
->events_by_id
, event
->id
+ 1);
1745 g_ptr_array_index(event
->stream
->events_by_id
, event
->id
) = event
;
1746 g_hash_table_insert(event
->stream
->event_quark_to_id
,
1747 (gpointer
) (unsigned long) event
->name
,
1752 if (event
->fields_decl
)
1753 declaration_unref(&event
->fields_decl
->p
);
1754 if (event
->context_decl
)
1755 declaration_unref(&event
->context_decl
->p
);
1756 free_declaration_scope(event
->declaration_scope
);
1763 int ctf_stream_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_stream_class
*stream
, struct ctf_trace
*trace
)
1767 switch (node
->type
) {
1769 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1770 stream
->declaration_scope
,
1771 node
->u
._typedef
.type_specifier_list
,
1772 &node
->u
._typedef
.type_declarators
,
1777 case NODE_TYPEALIAS
:
1778 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1779 stream
->declaration_scope
,
1780 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1785 case NODE_CTF_EXPRESSION
:
1789 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1790 if (!strcmp(left
, "id")) {
1791 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1792 fprintf(fd
, "[error] %s: id already declared in stream declaration\n", __func__
);
1796 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &stream
->stream_id
);
1798 fprintf(fd
, "[error] %s: unexpected unary expression for stream id\n", __func__
);
1802 CTF_STREAM_SET_FIELD(stream
, stream_id
);
1803 } else if (!strcmp(left
, "event.header")) {
1804 struct declaration
*declaration
;
1806 if (stream
->event_header_decl
) {
1807 fprintf(fd
, "[error] %s: event.header already declared in stream declaration\n", __func__
);
1811 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1812 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1813 struct ctf_node
, siblings
),
1814 stream
->declaration_scope
, trace
);
1819 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1823 stream
->event_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
1824 } else if (!strcmp(left
, "event.context")) {
1825 struct declaration
*declaration
;
1827 if (stream
->event_context_decl
) {
1828 fprintf(fd
, "[error] %s: event.context already declared in stream declaration\n", __func__
);
1832 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1833 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1834 struct ctf_node
, siblings
),
1835 stream
->declaration_scope
, trace
);
1840 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1844 stream
->event_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1845 } else if (!strcmp(left
, "packet.context")) {
1846 struct declaration
*declaration
;
1848 if (stream
->packet_context_decl
) {
1849 fprintf(fd
, "[error] %s: packet.context already declared in stream declaration\n", __func__
);
1853 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
1854 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
1855 struct ctf_node
, siblings
),
1856 stream
->declaration_scope
, trace
);
1861 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
1865 stream
->packet_context_decl
= container_of(declaration
, struct declaration_struct
, p
);
1867 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__
, left
);
1868 /* Fall-through after warning */
1877 /* TODO: declaration specifier should be added. */
1884 int ctf_stream_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
1885 struct declaration_scope
*parent_declaration_scope
, struct ctf_trace
*trace
)
1888 struct ctf_node
*iter
;
1889 struct ctf_stream_class
*stream
;
1891 stream
= g_new0(struct ctf_stream_class
, 1);
1892 stream
->declaration_scope
= new_declaration_scope(parent_declaration_scope
);
1893 stream
->events_by_id
= g_ptr_array_new();
1894 stream
->event_quark_to_id
= g_hash_table_new(g_direct_hash
, g_direct_equal
);
1895 stream
->streams
= g_ptr_array_new();
1897 cds_list_for_each_entry(iter
, &node
->u
.stream
.declaration_list
, siblings
) {
1898 ret
= ctf_stream_declaration_visit(fd
, depth
+ 1, iter
, stream
, trace
);
1903 if (CTF_STREAM_FIELD_IS_SET(stream
, stream_id
)) {
1904 /* check that packet header has stream_id field. */
1905 if (!trace
->packet_header_decl
1906 || struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("stream_id")) < 0) {
1908 fprintf(fd
, "[error] %s: missing stream_id field in packet header declaration, but stream_id attribute is declared for stream.\n", __func__
);
1912 /* Allow only one id-less stream */
1913 if (trace
->streams
->len
!= 0) {
1915 fprintf(fd
, "[error] %s: missing id field in stream declaration\n", __func__
);
1918 stream
->stream_id
= 0;
1920 if (trace
->streams
->len
<= stream
->stream_id
)
1921 g_ptr_array_set_size(trace
->streams
, stream
->stream_id
+ 1);
1922 g_ptr_array_index(trace
->streams
, stream
->stream_id
) = stream
;
1923 stream
->trace
= trace
;
1928 if (stream
->event_header_decl
)
1929 declaration_unref(&stream
->event_header_decl
->p
);
1930 if (stream
->event_context_decl
)
1931 declaration_unref(&stream
->event_context_decl
->p
);
1932 if (stream
->packet_context_decl
)
1933 declaration_unref(&stream
->packet_context_decl
->p
);
1934 g_ptr_array_free(stream
->streams
, TRUE
);
1935 g_ptr_array_free(stream
->events_by_id
, TRUE
);
1936 g_hash_table_destroy(stream
->event_quark_to_id
);
1937 free_declaration_scope(stream
->declaration_scope
);
1943 int ctf_trace_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
1947 switch (node
->type
) {
1949 ret
= ctf_typedef_visit(fd
, depth
+ 1,
1950 trace
->declaration_scope
,
1951 node
->u
._typedef
.type_specifier_list
,
1952 &node
->u
._typedef
.type_declarators
,
1957 case NODE_TYPEALIAS
:
1958 ret
= ctf_typealias_visit(fd
, depth
+ 1,
1959 trace
->declaration_scope
,
1960 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
1965 case NODE_CTF_EXPRESSION
:
1969 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
1970 if (!strcmp(left
, "major")) {
1971 if (CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
1972 fprintf(fd
, "[error] %s: major already declared in trace declaration\n", __func__
);
1976 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->major
);
1978 fprintf(fd
, "[error] %s: unexpected unary expression for trace major number\n", __func__
);
1982 CTF_TRACE_SET_FIELD(trace
, major
);
1983 } else if (!strcmp(left
, "minor")) {
1984 if (CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
1985 fprintf(fd
, "[error] %s: minor already declared in trace declaration\n", __func__
);
1989 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &trace
->minor
);
1991 fprintf(fd
, "[error] %s: unexpected unary expression for trace minor number\n", __func__
);
1995 CTF_TRACE_SET_FIELD(trace
, minor
);
1996 } else if (!strcmp(left
, "uuid")) {
1999 ret
= get_unary_uuid(&node
->u
.ctf_expression
.right
, &uuid
);
2001 fprintf(fd
, "[error] %s: unexpected unary expression for trace uuid\n", __func__
);
2005 if (CTF_TRACE_FIELD_IS_SET(trace
, uuid
)
2006 && uuid_compare(uuid
, trace
->uuid
)) {
2007 fprintf(fd
, "[error] %s: uuid mismatch\n", __func__
);
2011 memcpy(trace
->uuid
, uuid
, sizeof(uuid
));
2013 CTF_TRACE_SET_FIELD(trace
, uuid
);
2014 } else if (!strcmp(left
, "byte_order")) {
2015 struct ctf_node
*right
;
2018 right
= _cds_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2019 byte_order
= get_trace_byte_order(fd
, depth
, right
);
2023 if (CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)
2024 && byte_order
!= trace
->byte_order
) {
2025 fprintf(fd
, "[error] %s: endianness mismatch\n", __func__
);
2029 if (byte_order
!= trace
->byte_order
) {
2030 trace
->byte_order
= byte_order
;
2032 * We need to restart
2033 * construction of the
2034 * intermediate representation.
2036 trace
->field_mask
= 0;
2037 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2042 CTF_TRACE_SET_FIELD(trace
, byte_order
);
2043 } else if (!strcmp(left
, "packet.header")) {
2044 struct declaration
*declaration
;
2046 if (trace
->packet_header_decl
) {
2047 fprintf(fd
, "[error] %s: packet.header already declared in trace declaration\n", __func__
);
2051 declaration
= ctf_type_specifier_list_visit(fd
, depth
,
2052 _cds_list_first_entry(&node
->u
.ctf_expression
.right
,
2053 struct ctf_node
, siblings
),
2054 trace
->declaration_scope
, trace
);
2059 if (declaration
->id
!= CTF_TYPE_STRUCT
) {
2063 trace
->packet_header_decl
= container_of(declaration
, struct declaration_struct
, p
);
2065 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__
, left
);
2074 /* TODO: declaration specifier should be added. */
2081 int ctf_trace_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2084 struct ctf_node
*iter
;
2086 if (trace
->declaration_scope
)
2088 trace
->declaration_scope
= new_declaration_scope(trace
->root_declaration_scope
);
2089 trace
->streams
= g_ptr_array_new();
2090 cds_list_for_each_entry(iter
, &node
->u
.trace
.declaration_list
, siblings
) {
2091 ret
= ctf_trace_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2095 if (!CTF_TRACE_FIELD_IS_SET(trace
, major
)) {
2097 fprintf(fd
, "[error] %s: missing major field in trace declaration\n", __func__
);
2100 if (!CTF_TRACE_FIELD_IS_SET(trace
, minor
)) {
2102 fprintf(fd
, "[error] %s: missing minor field in trace declaration\n", __func__
);
2105 if (!CTF_TRACE_FIELD_IS_SET(trace
, uuid
)) {
2107 fprintf(fd
, "[error] %s: missing uuid field in trace declaration\n", __func__
);
2110 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2112 fprintf(fd
, "[error] %s: missing byte_order field in trace declaration\n", __func__
);
2116 if (!CTF_TRACE_FIELD_IS_SET(trace
, byte_order
)) {
2117 /* check that the packet header contains a "magic" field */
2118 if (!trace
->packet_header_decl
2119 || struct_declaration_lookup_field_index(trace
->packet_header_decl
, g_quark_from_static_string("magic")) < 0) {
2121 fprintf(fd
, "[error] %s: missing both byte_order and packet header magic number in trace declaration\n", __func__
);
2128 if (trace
->packet_header_decl
) {
2129 declaration_unref(&trace
->packet_header_decl
->p
);
2130 trace
->packet_header_decl
= NULL
;
2132 g_ptr_array_free(trace
->streams
, TRUE
);
2133 free_declaration_scope(trace
->declaration_scope
);
2134 trace
->declaration_scope
= NULL
;
2139 int ctf_clock_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
,
2140 struct ctf_clock
*clock
, struct ctf_trace
*trace
)
2144 switch (node
->type
) {
2145 case NODE_CTF_EXPRESSION
:
2149 left
= concatenate_unary_strings(&node
->u
.ctf_expression
.left
);
2150 if (!strcmp(left
, "name")) {
2153 if (CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2154 fprintf(fd
, "[error] %s: name already declared in clock declaration\n", __func__
);
2158 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2160 fprintf(fd
, "[error] %s: unexpected unary expression for clock name\n", __func__
);
2164 clock
->name
= g_quark_from_string(right
);
2166 CTF_EVENT_SET_FIELD(clock
, name
);
2167 } else if (!strcmp(left
, "uuid")) {
2171 fprintf(fd
, "[error] %s: uuid already declared in clock declaration\n", __func__
);
2175 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2177 fprintf(fd
, "[error] %s: unexpected unary expression for clock uuid\n", __func__
);
2181 clock
->uuid
= g_quark_from_string(right
);
2183 } else if (!strcmp(left
, "description")) {
2186 if (clock
->description
) {
2187 fprintf(fd
, "[warning] %s: duplicated clock description\n", __func__
);
2188 goto error
; /* ret is 0, so not an actual error, just warn. */
2190 right
= concatenate_unary_strings(&node
->u
.ctf_expression
.right
);
2192 fprintf(fd
, "[warning] %s: unexpected unary expression for clock description\n", __func__
);
2193 goto error
; /* ret is 0, so not an actual error, just warn. */
2195 clock
->description
= right
;
2196 } else if (!strcmp(left
, "freq")) {
2198 fprintf(fd
, "[error] %s: freq already declared in clock declaration\n", __func__
);
2202 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->freq
);
2204 fprintf(fd
, "[error] %s: unexpected unary expression for clock freq\n", __func__
);
2208 } else if (!strcmp(left
, "precision")) {
2209 if (clock
->precision
) {
2210 fprintf(fd
, "[error] %s: precision already declared in clock declaration\n", __func__
);
2214 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->precision
);
2216 fprintf(fd
, "[error] %s: unexpected unary expression for clock precision\n", __func__
);
2220 } else if (!strcmp(left
, "offset_s")) {
2221 if (clock
->offset_s
) {
2222 fprintf(fd
, "[error] %s: offset_s already declared in clock declaration\n", __func__
);
2226 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset_s
);
2228 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset_s\n", __func__
);
2232 } else if (!strcmp(left
, "offset")) {
2233 if (clock
->offset
) {
2234 fprintf(fd
, "[error] %s: offset already declared in clock declaration\n", __func__
);
2238 ret
= get_unary_unsigned(&node
->u
.ctf_expression
.right
, &clock
->offset
);
2240 fprintf(fd
, "[error] %s: unexpected unary expression for clock offset\n", __func__
);
2244 } else if (!strcmp(left
, "absolute")) {
2245 struct ctf_node
*right
;
2247 right
= _cds_list_first_entry(&node
->u
.ctf_expression
.right
, struct ctf_node
, siblings
);
2248 ret
= get_boolean(fd
, depth
, right
);
2250 fprintf(fd
, "[error] %s: unexpected \"absolute\" right member\n", __func__
);
2254 clock
->absolute
= ret
;
2256 fprintf(fd
, "[warning] %s: attribute \"%s\" is unknown in clock declaration.\n", __func__
, left
);
2265 /* TODO: declaration specifier should be added. */
2272 int ctf_clock_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2275 struct ctf_node
*iter
;
2276 struct ctf_clock
*clock
;
2278 clock
= g_new0(struct ctf_clock
, 1);
2279 cds_list_for_each_entry(iter
, &node
->u
.clock
.declaration_list
, siblings
) {
2280 ret
= ctf_clock_declaration_visit(fd
, depth
+ 1, iter
, clock
, trace
);
2284 if (!CTF_CLOCK_FIELD_IS_SET(clock
, name
)) {
2286 fprintf(fd
, "[error] %s: missing namefield in clock declaration\n", __func__
);
2289 g_hash_table_insert(trace
->clocks
, (gpointer
) (unsigned long) clock
->name
, clock
);
2293 g_free(clock
->description
);
2299 void clock_free(gpointer data
)
2301 struct ctf_clock
*clock
= data
;
2303 g_free(clock
->description
);
2308 int ctf_env_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2310 fprintf(fd
, "[warning] %s: environment declaration support not implement yet.\n", __func__
);
2311 return 0; /* continue */
2315 int ctf_root_declaration_visit(FILE *fd
, int depth
, struct ctf_node
*node
, struct ctf_trace
*trace
)
2319 switch (node
->type
) {
2321 ret
= ctf_typedef_visit(fd
, depth
+ 1,
2322 trace
->root_declaration_scope
,
2323 node
->u
._typedef
.type_specifier_list
,
2324 &node
->u
._typedef
.type_declarators
,
2329 case NODE_TYPEALIAS
:
2330 ret
= ctf_typealias_visit(fd
, depth
+ 1,
2331 trace
->root_declaration_scope
,
2332 node
->u
.typealias
.target
, node
->u
.typealias
.alias
,
2337 case NODE_TYPE_SPECIFIER_LIST
:
2339 struct declaration
*declaration
;
2342 * Just add the type specifier to the root scope
2343 * declaration scope. Release local reference.
2345 declaration
= ctf_type_specifier_list_visit(fd
, depth
+ 1,
2346 node
, trace
->root_declaration_scope
, trace
);
2349 declaration_unref(declaration
);
2359 /* TODO: missing metadata "destroy" (memory leak) */
2360 int ctf_visitor_construct_metadata(FILE *fd
, int depth
, struct ctf_node
*node
,
2361 struct ctf_trace
*trace
, int byte_order
)
2364 struct ctf_node
*iter
;
2365 int env_clock_done
= 0;
2367 printf_verbose("CTF visitor: metadata construction... ");
2368 trace
->byte_order
= byte_order
;
2369 trace
->clocks
= g_hash_table_new_full(g_direct_hash
, g_direct_equal
,
2373 trace
->root_declaration_scope
= new_declaration_scope(NULL
);
2375 switch (node
->type
) {
2377 if (!env_clock_done
) {
2378 cds_list_for_each_entry(iter
, &node
->u
.root
.env
, siblings
) {
2379 ret
= ctf_env_visit(fd
, depth
+ 1, iter
,
2382 fprintf(fd
, "[error] %s: env declaration error\n", __func__
);
2388 * declarations need to query clock hash table,
2389 * so clock need to be treated first.
2391 cds_list_for_each_entry(iter
, &node
->u
.root
.clock
, siblings
) {
2392 ret
= ctf_clock_visit(fd
, depth
+ 1, iter
,
2395 fprintf(fd
, "[error] %s: clock declaration error\n", __func__
);
2401 cds_list_for_each_entry(iter
, &node
->u
.root
.declaration_list
,
2403 ret
= ctf_root_declaration_visit(fd
, depth
+ 1, iter
, trace
);
2405 fprintf(fd
, "[error] %s: root declaration error\n", __func__
);
2409 cds_list_for_each_entry(iter
, &node
->u
.root
.trace
, siblings
) {
2410 ret
= ctf_trace_visit(fd
, depth
+ 1, iter
, trace
);
2411 if (ret
== -EINTR
) {
2412 free_declaration_scope(trace
->root_declaration_scope
);
2414 * Need to restart creation of type
2415 * definitions, aliases and
2416 * trace header declarations.
2421 fprintf(fd
, "[error] %s: trace declaration error\n", __func__
);
2425 if (!trace
->streams
) {
2426 fprintf(fd
, "[error] %s: missing trace declaration\n", __func__
);
2430 cds_list_for_each_entry(iter
, &node
->u
.root
.stream
, siblings
) {
2431 ret
= ctf_stream_visit(fd
, depth
+ 1, iter
,
2432 trace
->root_declaration_scope
, trace
);
2434 fprintf(fd
, "[error] %s: stream declaration error\n", __func__
);
2438 cds_list_for_each_entry(iter
, &node
->u
.root
.event
, siblings
) {
2439 ret
= ctf_event_visit(fd
, depth
+ 1, iter
,
2440 trace
->root_declaration_scope
, trace
);
2442 fprintf(fd
, "[error] %s: event declaration error\n", __func__
);
2449 fprintf(fd
, "[error] %s: unknown node type %d\n", __func__
,
2454 printf_verbose("done.\n");
2458 free_declaration_scope(trace
->root_declaration_scope
);
2459 g_hash_table_destroy(trace
->clocks
);