/*
- * 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:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
+ * Copyright 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2015-2018 Philippe Proulx <philippe.proulx@efficios.com>
*
- * 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)
#include "logging.h"
#include "scanner.h"
-#include "parser.h"
#include "ast.h"
#include "decoder.h"
#include "ctf-meta.h"
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
{
/* 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,
}
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) {
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;
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;
}
- 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,
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;
}
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) {