4 * Babeltrace - CTF IR: Type resolving internal
6 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
9 * Authors: Jérémie Galarneau <jeremie.galarneau@efficios.com>
10 * Philippe Proulx <pproulx@efficios.com>
12 * Permission is hereby granted, free of charge, to any person obtaining a copy
13 * of this software and associated documentation files (the "Software"), to deal
14 * in the Software without restriction, including without limitation the rights
15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 * copies of the Software, and to permit persons to whom the Software is
17 * furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include <babeltrace/ctf-ir/event.h>
32 #include <babeltrace/ctf-ir/stream-class.h>
33 #include <babeltrace/ctf-ir/resolve-internal.h>
34 #include <babeltrace/ctf-ir/field-types.h>
35 #include <babeltrace/ctf-ir/field-path.h>
36 #include <babeltrace/ctf-ir/field-path-internal.h>
37 #include <babeltrace/ctf-ir/event-internal.h>
38 #include <babeltrace/ref.h>
39 #include <babeltrace/babeltrace-internal.h>
40 #include <babeltrace/values.h>
44 #define _printf_error(fmt, args...) \
45 printf_verbose("[resolving] " fmt, ## args)
47 typedef GPtrArray type_stack
;
52 * `type` contains a compound field type (structure, variant, array,
53 * or sequence) and `index` indicates the index of the field type in
54 * the upper frame (-1 for array and sequence field types).
56 * `type` is owned by the stack frame.
58 struct type_stack_frame
{
59 struct bt_ctf_field_type
*type
;
64 * The current context of the resolving engine.
66 * `scopes` contain the 6 CTF scope field types (see CTF, sect. 7.3.2)
67 * in the following order:
72 * * Stream event context
76 struct resolve_context
{
77 struct bt_value
*environment
;
78 struct bt_ctf_field_type
*scopes
[6];
80 /* Root scope being visited */
81 enum bt_ctf_scope root_scope
;
82 type_stack
*type_stack
;
83 struct bt_ctf_field_type
*cur_field_type
;
86 /* TSDL dynamic scope prefixes as defined in CTF Section 7.3.2 */
87 static const char * const absolute_path_prefixes
[] = {
88 [BT_CTF_SCOPE_ENV
] = "env.",
89 [BT_CTF_SCOPE_TRACE_PACKET_HEADER
] = "trace.packet.header.",
90 [BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
] = "stream.packet.context.",
91 [BT_CTF_SCOPE_STREAM_EVENT_HEADER
] = "stream.event.header.",
92 [BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
] = "stream.event.context.",
93 [BT_CTF_SCOPE_EVENT_CONTEXT
] = "event.context.",
94 [BT_CTF_SCOPE_EVENT_FIELDS
] = "event.fields.",
97 /* Number of path tokens used for the absolute prefixes */
98 static const int absolute_path_prefix_ptoken_counts
[] = {
99 [BT_CTF_SCOPE_ENV
] = 1,
100 [BT_CTF_SCOPE_TRACE_PACKET_HEADER
] = 3,
101 [BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
] = 3,
102 [BT_CTF_SCOPE_STREAM_EVENT_HEADER
] = 3,
103 [BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
] = 3,
104 [BT_CTF_SCOPE_EVENT_CONTEXT
] = 2,
105 [BT_CTF_SCOPE_EVENT_FIELDS
] = 2,
109 * Destroys a type stack frame.
112 void type_stack_destroy_notify(gpointer data
)
114 struct type_stack_frame
*frame
= data
;
121 * Creates a type stack.
123 * Return value is owned by the caller.
126 type_stack
*type_stack_create(void)
128 return g_ptr_array_new_with_free_func(type_stack_destroy_notify
);
132 * Destroys a type stack.
135 void type_stack_destroy(type_stack
*stack
)
137 g_ptr_array_free(stack
, TRUE
);
141 * Pushes a field type onto a type stack.
143 * `type` is owned by the caller (stack frame gets a new reference).
146 int type_stack_push(type_stack
*stack
, struct bt_ctf_field_type
*type
)
149 struct type_stack_frame
*frame
= NULL
;
151 if (!stack
|| !type
) {
156 frame
= g_new0(struct type_stack_frame
, 1);
162 frame
->type
= bt_get(type
);
163 g_ptr_array_add(stack
, frame
);
170 * Checks whether or not `stack` is empty.
173 bool type_stack_empty(type_stack
*stack
)
175 return stack
->len
== 0;
179 * Returns the number of frames in `stack`.
182 size_t type_stack_size(type_stack
*stack
)
188 * Returns the top frame of `stack`.
190 * Return value is owned by `stack`.
193 struct type_stack_frame
*type_stack_peek(type_stack
*stack
)
195 struct type_stack_frame
*entry
= NULL
;
197 if (!stack
|| type_stack_empty(stack
)) {
201 entry
= g_ptr_array_index(stack
, stack
->len
- 1);
207 * Returns the frame at index `index` in `stack`.
209 * Return value is owned by `stack`.
212 struct type_stack_frame
*type_stack_at(type_stack
*stack
,
215 struct type_stack_frame
*entry
= NULL
;
217 if (!stack
|| index
>= stack
->len
) {
221 entry
= g_ptr_array_index(stack
, index
);
228 * Removes the top frame of `stack`.
231 void type_stack_pop(type_stack
*stack
)
233 if (!type_stack_empty(stack
)) {
235 * This will call the frame's destructor and free it, as
236 * well as put its contained field type.
238 g_ptr_array_set_size(stack
, stack
->len
- 1);
243 * Returns the scope field type of `scope` in the context `ctx`.
245 * Return value is owned by `ctx` on success.
248 struct bt_ctf_field_type
*get_type_from_ctx(struct resolve_context
*ctx
,
249 enum bt_ctf_scope scope
)
251 assert(scope
>= BT_CTF_SCOPE_TRACE_PACKET_HEADER
&&
252 scope
<= BT_CTF_SCOPE_EVENT_FIELDS
);
254 return ctx
->scopes
[scope
- BT_CTF_SCOPE_TRACE_PACKET_HEADER
];
258 * Returns the CTF scope from a path string. May return
259 * CTF_NODE_UNKNOWN if the path is found to be relative.
262 enum bt_ctf_scope
get_root_scope_from_absolute_pathstr(const char *pathstr
)
264 enum bt_ctf_scope scope
;
265 enum bt_ctf_scope ret
= BT_CTF_SCOPE_UNKNOWN
;
266 const size_t prefixes_count
= sizeof(absolute_path_prefixes
) /
267 sizeof(*absolute_path_prefixes
);
269 for (scope
= BT_CTF_SCOPE_ENV
; scope
< BT_CTF_SCOPE_ENV
+
270 prefixes_count
; scope
++) {
272 * Chech if path string starts with a known absolute
275 * Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES.
277 if (strncmp(pathstr
, absolute_path_prefixes
[scope
],
278 strlen(absolute_path_prefixes
[scope
]))) {
279 /* Prefix does not match: try the next one */
293 * Destroys a path token.
296 void ptokens_destroy_func(gpointer ptoken
, gpointer data
)
298 g_string_free(ptoken
, TRUE
);
302 * Destroys a path token list.
305 void ptokens_destroy(GList
*ptokens
)
311 g_list_foreach(ptokens
, ptokens_destroy_func
, NULL
);
312 g_list_free(ptokens
);
316 * Returns the string contained in a path token.
319 const char *ptoken_get_string(GList
*ptoken
)
321 GString
*tokenstr
= (GString
*) ptoken
->data
;
323 return tokenstr
->str
;
327 * Converts a path string to a path token list, that is, splits the
328 * individual words of a path string into a list of individual
331 * Return value is owned by the caller on success.
334 GList
*pathstr_to_ptokens(const char *pathstr
)
336 const char *at
= pathstr
;
337 const char *last
= at
;
338 GList
*ptokens
= NULL
;
341 if (*at
== '.' || *at
== '\0') {
345 /* Error: empty token */
346 _printf_error("Empty token in path string at position %d\n",
347 (int) (at
- pathstr
));
351 tokenstr
= g_string_new(NULL
);
352 g_string_append_len(tokenstr
, last
, at
- last
);
353 ptokens
= g_list_append(ptokens
, tokenstr
);
367 ptokens_destroy(ptokens
);
372 * Converts a path token list to a field path object. The path token
373 * list is relative from `type`. The index of the source looking for
374 * its target within `type` is indicated by `src_index`. This can be
375 * `INT_MAX` if the source is contained in `type`.
377 * `ptokens` is owned by the caller. `field_path` is an output parameter
378 * owned by the caller that must be filled here. `type` is owned by the
382 int ptokens_to_field_path(GList
*ptokens
, struct bt_ctf_field_path
*field_path
,
383 struct bt_ctf_field_type
*type
, int src_index
)
386 GList
*cur_ptoken
= ptokens
;
387 bool first_level_done
= false;
389 /* Get our own reference */
395 struct bt_ctf_field_type
*child_type
;
396 const char *field_name
= ptoken_get_string(cur_ptoken
);
397 enum bt_ctf_field_type_id type_id
=
398 bt_ctf_field_type_get_type_id(type
);
400 /* Find to which index corresponds the current path token */
401 if (type_id
== CTF_TYPE_ARRAY
|| type_id
== CTF_TYPE_SEQUENCE
) {
404 child_index
= bt_ctf_field_type_get_field_index(type
,
406 if (child_index
< 0) {
408 * Error: field name does not exist or
409 * wrong current type.
411 _printf_error("Cannot get index of field type named \"%s\"\n",
415 } else if (child_index
> src_index
&&
417 _printf_error("Child type is located after source index (%d)\n",
423 /* Next path token */
424 cur_ptoken
= g_list_next(cur_ptoken
);
425 first_level_done
= true;
428 /* Create new field path entry */
429 g_array_append_val(field_path
->indexes
, child_index
);
431 /* Get child field type */
432 child_type
= bt_ctf_field_type_get_field_at_index(type
,
435 _printf_error("Cannot get child type at index %d (field \"%s\")\n",
436 child_index
, field_name
);
441 /* Move child type to current type */
442 BT_MOVE(type
, child_type
);
451 * Converts a known absolute path token list to a field path object
452 * within the resolving context `ctx`.
454 * `ptokens` is owned by the caller. `field_path` is an output parameter
455 * owned by the caller that must be filled here.
458 int absolute_ptokens_to_field_path(GList
*ptokens
,
459 struct bt_ctf_field_path
*field_path
,
460 struct resolve_context
*ctx
)
464 struct bt_ctf_field_type
*type
;
466 /* Skip absolute path tokens */
467 cur_ptoken
= g_list_nth(ptokens
,
468 absolute_path_prefix_ptoken_counts
[field_path
->root
]);
470 /* Start with root type */
471 type
= get_type_from_ctx(ctx
, field_path
->root
);
473 /* Error: root type is not available */
474 _printf_error("Root type with scope type %d is not available\n",
481 ret
= ptokens_to_field_path(cur_ptoken
, field_path
, type
, INT_MAX
);
488 * Converts a known relative path token list to a field path object
489 * within the resolving context `ctx`.
491 * `ptokens` is owned by the caller. `field_path` is an output parameter
492 * owned by the caller that must be filled here.
495 int relative_ptokens_to_field_path(GList
*ptokens
,
496 struct bt_ctf_field_path
*field_path
,
497 struct resolve_context
*ctx
)
500 int parent_pos_in_stack
;
501 struct bt_ctf_field_path
*tail_field_path
= bt_ctf_field_path_create();
503 if (!tail_field_path
) {
504 _printf_error("Cannot create field path\n");
509 parent_pos_in_stack
= type_stack_size(ctx
->type_stack
) - 1;
511 while (parent_pos_in_stack
>= 0) {
512 struct bt_ctf_field_type
*parent_type
=
513 type_stack_at(ctx
->type_stack
,
514 parent_pos_in_stack
)->type
;
515 int cur_index
= type_stack_at(ctx
->type_stack
,
516 parent_pos_in_stack
)->index
;
518 /* Locate target from current parent type */
519 ret
= ptokens_to_field_path(ptokens
, tail_field_path
,
520 parent_type
, cur_index
);
522 /* Not found... yet */
523 bt_ctf_field_path_clear(tail_field_path
);
525 /* Found: stitch tail field path to head field path */
527 int tail_field_path_len
=
528 tail_field_path
->indexes
->len
;
531 struct bt_ctf_field_type
*cur_type
=
532 type_stack_at(ctx
->type_stack
, i
)->type
;
533 int index
= type_stack_at(
534 ctx
->type_stack
, i
)->index
;
536 if (cur_type
== parent_type
) {
540 g_array_append_val(field_path
->indexes
,
545 for (i
= 0; i
< tail_field_path_len
; i
++) {
546 int index
= g_array_index(
547 tail_field_path
->indexes
,
550 g_array_append_val(field_path
->indexes
,
556 parent_pos_in_stack
--;
559 if (parent_pos_in_stack
< 0) {
560 /* Not found: look in previous scopes */
563 while (field_path
->root
>= BT_CTF_SCOPE_TRACE_PACKET_HEADER
) {
564 struct bt_ctf_field_type
*root_type
;
565 bt_ctf_field_path_clear(field_path
);
567 root_type
= get_type_from_ctx(ctx
, field_path
->root
);
573 /* Locate target in previous scope */
574 ret
= ptokens_to_field_path(ptokens
, field_path
,
588 BT_PUT(tail_field_path
);
593 * Converts a path string to a field path object within the resolving
596 * Return value is owned by the caller on success.
599 struct bt_ctf_field_path
*pathstr_to_field_path(const char *pathstr
,
600 struct resolve_context
*ctx
)
603 enum bt_ctf_scope root_scope
;
604 GList
*ptokens
= NULL
;
605 struct bt_ctf_field_path
*field_path
= NULL
;
607 /* Create field path */
608 field_path
= bt_ctf_field_path_create();
610 _printf_error("Cannot create field path\n");
615 /* Convert path string to path tokens */
616 ptokens
= pathstr_to_ptokens(pathstr
);
618 _printf_error("Cannot convert path string \"%s\" to path tokens\n",
624 /* Absolute or relative path? */
625 root_scope
= get_root_scope_from_absolute_pathstr(pathstr
);
627 if (root_scope
== BT_CTF_SCOPE_UNKNOWN
) {
628 /* Relative path: start with current root scope */
629 field_path
->root
= ctx
->root_scope
;
630 ret
= relative_ptokens_to_field_path(ptokens
, field_path
, ctx
);
632 _printf_error("Cannot get relative field path of path string \"%s\"\n",
634 _printf_error(" Starting at root scope %d, finished at root scope %d\n",
635 ctx
->root_scope
, field_path
->root
);
638 } else if (root_scope
== BT_CTF_SCOPE_ENV
) {
639 _printf_error("Sequence field types referring the trace environment are not supported as of this version\n");
643 /* Absolute path: use found root scope */
644 field_path
->root
= root_scope
;
645 ret
= absolute_ptokens_to_field_path(ptokens
, field_path
, ctx
);
647 _printf_error("Cannot get absolute field path of path string \"%s\"\n",
649 _printf_error(" Looking in root scope %d\n", root_scope
);
659 ptokens_destroy(ptokens
);
665 * Retrieves a field type by following the field path `field_path` in
666 * the resolving context `ctx`.
668 * Return value is owned by the caller on success.
671 struct bt_ctf_field_type
*field_path_to_field_type(
672 struct bt_ctf_field_path
*field_path
,
673 struct resolve_context
*ctx
)
676 struct bt_ctf_field_type
*type
;
678 /* Start with root type */
679 type
= get_type_from_ctx(ctx
, field_path
->root
);
682 /* Error: root type is not available */
683 _printf_error("Root type with scope type %d is not available\n",
689 for (i
= 0; i
< field_path
->indexes
->len
; i
++) {
690 struct bt_ctf_field_type
*child_type
;
692 g_array_index(field_path
->indexes
, int, i
);
694 /* Get child field type */
695 child_type
= bt_ctf_field_type_get_field_at_index(type
,
698 _printf_error("Cannot get field type field at index %d\n",
703 /* Move child type to current type */
704 BT_MOVE(type
, child_type
);
715 * Returns the equivalent field path object of the context type stack.
717 * Return value is owned by the caller on success.
720 struct bt_ctf_field_path
*get_ctx_stack_field_path(struct resolve_context
*ctx
)
723 struct bt_ctf_field_path
*field_path
;
725 /* Create field path */
726 field_path
= bt_ctf_field_path_create();
728 _printf_error("Cannot create field path\n");
732 field_path
->root
= ctx
->root_scope
;
734 for (i
= 0; i
< type_stack_size(ctx
->type_stack
); i
++) {
735 struct type_stack_frame
*frame
;
737 frame
= type_stack_at(ctx
->type_stack
, i
);
738 g_array_append_val(field_path
->indexes
, frame
->index
);
749 * Returns the lowest common ancestor of two field path objects
750 * having the same root scope.
752 * `field_path1` and `field_path2` are owned by the caller.
754 int get_field_paths_lca_index(struct bt_ctf_field_path
*field_path1
,
755 struct bt_ctf_field_path
*field_path2
)
758 int field_path1_len
, field_path2_len
;
761 * Start from both roots and find the first mismatch.
763 assert(field_path1
->root
== field_path2
->root
);
764 field_path1_len
= field_path1
->indexes
->len
;
765 field_path2_len
= field_path2
->indexes
->len
;
768 int target_index
, ctx_index
;
770 if (lca_index
== field_path2_len
||
771 lca_index
== field_path1_len
) {
773 * This means that both field paths never split.
774 * This is invalid because the target cannot be
775 * an ancestor of the source.
777 _printf_error("In source and target: one is an ancestor of the other\n");
782 target_index
= g_array_index(field_path1
->indexes
, int,
784 ctx_index
= g_array_index(field_path2
->indexes
, int,
787 if (target_index
!= ctx_index
) {
788 /* LCA index is the previous */
799 * Validates a target field path.
801 * `target_field_path` and `target_type` are owned by the caller.
804 int validate_target_field_path(struct bt_ctf_field_path
*target_field_path
,
805 struct bt_ctf_field_type
*target_type
,
806 struct resolve_context
*ctx
)
809 struct bt_ctf_field_path
*ctx_field_path
;
810 int target_field_path_len
= target_field_path
->indexes
->len
;
812 int ctx_cur_field_type_id
;
815 /* Get context field path */
816 ctx_field_path
= get_ctx_stack_field_path(ctx
);
817 if (!ctx_field_path
) {
818 _printf_error("Cannot get source field path\n");
824 * Make sure the target is not a root.
826 if (target_field_path_len
== 0) {
827 _printf_error("Target field path's length is 0 (targeting the root)\n");
833 * Make sure the root of the target field path is not located
834 * after the context field path's root.
836 if (target_field_path
->root
> ctx_field_path
->root
) {
837 _printf_error("Target is located after source\n");
842 if (target_field_path
->root
== ctx_field_path
->root
) {
843 int target_index
, ctx_index
;
846 * Find the index of the lowest common ancestor of both field
849 lca_index
= get_field_paths_lca_index(target_field_path
,
852 _printf_error("Cannot get least common ancestor\n");
858 * Make sure the target field path is located before the
859 * context field path.
861 target_index
= g_array_index(target_field_path
->indexes
,
863 ctx_index
= g_array_index(ctx_field_path
->indexes
,
866 if (target_index
>= ctx_index
) {
867 _printf_error("Target index (%d) is greater or equal to source index (%d) in LCA\n",
868 target_index
, ctx_index
);
875 * Make sure the target type has the right type and properties.
877 ctx_cur_field_type_id
= bt_ctf_field_type_get_type_id(
878 ctx
->cur_field_type
);
879 target_type_id
= bt_ctf_field_type_get_type_id(target_type
);
881 if (ctx_cur_field_type_id
== CTF_TYPE_VARIANT
) {
882 if (target_type_id
!= CTF_TYPE_ENUM
) {
883 _printf_error("Variant type's tag field type is not an enumeration\n");
887 } else if (ctx_cur_field_type_id
== CTF_TYPE_SEQUENCE
) {
888 if (target_type_id
!= CTF_TYPE_INTEGER
||
889 bt_ctf_field_type_integer_get_signed(
891 _printf_error("Sequence type's length field type is not an unsigned integer\n");
900 BT_PUT(ctx_field_path
);
905 * Resolves a variant or sequence field type `type`.
907 * `type` is owned by the caller.
910 int resolve_sequence_or_variant_type(struct bt_ctf_field_type
*type
,
911 struct resolve_context
*ctx
)
915 int type_id
= bt_ctf_field_type_get_type_id(type
);
916 struct bt_ctf_field_path
*target_field_path
= NULL
;
917 struct bt_ctf_field_type
*target_type
= NULL
;
919 /* Get path string */
921 case CTF_TYPE_SEQUENCE
:
923 bt_ctf_field_type_sequence_get_length_field_name(type
);
925 case CTF_TYPE_VARIANT
:
927 bt_ctf_field_type_variant_get_tag_name(type
);
935 /* Get target field path out of path string */
936 target_field_path
= pathstr_to_field_path(pathstr
, ctx
);
937 if (!target_field_path
) {
938 _printf_error("Cannot get target field path for path string \"%s\"\n",
944 /* Get target field type */
945 target_type
= field_path_to_field_type(target_field_path
, ctx
);
947 _printf_error("Cannot get target field type for path string \"%s\"\n",
953 ret
= validate_target_field_path(target_field_path
, target_type
, ctx
);
955 _printf_error("Invalid target field path for path string \"%s\"\n",
960 /* Set target field path and target field type */
961 if (type_id
== CTF_TYPE_SEQUENCE
) {
962 ret
= bt_ctf_field_type_sequence_set_length_field_path(
963 type
, target_field_path
);
965 _printf_error("Cannot set sequence field type's length field path\n");
968 } else if (type_id
== CTF_TYPE_VARIANT
) {
969 ret
= bt_ctf_field_type_variant_set_tag_field_path(
970 type
, target_field_path
);
972 _printf_error("Cannot set variant field type's tag field path\n");
976 ret
= bt_ctf_field_type_variant_set_tag_field_type(
979 _printf_error("Cannot set variant field type's tag field type\n");
987 BT_PUT(target_field_path
);
993 * Resolves a field type `type`.
995 * `type` is owned by the caller.
998 int resolve_type(struct bt_ctf_field_type
*type
, struct resolve_context
*ctx
)
1004 /* Type is not available; still valid */
1008 type_id
= bt_ctf_field_type_get_type_id(type
);
1009 ctx
->cur_field_type
= type
;
1011 /* Resolve sequence/variant field type */
1013 case CTF_TYPE_SEQUENCE
:
1014 case CTF_TYPE_VARIANT
:
1015 ret
= resolve_sequence_or_variant_type(type
, ctx
);
1017 _printf_error("Cannot resolve sequence or variant field type's length/tag\n");
1025 /* Recurse into compound types */
1027 case CTF_TYPE_STRUCT
:
1028 case CTF_TYPE_VARIANT
:
1029 case CTF_TYPE_SEQUENCE
:
1030 case CTF_TYPE_ARRAY
:
1032 int field_count
, f_index
;
1034 ret
= type_stack_push(ctx
->type_stack
, type
);
1036 _printf_error("Cannot push field type on type stack\n");
1037 _printf_error(" Stack size: %zu\n",
1038 type_stack_size(ctx
->type_stack
));
1042 field_count
= bt_ctf_field_type_get_field_count(type
);
1043 if (field_count
< 0) {
1044 _printf_error("Cannot get field type field count\n");
1049 for (f_index
= 0; f_index
< field_count
; f_index
++) {
1050 struct bt_ctf_field_type
*child_type
=
1051 bt_ctf_field_type_get_field_at_index(type
,
1055 _printf_error("Cannot get field type field at index %d/%d\n",
1056 f_index
, field_count
);
1061 if (type_id
== CTF_TYPE_ARRAY
||
1062 type_id
== CTF_TYPE_SEQUENCE
) {
1063 type_stack_peek(ctx
->type_stack
)->index
= -1;
1065 type_stack_peek(ctx
->type_stack
)->index
=
1069 ret
= resolve_type(child_type
, ctx
);
1076 type_stack_pop(ctx
->type_stack
);
1088 * Resolves the root field type corresponding to the scope `root_scope`.
1091 int resolve_root_type(enum bt_ctf_scope root_scope
, struct resolve_context
*ctx
)
1095 assert(type_stack_size(ctx
->type_stack
) == 0);
1096 ctx
->root_scope
= root_scope
;
1097 ret
= resolve_type(get_type_from_ctx(ctx
, root_scope
), ctx
);
1098 ctx
->root_scope
= BT_CTF_SCOPE_UNKNOWN
;
1104 int bt_ctf_resolve_types(
1105 struct bt_value
*environment
,
1106 struct bt_ctf_field_type
*packet_header_type
,
1107 struct bt_ctf_field_type
*packet_context_type
,
1108 struct bt_ctf_field_type
*event_header_type
,
1109 struct bt_ctf_field_type
*stream_event_ctx_type
,
1110 struct bt_ctf_field_type
*event_context_type
,
1111 struct bt_ctf_field_type
*event_payload_type
,
1112 enum bt_ctf_resolve_flag flags
)
1115 struct resolve_context ctx
= {
1116 .environment
= environment
,
1119 packet_context_type
,
1121 stream_event_ctx_type
,
1125 .root_scope
= BT_CTF_SCOPE_UNKNOWN
,
1128 /* Initialize type stack */
1129 ctx
.type_stack
= type_stack_create();
1130 if (!ctx
.type_stack
) {
1131 printf_error("Cannot create type stack\n");
1136 /* Resolve packet header type */
1137 if (flags
& BT_CTF_RESOLVE_FLAG_PACKET_HEADER
) {
1138 ret
= resolve_root_type(BT_CTF_SCOPE_TRACE_PACKET_HEADER
, &ctx
);
1140 _printf_error("Cannot resolve trace packet header type\n");
1145 /* Resolve packet context type */
1146 if (flags
& BT_CTF_RESOLVE_FLAG_PACKET_CONTEXT
) {
1147 ret
= resolve_root_type(BT_CTF_SCOPE_STREAM_PACKET_CONTEXT
, &ctx
);
1149 _printf_error("Cannot resolve stream packet context type\n");
1154 /* Resolve event header type */
1155 if (flags
& BT_CTF_RESOLVE_FLAG_EVENT_HEADER
) {
1156 ret
= resolve_root_type(BT_CTF_SCOPE_STREAM_EVENT_HEADER
, &ctx
);
1158 _printf_error("Cannot resolve stream event header type\n");
1163 /* Resolve stream event context type */
1164 if (flags
& BT_CTF_RESOLVE_FLAG_STREAM_EVENT_CTX
) {
1165 ret
= resolve_root_type(BT_CTF_SCOPE_STREAM_EVENT_CONTEXT
, &ctx
);
1167 _printf_error("Cannot resolve stream event context type\n");
1172 /* Resolve event context type */
1173 if (flags
& BT_CTF_RESOLVE_FLAG_EVENT_CONTEXT
) {
1174 ret
= resolve_root_type(BT_CTF_SCOPE_EVENT_CONTEXT
, &ctx
);
1176 _printf_error("Cannot resolve event context type\n");
1181 /* Resolve event payload type */
1182 if (flags
& BT_CTF_RESOLVE_FLAG_EVENT_PAYLOAD
) {
1183 ret
= resolve_root_type(BT_CTF_SCOPE_EVENT_FIELDS
, &ctx
);
1185 _printf_error("Cannot resolve event payload type\n");
1191 type_stack_destroy(ctx
.type_stack
);