/*
- * Copyright 2016-2018 - Philippe Proulx <pproulx@efficios.com>
- * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * SPDX-License-Identifier: MIT
*
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*/
#define BT_COMP_LOG_SELF_COMP (ctx->self_comp)
+#define BT_COMP_LOG_SELF_COMP_CLASS (ctx->self_comp_class)
#define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
#define BT_LOG_TAG "PLUGIN/CTF/META/RESOLVE"
-#include "plugins/comp-logging.h"
+#include "logging/comp-logging.h"
#include <babeltrace2/babeltrace.h>
#include "common/macros.h"
#include "common/assert.h"
#include "common/common.h"
#include <glib.h>
+#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <inttypes.h>
*/
struct resolve_context {
bt_logging_level log_level;
+
+ /* Weak, exactly one of these must be set */
bt_self_component *self_comp;
+ bt_self_component_class *self_comp_class;
+
struct ctf_trace_class *tc;
struct ctf_stream_class *sc;
struct ctf_event_class *ec;
struct field_class_stack_frame *frame = NULL;
if (!stack || !fc) {
- BT_COMP_LOGE("Invalid parameter: stack or field class is NULL.");
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid parameter: stack or field class is `NULL`.");
ret = -1;
goto end;
}
frame = g_new0(struct field_class_stack_frame, 1);
if (!frame) {
- BT_COMP_LOGE_STR("Failed to allocate one field class stack frame.");
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Failed to allocate one field class stack frame.");
ret = -1;
goto end;
}
static
struct field_class_stack_frame *field_class_stack_peek(field_class_stack *stack)
{
- struct field_class_stack_frame *entry = NULL;
-
- if (!stack || field_class_stack_empty(stack)) {
- goto end;
- }
+ BT_ASSERT(stack);
+ BT_ASSERT(!field_class_stack_empty(stack));
- entry = g_ptr_array_index(stack, stack->len - 1);
-end:
- return entry;
+ return g_ptr_array_index(stack, stack->len - 1);
}
/*
struct field_class_stack_frame *field_class_stack_at(field_class_stack *stack,
size_t index)
{
- struct field_class_stack_frame *entry = NULL;
-
- if (!stack || index >= stack->len) {
- goto end;
- }
+ BT_ASSERT(stack);
+ BT_ASSERT(index < stack->len);
- entry = g_ptr_array_index(stack, index);
-
-end:
- return entry;
+ return g_ptr_array_index(stack, index);
}
/*
case CTF_SCOPE_EVENT_PAYLOAD:
return ctx->scopes.event_payload;
default:
- abort();
+ bt_common_abort();
}
return NULL;
struct resolve_context *ctx)
{
enum ctf_scope scope;
- enum ctf_scope ret = -1;
+ enum ctf_scope ret = CTF_SCOPE_PACKET_UNKNOWN;
const size_t prefixes_count = sizeof(absolute_path_prefixes) /
sizeof(*absolute_path_prefixes);
for (scope = CTF_SCOPE_PACKET_HEADER; scope < CTF_SCOPE_PACKET_HEADER +
prefixes_count; scope++) {
/*
- * Chech if path string starts with a known absolute
+ * Check if path string starts with a known absolute
* path prefix.
*
* Refer to CTF 7.3.2 STATIC AND DYNAMIC SCOPES.
if (at == last) {
/* Error: empty token */
- BT_COMP_LOGE("Empty path token: path=\"%s\", pos=%u",
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Empty path token: path=\"%s\", pos=%u",
pathstr, (unsigned int) (at - pathstr));
goto error;
}
switch (field_path->root) {
case CTF_SCOPE_PACKET_HEADER:
if (ctx->tc->is_translated) {
- BT_COMP_LOGE("Trace class is already translated: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Trace class is already translated: "
"root-scope=%s",
ctf_scope_string(field_path->root));
ret = -1;
case CTF_SCOPE_EVENT_HEADER:
case CTF_SCOPE_EVENT_COMMON_CONTEXT:
if (!ctx->sc) {
- BT_COMP_LOGE("No current stream class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("No current stream class: "
"root-scope=%s",
ctf_scope_string(field_path->root));
ret = -1;
}
if (ctx->sc->is_translated) {
- BT_COMP_LOGE("Stream class is already translated: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Stream class is already translated: "
"root-scope=%s",
ctf_scope_string(field_path->root));
ret = -1;
case CTF_SCOPE_EVENT_SPECIFIC_CONTEXT:
case CTF_SCOPE_EVENT_PAYLOAD:
if (!ctx->ec) {
- BT_COMP_LOGE("No current event class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("No current event class: "
"root-scope=%s",
ctf_scope_string(field_path->root));
ret = -1;
}
if (ctx->ec->is_translated) {
- BT_COMP_LOGE("Event class is already translated: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Event class is already translated: "
"root-scope=%s",
ctf_scope_string(field_path->root));
ret = -1;
break;
default:
- abort();
+ bt_common_abort();
}
/* Skip absolute path tokens */
fc = borrow_class_from_ctx(ctx, field_path->root);
if (!fc) {
/* Error: root class is not available */
- BT_COMP_LOGE("Root field class is not available: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Root field class is not available: "
"root-scope=%s",
ctf_scope_string(field_path->root));
ret = -1;
/* Convert path string to path tokens */
ptokens = pathstr_to_ptokens(pathstr, ctx);
if (!ptokens) {
- BT_COMP_LOGE("Cannot convert path string to path tokens: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot convert path string to path tokens: "
"path=\"%s\"", pathstr);
ret = -1;
goto end;
/* Absolute or relative path? */
root_scope = get_root_scope_from_absolute_pathstr(pathstr, ctx);
- if (root_scope == -1) {
+ if (root_scope == CTF_SCOPE_PACKET_UNKNOWN) {
/* Relative path: start with current root scope */
field_path->root = ctx->root_scope;
BT_COMP_LOGD("Detected relative path: starting with current root scope: "
"scope=%s", ctf_scope_string(field_path->root));
ret = relative_ptokens_to_field_path(ptokens, field_path, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot get relative field path of path string: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get relative field path of path string: "
"path=\"%s\", start-scope=%s, end-scope=%s",
pathstr, ctf_scope_string(ctx->root_scope),
ctf_scope_string(field_path->root));
"scope=%s", ctf_scope_string(field_path->root));
ret = absolute_ptokens_to_field_path(ptokens, field_path, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot get absolute field path of path string: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get absolute field path of path string: "
"path=\"%s\", root-scope=%s",
pathstr, ctf_scope_string(root_scope));
goto end;
fc = borrow_class_from_ctx(ctx, field_path->root);
if (!fc) {
/* Error: root class is not available */
- BT_COMP_LOGE("Root field class is not available: root-scope=%s",
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Root field class is not available: root-scope=%s",
ctf_scope_string(field_path->root));
goto end;
}
* Returns the index of the lowest common ancestor of two field path
* objects having the same root scope.
*/
+static
int64_t get_field_paths_lca_index(struct ctf_field_path *field_path1,
struct ctf_field_path *field_path2,
struct resolve_context *ctx)
* This is invalid because the target cannot be
* an ancestor of the source.
*/
- BT_COMP_LOGE("Source field class is an ancestor of target field class or vice versa: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Source field class is an ancestor of target field class or vice versa: "
"lca-index=%" PRId64 ", "
"field-path-1-len=%" PRIu64 ", "
"field-path-2-len=%" PRIu64,
* Make sure the target is not a root.
*/
if (target_field_path_len == 0) {
- BT_COMP_LOGE_STR("Target field path's length is 0 (targeting the root).");
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Target field path's length is 0 (targeting the root).");
ret = -1;
goto end;
}
* after the context field path's root.
*/
if (target_field_path->root > ctx_field_path.root) {
- BT_COMP_LOGE("Target field class is located after source field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Target field class is located after source field class: "
"target-root=%s, source-root=%s",
ctf_scope_string(target_field_path->root),
ctf_scope_string(ctx_field_path.root));
lca_index = get_field_paths_lca_index(target_field_path,
&ctx_field_path, ctx);
if (lca_index < 0) {
- BT_COMP_LOGE_STR("Cannot get least common ancestor.");
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get least common ancestor.");
ret = -1;
goto end;
}
&ctx_field_path, (uint64_t) lca_index);
if (target_index >= ctx_index) {
- BT_COMP_LOGE("Target field class's index is greater than or equal to source field class's index in LCA: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Target field class's index is greater than or equal to source field class's index in LCA: "
"lca-index=%" PRId64 ", "
"target-index=%" PRId64 ", "
"source-index=%" PRId64,
switch (ctx->cur_fc->type) {
case CTF_FIELD_CLASS_TYPE_VARIANT:
if (target_fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
- BT_COMP_LOGE("Variant field class's tag field class is not an enumeration field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Variant field class's tag field class is not an enumeration field class: "
"tag-fc-addr=%p, tag-fc-id=%d",
target_fc, target_fc->type);
ret = -1;
if (target_fc->type != CTF_FIELD_CLASS_TYPE_INT &&
target_fc->type != CTF_FIELD_CLASS_TYPE_ENUM) {
- BT_COMP_LOGE("Sequence field class's length field class is not an unsigned integer field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Sequence field class's length field class is not an unsigned integer field class: "
"length-fc-addr=%p, length-fc-id=%d",
target_fc, target_fc->type);
ret = -1;
}
if (int_fc->is_signed) {
- BT_COMP_LOGE("Sequence field class's length field class is not an unsigned integer field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Sequence field class's length field class is not an unsigned integer field class: "
"length-fc-addr=%p, length-fc-id=%d",
target_fc, target_fc->type);
ret = -1;
break;
}
default:
- abort();
+ bt_common_abort();
}
end:
break;
}
default:
- abort();
+ bt_common_abort();
}
if (!pathstr) {
- BT_COMP_LOGE_STR("Cannot get path string.");
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get path string.");
ret = -1;
goto end;
}
/* Get target field path out of path string */
ret = pathstr_to_field_path(pathstr, &target_field_path, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot get target field path for path string: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get target field path for path string: "
"path=\"%s\"", pathstr);
goto end;
}
/* Get target field class */
target_fc = field_path_to_field_class(&target_field_path, ctx);
if (!target_fc) {
- BT_COMP_LOGE("Cannot get target field class for path string: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot get target field class for path string: "
"path=\"%s\", target-field-path=\"%s\"",
pathstr, target_field_path_pretty_str);
ret = -1;
ret = validate_target_field_path(&target_field_path,
target_fc, ctx);
if (ret) {
- BT_COMP_LOGE("Invalid target field path for path string: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid target field path for path string: "
"path=\"%s\", target-field-path=\"%s\"",
pathstr, target_field_path_pretty_str);
goto end;
break;
}
default:
- abort();
+ bt_common_abort();
}
end:
case CTF_FIELD_CLASS_TYPE_VARIANT:
ret = resolve_sequence_or_variant_field_class(fc, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve sequence field class's length or variant field class's tag: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve sequence field class's length or variant field class's tag: "
"ret=%d, fc-addr=%p", ret, fc);
goto end;
}
ret = field_class_stack_push(ctx->field_class_stack, fc, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot push field class on context's stack: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot push field class on context's stack: "
"fc-addr=%p", fc);
goto end;
}
ctx->scopes.event_spec_context = ec->spec_context_fc;
ret = resolve_root_class(CTF_SCOPE_EVENT_COMMON_CONTEXT, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve event specific context field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event specific context field class: "
"ret=%d", ret);
goto end;
}
ctx->scopes.event_payload = ec->payload_fc;
ret = resolve_root_class(CTF_SCOPE_EVENT_PAYLOAD, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve event payload field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event payload field class: "
"ret=%d", ret);
goto end;
}
ctx->scopes.packet_context = sc->packet_context_fc;
ret = resolve_root_class(CTF_SCOPE_PACKET_CONTEXT, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve packet context field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve packet context field class: "
"ret=%d", ret);
goto end;
}
ctx->scopes.event_header = sc->event_header_fc;
ret = resolve_root_class(CTF_SCOPE_EVENT_HEADER, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve event header field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event header field class: "
"ret=%d", ret);
goto end;
}
ctx->scopes.event_common_context = sc->event_common_context_fc;
- ret = resolve_root_class(CTF_SCOPE_EVENT_SPECIFIC_CONTEXT, ctx);
+ ret = resolve_root_class(CTF_SCOPE_EVENT_COMMON_CONTEXT, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve event common context field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event common context field class: "
"ret=%d", ret);
goto end;
}
ret = resolve_event_class_field_classes(ctx, ec);
if (ret) {
- BT_COMP_LOGE("Cannot resolve event class's field classes: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve event class's field classes: "
"ec-id=%" PRIu64 ", ec-name=\"%s\"",
ec->id, ec->name->str);
goto end;
struct resolve_context local_ctx = {
.log_level = log_cfg->log_level,
.self_comp = log_cfg->self_comp,
+ .self_comp_class = log_cfg->self_comp_class,
.tc = tc,
.sc = NULL,
.ec = NULL,
/* Initialize class stack */
ctx->field_class_stack = field_class_stack_create();
if (!ctx->field_class_stack) {
- BT_COMP_LOGE_STR("Cannot create field class stack.");
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot create field class stack.");
ret = -1;
goto end;
}
ctx->scopes.packet_header = tc->packet_header_fc;
ret = resolve_root_class(CTF_SCOPE_PACKET_HEADER, ctx);
if (ret) {
- BT_COMP_LOGE("Cannot resolve packet header field class: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve packet header field class: "
"ret=%d", ret);
goto end;
}
ret = resolve_stream_class_field_classes(ctx, sc);
if (ret) {
- BT_COMP_LOGE("Cannot resolve stream class's field classes: "
+ _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot resolve stream class's field classes: "
"sc-id=%" PRIu64, sc->id);
goto end;
}