/*
- * ctf-visitor-generate-ir.c
+ * SPDX-License-Identifier: MIT
*
- * Common Trace Format metadata visitor (generates CTF IR objects).
- *
- * Based on older ctf-visitor-generate-io-struct.c.
- *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright 2015-2018 - Philippe Proulx <philippe.proulx@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:
+ * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2015-2018 Philippe Proulx <philippe.proulx@efficios.com>
*
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Common Trace Format metadata visitor (generates CTF IR objects).
*/
#define BT_COMP_LOG_SELF_COMP (ctx->log_cfg.self_comp)
#define BT_LOG_OUTPUT_LEVEL (ctx->log_cfg.log_level)
#define BT_LOG_TAG "PLUGIN/CTF/META/IR-VISITOR"
-#include "plugins/comp-logging.h"
+#include "logging/comp-logging.h"
#include <stdio.h>
#include <unistd.h>
#include "logging.h"
#include "scanner.h"
-#include "parser.h"
#include "ast.h"
#include "decoder.h"
#include "ctf-meta.h"
int visit_field_class_specifier_list(struct ctx *ctx, struct ctf_node *ts_list,
struct ctf_field_class **decl);
-static
-char *remove_underscores_from_field_ref(struct ctx *ctx, const char *field_ref)
-{
- const char *in_ch;
- char *out_ch;
- char *ret;
- enum {
- UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE,
- UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE,
- } state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
-
- BT_ASSERT(field_ref);
- ret = calloc(strlen(field_ref) + 1, 1);
- if (!ret) {
- BT_COMP_LOGE("Failed to allocate a string: size=%zu",
- strlen(field_ref) + 1);
- goto end;
- }
-
- in_ch = field_ref;
- out_ch = ret;
-
- while (*in_ch != '\0') {
- switch (*in_ch) {
- case ' ':
- case '\t':
- /* Remove whitespace */
- in_ch++;
- continue;
- case '_':
- if (state == UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE) {
- in_ch++;
- state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE;
- continue;
- }
-
- goto copy;
- case '.':
- state = UNDERSCORE_REMOVE_STATE_REMOVE_NEXT_UNDERSCORE;
- goto copy;
- default:
- state = UNDERSCORE_REMOVE_STATE_DO_NOT_REMOVE_NEXT_UNDERSCORE;
- goto copy;
- }
-
-copy:
- *out_ch = *in_ch;
- in_ch++;
- out_ch++;
- }
-
-end:
- return ret;
-}
-
static
int is_unary_string(struct bt_list_head *head)
{
return ret;
}
-static
-char *concatenate_unary_strings(struct bt_list_head *head)
-{
- int i = 0;
- GString *str;
- struct ctf_node *node;
-
- str = g_string_new(NULL);
- BT_ASSERT(str);
-
- bt_list_for_each_entry(node, head, siblings) {
- char *src_string;
-
- if (
- node->type != NODE_UNARY_EXPRESSION ||
- node->u.unary_expression.type != UNARY_STRING ||
- !(
- (
- node->u.unary_expression.link !=
- UNARY_LINK_UNKNOWN
- ) ^ (i == 0)
- )
- ) {
- goto error;
- }
-
- switch (node->u.unary_expression.link) {
- case UNARY_DOTLINK:
- g_string_append(str, ".");
- break;
- case UNARY_ARROWLINK:
- g_string_append(str, "->");
- break;
- case UNARY_DOTDOTDOT:
- g_string_append(str, "...");
- break;
- default:
- break;
- }
-
- src_string = node->u.unary_expression.u.string;
- g_string_append(str, src_string);
- i++;
- }
-
- /* Destroys the container, returns the underlying string */
- return g_string_free(str, FALSE);
-
-error:
- /* This always returns NULL */
- return g_string_free(str, TRUE);
-}
-
static
const char *get_map_clock_name_value(struct bt_list_head *head)
{
static
int get_unary_uuid(struct ctx *ctx, struct bt_list_head *head,
- uint8_t *uuid)
+ bt_uuid_t uuid)
{
- int i = 0;
- int ret = 0;
- struct ctf_node *node;
-
- bt_list_for_each_entry(node, head, siblings) {
- int uexpr_type = node->u.unary_expression.type;
- int uexpr_link = node->u.unary_expression.link;
- const char *src_string;
-
- if (node->type != NODE_UNARY_EXPRESSION ||
- uexpr_type != UNARY_STRING ||
- uexpr_link != UNARY_LINK_UNKNOWN ||
- i != 0) {
- ret = -EINVAL;
- goto end;
- }
-
- src_string = node->u.unary_expression.u.string;
- ret = bt_uuid_from_str(src_string, uuid);
- if (ret) {
- _BT_COMP_LOGE_NODE(node,
- "Cannot parse UUID: uuid=\"%s\"", src_string);
- goto end;
- }
- }
-
-end:
- return ret;
+ return ctf_ast_get_unary_uuid(head, uuid, ctx->log_cfg.log_level,
+ ctx->log_cfg.self_comp);
}
static
struct ctf_node *unary_expr)
{
const char *str;
- enum ctf_byte_order bo = -1;
+ enum ctf_byte_order bo = CTF_BYTE_ORDER_UNKNOWN;
if (unary_expr->u.unary_expression.type != UNARY_STRING) {
_BT_COMP_LOGE_NODE(unary_expr,
const char *id =
node_field_class_declarator->u.field_class_declarator.u.id;
- if (id[0] == '_') {
- id++;
- }
-
*field_name = g_quark_from_string(id);
} else {
*field_name = 0;
{
/* Lookup unsigned integer definition, create seq. */
struct ctf_field_class_sequence *seq_decl = NULL;
- char *length_name = concatenate_unary_strings(length);
+ char *length_name = ctf_ast_concatenate_unary_strings(length);
if (!length_name) {
_BT_COMP_LOGE_NODE(node_field_class_declarator,
nested_decl = NULL;
decl = (void *) array_decl;
} else {
- char *length_name_no_underscore =
- remove_underscores_from_field_ref(ctx,
- length_name);
- if (!length_name_no_underscore) {
- /*
- * remove_underscores_from_field_ref()
- * logs errors
- */
- ret = -EINVAL;
- goto error;
- }
seq_decl = ctf_field_class_sequence_create();
BT_ASSERT(seq_decl);
seq_decl->base.elem_fc = nested_decl;
nested_decl = NULL;
g_string_assign(seq_decl->length_ref,
- length_name_no_underscore);
- free(length_name_no_underscore);
+ length_name);
decl = (void *) seq_decl;
}
* At this point, we have a fresh untagged variant; nobody
* else owns it. Set its tag now.
*/
- char *tag_no_underscore =
- remove_underscores_from_field_ref(ctx, tag);
-
- if (!tag_no_underscore) {
- /* remove_underscores_from_field_ref() logs errors */
- goto error;
- }
-
- g_string_assign(untagged_variant_decl->tag_ref,
- tag_no_underscore);
- free(tag_no_underscore);
+ g_string_assign(untagged_variant_decl->tag_ref, tag);
*variant_decl = untagged_variant_decl;
untagged_variant_decl = NULL;
}
.value.u = 0,
};
const char *label = enumerator->u.enumerator.id;
- const char *effective_label = label;
struct bt_list_head *values = &enumerator->u.enumerator.values;
bt_list_for_each_entry(iter, values, siblings) {
last->value.u = end.value.u + 1;
}
- if (label[0] == '_') {
- /*
- * Strip the first underscore of any enumeration field
- * class's label in case this enumeration FC is used as
- * a variant FC tag later. The variant FC choice names
- * could also start with `_`, in which case the prefix
- * is removed, and it the resulting choice name needs to
- * match tag labels.
- */
- effective_label = &label[1];
- }
-
- ctf_field_class_enum_append_mapping(enum_decl, effective_label,
+ ctf_field_class_enum_map_range(enum_decl, label,
start.value.u, end.value.u);
return 0;
}
byte_order = get_real_byte_order(ctx, right);
- if (byte_order == -1) {
+ if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
_BT_COMP_LOGE_NODE(right,
"Invalid `byte_order` attribute in integer field class: "
"ret=%d", ret);
}
case UNARY_STRING:
{
- char *s_right = concatenate_unary_strings(
+ char *s_right = ctf_ast_concatenate_unary_strings(
&expression->u.ctf_expression.right);
if (!s_right) {
_BT_COMP_LOGE_NODE(right,
goto error;
}
- s_right = concatenate_unary_strings(
+ s_right = ctf_ast_concatenate_unary_strings(
&expression->u.ctf_expression.right);
if (!s_right) {
_BT_COMP_LOGE_NODE(right,
get_map_clock_name_value(
&expression->u.ctf_expression.right);
if (!clock_name) {
- char *s_right = concatenate_unary_strings(
+ char *s_right = ctf_ast_concatenate_unary_strings(
&expression->u.ctf_expression.right);
if (!s_right) {
}
byte_order = get_real_byte_order(ctx, right);
- if (byte_order == -1) {
+ if (byte_order == CTF_BYTE_ORDER_UNKNOWN) {
_BT_COMP_LOGE_NODE(right,
"Invalid `byte_order` attribute in floating point number field class: "
"ret=%d", ret);
goto error;
}
- s_right = concatenate_unary_strings(
+ s_right = ctf_ast_concatenate_unary_strings(
&expression->u.ctf_expression.right);
if (!s_right) {
_BT_COMP_LOGE_NODE(right,
break;
case NODE_CTF_EXPRESSION:
{
- left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(node, "Cannot concatenate unary strings.");
ret = -EINVAL;
_SET(set, _EVENT_FIELDS_SET);
} else if (strcmp(left, "loglevel") == 0) {
uint64_t loglevel_value;
+ bool is_log_level_known = true;
bt_event_class_log_level log_level = -1;
if (_IS_SET(set, _EVENT_LOG_LEVEL_SET)) {
log_level = BT_EVENT_CLASS_LOG_LEVEL_DEBUG;
break;
default:
+ is_log_level_known = false;
_BT_COMP_LOGW_NODE(node, "Not setting event class's log level because its value is unknown: "
"log-level=%" PRIu64, loglevel_value);
}
- if (log_level != -1) {
- event_class->log_level = log_level;
+ if (is_log_level_known) {
+ ctf_event_class_set_log_level(event_class, log_level);
}
_SET(set, _EVENT_LOG_LEVEL_SET);
goto error;
}
- right = concatenate_unary_strings(
+ right = ctf_ast_concatenate_unary_strings(
&node->u.ctf_expression.right);
if (!right) {
_BT_COMP_LOGE_NODE(node,
continue;
}
- left = concatenate_unary_strings(&iter->u.ctf_expression.left);
+ left = ctf_ast_concatenate_unary_strings(&iter->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(iter,
"Cannot concatenate unary strings.");
}
if (strcmp(left, "name") == 0) {
- name = concatenate_unary_strings(
+ name = ctf_ast_concatenate_unary_strings(
&iter->u.ctf_expression.right);
if (!name) {
_BT_COMP_LOGE_NODE(iter,
} else if (root_fc->type == CTF_FIELD_CLASS_TYPE_VARIANT) {
named_fc = ctf_field_class_variant_borrow_option_by_index(
var_fc, i);
+ } else {
+ bt_common_abort();
}
if (strcmp(named_fc->name->str, field_name) == 0) {
break;
case NODE_CTF_EXPRESSION:
{
- left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(node, "Cannot concatenate unary strings.");
ret = -EINVAL;
break;
case NODE_CTF_EXPRESSION:
{
- left = concatenate_unary_strings(&node->u.ctf_expression.left);
+ left = ctf_ast_concatenate_unary_strings(&node->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(node, "Cannot concatenate unary strings.");
ret = -EINVAL;
goto error;
}
- BT_ASSERT(ctx->ctf_tc->default_byte_order != -1);
+ BT_ASSERT(ctx->ctf_tc->default_byte_order != CTF_BYTE_ORDER_UNKNOWN);
_SET(set, _TRACE_BYTE_ORDER_SET);
} else if (strcmp(left, "packet.header") == 0) {
if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) {
goto error;
}
- left = concatenate_unary_strings(
+ left = ctf_ast_concatenate_unary_strings(
&entry_node->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(entry_node,
}
if (is_unary_string(right_head)) {
- char *right = concatenate_unary_strings(right_head);
+ char *right = ctf_ast_concatenate_unary_strings(right_head);
if (!right) {
_BT_COMP_LOGE_NODE(entry_node,
if (node->type == NODE_CTF_EXPRESSION) {
struct ctf_node *right_node;
- left = concatenate_unary_strings(
+ left = ctf_ast_concatenate_unary_strings(
&node->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(node,
struct ctf_node, siblings);
bo = byte_order_from_unary_expr(ctx,
right_node);
- if (bo == -1) {
+ if (bo == CTF_BYTE_ORDER_UNKNOWN) {
_BT_COMP_LOGE_NODE(node,
"Invalid `byte_order` attribute in trace (`trace` block): "
"expecting `le`, `be`, or `network`.");
goto error;
}
- left = concatenate_unary_strings(&entry_node->u.ctf_expression.left);
+ left = ctf_ast_concatenate_unary_strings(&entry_node->u.ctf_expression.left);
if (!left) {
_BT_COMP_LOGE_NODE(entry_node, "Cannot concatenate unary strings.");
ret = -EINVAL;
goto error;
}
- right = concatenate_unary_strings(
+ right = ctf_ast_concatenate_unary_strings(
&entry_node->u.ctf_expression.right);
if (!right) {
_BT_COMP_LOGE_NODE(entry_node,
goto error;
}
- right = concatenate_unary_strings(
+ right = ctf_ast_concatenate_unary_strings(
&entry_node->u.ctf_expression.right);
if (!right) {
_BT_COMP_LOGE_NODE(entry_node,
}
}
+static
+void apply_clock_class_is_absolute(struct ctx *ctx,
+ struct ctf_clock_class *clock)
+{
+ if (ctx->decoder_config.force_clock_class_origin_unix_epoch) {
+ clock->is_absolute = true;
+ }
+
+ return;
+}
+
static
void apply_clock_class_offset(struct ctx *ctx,
struct ctf_clock_class *clock)
clock->offset_seconds = offset_seconds;
clock->offset_cycles = offset_cycles;
apply_clock_class_offset(ctx, clock);
+ apply_clock_class_is_absolute(ctx, clock);
g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
clock = NULL;
/* Create visitor's context */
ctx = ctx_create(decoder_config);
if (!ctx) {
- BT_COMP_LOGE_STR("Cannot create visitor's context.");
+ BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, decoder_config->log_level,
+ decoder_config->self_comp,
+ "Cannot create visitor's context.");
goto error;
}
{
struct ctx *ctx = (void *) visitor;
- BT_ASSERT(ctx);
+ BT_ASSERT_DBG(ctx);
if (ctx->trace_class) {
bt_trace_class_get_ref(ctx->trace_class);
{
struct ctx *ctx = (void *) visitor;
- BT_ASSERT(ctx);
- BT_ASSERT(ctx->ctf_tc);
+ BT_ASSERT_DBG(ctx);
+ BT_ASSERT_DBG(ctx->ctf_tc);
return ctx->ctf_tc;
}
* have the native byte order yet, and we don't have any
* trace block yet, then fail with EINCOMPLETE.
*/
- if (ctx->ctf_tc->default_byte_order == -1) {
+ if (ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_UNKNOWN) {
bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
if (got_trace_decl) {
_BT_COMP_LOGE_NODE(node,
BT_ASSERT(ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_LITTLE ||
ctx->ctf_tc->default_byte_order == CTF_BYTE_ORDER_BIG);
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/* Environment */
bt_list_for_each_entry(iter, &node->u.root.env, siblings) {
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/*
* Visit clock blocks.
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/*
* Visit root declarations next, as they can be used by any
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/* Callsite blocks are not supported */
bt_list_for_each_entry(iter, &node->u.root.callsite, siblings) {
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/* Trace */
bt_list_for_each_entry(iter, &node->u.root.trace, siblings) {
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/* Streams */
bt_list_for_each_entry(iter, &node->u.root.stream, siblings) {
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
/* Events */
bt_list_for_each_entry(iter, &node->u.root.event, siblings) {
}
BT_ASSERT(ctx->current_scope &&
- ctx->current_scope->parent_scope == NULL);
+ !ctx->current_scope->parent_scope);
break;
}
default:
goto end;
}
+ /* Update structure/array/sequence alignments */
+ ret = ctf_trace_class_update_alignments(ctx->ctf_tc);
+ if (ret) {
+ ret = -EINVAL;
+ goto end;
+ }
+
/* Resolve sequence lengths and variant tags */
ret = ctf_trace_class_resolve_field_classes(ctx->ctf_tc, &ctx->log_cfg);
if (ret) {