`ctf` plugin: `bt_msg_iter`: use BT_COMP_LOG*() instead of BT_LOG*()
[babeltrace.git] / src / plugins / ctf / common / metadata / ctf-meta-resolve.c
CommitLineData
44c440bc
PP
1/*
2 * Copyright 2016-2018 - Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 */
15
0746848c 16#define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
350ad6c1 17#define BT_LOG_TAG "PLUGIN/CTF/META/RESOLVE"
0746848c 18#include "logging/log.h"
44c440bc 19
3fadfbc0 20#include <babeltrace2/babeltrace.h>
91d81473 21#include "common/macros.h"
578e048b
MJ
22#include "common/assert.h"
23#include "common/common.h"
44c440bc
PP
24#include <glib.h>
25#include <stdint.h>
26#include <string.h>
27#include <inttypes.h>
28#include <limits.h>
29#include <stdlib.h>
30#include <glib.h>
31
32#include "ctf-meta-visitors.h"
33
5cd6d0e5 34typedef GPtrArray field_class_stack;
44c440bc
PP
35
36/*
37 * A stack frame.
38 *
5cd6d0e5
PP
39 * `fc` contains a compound field class (structure, variant, array,
40 * or sequence) and `index` indicates the index of the field class in
41 * the upper frame (-1 for array and sequence field classes). `name`
42 * indicates the name of the field class in the upper frame (empty
43 * string for array and sequence field classes).
44c440bc 44 */
5cd6d0e5
PP
45struct field_class_stack_frame {
46 struct ctf_field_class *fc;
44c440bc
PP
47 int64_t index;
48};
49
50/*
51 * The current context of the resolving engine.
52 */
53struct resolve_context {
0746848c 54 bt_logging_level log_level;
44c440bc
PP
55 struct ctf_trace_class *tc;
56 struct ctf_stream_class *sc;
57 struct ctf_event_class *ec;
58
59 struct {
5cd6d0e5
PP
60 struct ctf_field_class *packet_header;
61 struct ctf_field_class *packet_context;
62 struct ctf_field_class *event_header;
63 struct ctf_field_class *event_common_context;
64 struct ctf_field_class *event_spec_context;
65 struct ctf_field_class *event_payload;
44c440bc
PP
66 } scopes;
67
68 /* Root scope being visited */
83ebb7f1 69 enum ctf_scope root_scope;
5cd6d0e5
PP
70 field_class_stack *field_class_stack;
71 struct ctf_field_class *cur_fc;
44c440bc
PP
72};
73
74/* TSDL dynamic scope prefixes as defined in CTF Section 7.3.2 */
75static const char * const absolute_path_prefixes[] = {
83ebb7f1
PP
76 [CTF_SCOPE_PACKET_HEADER] = "trace.packet.header.",
77 [CTF_SCOPE_PACKET_CONTEXT] = "stream.packet.context.",
78 [CTF_SCOPE_EVENT_HEADER] = "stream.event.header.",
79 [CTF_SCOPE_EVENT_COMMON_CONTEXT] = "stream.event.context.",
80 [CTF_SCOPE_EVENT_SPECIFIC_CONTEXT] = "event.context.",
81 [CTF_SCOPE_EVENT_PAYLOAD] = "event.fields.",
44c440bc
PP
82};
83
84/* Number of path tokens used for the absolute prefixes */
85static const uint64_t absolute_path_prefix_ptoken_counts[] = {
83ebb7f1
PP
86 [CTF_SCOPE_PACKET_HEADER] = 3,
87 [CTF_SCOPE_PACKET_CONTEXT] = 3,
88 [CTF_SCOPE_EVENT_HEADER] = 3,
89 [CTF_SCOPE_EVENT_COMMON_CONTEXT] = 3,
90 [CTF_SCOPE_EVENT_SPECIFIC_CONTEXT] = 2,
91 [CTF_SCOPE_EVENT_PAYLOAD] = 2,
44c440bc
PP
92};
93
94static
5cd6d0e5 95void destroy_field_class_stack_frame(struct field_class_stack_frame *frame)
44c440bc
PP
96{
97 if (!frame) {
98 return;
99 }
100
101 g_free(frame);
102}
103
104/*
5cd6d0e5 105 * Creates a class stack.
44c440bc
PP
106 */
107static
5cd6d0e5 108field_class_stack *field_class_stack_create(void)
44c440bc
PP
109{
110 return g_ptr_array_new_with_free_func(
5cd6d0e5 111 (GDestroyNotify) destroy_field_class_stack_frame);
44c440bc
PP
112}
113
114/*
5cd6d0e5 115 * Destroys a class stack.
44c440bc
PP
116 */
117static
5cd6d0e5 118void field_class_stack_destroy(field_class_stack *stack)
44c440bc
PP
119{
120 if (stack) {
121 g_ptr_array_free(stack, TRUE);
122 }
123}
124
125/*
5cd6d0e5 126 * Pushes a field class onto a class stack.
44c440bc
PP
127 */
128static
0746848c
PP
129int field_class_stack_push(field_class_stack *stack, struct ctf_field_class *fc,
130 struct resolve_context *ctx)
44c440bc
PP
131{
132 int ret = 0;
5cd6d0e5 133 struct field_class_stack_frame *frame = NULL;
44c440bc 134
5cd6d0e5
PP
135 if (!stack || !fc) {
136 BT_LOGE("Invalid parameter: stack or field class is NULL.");
44c440bc
PP
137 ret = -1;
138 goto end;
139 }
140
5cd6d0e5 141 frame = g_new0(struct field_class_stack_frame, 1);
44c440bc 142 if (!frame) {
5cd6d0e5 143 BT_LOGE_STR("Failed to allocate one field class stack frame.");
44c440bc
PP
144 ret = -1;
145 goto end;
146 }
147
3f7d4d90 148 BT_LOGD("Pushing field class on context's stack: "
5cd6d0e5
PP
149 "fc-addr=%p, stack-size-before=%u", fc, stack->len);
150 frame->fc = fc;
44c440bc
PP
151 g_ptr_array_add(stack, frame);
152
153end:
154 return ret;
155}
156
157/*
158 * Checks whether or not `stack` is empty.
159 */
160static
5cd6d0e5 161bool field_class_stack_empty(field_class_stack *stack)
44c440bc
PP
162{
163 return stack->len == 0;
164}
165
166/*
167 * Returns the number of frames in `stack`.
168 */
169static
5cd6d0e5 170size_t field_class_stack_size(field_class_stack *stack)
44c440bc
PP
171{
172 return stack->len;
173}
174
175/*
176 * Returns the top frame of `stack`.
177 */
178static
5cd6d0e5 179struct field_class_stack_frame *field_class_stack_peek(field_class_stack *stack)
44c440bc 180{
5cd6d0e5 181 struct field_class_stack_frame *entry = NULL;
44c440bc 182
5cd6d0e5 183 if (!stack || field_class_stack_empty(stack)) {
44c440bc
PP
184 goto end;
185 }
186
187 entry = g_ptr_array_index(stack, stack->len - 1);
188end:
189 return entry;
190}
191
192/*
193 * Returns the frame at index `index` in `stack`.
194 */
195static
5cd6d0e5 196struct field_class_stack_frame *field_class_stack_at(field_class_stack *stack,
44c440bc
PP
197 size_t index)
198{
5cd6d0e5 199 struct field_class_stack_frame *entry = NULL;
44c440bc
PP
200
201 if (!stack || index >= stack->len) {
202 goto end;
203 }
204
205 entry = g_ptr_array_index(stack, index);
206
207end:
208 return entry;
209}
210
211/*
212 * Removes the top frame of `stack`.
213 */
214static
0746848c
PP
215void field_class_stack_pop(field_class_stack *stack,
216 struct resolve_context *ctx)
44c440bc 217{
5cd6d0e5 218 if (!field_class_stack_empty(stack)) {
44c440bc
PP
219 /*
220 * This will call the frame's destructor and free it, as
5cd6d0e5 221 * well as put its contained field class.
44c440bc 222 */
3f7d4d90 223 BT_LOGD("Popping context's stack: stack-size-before=%u",
44c440bc
PP
224 stack->len);
225 g_ptr_array_set_size(stack, stack->len - 1);
226 }
227}
228
229/*
5cd6d0e5 230 * Returns the scope field class of `scope` in the context `ctx`.
44c440bc
PP
231 */
232static
5cd6d0e5 233struct ctf_field_class *borrow_class_from_ctx(struct resolve_context *ctx,
83ebb7f1 234 enum ctf_scope scope)
44c440bc
PP
235{
236 switch (scope) {
83ebb7f1 237 case CTF_SCOPE_PACKET_HEADER:
44c440bc 238 return ctx->scopes.packet_header;
83ebb7f1 239 case CTF_SCOPE_PACKET_CONTEXT:
44c440bc 240 return ctx->scopes.packet_context;
83ebb7f1 241 case CTF_SCOPE_EVENT_HEADER:
44c440bc 242 return ctx->scopes.event_header;
83ebb7f1 243 case CTF_SCOPE_EVENT_COMMON_CONTEXT:
44c440bc 244 return ctx->scopes.event_common_context;
83ebb7f1 245 case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
44c440bc 246 return ctx->scopes.event_spec_context;
83ebb7f1 247 case CTF_SCOPE_EVENT_PAYLOAD:
44c440bc
PP
248 return ctx->scopes.event_payload;
249 default:
250 abort();
251 }
252
253 return NULL;
254}
255
256/*
257 * Returns the CTF scope from a path string. May return -1 if the path
258 * is found to be relative.
259 */
260static
0746848c
PP
261enum ctf_scope get_root_scope_from_absolute_pathstr(const char *pathstr,
262 struct resolve_context *ctx)
44c440bc 263{
83ebb7f1
PP
264 enum ctf_scope scope;
265 enum ctf_scope ret = -1;
44c440bc
PP
266 const size_t prefixes_count = sizeof(absolute_path_prefixes) /
267 sizeof(*absolute_path_prefixes);
268
83ebb7f1 269 for (scope = CTF_SCOPE_PACKET_HEADER; scope < CTF_SCOPE_PACKET_HEADER +
44c440bc
PP
270 prefixes_count; scope++) {
271 /*
272 * Chech if path string starts with a known absolute
273 * path prefix.
274 *
275 * Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES.
276 */
277 if (strncmp(pathstr, absolute_path_prefixes[scope],
278 strlen(absolute_path_prefixes[scope]))) {
279 /* Prefix does not match: try the next one */
3f7d4d90 280 BT_LOGD("Prefix does not match: trying the next one: "
44c440bc
PP
281 "path=\"%s\", path-prefix=\"%s\", scope=%s",
282 pathstr, absolute_path_prefixes[scope],
d4928fcd 283 ctf_scope_string(scope));
44c440bc
PP
284 continue;
285 }
286
287 /* Found it! */
288 ret = scope;
3f7d4d90 289 BT_LOGD("Found root scope from absolute path: "
44c440bc 290 "path=\"%s\", scope=%s", pathstr,
d4928fcd 291 ctf_scope_string(scope));
44c440bc
PP
292 goto end;
293 }
294
295end:
296 return ret;
297}
298
299/*
300 * Destroys a path token.
301 */
302static
303void ptokens_destroy_func(gpointer ptoken, gpointer data)
304{
305 g_string_free(ptoken, TRUE);
306}
307
308/*
309 * Destroys a path token list.
310 */
311static
312void ptokens_destroy(GList *ptokens)
313{
314 if (!ptokens) {
315 return;
316 }
317
318 g_list_foreach(ptokens, ptokens_destroy_func, NULL);
319 g_list_free(ptokens);
320}
321
322/*
323 * Returns the string contained in a path token.
324 */
325static
326const char *ptoken_get_string(GList *ptoken)
327{
328 GString *tokenstr = (GString *) ptoken->data;
329
330 return tokenstr->str;
331}
332
333/*
334 * Converts a path string to a path token list, that is, splits the
335 * individual words of a path string into a list of individual
336 * strings.
337 */
338static
0746848c 339GList *pathstr_to_ptokens(const char *pathstr, struct resolve_context *ctx)
44c440bc
PP
340{
341 const char *at = pathstr;
342 const char *last = at;
343 GList *ptokens = NULL;
344
345 for (;;) {
346 if (*at == '.' || *at == '\0') {
347 GString *tokenstr;
348
349 if (at == last) {
350 /* Error: empty token */
351 BT_LOGE("Empty path token: path=\"%s\", pos=%u",
352 pathstr, (unsigned int) (at - pathstr));
353 goto error;
354 }
355
356 tokenstr = g_string_new(NULL);
357 g_string_append_len(tokenstr, last, at - last);
358 ptokens = g_list_append(ptokens, tokenstr);
359 last = at + 1;
360 }
361
362 if (*at == '\0') {
363 break;
364 }
365
366 at++;
367 }
368
369 return ptokens;
370
371error:
372 ptokens_destroy(ptokens);
373 return NULL;
374}
375
376/*
377 * Converts a path token list to a field path object. The path token
5cd6d0e5
PP
378 * list is relative from `fc`. The index of the source looking for its
379 * target within `fc` is indicated by `src_index`. This can be `INT64_MAX`
380 * if the source is contained in `fc`.
44c440bc
PP
381 *
382 * `field_path` is an output parameter owned by the caller that must be
383 * filled here.
384 */
385static
386int ptokens_to_field_path(GList *ptokens, struct ctf_field_path *field_path,
0746848c
PP
387 struct ctf_field_class *fc, int64_t src_index,
388 struct resolve_context *ctx)
44c440bc
PP
389{
390 int ret = 0;
391 GList *cur_ptoken = ptokens;
392 bool first_level_done = false;
393
394 /* Locate target */
395 while (cur_ptoken) {
396 int64_t child_index;
5cd6d0e5 397 struct ctf_field_class *child_fc;
44c440bc
PP
398 const char *ft_name = ptoken_get_string(cur_ptoken);
399
3f7d4d90 400 BT_LOGD("Current path token: token=\"%s\"", ft_name);
44c440bc
PP
401
402 /* Find to which index corresponds the current path token */
864cad70
PP
403 if (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY ||
404 fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE) {
44c440bc
PP
405 child_index = -1;
406 } else {
407 child_index =
5cd6d0e5
PP
408 ctf_field_class_compound_get_field_class_index_from_name(
409 fc, ft_name);
44c440bc
PP
410 if (child_index < 0) {
411 /*
412 * Error: field name does not exist or
5cd6d0e5 413 * wrong current class.
44c440bc 414 */
3f7d4d90 415 BT_LOGD("Cannot get index of field class: "
44c440bc
PP
416 "field-name=\"%s\", "
417 "src-index=%" PRId64 ", "
418 "child-index=%" PRId64 ", "
419 "first-level-done=%d",
420 ft_name, src_index, child_index,
421 first_level_done);
422 ret = -1;
423 goto end;
424 } else if (child_index > src_index &&
425 !first_level_done) {
3f7d4d90 426 BT_LOGD("Child field class is located after source field class: "
44c440bc
PP
427 "field-name=\"%s\", "
428 "src-index=%" PRId64 ", "
429 "child-index=%" PRId64 ", "
430 "first-level-done=%d",
431 ft_name, src_index, child_index,
432 first_level_done);
433 ret = -1;
434 goto end;
435 }
436
437 /* Next path token */
438 cur_ptoken = g_list_next(cur_ptoken);
439 first_level_done = true;
440 }
441
442 /* Create new field path entry */
443 ctf_field_path_append_index(field_path, child_index);
444
5cd6d0e5
PP
445 /* Get child field class */
446 child_fc = ctf_field_class_compound_borrow_field_class_by_index(
447 fc, child_index);
448 BT_ASSERT(child_fc);
44c440bc 449
5cd6d0e5
PP
450 /* Move child class to current class */
451 fc = child_fc;
44c440bc
PP
452 }
453
454end:
455 return ret;
456}
457
458/*
459 * Converts a known absolute path token list to a field path object
460 * within the resolving context `ctx`.
461 *
462 * `field_path` is an output parameter owned by the caller that must be
463 * filled here.
464 */
465static
466int absolute_ptokens_to_field_path(GList *ptokens,
467 struct ctf_field_path *field_path,
468 struct resolve_context *ctx)
469{
470 int ret = 0;
471 GList *cur_ptoken;
5cd6d0e5 472 struct ctf_field_class *fc;
44c440bc
PP
473
474 /*
475 * Make sure we're not referring to a scope within a translated
476 * object.
477 */
478 switch (field_path->root) {
83ebb7f1 479 case CTF_SCOPE_PACKET_HEADER:
44c440bc
PP
480 if (ctx->tc->is_translated) {
481 BT_LOGE("Trace class is already translated: "
482 "root-scope=%s",
d4928fcd 483 ctf_scope_string(field_path->root));
44c440bc
PP
484 ret = -1;
485 goto end;
486 }
487
488 break;
83ebb7f1
PP
489 case CTF_SCOPE_PACKET_CONTEXT:
490 case CTF_SCOPE_EVENT_HEADER:
491 case CTF_SCOPE_EVENT_COMMON_CONTEXT:
44c440bc
PP
492 if (!ctx->sc) {
493 BT_LOGE("No current stream class: "
494 "root-scope=%s",
d4928fcd 495 ctf_scope_string(field_path->root));
44c440bc
PP
496 ret = -1;
497 goto end;
498 }
499
500 if (ctx->sc->is_translated) {
501 BT_LOGE("Stream class is already translated: "
502 "root-scope=%s",
d4928fcd 503 ctf_scope_string(field_path->root));
44c440bc
PP
504 ret = -1;
505 goto end;
506 }
507
508 break;
83ebb7f1
PP
509 case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
510 case CTF_SCOPE_EVENT_PAYLOAD:
44c440bc
PP
511 if (!ctx->ec) {
512 BT_LOGE("No current event class: "
513 "root-scope=%s",
d4928fcd 514 ctf_scope_string(field_path->root));
44c440bc
PP
515 ret = -1;
516 goto end;
517 }
518
519 if (ctx->ec->is_translated) {
520 BT_LOGE("Event class is already translated: "
521 "root-scope=%s",
d4928fcd 522 ctf_scope_string(field_path->root));
44c440bc
PP
523 ret = -1;
524 goto end;
525 }
526
527 break;
528
529 default:
530 abort();
531 }
532
533 /* Skip absolute path tokens */
534 cur_ptoken = g_list_nth(ptokens,
535 absolute_path_prefix_ptoken_counts[field_path->root]);
536
5cd6d0e5
PP
537 /* Start with root class */
538 fc = borrow_class_from_ctx(ctx, field_path->root);
539 if (!fc) {
540 /* Error: root class is not available */
541 BT_LOGE("Root field class is not available: "
44c440bc 542 "root-scope=%s",
d4928fcd 543 ctf_scope_string(field_path->root));
44c440bc
PP
544 ret = -1;
545 goto end;
546 }
547
548 /* Locate target */
0746848c 549 ret = ptokens_to_field_path(cur_ptoken, field_path, fc, INT64_MAX, ctx);
44c440bc
PP
550
551end:
552 return ret;
553}
554
555/*
556 * Converts a known relative path token list to a field path object
557 * within the resolving context `ctx`.
558 *
559 * `field_path` is an output parameter owned by the caller that must be
560 * filled here.
561 */
562static
563int relative_ptokens_to_field_path(GList *ptokens,
564 struct ctf_field_path *field_path, struct resolve_context *ctx)
565{
566 int ret = 0;
567 int64_t parent_pos_in_stack;
568 struct ctf_field_path tail_field_path;
569
570 ctf_field_path_init(&tail_field_path);
5cd6d0e5 571 parent_pos_in_stack = field_class_stack_size(ctx->field_class_stack) - 1;
44c440bc
PP
572
573 while (parent_pos_in_stack >= 0) {
5cd6d0e5
PP
574 struct ctf_field_class *parent_class =
575 field_class_stack_at(ctx->field_class_stack,
576 parent_pos_in_stack)->fc;
577 int64_t cur_index = field_class_stack_at(ctx->field_class_stack,
44c440bc
PP
578 parent_pos_in_stack)->index;
579
3f7d4d90 580 BT_LOGD("Locating target field class from current parent field class: "
5cd6d0e5 581 "parent-pos=%" PRId64 ", parent-fc-addr=%p, "
44c440bc 582 "cur-index=%" PRId64,
5cd6d0e5 583 parent_pos_in_stack, parent_class, cur_index);
44c440bc 584
5cd6d0e5 585 /* Locate target from current parent class */
44c440bc 586 ret = ptokens_to_field_path(ptokens, &tail_field_path,
0746848c 587 parent_class, cur_index, ctx);
44c440bc
PP
588 if (ret) {
589 /* Not found... yet */
3f7d4d90 590 BT_LOGD_STR("Not found at this point.");
44c440bc
PP
591 ctf_field_path_clear(&tail_field_path);
592 } else {
593 /* Found: stitch tail field path to head field path */
594 uint64_t i = 0;
595 size_t tail_field_path_len =
596 tail_field_path.path->len;
597
598 while (BT_TRUE) {
5cd6d0e5
PP
599 struct ctf_field_class *cur_class =
600 field_class_stack_at(
601 ctx->field_class_stack, i)->fc;
602 int64_t index = field_class_stack_at(
603 ctx->field_class_stack, i)->index;
44c440bc 604
5cd6d0e5 605 if (cur_class == parent_class) {
44c440bc
PP
606 break;
607 }
608
609 ctf_field_path_append_index(field_path,
610 index);
611 i++;
612 }
613
614 for (i = 0; i < tail_field_path_len; i++) {
615 int64_t index =
616 ctf_field_path_borrow_index_by_index(
617 &tail_field_path, i);
618
619 ctf_field_path_append_index(field_path,
620 (int64_t) index);
621 }
622 break;
623 }
624
625 parent_pos_in_stack--;
626 }
627
628 if (parent_pos_in_stack < 0) {
629 /* Not found */
630 ret = -1;
631 }
632
633 ctf_field_path_fini(&tail_field_path);
634 return ret;
635}
636
637/*
638 * Converts a path string to a field path object within the resolving
639 * context `ctx`.
640 */
641static
642int pathstr_to_field_path(const char *pathstr,
643 struct ctf_field_path *field_path, struct resolve_context *ctx)
644{
645 int ret = 0;
83ebb7f1 646 enum ctf_scope root_scope;
44c440bc
PP
647 GList *ptokens = NULL;
648
649 /* Convert path string to path tokens */
0746848c 650 ptokens = pathstr_to_ptokens(pathstr, ctx);
44c440bc
PP
651 if (!ptokens) {
652 BT_LOGE("Cannot convert path string to path tokens: "
653 "path=\"%s\"", pathstr);
654 ret = -1;
655 goto end;
656 }
657
658 /* Absolute or relative path? */
0746848c 659 root_scope = get_root_scope_from_absolute_pathstr(pathstr, ctx);
44c440bc
PP
660
661 if (root_scope == -1) {
662 /* Relative path: start with current root scope */
663 field_path->root = ctx->root_scope;
3f7d4d90 664 BT_LOGD("Detected relative path: starting with current root scope: "
d4928fcd 665 "scope=%s", ctf_scope_string(field_path->root));
44c440bc
PP
666 ret = relative_ptokens_to_field_path(ptokens, field_path, ctx);
667 if (ret) {
668 BT_LOGE("Cannot get relative field path of path string: "
669 "path=\"%s\", start-scope=%s, end-scope=%s",
d4928fcd
FD
670 pathstr, ctf_scope_string(ctx->root_scope),
671 ctf_scope_string(field_path->root));
44c440bc
PP
672 goto end;
673 }
674 } else {
675 /* Absolute path: use found root scope */
676 field_path->root = root_scope;
3f7d4d90 677 BT_LOGD("Detected absolute path: using root scope: "
d4928fcd 678 "scope=%s", ctf_scope_string(field_path->root));
44c440bc
PP
679 ret = absolute_ptokens_to_field_path(ptokens, field_path, ctx);
680 if (ret) {
681 BT_LOGE("Cannot get absolute field path of path string: "
682 "path=\"%s\", root-scope=%s",
d4928fcd 683 pathstr, ctf_scope_string(root_scope));
44c440bc
PP
684 goto end;
685 }
686 }
687
688 if (BT_LOG_ON_VERBOSE && ret == 0) {
689 GString *field_path_pretty = ctf_field_path_string(field_path);
690 const char *field_path_pretty_str =
691 field_path_pretty ? field_path_pretty->str : NULL;
692
3f7d4d90 693 BT_LOGD("Found field path: path=\"%s\", field-path=\"%s\"",
44c440bc
PP
694 pathstr, field_path_pretty_str);
695
696 if (field_path_pretty) {
697 g_string_free(field_path_pretty, TRUE);
698 }
699 }
700
701end:
702 ptokens_destroy(ptokens);
703 return ret;
704}
705
706/*
5cd6d0e5 707 * Retrieves a field class by following the field path `field_path` in
44c440bc
PP
708 * the resolving context `ctx`.
709 */
710static
5cd6d0e5 711struct ctf_field_class *field_path_to_field_class(
44c440bc
PP
712 struct ctf_field_path *field_path, struct resolve_context *ctx)
713{
714 uint64_t i;
5cd6d0e5 715 struct ctf_field_class *fc;
44c440bc 716
5cd6d0e5
PP
717 /* Start with root class */
718 fc = borrow_class_from_ctx(ctx, field_path->root);
719 if (!fc) {
720 /* Error: root class is not available */
721 BT_LOGE("Root field class is not available: root-scope=%s",
d4928fcd 722 ctf_scope_string(field_path->root));
44c440bc
PP
723 goto end;
724 }
725
726 /* Locate target */
727 for (i = 0; i < field_path->path->len; i++) {
5cd6d0e5 728 struct ctf_field_class *child_fc;
44c440bc
PP
729 int64_t child_index =
730 ctf_field_path_borrow_index_by_index(field_path, i);
731
5cd6d0e5
PP
732 /* Get child field class */
733 child_fc = ctf_field_class_compound_borrow_field_class_by_index(
734 fc, child_index);
735 BT_ASSERT(child_fc);
44c440bc 736
5cd6d0e5
PP
737 /* Move child class to current class */
738 fc = child_fc;
44c440bc
PP
739 }
740
741end:
5cd6d0e5 742 return fc;
44c440bc
PP
743}
744
745/*
5cd6d0e5 746 * Fills the equivalent field path object of the context class stack.
44c440bc
PP
747 */
748static
749void get_ctx_stack_field_path(struct resolve_context *ctx,
750 struct ctf_field_path *field_path)
751{
752 uint64_t i;
753
754 BT_ASSERT(field_path);
755 field_path->root = ctx->root_scope;
756 ctf_field_path_clear(field_path);
757
5cd6d0e5
PP
758 for (i = 0; i < field_class_stack_size(ctx->field_class_stack); i++) {
759 struct field_class_stack_frame *frame =
760 field_class_stack_at(ctx->field_class_stack, i);
44c440bc
PP
761
762 ctf_field_path_append_index(field_path, frame->index);
763 }
764}
765
766/*
767 * Returns the index of the lowest common ancestor of two field path
768 * objects having the same root scope.
769 */
770int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1,
0746848c
PP
771 struct ctf_field_path *field_path2,
772 struct resolve_context *ctx)
44c440bc
PP
773{
774 int64_t lca_index = 0;
775 uint64_t field_path1_len, field_path2_len;
776
777 if (BT_LOG_ON_VERBOSE) {
778 GString *field_path1_pretty =
779 ctf_field_path_string(field_path1);
780 GString *field_path2_pretty =
781 ctf_field_path_string(field_path2);
782 const char *field_path1_pretty_str =
783 field_path1_pretty ? field_path1_pretty->str : NULL;
784 const char *field_path2_pretty_str =
785 field_path2_pretty ? field_path2_pretty->str : NULL;
786
3f7d4d90 787 BT_LOGD("Finding lowest common ancestor (LCA) between two field paths: "
44c440bc
PP
788 "field-path-1=\"%s\", field-path-2=\"%s\"",
789 field_path1_pretty_str, field_path2_pretty_str);
790
791 if (field_path1_pretty) {
792 g_string_free(field_path1_pretty, TRUE);
793 }
794
795 if (field_path2_pretty) {
796 g_string_free(field_path2_pretty, TRUE);
797 }
798 }
799
800 /*
801 * Start from both roots and find the first mismatch.
802 */
803 BT_ASSERT(field_path1->root == field_path2->root);
804 field_path1_len = field_path1->path->len;
805 field_path2_len = field_path2->path->len;
806
807 while (true) {
808 int64_t target_index, ctx_index;
809
810 if (lca_index == (int64_t) field_path2_len ||
811 lca_index == (int64_t) field_path1_len) {
812 /*
813 * This means that both field paths never split.
814 * This is invalid because the target cannot be
815 * an ancestor of the source.
816 */
5cd6d0e5 817 BT_LOGE("Source field class is an ancestor of target field class or vice versa: "
44c440bc
PP
818 "lca-index=%" PRId64 ", "
819 "field-path-1-len=%" PRIu64 ", "
820 "field-path-2-len=%" PRIu64,
821 lca_index, field_path1_len, field_path2_len);
822 lca_index = -1;
823 break;
824 }
825
826 target_index = ctf_field_path_borrow_index_by_index(field_path1,
827 lca_index);
828 ctx_index = ctf_field_path_borrow_index_by_index(field_path2,
829 lca_index);
830
831 if (target_index != ctx_index) {
832 /* LCA index is the previous */
833 break;
834 }
835
836 lca_index++;
837 }
838
3f7d4d90 839 BT_LOGD("Found LCA: lca-index=%" PRId64, lca_index);
44c440bc
PP
840 return lca_index;
841}
842
843/*
844 * Validates a target field path.
845 */
846static
847int validate_target_field_path(struct ctf_field_path *target_field_path,
5cd6d0e5 848 struct ctf_field_class *target_fc,
44c440bc
PP
849 struct resolve_context *ctx)
850{
851 int ret = 0;
852 struct ctf_field_path ctx_field_path;
853 uint64_t target_field_path_len = target_field_path->path->len;
854 int64_t lca_index;
855
856 /* Get context field path */
857 ctf_field_path_init(&ctx_field_path);
858 get_ctx_stack_field_path(ctx, &ctx_field_path);
859
860 /*
861 * Make sure the target is not a root.
862 */
863 if (target_field_path_len == 0) {
864 BT_LOGE_STR("Target field path's length is 0 (targeting the root).");
865 ret = -1;
866 goto end;
867 }
868
869 /*
870 * Make sure the root of the target field path is not located
871 * after the context field path's root.
872 */
873 if (target_field_path->root > ctx_field_path.root) {
5cd6d0e5 874 BT_LOGE("Target field class is located after source field class: "
44c440bc 875 "target-root=%s, source-root=%s",
d4928fcd
FD
876 ctf_scope_string(target_field_path->root),
877 ctf_scope_string(ctx_field_path.root));
44c440bc
PP
878 ret = -1;
879 goto end;
880 }
881
882 if (target_field_path->root == ctx_field_path.root) {
883 int64_t target_index, ctx_index;
884
885 /*
886 * Find the index of the lowest common ancestor of both field
887 * paths.
888 */
889 lca_index = get_field_paths_lca_index(target_field_path,
0746848c 890 &ctx_field_path, ctx);
44c440bc
PP
891 if (lca_index < 0) {
892 BT_LOGE_STR("Cannot get least common ancestor.");
893 ret = -1;
894 goto end;
895 }
896
897 /*
898 * Make sure the target field path is located before the
899 * context field path.
900 */
901 target_index = ctf_field_path_borrow_index_by_index(
902 target_field_path, (uint64_t) lca_index);
903 ctx_index = ctf_field_path_borrow_index_by_index(
904 &ctx_field_path, (uint64_t) lca_index);
905
906 if (target_index >= ctx_index) {
5cd6d0e5 907 BT_LOGE("Target field class's index is greater than or equal to source field class's index in LCA: "
44c440bc
PP
908 "lca-index=%" PRId64 ", "
909 "target-index=%" PRId64 ", "
910 "source-index=%" PRId64,
911 lca_index, target_index, ctx_index);
912 ret = -1;
913 goto end;
914 }
915 }
916
917 /*
5cd6d0e5 918 * Make sure the target class has the right class and properties.
44c440bc 919 */
864cad70
PP
920 switch (ctx->cur_fc->type) {
921 case CTF_FIELD_CLASS_TYPE_VARIANT:
922 if (target_fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
5cd6d0e5
PP
923 BT_LOGE("Variant field class's tag field class is not an enumeration field class: "
924 "tag-fc-addr=%p, tag-fc-id=%d",
864cad70 925 target_fc, target_fc->type);
44c440bc
PP
926 ret = -1;
927 goto end;
928 }
929 break;
864cad70 930 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 931 {
5cd6d0e5 932 struct ctf_field_class_int *int_fc = (void *) target_fc;
44c440bc 933
864cad70
PP
934 if (target_fc->type != CTF_FIELD_CLASS_TYPE_INT &&
935 target_fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
5cd6d0e5
PP
936 BT_LOGE("Sequence field class's length field class is not an unsigned integer field class: "
937 "length-fc-addr=%p, length-fc-id=%d",
864cad70 938 target_fc, target_fc->type);
44c440bc
PP
939 ret = -1;
940 goto end;
941 }
942
5cd6d0e5
PP
943 if (int_fc->is_signed) {
944 BT_LOGE("Sequence field class's length field class is not an unsigned integer field class: "
945 "length-fc-addr=%p, length-fc-id=%d",
864cad70 946 target_fc, target_fc->type);
44c440bc
PP
947 ret = -1;
948 goto end;
949 }
950 break;
951 }
952 default:
953 abort();
954 }
955
956end:
957 ctf_field_path_fini(&ctx_field_path);
958 return ret;
959}
960
961/*
5cd6d0e5 962 * Resolves a variant or sequence field class `fc`.
44c440bc
PP
963 */
964static
5cd6d0e5 965int resolve_sequence_or_variant_field_class(struct ctf_field_class *fc,
44c440bc
PP
966 struct resolve_context *ctx)
967{
968 int ret = 0;
969 const char *pathstr;
970 struct ctf_field_path target_field_path;
5cd6d0e5 971 struct ctf_field_class *target_fc = NULL;
44c440bc
PP
972 GString *target_field_path_pretty = NULL;
973 const char *target_field_path_pretty_str;
974
975 ctf_field_path_init(&target_field_path);
976
977 /* Get path string */
864cad70
PP
978 switch (fc->type) {
979 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 980 {
5cd6d0e5
PP
981 struct ctf_field_class_sequence *seq_fc = (void *) fc;
982 pathstr = seq_fc->length_ref->str;
44c440bc
PP
983 break;
984 }
864cad70 985 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 986 {
5cd6d0e5
PP
987 struct ctf_field_class_variant *var_fc = (void *) fc;
988 pathstr = var_fc->tag_ref->str;
44c440bc
PP
989 break;
990 }
991 default:
992 abort();
993 }
994
995 if (!pathstr) {
996 BT_LOGE_STR("Cannot get path string.");
997 ret = -1;
998 goto end;
999 }
1000
1001 /* Get target field path out of path string */
1002 ret = pathstr_to_field_path(pathstr, &target_field_path, ctx);
1003 if (ret) {
1004 BT_LOGE("Cannot get target field path for path string: "
1005 "path=\"%s\"", pathstr);
1006 goto end;
1007 }
1008
1009 target_field_path_pretty = ctf_field_path_string(
1010 &target_field_path);
1011 target_field_path_pretty_str =
1012 target_field_path_pretty ? target_field_path_pretty->str : NULL;
1013
5cd6d0e5
PP
1014 /* Get target field class */
1015 target_fc = field_path_to_field_class(&target_field_path, ctx);
1016 if (!target_fc) {
1017 BT_LOGE("Cannot get target field class for path string: "
44c440bc
PP
1018 "path=\"%s\", target-field-path=\"%s\"",
1019 pathstr, target_field_path_pretty_str);
1020 ret = -1;
1021 goto end;
1022 }
1023
1024 ret = validate_target_field_path(&target_field_path,
5cd6d0e5 1025 target_fc, ctx);
44c440bc
PP
1026 if (ret) {
1027 BT_LOGE("Invalid target field path for path string: "
1028 "path=\"%s\", target-field-path=\"%s\"",
1029 pathstr, target_field_path_pretty_str);
1030 goto end;
1031 }
1032
5cd6d0e5 1033 /* Set target field path and target field class */
864cad70
PP
1034 switch (fc->type) {
1035 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
44c440bc 1036 {
5cd6d0e5 1037 struct ctf_field_class_sequence *seq_fc = (void *) fc;
44c440bc 1038
5cd6d0e5 1039 ctf_field_path_copy_content(&seq_fc->length_path,
44c440bc 1040 &target_field_path);
5cd6d0e5 1041 seq_fc->length_fc = (void *) target_fc;
44c440bc
PP
1042 break;
1043 }
864cad70 1044 case CTF_FIELD_CLASS_TYPE_VARIANT:
44c440bc 1045 {
5cd6d0e5 1046 struct ctf_field_class_variant *var_fc = (void *) fc;
44c440bc 1047
5cd6d0e5 1048 ctf_field_path_copy_content(&var_fc->tag_path,
44c440bc 1049 &target_field_path);
5cd6d0e5
PP
1050 ctf_field_class_variant_set_tag_field_class(var_fc,
1051 (void *) target_fc);
44c440bc
PP
1052 break;
1053 }
1054 default:
1055 abort();
1056 }
1057
1058end:
1059 if (target_field_path_pretty) {
1060 g_string_free(target_field_path_pretty, TRUE);
1061 }
1062
1063 ctf_field_path_fini(&target_field_path);
1064 return ret;
1065}
1066
1067/*
5cd6d0e5 1068 * Resolves a field class `fc`.
44c440bc
PP
1069 */
1070static
5cd6d0e5 1071int resolve_field_class(struct ctf_field_class *fc, struct resolve_context *ctx)
44c440bc
PP
1072{
1073 int ret = 0;
1074
5cd6d0e5
PP
1075 if (!fc) {
1076 /* Field class is not available; still valid */
44c440bc
PP
1077 goto end;
1078 }
1079
5cd6d0e5 1080 ctx->cur_fc = fc;
44c440bc 1081
5cd6d0e5 1082 /* Resolve sequence/variant field class */
864cad70
PP
1083 switch (fc->type) {
1084 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
1085 case CTF_FIELD_CLASS_TYPE_VARIANT:
5cd6d0e5 1086 ret = resolve_sequence_or_variant_field_class(fc, ctx);
44c440bc 1087 if (ret) {
5cd6d0e5
PP
1088 BT_LOGE("Cannot resolve sequence field class's length or variant field class's tag: "
1089 "ret=%d, fc-addr=%p", ret, fc);
44c440bc
PP
1090 goto end;
1091 }
1092
1093 break;
1094 default:
1095 break;
1096 }
1097
5cd6d0e5 1098 /* Recurse into compound classes */
864cad70
PP
1099 switch (fc->type) {
1100 case CTF_FIELD_CLASS_TYPE_STRUCT:
1101 case CTF_FIELD_CLASS_TYPE_VARIANT:
1102 case CTF_FIELD_CLASS_TYPE_SEQUENCE:
1103 case CTF_FIELD_CLASS_TYPE_ARRAY:
44c440bc
PP
1104 {
1105 uint64_t i;
1106 uint64_t field_count =
5cd6d0e5 1107 ctf_field_class_compound_get_field_class_count(fc);
44c440bc 1108
0746848c 1109 ret = field_class_stack_push(ctx->field_class_stack, fc, ctx);
44c440bc 1110 if (ret) {
5cd6d0e5
PP
1111 BT_LOGE("Cannot push field class on context's stack: "
1112 "fc-addr=%p", fc);
44c440bc
PP
1113 goto end;
1114 }
1115
1116 for (i = 0; i < field_count; i++) {
5cd6d0e5
PP
1117 struct ctf_field_class *child_fc =
1118 ctf_field_class_compound_borrow_field_class_by_index(
1119 fc, i);
44c440bc 1120
5cd6d0e5 1121 BT_ASSERT(child_fc);
44c440bc 1122
864cad70
PP
1123 if (fc->type == CTF_FIELD_CLASS_TYPE_ARRAY||
1124 fc->type == CTF_FIELD_CLASS_TYPE_SEQUENCE) {
5cd6d0e5
PP
1125 field_class_stack_peek(
1126 ctx->field_class_stack)->index = -1;
44c440bc 1127 } else {
5cd6d0e5
PP
1128 field_class_stack_peek(
1129 ctx->field_class_stack)->index =
44c440bc
PP
1130 (int64_t) i;
1131 }
1132
3f7d4d90 1133 BT_LOGD("Resolving field class's child field class: "
5cd6d0e5 1134 "parent-fc-addr=%p, child-fc-addr=%p, "
44c440bc 1135 "index=%" PRIu64 ", count=%" PRIu64,
5cd6d0e5
PP
1136 fc, child_fc, i, field_count);
1137 ret = resolve_field_class(child_fc, ctx);
44c440bc
PP
1138 if (ret) {
1139 goto end;
1140 }
1141 }
1142
0746848c 1143 field_class_stack_pop(ctx->field_class_stack, ctx);
44c440bc
PP
1144 break;
1145 }
1146 default:
1147 break;
1148 }
1149
1150end:
1151 return ret;
1152}
1153
1154/*
5cd6d0e5 1155 * Resolves the root field class corresponding to the scope `root_scope`.
44c440bc
PP
1156 */
1157static
83ebb7f1 1158int resolve_root_class(enum ctf_scope root_scope, struct resolve_context *ctx)
44c440bc
PP
1159{
1160 int ret;
1161
5cd6d0e5 1162 BT_ASSERT(field_class_stack_size(ctx->field_class_stack) == 0);
44c440bc 1163 ctx->root_scope = root_scope;
5cd6d0e5 1164 ret = resolve_field_class(borrow_class_from_ctx(ctx, root_scope), ctx);
44c440bc
PP
1165 ctx->root_scope = -1;
1166 return ret;
1167}
1168
1169static
5cd6d0e5 1170int resolve_event_class_field_classes(struct resolve_context *ctx,
44c440bc
PP
1171 struct ctf_event_class *ec)
1172{
1173 int ret = 0;
1174
1175 BT_ASSERT(!ctx->scopes.event_spec_context);
1176 BT_ASSERT(!ctx->scopes.event_payload);
1177
1178 if (ec->is_translated) {
1179 goto end;
1180 }
1181
1182 ctx->ec = ec;
5cd6d0e5 1183 ctx->scopes.event_spec_context = ec->spec_context_fc;
83ebb7f1 1184 ret = resolve_root_class(CTF_SCOPE_EVENT_COMMON_CONTEXT, ctx);
44c440bc 1185 if (ret) {
5cd6d0e5 1186 BT_LOGE("Cannot resolve event specific context field class: "
44c440bc
PP
1187 "ret=%d", ret);
1188 goto end;
1189 }
1190
5cd6d0e5 1191 ctx->scopes.event_payload = ec->payload_fc;
83ebb7f1 1192 ret = resolve_root_class(CTF_SCOPE_EVENT_PAYLOAD, ctx);
44c440bc 1193 if (ret) {
5cd6d0e5 1194 BT_LOGE("Cannot resolve event payload field class: "
44c440bc
PP
1195 "ret=%d", ret);
1196 goto end;
1197 }
1198
1199end:
1200 ctx->scopes.event_spec_context = NULL;
1201 ctx->scopes.event_payload = NULL;
1202 ctx->ec = NULL;
1203 return ret;
1204}
1205
1206static
5cd6d0e5 1207int resolve_stream_class_field_classes(struct resolve_context *ctx,
44c440bc
PP
1208 struct ctf_stream_class *sc)
1209{
1210 int ret = 0;
1211 uint64_t i;
1212
1213 BT_ASSERT(!ctx->scopes.packet_context);
1214 BT_ASSERT(!ctx->scopes.event_header);
1215 BT_ASSERT(!ctx->scopes.event_common_context);
1216 ctx->sc = sc;
1217
1218 if (!sc->is_translated) {
5cd6d0e5 1219 ctx->scopes.packet_context = sc->packet_context_fc;
83ebb7f1 1220 ret = resolve_root_class(CTF_SCOPE_PACKET_CONTEXT, ctx);
44c440bc 1221 if (ret) {
5cd6d0e5 1222 BT_LOGE("Cannot resolve packet context field class: "
44c440bc
PP
1223 "ret=%d", ret);
1224 goto end;
1225 }
1226
5cd6d0e5 1227 ctx->scopes.event_header = sc->event_header_fc;
83ebb7f1 1228 ret = resolve_root_class(CTF_SCOPE_EVENT_HEADER, ctx);
44c440bc 1229 if (ret) {
5cd6d0e5 1230 BT_LOGE("Cannot resolve event header field class: "
44c440bc
PP
1231 "ret=%d", ret);
1232 goto end;
1233 }
1234
5cd6d0e5 1235 ctx->scopes.event_common_context = sc->event_common_context_fc;
83ebb7f1 1236 ret = resolve_root_class(CTF_SCOPE_EVENT_SPECIFIC_CONTEXT, ctx);
44c440bc 1237 if (ret) {
5cd6d0e5 1238 BT_LOGE("Cannot resolve event common context field class: "
44c440bc
PP
1239 "ret=%d", ret);
1240 goto end;
1241 }
1242 }
1243
5cd6d0e5
PP
1244 ctx->scopes.packet_context = sc->packet_context_fc;
1245 ctx->scopes.event_header = sc->event_header_fc;
1246 ctx->scopes.event_common_context = sc->event_common_context_fc;
44c440bc
PP
1247
1248 for (i = 0; i < sc->event_classes->len; i++) {
1249 struct ctf_event_class *ec = sc->event_classes->pdata[i];
1250
5cd6d0e5 1251 ret = resolve_event_class_field_classes(ctx, ec);
44c440bc 1252 if (ret) {
5cd6d0e5 1253 BT_LOGE("Cannot resolve event class's field classes: "
44c440bc
PP
1254 "ec-id=%" PRIu64 ", ec-name=\"%s\"",
1255 ec->id, ec->name->str);
1256 goto end;
1257 }
1258 }
1259
1260end:
1261 ctx->scopes.packet_context = NULL;
1262 ctx->scopes.event_header = NULL;
1263 ctx->scopes.event_common_context = NULL;
1264 ctx->sc = NULL;
1265 return ret;
1266}
1267
1268BT_HIDDEN
0746848c
PP
1269int ctf_trace_class_resolve_field_classes(struct ctf_trace_class *tc,
1270 bt_logging_level log_level)
44c440bc
PP
1271{
1272 int ret = 0;
1273 uint64_t i;
0746848c
PP
1274 struct resolve_context local_ctx = {
1275 .log_level = log_level,
44c440bc
PP
1276 .tc = tc,
1277 .sc = NULL,
1278 .ec = NULL,
1279 .scopes = {
5cd6d0e5 1280 .packet_header = tc->packet_header_fc,
44c440bc
PP
1281 .packet_context = NULL,
1282 .event_header = NULL,
1283 .event_common_context = NULL,
1284 .event_spec_context = NULL,
1285 .event_payload = NULL,
1286 },
83ebb7f1 1287 .root_scope = CTF_SCOPE_PACKET_HEADER,
5cd6d0e5 1288 .cur_fc = NULL,
44c440bc 1289 };
0746848c 1290 struct resolve_context *ctx = &local_ctx;
44c440bc 1291
5cd6d0e5 1292 /* Initialize class stack */
0746848c
PP
1293 ctx->field_class_stack = field_class_stack_create();
1294 if (!ctx->field_class_stack) {
5cd6d0e5 1295 BT_LOGE_STR("Cannot create field class stack.");
44c440bc
PP
1296 ret = -1;
1297 goto end;
1298 }
1299
1300 if (!tc->is_translated) {
0746848c
PP
1301 ctx->scopes.packet_header = tc->packet_header_fc;
1302 ret = resolve_root_class(CTF_SCOPE_PACKET_HEADER, ctx);
44c440bc 1303 if (ret) {
5cd6d0e5 1304 BT_LOGE("Cannot resolve packet header field class: "
44c440bc
PP
1305 "ret=%d", ret);
1306 goto end;
1307 }
1308 }
1309
0746848c 1310 ctx->scopes.packet_header = tc->packet_header_fc;
44c440bc
PP
1311
1312 for (i = 0; i < tc->stream_classes->len; i++) {
1313 struct ctf_stream_class *sc = tc->stream_classes->pdata[i];
1314
0746848c 1315 ret = resolve_stream_class_field_classes(ctx, sc);
44c440bc 1316 if (ret) {
5cd6d0e5 1317 BT_LOGE("Cannot resolve stream class's field classes: "
44c440bc
PP
1318 "sc-id=%" PRIu64, sc->id);
1319 goto end;
1320 }
1321 }
1322
1323end:
0746848c 1324 field_class_stack_destroy(ctx->field_class_stack);
44c440bc
PP
1325 return ret;
1326}
This page took 0.091076 seconds and 4 git commands to generate.