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/event-types-internal.h>
35 #include <babeltrace/ctf-ir/event-internal.h>
36 #include <babeltrace/ref.h>
37 #include <babeltrace/babeltrace-internal.h>
38 #include <babeltrace/values.h>
42 #define _printf_error(fmt, args...) \
43 printf_verbose("[resolving] " fmt, ## args)
45 typedef GPtrArray type_stack
;
50 * `type` contains a compound field type (structure, variant, array,
51 * or sequence) and `index` indicates the index of the field type in
52 * the upper frame (-1 for array and sequence field types).
54 * `type` is owned by the stack frame.
56 struct type_stack_frame
{
57 struct bt_ctf_field_type
*type
;
62 * The current context of the resolving engine.
64 * `scopes` contain the 6 CTF scope field types (see CTF, sect. 7.3.2)
65 * in the following order:
70 * * Stream event context
74 struct resolve_context
{
75 struct bt_value
*environment
;
76 struct bt_ctf_field_type
*scopes
[6];
78 /* Root node being visited */
79 enum bt_ctf_node root_node
;
80 type_stack
*type_stack
;
81 struct bt_ctf_field_type
*cur_field_type
;
84 /* TSDL dynamic scope prefixes as defined in CTF Section 7.3.2 */
85 static const char * const absolute_path_prefixes
[] = {
86 [CTF_NODE_ENV
] = "env.",
87 [CTF_NODE_TRACE_PACKET_HEADER
] = "trace.packet.header.",
88 [CTF_NODE_STREAM_PACKET_CONTEXT
] = "stream.packet.context.",
89 [CTF_NODE_STREAM_EVENT_HEADER
] = "stream.event.header.",
90 [CTF_NODE_STREAM_EVENT_CONTEXT
] = "stream.event.context.",
91 [CTF_NODE_EVENT_CONTEXT
] = "event.context.",
92 [CTF_NODE_EVENT_FIELDS
] = "event.fields.",
95 /* Number of path tokens used for the absolute prefixes */
96 static const int absolute_path_prefix_ptoken_counts
[] = {
98 [CTF_NODE_TRACE_PACKET_HEADER
] = 3,
99 [CTF_NODE_STREAM_PACKET_CONTEXT
] = 3,
100 [CTF_NODE_STREAM_EVENT_HEADER
] = 3,
101 [CTF_NODE_STREAM_EVENT_CONTEXT
] = 3,
102 [CTF_NODE_EVENT_CONTEXT
] = 2,
103 [CTF_NODE_EVENT_FIELDS
] = 2,
107 * Destroys a type stack frame.
110 void type_stack_destroy_notify(gpointer data
)
112 struct type_stack_frame
*frame
= data
;
119 * Creates a type stack.
121 * Return value is owned by the caller.
124 type_stack
*type_stack_create(void)
126 return g_ptr_array_new_with_free_func(type_stack_destroy_notify
);
130 * Destroys a type stack.
133 void type_stack_destroy(type_stack
*stack
)
135 g_ptr_array_free(stack
, TRUE
);
139 * Pushes a field type onto a type stack.
141 * `type` is owned by the caller (stack frame gets a new reference).
144 int type_stack_push(type_stack
*stack
, struct bt_ctf_field_type
*type
)
147 struct type_stack_frame
*frame
= NULL
;
149 if (!stack
|| !type
) {
154 frame
= g_new0(struct type_stack_frame
, 1);
160 frame
->type
= bt_get(type
);
161 g_ptr_array_add(stack
, frame
);
168 * Checks whether or not `stack` is empty.
171 bool type_stack_empty(type_stack
*stack
)
173 return stack
->len
== 0;
177 * Returns the number of frames in `stack`.
180 size_t type_stack_size(type_stack
*stack
)
186 * Returns the top frame of `stack`.
188 * Return value is owned by `stack`.
191 struct type_stack_frame
*type_stack_peek(type_stack
*stack
)
193 struct type_stack_frame
*entry
= NULL
;
195 if (!stack
|| type_stack_empty(stack
)) {
199 entry
= g_ptr_array_index(stack
, stack
->len
- 1);
205 * Returns the frame at index `index` in `stack`.
207 * Return value is owned by `stack`.
210 struct type_stack_frame
*type_stack_at(type_stack
*stack
,
213 struct type_stack_frame
*entry
= NULL
;
215 if (!stack
|| index
>= stack
->len
) {
219 entry
= g_ptr_array_index(stack
, index
);
226 * Removes the top frame of `stack`.
229 void type_stack_pop(type_stack
*stack
)
231 if (!type_stack_empty(stack
)) {
233 * This will call the frame's destructor and free it, as
234 * well as put its contained field type.
236 g_ptr_array_set_size(stack
, stack
->len
- 1);
241 * Returns the scope field type of `scope` in the context `ctx`.
243 * Return value is owned by `ctx` on success.
246 struct bt_ctf_field_type
*get_type_from_ctx(struct resolve_context
*ctx
,
247 enum bt_ctf_node node
)
249 assert(node
>= CTF_NODE_TRACE_PACKET_HEADER
&&
250 node
<= CTF_NODE_EVENT_FIELDS
);
252 return ctx
->scopes
[node
- CTF_NODE_TRACE_PACKET_HEADER
];
256 * Returns the CTF scope from a path string. May return
257 * CTF_NODE_UNKNOWN if the path is found to be relative.
260 enum bt_ctf_node
get_root_node_from_absolute_pathstr(const char *pathstr
)
262 enum bt_ctf_node node
;
263 enum bt_ctf_node ret
= CTF_NODE_UNKNOWN
;
264 const size_t prefixes_count
= sizeof(absolute_path_prefixes
) /
265 sizeof(*absolute_path_prefixes
);
267 for (node
= CTF_NODE_ENV
; node
< CTF_NODE_ENV
+ prefixes_count
;
270 * Chech if path string starts with a known absolute
273 * Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES.
275 if (strncmp(pathstr
, absolute_path_prefixes
[node
],
276 strlen(absolute_path_prefixes
[node
]))) {
277 /* Prefix does not match: try the next one */
291 * Destroys a path token.
294 void ptokens_destroy_func(gpointer ptoken
, gpointer data
)
296 g_string_free(ptoken
, TRUE
);
300 * Destroys a path token list.
303 void ptokens_destroy(GList
*ptokens
)
309 g_list_foreach(ptokens
, ptokens_destroy_func
, NULL
);
310 g_list_free(ptokens
);
314 * Returns the string contained in a path token.
317 const char *ptoken_get_string(GList
*ptoken
)
319 GString
*tokenstr
= (GString
*) ptoken
->data
;
321 return tokenstr
->str
;
325 * Converts a path string to a path token list, that is, splits the
326 * individual words of a path string into a list of individual
329 * Return value is owned by the caller on success.
332 GList
*pathstr_to_ptokens(const char *pathstr
)
334 const char *at
= pathstr
;
335 const char *last
= at
;
336 GList
*ptokens
= NULL
;
339 if (*at
== '.' || *at
== '\0') {
343 /* Error: empty token */
344 _printf_error("Empty token in path string at position %d\n",
345 (int) (at
- pathstr
));
349 tokenstr
= g_string_new(NULL
);
350 g_string_append_len(tokenstr
, last
, at
- last
);
351 ptokens
= g_list_append(ptokens
, tokenstr
);
365 ptokens_destroy(ptokens
);
370 * Converts a path token list to a field path object. The path token
371 * list is relative from `type`. The index of the source looking for
372 * its target within `type` is indicated by `src_index`. This can be
373 * `INT_MAX` if the source is contained in `type`.
375 * `ptokens` is owned by the caller. `field_path` is an output parameter
376 * owned by the caller that must be filled here. `type` is owned by the
380 int ptokens_to_field_path(GList
*ptokens
, struct bt_ctf_field_path
*field_path
,
381 struct bt_ctf_field_type
*type
, int src_index
)
384 GList
*cur_ptoken
= ptokens
;
385 bool first_level_done
= false;
387 /* Get our own reference */
393 struct bt_ctf_field_type
*child_type
;
394 const char *field_name
= ptoken_get_string(cur_ptoken
);
395 enum ctf_type_id type_id
= bt_ctf_field_type_get_type_id(type
);
397 /* Find to which index corresponds the current path token */
398 if (type_id
== CTF_TYPE_ARRAY
|| type_id
== CTF_TYPE_SEQUENCE
) {
401 child_index
= bt_ctf_field_type_get_field_index(type
,
403 if (child_index
< 0) {
405 * Error: field name does not exist or
406 * wrong current type.
408 _printf_error("Cannot get index of field type named \"%s\"\n",
412 } else if (child_index
> src_index
&&
414 _printf_error("Child type is located after source index (%d)\n",
420 /* Next path token */
421 cur_ptoken
= g_list_next(cur_ptoken
);
422 first_level_done
= true;
425 /* Create new field path entry */
426 g_array_append_val(field_path
->path_indexes
, child_index
);
428 /* Get child field type */
429 child_type
= bt_ctf_field_type_get_field_at_index(type
,
432 _printf_error("Cannot get child type at index %d (field \"%s\")\n",
433 child_index
, field_name
);
438 /* Move child type to current type */
439 BT_MOVE(type
, child_type
);
448 * Converts a known absolute path token list to a field path object
449 * within the resolving context `ctx`.
451 * `ptokens` is owned by the caller. `field_path` is an output parameter
452 * owned by the caller that must be filled here.
455 int absolute_ptokens_to_field_path(GList
*ptokens
,
456 struct bt_ctf_field_path
*field_path
,
457 struct resolve_context
*ctx
)
461 struct bt_ctf_field_type
*type
;
463 /* Skip absolute path tokens */
464 cur_ptoken
= g_list_nth(ptokens
,
465 absolute_path_prefix_ptoken_counts
[field_path
->root
]);
467 /* Start with root type */
468 type
= get_type_from_ctx(ctx
, field_path
->root
);
470 /* Error: root type is not available */
471 _printf_error("Root type with node type %d is not available\n",
478 ret
= ptokens_to_field_path(cur_ptoken
, field_path
, type
, INT_MAX
);
485 * Converts a known relative path token list to a field path object
486 * within the resolving context `ctx`.
488 * `ptokens` is owned by the caller. `field_path` is an output parameter
489 * owned by the caller that must be filled here.
492 int relative_ptokens_to_field_path(GList
*ptokens
,
493 struct bt_ctf_field_path
*field_path
,
494 struct resolve_context
*ctx
)
497 int parent_pos_in_stack
;
498 struct bt_ctf_field_path
*tail_field_path
= bt_ctf_field_path_create();
500 if (!tail_field_path
) {
501 _printf_error("Cannot create field path\n");
506 parent_pos_in_stack
= type_stack_size(ctx
->type_stack
) - 1;
508 while (parent_pos_in_stack
>= 0) {
509 struct bt_ctf_field_type
*parent_type
=
510 type_stack_at(ctx
->type_stack
,
511 parent_pos_in_stack
)->type
;
512 int cur_index
= type_stack_at(ctx
->type_stack
,
513 parent_pos_in_stack
)->index
;
515 /* Locate target from current parent type */
516 ret
= ptokens_to_field_path(ptokens
, tail_field_path
,
517 parent_type
, cur_index
);
519 /* Not found... yet */
520 bt_ctf_field_path_clear(tail_field_path
);
522 /* Found: stitch tail field path to head field path */
524 int tail_field_path_len
=
525 tail_field_path
->path_indexes
->len
;
528 struct bt_ctf_field_type
*cur_type
=
529 type_stack_at(ctx
->type_stack
, i
)->type
;
530 int index
= type_stack_at(
531 ctx
->type_stack
, i
)->index
;
533 if (cur_type
== parent_type
) {
537 g_array_append_val(field_path
->path_indexes
,
542 for (i
= 0; i
< tail_field_path_len
; i
++) {
543 int index
= g_array_index(
544 tail_field_path
->path_indexes
,
547 g_array_append_val(field_path
->path_indexes
,
553 parent_pos_in_stack
--;
556 if (parent_pos_in_stack
< 0) {
557 /* Not found: look in previous scopes */
560 while (field_path
->root
>= CTF_NODE_TRACE_PACKET_HEADER
) {
561 struct bt_ctf_field_type
*root_type
;
562 bt_ctf_field_path_clear(field_path
);
564 root_type
= get_type_from_ctx(ctx
, field_path
->root
);
570 /* Locate target in previous scope */
571 ret
= ptokens_to_field_path(ptokens
, field_path
,
585 bt_ctf_field_path_destroy(tail_field_path
);
590 * Converts a path string to a field path object within the resolving
593 * Return value is owned by the caller on success.
596 struct bt_ctf_field_path
*pathstr_to_field_path(const char *pathstr
,
597 struct resolve_context
*ctx
)
600 enum bt_ctf_node root_node
;
601 GList
*ptokens
= NULL
;
602 struct bt_ctf_field_path
*field_path
= NULL
;
604 /* Create field path */
605 field_path
= bt_ctf_field_path_create();
607 _printf_error("Cannot create field path\n");
612 /* Convert path string to path tokens */
613 ptokens
= pathstr_to_ptokens(pathstr
);
615 _printf_error("Cannot convert path string \"%s\" to path tokens\n",
621 /* Absolute or relative path? */
622 root_node
= get_root_node_from_absolute_pathstr(pathstr
);
624 if (root_node
== CTF_NODE_UNKNOWN
) {
625 /* Relative path: start with current root node */
626 field_path
->root
= ctx
->root_node
;
627 ret
= relative_ptokens_to_field_path(ptokens
, field_path
, ctx
);
629 _printf_error("Cannot get relative field path of path string \"%s\"\n",
631 _printf_error(" Starting at root node %d, finished at root node %d\n",
632 ctx
->root_node
, field_path
->root
);
635 } else if (root_node
== CTF_NODE_ENV
) {
636 _printf_error("Sequence field types referring the trace environment are not supported as of this version\n");
640 /* Absolute path: use found root node */
641 field_path
->root
= root_node
;
642 ret
= absolute_ptokens_to_field_path(ptokens
, field_path
, ctx
);
644 _printf_error("Cannot get absolute field path of path string \"%s\"\n",
646 _printf_error(" Looking in root node %d\n", root_node
);
653 bt_ctf_field_path_destroy(field_path
);
657 ptokens_destroy(ptokens
);
663 * Retrieves a field type by following the field path `field_path` in
664 * the resolving context `ctx`.
666 * Return value is owned by the caller on success.
669 struct bt_ctf_field_type
*field_path_to_field_type(
670 struct bt_ctf_field_path
*field_path
,
671 struct resolve_context
*ctx
)
674 struct bt_ctf_field_type
*type
;
676 /* Start with root type */
677 type
= get_type_from_ctx(ctx
, field_path
->root
);
680 /* Error: root type is not available */
681 _printf_error("Root type with node type %d is not available\n",
687 for (i
= 0; i
< field_path
->path_indexes
->len
; i
++) {
688 struct bt_ctf_field_type
*child_type
;
690 g_array_index(field_path
->path_indexes
, int, i
);
692 /* Get child field type */
693 child_type
= bt_ctf_field_type_get_field_at_index(type
,
696 _printf_error("Cannot get field type field at index %d\n",
701 /* Move child type to current type */
702 BT_MOVE(type
, child_type
);
713 * Returns the equivalent field path object of the context type stack.
715 * Return value is owned by the caller on success.
718 struct bt_ctf_field_path
*get_ctx_stack_field_path(struct resolve_context
*ctx
)
721 struct bt_ctf_field_path
*field_path
;
723 /* Create field path */
724 field_path
= bt_ctf_field_path_create();
726 _printf_error("Cannot create field path\n");
730 field_path
->root
= ctx
->root_node
;
732 for (i
= 0; i
< type_stack_size(ctx
->type_stack
); i
++) {
733 struct type_stack_frame
*frame
;
735 frame
= type_stack_at(ctx
->type_stack
, i
);
736 g_array_append_val(field_path
->path_indexes
, frame
->index
);
742 bt_ctf_field_path_destroy(field_path
);
747 * Returns the lowest common ancestor of two field path objects
748 * having the same root scope.
750 * `field_path1` and `field_path2` are owned by the caller.
752 int get_field_paths_lca_index(struct bt_ctf_field_path
*field_path1
,
753 struct bt_ctf_field_path
*field_path2
)
756 int field_path1_len
, field_path2_len
;
759 * Start from both roots and find the first mismatch.
761 assert(field_path1
->root
== field_path2
->root
);
762 field_path1_len
= field_path1
->path_indexes
->len
;
763 field_path2_len
= field_path2
->path_indexes
->len
;
766 int target_index
, ctx_index
;
768 if (lca_index
== field_path2_len
||
769 lca_index
== field_path1_len
) {
771 * This means that both field paths never split.
772 * This is invalid because the target cannot be
773 * an ancestor of the source.
775 _printf_error("In source and target: one is an ancestor of the other\n");
780 target_index
= g_array_index(field_path1
->path_indexes
, int,
782 ctx_index
= g_array_index(field_path2
->path_indexes
, int,
785 if (target_index
!= ctx_index
) {
786 /* LCA index is the previous */
797 * Validates a target field path.
799 * `target_field_path` and `target_type` are owned by the caller.
802 int validate_target_field_path(struct bt_ctf_field_path
*target_field_path
,
803 struct bt_ctf_field_type
*target_type
,
804 struct resolve_context
*ctx
)
807 struct bt_ctf_field_path
*ctx_field_path
;
808 int target_field_path_len
= target_field_path
->path_indexes
->len
;
810 int ctx_cur_field_type_id
;
813 /* Get context field path */
814 ctx_field_path
= get_ctx_stack_field_path(ctx
);
815 if (!ctx_field_path
) {
816 _printf_error("Cannot get source field path\n");
822 * Make sure the target is not a root.
824 if (target_field_path_len
== 0) {
825 _printf_error("Target field path's length is 0 (targeting the root)\n");
831 * Make sure the root of the target field path is not located
832 * after the context field path's root.
834 if (target_field_path
->root
> ctx_field_path
->root
) {
835 _printf_error("Target is located after source\n");
840 if (target_field_path
->root
== ctx_field_path
->root
) {
841 int target_index
, ctx_index
;
844 * Find the index of the lowest common ancestor of both field
847 lca_index
= get_field_paths_lca_index(target_field_path
,
850 _printf_error("Cannot get least common ancestor\n");
856 * Make sure the target field path is located before the
857 * context field path.
859 target_index
= g_array_index(target_field_path
->path_indexes
,
861 ctx_index
= g_array_index(ctx_field_path
->path_indexes
,
864 if (target_index
>= ctx_index
) {
865 _printf_error("Target index (%d) is greater or equal to source index (%d) in LCA\n",
866 target_index
, ctx_index
);
873 * Make sure the target type has the right type and properties.
875 ctx_cur_field_type_id
= bt_ctf_field_type_get_type_id(
876 ctx
->cur_field_type
);
877 target_type_id
= bt_ctf_field_type_get_type_id(target_type
);
879 if (ctx_cur_field_type_id
== CTF_TYPE_VARIANT
) {
880 if (target_type_id
!= CTF_TYPE_ENUM
) {
881 _printf_error("Variant type's tag field type is not an enumeration\n");
885 } else if (ctx_cur_field_type_id
== CTF_TYPE_SEQUENCE
) {
886 if (target_type_id
!= CTF_TYPE_INTEGER
||
887 bt_ctf_field_type_integer_get_signed(
889 _printf_error("Sequence type's length field type is not an unsigned integer\n");
898 bt_ctf_field_path_destroy(ctx_field_path
);
903 * Resolves a variant or sequence field type `type`.
905 * `type` is owned by the caller.
908 int resolve_sequence_or_variant_type(struct bt_ctf_field_type
*type
,
909 struct resolve_context
*ctx
)
913 int type_id
= bt_ctf_field_type_get_type_id(type
);
914 struct bt_ctf_field_path
*target_field_path
= NULL
;
915 struct bt_ctf_field_type
*target_type
= NULL
;
917 /* Get path string */
919 case CTF_TYPE_SEQUENCE
:
921 bt_ctf_field_type_sequence_get_length_field_name(type
);
923 case CTF_TYPE_VARIANT
:
925 bt_ctf_field_type_variant_get_tag_name(type
);
931 /* Get target field path out of path string */
932 target_field_path
= pathstr_to_field_path(pathstr
, ctx
);
933 if (!target_field_path
) {
934 _printf_error("Cannot get target field path for path string \"%s\"\n",
940 /* Get target field type */
941 target_type
= field_path_to_field_type(target_field_path
, ctx
);
943 _printf_error("Cannot get target field type for path string \"%s\"\n",
949 ret
= validate_target_field_path(target_field_path
, target_type
, ctx
);
951 _printf_error("Invalid target field path for path string \"%s\"\n",
956 /* Set target field path and target field type */
957 if (type_id
== CTF_TYPE_SEQUENCE
) {
958 ret
= bt_ctf_field_type_sequence_set_length_field_path(
959 type
, target_field_path
);
961 _printf_error("Cannot set sequence field type's length field path\n");
965 target_field_path
= NULL
;
966 } else if (type_id
== CTF_TYPE_VARIANT
) {
967 ret
= bt_ctf_field_type_variant_set_tag_field_path(
968 type
, target_field_path
);
970 _printf_error("Cannot set variant field type's tag field path\n");
974 target_field_path
= NULL
;
976 ret
= bt_ctf_field_type_variant_set_tag(type
, target_type
);
978 _printf_error("Cannot set variant field type's tag field type\n");
986 bt_ctf_field_path_destroy(target_field_path
);
992 * Resolves a field type `type`.
994 * `type` is owned by the caller.
997 int resolve_type(struct bt_ctf_field_type
*type
, struct resolve_context
*ctx
)
1003 /* Type is not available; still valid */
1007 type_id
= bt_ctf_field_type_get_type_id(type
);
1008 ctx
->cur_field_type
= type
;
1010 /* Resolve sequence/variant field type */
1012 case CTF_TYPE_SEQUENCE
:
1013 case CTF_TYPE_VARIANT
:
1014 ret
= resolve_sequence_or_variant_type(type
, ctx
);
1016 _printf_error("Cannot resolve sequence or variant field type's length/tag\n");
1024 /* Recurse into compound types */
1026 case CTF_TYPE_STRUCT
:
1027 case CTF_TYPE_VARIANT
:
1028 case CTF_TYPE_SEQUENCE
:
1029 case CTF_TYPE_ARRAY
:
1031 int field_count
, f_index
;
1033 ret
= type_stack_push(ctx
->type_stack
, type
);
1035 _printf_error("Cannot push field type on type stack\n");
1036 _printf_error(" Stack size: %zu\n",
1037 type_stack_size(ctx
->type_stack
));
1041 field_count
= bt_ctf_field_type_get_field_count(type
);
1042 if (field_count
< 0) {
1043 _printf_error("Cannot get field type field count\n");
1048 for (f_index
= 0; f_index
< field_count
; f_index
++) {
1049 struct bt_ctf_field_type
*child_type
=
1050 bt_ctf_field_type_get_field_at_index(type
,
1054 _printf_error("Cannot get field type field at index %d/%d\n",
1055 f_index
, field_count
);
1060 if (type_id
== CTF_TYPE_ARRAY
||
1061 type_id
== CTF_TYPE_SEQUENCE
) {
1062 type_stack_peek(ctx
->type_stack
)->index
= -1;
1064 type_stack_peek(ctx
->type_stack
)->index
=
1068 ret
= resolve_type(child_type
, ctx
);
1075 type_stack_pop(ctx
->type_stack
);
1087 * Resolves the root field type corresponding to the scope `root_scope`.
1090 int resolve_root_type(enum ctf_type_id root_node
, struct resolve_context
*ctx
)
1094 assert(type_stack_size(ctx
->type_stack
) == 0);
1095 ctx
->root_node
= root_node
;
1096 ret
= resolve_type(get_type_from_ctx(ctx
, root_node
), ctx
);
1097 ctx
->root_node
= CTF_NODE_UNKNOWN
;
1103 int bt_ctf_resolve_types(
1104 struct bt_value
*environment
,
1105 struct bt_ctf_field_type
*packet_header_type
,
1106 struct bt_ctf_field_type
*packet_context_type
,
1107 struct bt_ctf_field_type
*event_header_type
,
1108 struct bt_ctf_field_type
*stream_event_ctx_type
,
1109 struct bt_ctf_field_type
*event_context_type
,
1110 struct bt_ctf_field_type
*event_payload_type
,
1111 enum bt_ctf_resolve_flag flags
)
1114 struct resolve_context ctx
= {
1115 .environment
= environment
,
1118 packet_context_type
,
1120 stream_event_ctx_type
,
1124 .root_node
= CTF_NODE_UNKNOWN
,
1127 /* Initialize type stack */
1128 ctx
.type_stack
= type_stack_create();
1129 if (!ctx
.type_stack
) {
1130 printf_error("Cannot create type stack\n");
1135 /* Resolve packet header type */
1136 if (flags
& BT_CTF_RESOLVE_FLAG_PACKET_HEADER
) {
1137 ret
= resolve_root_type(CTF_NODE_TRACE_PACKET_HEADER
, &ctx
);
1139 _printf_error("Cannot resolve trace packet header type\n");
1144 /* Resolve packet context type */
1145 if (flags
& BT_CTF_RESOLVE_FLAG_PACKET_CONTEXT
) {
1146 ret
= resolve_root_type(CTF_NODE_STREAM_PACKET_CONTEXT
, &ctx
);
1148 _printf_error("Cannot resolve stream packet context type\n");
1153 /* Resolve event header type */
1154 if (flags
& BT_CTF_RESOLVE_FLAG_EVENT_HEADER
) {
1155 ret
= resolve_root_type(CTF_NODE_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(CTF_NODE_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(CTF_NODE_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(CTF_NODE_EVENT_FIELDS
, &ctx
);
1185 _printf_error("Cannot resolve event payload type\n");
1191 type_stack_destroy(ctx
.type_stack
);