X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmetadata%2Fvisitor-generate-ir.c;h=604388b4cf2e17cf005a05ca9b9ab60911280f8f;hb=498e7994d60bd0e9f63c3d5c0fd00eec77ba7c34;hp=9b0f16e674406ba319c698b660665395d5b4d613;hpb=6da709aa5711ee57761028c143fc00b65026c15d;p=babeltrace.git diff --git a/src/plugins/ctf/common/metadata/visitor-generate-ir.c b/src/plugins/ctf/common/metadata/visitor-generate-ir.c index 9b0f16e6..604388b4 100644 --- a/src/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/src/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -49,7 +49,6 @@ #include "logging.h" #include "scanner.h" -#include "parser.h" #include "ast.h" #include "decoder.h" #include "ctf-meta.h" @@ -698,59 +697,6 @@ 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) { @@ -924,36 +870,10 @@ end: 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 @@ -1009,7 +929,7 @@ enum ctf_byte_order byte_order_from_unary_expr(struct ctx *ctx, 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, @@ -1381,7 +1301,7 @@ int visit_field_class_declarator(struct ctx *ctx, { /* 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, @@ -2329,7 +2249,7 @@ int visit_integer_decl(struct ctx *ctx, } 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); @@ -2445,7 +2365,7 @@ int visit_integer_decl(struct ctx *ctx, } 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, @@ -2512,7 +2432,7 @@ int visit_integer_decl(struct ctx *ctx, 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, @@ -2564,7 +2484,7 @@ int visit_integer_decl(struct ctx *ctx, 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) { @@ -2676,7 +2596,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, } 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); @@ -2868,7 +2788,7 @@ int visit_string_decl(struct ctx *ctx, 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, @@ -3068,7 +2988,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, 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; @@ -3259,7 +3179,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto error; } - right = concatenate_unary_strings( + right = ctf_ast_concatenate_unary_strings( &node->u.ctf_expression.right); if (!right) { _BT_COMP_LOGE_NODE(node, @@ -3315,7 +3235,7 @@ char *get_event_decl_name(struct ctx *ctx, struct ctf_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."); @@ -3323,7 +3243,7 @@ char *get_event_decl_name(struct ctx *ctx, struct ctf_node *node) } 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, @@ -3574,6 +3494,8 @@ int auto_map_fields_to_trace_clock_class(struct ctx *ctx, } 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) { @@ -3628,7 +3550,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, 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; @@ -3904,7 +3826,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) 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; @@ -3986,7 +3908,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) 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)) { @@ -4122,7 +4044,7 @@ int visit_env(struct ctx *ctx, struct ctf_node *node) 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, @@ -4132,7 +4054,7 @@ int visit_env(struct ctx *ctx, struct ctf_node *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, @@ -4207,7 +4129,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_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, @@ -4232,7 +4154,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_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`."); @@ -4284,7 +4206,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_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; @@ -4300,7 +4222,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_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, @@ -4342,7 +4264,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_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, @@ -4503,6 +4425,17 @@ void calibrate_clock_class_offsets(int64_t *offset_seconds, } } +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) @@ -4630,6 +4563,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node) 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; @@ -4714,7 +4648,9 @@ struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create( /* 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; } @@ -4740,7 +4676,7 @@ bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class( { struct ctx *ctx = (void *) visitor; - BT_ASSERT(ctx); + BT_ASSERT_DBG(ctx); if (ctx->trace_class) { bt_trace_class_get_ref(ctx->trace_class); @@ -4755,8 +4691,8 @@ struct ctf_trace_class *ctf_visitor_generate_ir_borrow_ctf_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; } @@ -4782,7 +4718,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, * 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,