X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Fcommon%2Fmetadata%2Fvisitor-generate-ir.c;h=cfb577053cb2e351d5c57784a30f0046cf9f37d0;hp=56e5b70605471f3ab5164fd595d336120039029a;hb=0235b0db7de5bcacdb3650c92461f2ce5eb2143d;hpb=6162e6b7a6d907974d954419c2375f654f39eb72 diff --git a/src/plugins/ctf/common/metadata/visitor-generate-ir.c b/src/plugins/ctf/common/metadata/visitor-generate-ir.c index 56e5b706..cfb57705 100644 --- a/src/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/src/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -1,36 +1,16 @@ /* - * 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 - * Copyright 2015-2018 - Philippe Proulx - * - * 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 + * Copyright 2015-2018 Philippe Proulx * - * 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 #include @@ -49,7 +29,6 @@ #include "logging.h" #include "scanner.h" -#include "parser.h" #include "ast.h" #include "decoder.h" #include "ctf-meta.h" @@ -679,61 +658,6 @@ static 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) { @@ -753,59 +677,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) { @@ -979,36 +850,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 @@ -1035,9 +880,9 @@ int get_boolean(struct ctx *ctx, struct ctf_node *unary_expr) { const char *str = unary_expr->u.unary_expression.u.string; - if (!strcmp(str, "true") || !strcmp(str, "TRUE")) { + if (strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0) { ret = TRUE; - } else if (!strcmp(str, "false") || !strcmp(str, "FALSE")) { + } else if (strcmp(str, "false") == 0 || strcmp(str, "FALSE") == 0) { ret = FALSE; } else { _BT_COMP_LOGE_NODE(unary_expr, @@ -1064,7 +909,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, @@ -1074,11 +919,11 @@ enum ctf_byte_order byte_order_from_unary_expr(struct ctx *ctx, str = unary_expr->u.unary_expression.u.string; - if (!strcmp(str, "be") || !strcmp(str, "network")) { + if (strcmp(str, "be") == 0 || strcmp(str, "network") == 0) { bo = CTF_BYTE_ORDER_BIG; - } else if (!strcmp(str, "le")) { + } else if (strcmp(str, "le") == 0) { bo = CTF_BYTE_ORDER_LITTLE; - } else if (!strcmp(str, "native")) { + } else if (strcmp(str, "native") == 0) { bo = CTF_BYTE_ORDER_DEFAULT; } else { _BT_COMP_LOGE_NODE(unary_expr, @@ -1385,10 +1230,6 @@ int visit_field_class_declarator(struct ctx *ctx, 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; @@ -1440,7 +1281,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, @@ -1493,24 +1334,12 @@ int visit_field_class_declarator(struct ctx *ctx, 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; } @@ -2067,17 +1896,7 @@ int visit_variant_decl(struct ctx *ctx, const char *name, * 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; } @@ -2118,7 +1937,6 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator, .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) { @@ -2185,19 +2003,7 @@ int visit_enum_decl_entry(struct ctx *ctx, struct ctf_node *enumerator, 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; @@ -2396,7 +2202,7 @@ int visit_integer_decl(struct ctx *ctx, goto error; } - if (!strcmp(left->u.unary_expression.u.string, "signed")) { + if (strcmp(left->u.unary_expression.u.string, "signed") == 0) { if (_IS_SET(&set, _INTEGER_SIGNED_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "signed", "integer field class"); @@ -2414,8 +2220,7 @@ int visit_integer_decl(struct ctx *ctx, } _SET(&set, _INTEGER_SIGNED_SET); - } else if (!strcmp(left->u.unary_expression.u.string, - "byte_order")) { + } else if (strcmp(left->u.unary_expression.u.string, "byte_order") == 0) { if (_IS_SET(&set, _INTEGER_BYTE_ORDER_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "byte_order", "integer field class"); @@ -2424,7 +2229,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); @@ -2433,7 +2238,7 @@ int visit_integer_decl(struct ctx *ctx, } _SET(&set, _INTEGER_BYTE_ORDER_SET); - } else if (!strcmp(left->u.unary_expression.u.string, "size")) { + } else if (strcmp(left->u.unary_expression.u.string, "size") == 0) { if (_IS_SET(&set, _INTEGER_SIZE_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "size", "integer field class"); @@ -2470,8 +2275,7 @@ int visit_integer_decl(struct ctx *ctx, } _SET(&set, _INTEGER_SIZE_SET); - } else if (!strcmp(left->u.unary_expression.u.string, - "align")) { + } else if (strcmp(left->u.unary_expression.u.string, "align") == 0) { if (_IS_SET(&set, _INTEGER_ALIGN_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "align", "integer field class"); @@ -2502,7 +2306,7 @@ int visit_integer_decl(struct ctx *ctx, } _SET(&set, _INTEGER_ALIGN_SET); - } else if (!strcmp(left->u.unary_expression.u.string, "base")) { + } else if (strcmp(left->u.unary_expression.u.string, "base") == 0) { if (_IS_SET(&set, _INTEGER_BASE_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "base", "integer field class"); @@ -2541,7 +2345,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, @@ -2550,24 +2354,24 @@ int visit_integer_decl(struct ctx *ctx, goto error; } - if (!strcmp(s_right, "decimal") || - !strcmp(s_right, "dec") || - !strcmp(s_right, "d") || - !strcmp(s_right, "i") || - !strcmp(s_right, "u")) { + if (strcmp(s_right, "decimal") == 0 || + strcmp(s_right, "dec") == 0 || + strcmp(s_right, "d") == 0 || + strcmp(s_right, "i") == 0 || + strcmp(s_right, "u") == 0) { base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL; - } else if (!strcmp(s_right, "hexadecimal") || - !strcmp(s_right, "hex") || - !strcmp(s_right, "x") || - !strcmp(s_right, "X") || - !strcmp(s_right, "p")) { + } else if (strcmp(s_right, "hexadecimal") == 0 || + strcmp(s_right, "hex") == 0 || + strcmp(s_right, "x") == 0 || + strcmp(s_right, "X") == 0 || + strcmp(s_right, "p") == 0) { base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_HEXADECIMAL; - } else if (!strcmp(s_right, "octal") || - !strcmp(s_right, "oct") || - !strcmp(s_right, "o")) { + } else if (strcmp(s_right, "octal") == 0 || + strcmp(s_right, "oct") == 0 || + strcmp(s_right, "o") == 0) { base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_OCTAL; - } else if (!strcmp(s_right, "binary") || - !strcmp(s_right, "b")) { + } else if (strcmp(s_right, "binary") == 0 || + strcmp(s_right, "b") == 0) { base = BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_BINARY; } else { _BT_COMP_LOGE_NODE(right, @@ -2590,8 +2394,7 @@ int visit_integer_decl(struct ctx *ctx, } _SET(&set, _INTEGER_BASE_SET); - } else if (!strcmp(left->u.unary_expression.u.string, - "encoding")) { + } else if (strcmp(left->u.unary_expression.u.string, "encoding") == 0) { char *s_right; if (_IS_SET(&set, _INTEGER_ENCODING_SET)) { @@ -2609,7 +2412,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, @@ -2618,14 +2421,14 @@ int visit_integer_decl(struct ctx *ctx, goto error; } - if (!strcmp(s_right, "UTF8") || - !strcmp(s_right, "utf8") || - !strcmp(s_right, "utf-8") || - !strcmp(s_right, "UTF-8") || - !strcmp(s_right, "ASCII") || - !strcmp(s_right, "ascii")) { + if (strcmp(s_right, "UTF8") == 0 || + strcmp(s_right, "utf8") == 0 || + strcmp(s_right, "utf-8") == 0 || + strcmp(s_right, "UTF-8") == 0 || + strcmp(s_right, "ASCII") == 0 || + strcmp(s_right, "ascii") == 0) { encoding = CTF_ENCODING_UTF8; - } else if (!strcmp(s_right, "none")) { + } else if (strcmp(s_right, "none") == 0) { encoding = CTF_ENCODING_NONE; } else { _BT_COMP_LOGE_NODE(right, @@ -2639,7 +2442,7 @@ int visit_integer_decl(struct ctx *ctx, g_free(s_right); _SET(&set, _INTEGER_ENCODING_SET); - } else if (!strcmp(left->u.unary_expression.u.string, "map")) { + } else if (strcmp(left->u.unary_expression.u.string, "map") == 0) { const char *clock_name; if (_IS_SET(&set, _INTEGER_MAP_SET)) { @@ -2661,7 +2464,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) { @@ -2764,7 +2567,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, goto error; } - if (!strcmp(left->u.unary_expression.u.string, "byte_order")) { + if (strcmp(left->u.unary_expression.u.string, "byte_order") == 0) { if (_IS_SET(&set, _FLOAT_BYTE_ORDER_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "byte_order", "floating point number field class"); @@ -2773,7 +2576,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); @@ -2782,8 +2585,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, } _SET(&set, _FLOAT_BYTE_ORDER_SET); - } else if (!strcmp(left->u.unary_expression.u.string, - "exp_dig")) { + } else if (strcmp(left->u.unary_expression.u.string, "exp_dig") == 0) { if (_IS_SET(&set, _FLOAT_EXP_DIG_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "exp_dig", "floating point number field class"); @@ -2804,8 +2606,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, exp_dig = right->u.unary_expression.u.unsigned_constant; _SET(&set, _FLOAT_EXP_DIG_SET); - } else if (!strcmp(left->u.unary_expression.u.string, - "mant_dig")) { + } else if (strcmp(left->u.unary_expression.u.string, "mant_dig") == 0) { if (_IS_SET(&set, _FLOAT_MANT_DIG_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "mant_dig", "floating point number field class"); @@ -2827,8 +2628,7 @@ int visit_floating_point_number_decl(struct ctx *ctx, mant_dig = right->u.unary_expression.u. unsigned_constant; _SET(&set, _FLOAT_MANT_DIG_SET); - } else if (!strcmp(left->u.unary_expression.u.string, - "align")) { + } else if (strcmp(left->u.unary_expression.u.string, "align") == 0) { if (_IS_SET(&set, _FLOAT_ALIGN_SET)) { _BT_COMP_LOGE_DUP_ATTR(left, "align", "floating point number field class"); @@ -2950,7 +2750,7 @@ int visit_string_decl(struct ctx *ctx, goto error; } - if (!strcmp(left->u.unary_expression.u.string, "encoding")) { + if (strcmp(left->u.unary_expression.u.string, "encoding") == 0) { char *s_right; if (_IS_SET(&set, _STRING_ENCODING_SET)) { @@ -2968,7 +2768,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, @@ -2977,14 +2777,14 @@ int visit_string_decl(struct ctx *ctx, goto error; } - if (!strcmp(s_right, "UTF8") || - !strcmp(s_right, "utf8") || - !strcmp(s_right, "utf-8") || - !strcmp(s_right, "UTF-8") || - !strcmp(s_right, "ASCII") || - !strcmp(s_right, "ascii")) { + if (strcmp(s_right, "UTF8") == 0 || + strcmp(s_right, "utf8") == 0 || + strcmp(s_right, "utf-8") == 0 || + strcmp(s_right, "UTF-8") == 0 || + strcmp(s_right, "ASCII") == 0 || + strcmp(s_right, "ascii") == 0) { encoding = CTF_ENCODING_UTF8; - } else if (!strcmp(s_right, "none")) { + } else if (strcmp(s_right, "none") == 0) { encoding = CTF_ENCODING_NONE; } else { _BT_COMP_LOGE_NODE(right, @@ -3168,14 +2968,14 @@ 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; goto error; } - if (!strcmp(left, "name")) { + if (strcmp(left, "name") == 0) { /* This is already known at this stage */ if (_IS_SET(set, _EVENT_NAME_SET)) { _BT_COMP_LOGE_DUP_ATTR(node, "name", "event class"); @@ -3184,7 +2984,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, } _SET(set, _EVENT_NAME_SET); - } else if (!strcmp(left, "id")) { + } else if (strcmp(left, "id") == 0) { int64_t id = -1; if (_IS_SET(set, _EVENT_ID_SET)) { @@ -3206,7 +3006,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, event_class->id = id; _SET(set, _EVENT_ID_SET); - } else if (!strcmp(left, "stream_id")) { + } else if (strcmp(left, "stream_id") == 0) { if (_IS_SET(set, _EVENT_STREAM_ID_SET)) { _BT_COMP_LOGE_DUP_ATTR(node, "stream_id", "event class"); @@ -3229,7 +3029,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, } _SET(set, _EVENT_STREAM_ID_SET); - } else if (!strcmp(left, "context")) { + } else if (strcmp(left, "context") == 0) { if (_IS_SET(set, _EVENT_CONTEXT_SET)) { _BT_COMP_LOGE_NODE(node, "Duplicate `context` entry in event class."); @@ -3250,7 +3050,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, BT_ASSERT(event_class->spec_context_fc); _SET(set, _EVENT_CONTEXT_SET); - } else if (!strcmp(left, "fields")) { + } else if (strcmp(left, "fields") == 0) { if (_IS_SET(set, _EVENT_FIELDS_SET)) { _BT_COMP_LOGE_NODE(node, "Duplicate `fields` entry in event class."); @@ -3271,8 +3071,9 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, BT_ASSERT(event_class->payload_fc); _SET(set, _EVENT_FIELDS_SET); - } else if (!strcmp(left, "loglevel")) { + } 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)) { @@ -3338,16 +3139,17 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, 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); - } else if (!strcmp(left, "model.emf.uri")) { + } else if (strcmp(left, "model.emf.uri") == 0) { char *right; if (_IS_SET(set, _EVENT_MODEL_EMF_URI_SET)) { @@ -3357,7 +3159,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, @@ -3394,9 +3196,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node, goto end; error: - if (left) { - g_free(left); - } + g_free(left); end: return ret; @@ -3415,15 +3215,15 @@ 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."); goto error; } - if (!strcmp(left, "name")) { - name = concatenate_unary_strings( + if (strcmp(left, "name") == 0) { + name = ctf_ast_concatenate_unary_strings( &iter->u.ctf_expression.right); if (!name) { _BT_COMP_LOGE_NODE(iter, @@ -3571,9 +3371,7 @@ end: ctx_pop_scope(ctx); } - if (event_name) { - g_free(event_name); - } + g_free(event_name); return ret; } @@ -3676,6 +3474,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) { @@ -3730,14 +3530,14 @@ 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; goto error; } - if (!strcmp(left, "id")) { + if (strcmp(left, "id") == 0) { int64_t id; if (_IS_SET(set, _STREAM_ID_SET)) { @@ -3770,7 +3570,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, stream_class->id = id; _SET(set, _STREAM_ID_SET); - } else if (!strcmp(left, "event.header")) { + } else if (strcmp(left, "event.header") == 0) { if (_IS_SET(set, _STREAM_EVENT_HEADER_SET)) { _BT_COMP_LOGE_NODE(node, "Duplicate `event.header` entry in stream class."); @@ -3799,7 +3599,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, } _SET(set, _STREAM_EVENT_HEADER_SET); - } else if (!strcmp(left, "event.context")) { + } else if (strcmp(left, "event.context") == 0) { if (_IS_SET(set, _STREAM_EVENT_CONTEXT_SET)) { _BT_COMP_LOGE_NODE(node, "Duplicate `event.context` entry in stream class."); @@ -3820,7 +3620,7 @@ int visit_stream_decl_entry(struct ctx *ctx, struct ctf_node *node, BT_ASSERT(stream_class->event_common_context_fc); _SET(set, _STREAM_EVENT_CONTEXT_SET); - } else if (!strcmp(left, "packet.context")) { + } else if (strcmp(left, "packet.context") == 0) { if (_IS_SET(set, _STREAM_PACKET_CONTEXT_SET)) { _BT_COMP_LOGE_NODE(node, "Duplicate `packet.context` entry in stream class."); @@ -4006,14 +3806,14 @@ 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; goto error; } - if (!strcmp(left, "major")) { + if (strcmp(left, "major") == 0) { if (_IS_SET(set, _TRACE_MAJOR_SET)) { _BT_COMP_LOGE_DUP_ATTR(node, "major", "trace"); ret = -EPERM; @@ -4037,7 +3837,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) ctx->ctf_tc->major = val; _SET(set, _TRACE_MAJOR_SET); - } else if (!strcmp(left, "minor")) { + } else if (strcmp(left, "minor") == 0) { if (_IS_SET(set, _TRACE_MINOR_SET)) { _BT_COMP_LOGE_DUP_ATTR(node, "minor", "trace"); ret = -EPERM; @@ -4061,7 +3861,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) ctx->ctf_tc->minor = val; _SET(set, _TRACE_MINOR_SET); - } else if (!strcmp(left, "uuid")) { + } else if (strcmp(left, "uuid") == 0) { if (_IS_SET(set, _TRACE_UUID_SET)) { _BT_COMP_LOGE_DUP_ATTR(node, "uuid", "trace"); ret = -EPERM; @@ -4079,7 +3879,7 @@ int visit_trace_decl_entry(struct ctx *ctx, struct ctf_node *node, int *set) ctx->ctf_tc->is_uuid_set = true; _SET(set, _TRACE_UUID_SET); - } else if (!strcmp(left, "byte_order")) { + } else if (strcmp(left, "byte_order") == 0) { /* Default byte order is already known at this stage */ if (_IS_SET(set, _TRACE_BYTE_ORDER_SET)) { _BT_COMP_LOGE_DUP_ATTR(node, "byte_order", @@ -4088,9 +3888,9 @@ 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")) { + } else if (strcmp(left, "packet.header") == 0) { if (_IS_SET(set, _TRACE_PACKET_HEADER_SET)) { _BT_COMP_LOGE_NODE(node, "Duplicate `packet.header` entry in trace."); @@ -4224,7 +4024,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, @@ -4234,7 +4034,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, @@ -4309,7 +4109,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, @@ -4318,7 +4118,7 @@ int set_trace_byte_order(struct ctx *ctx, struct ctf_node *trace_node) goto error; } - if (!strcmp(left, "byte_order")) { + if (strcmp(left, "byte_order") == 0) { enum ctf_byte_order bo; if (_IS_SET(&set, _TRACE_BYTE_ORDER_SET)) { @@ -4334,7 +4134,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`."); @@ -4386,14 +4186,14 @@ 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; goto error; } - if (!strcmp(left, "name")) { + if (strcmp(left, "name") == 0) { char *right; if (_IS_SET(set, _CLOCK_NAME_SET)) { @@ -4402,7 +4202,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, @@ -4414,7 +4214,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, g_string_assign(clock->name, right); g_free(right); _SET(set, _CLOCK_NAME_SET); - } else if (!strcmp(left, "uuid")) { + } else if (strcmp(left, "uuid") == 0) { bt_uuid_t uuid; if (_IS_SET(set, _CLOCK_UUID_SET)) { @@ -4434,7 +4234,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, clock->has_uuid = true; bt_uuid_copy(clock->uuid, uuid); _SET(set, _CLOCK_UUID_SET); - } else if (!strcmp(left, "description")) { + } else if (strcmp(left, "description") == 0) { char *right; if (_IS_SET(set, _CLOCK_DESCRIPTION_SET)) { @@ -4444,7 +4244,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, @@ -4456,7 +4256,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, g_string_assign(clock->description, right); g_free(right); _SET(set, _CLOCK_DESCRIPTION_SET); - } else if (!strcmp(left, "freq")) { + } else if (strcmp(left, "freq") == 0) { uint64_t freq = UINT64_C(-1); if (_IS_SET(set, _CLOCK_FREQ_SET)) { @@ -4484,7 +4284,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, clock->frequency = freq; _SET(set, _CLOCK_FREQ_SET); - } else if (!strcmp(left, "precision")) { + } else if (strcmp(left, "precision") == 0) { uint64_t precision; if (_IS_SET(set, _CLOCK_PRECISION_SET)) { @@ -4505,7 +4305,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, clock->precision = precision; _SET(set, _CLOCK_PRECISION_SET); - } else if (!strcmp(left, "offset_s")) { + } else if (strcmp(left, "offset_s") == 0) { if (_IS_SET(set, _CLOCK_OFFSET_S_SET)) { _BT_COMP_LOGE_DUP_ATTR(entry_node, "offset_s", "clock class"); @@ -4523,7 +4323,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, } _SET(set, _CLOCK_OFFSET_S_SET); - } else if (!strcmp(left, "offset")) { + } else if (strcmp(left, "offset") == 0) { if (_IS_SET(set, _CLOCK_OFFSET_SET)) { _BT_COMP_LOGE_DUP_ATTR(entry_node, "offset", "clock class"); ret = -EPERM; @@ -4540,7 +4340,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node, } _SET(set, _CLOCK_OFFSET_SET); - } else if (!strcmp(left, "absolute")) { + } else if (strcmp(left, "absolute") == 0) { struct ctf_node *right; if (_IS_SET(set, _CLOCK_ABSOLUTE_SET)) { @@ -4605,6 +4405,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) @@ -4732,6 +4543,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; @@ -4816,7 +4628,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; } @@ -4842,7 +4656,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); @@ -4857,8 +4671,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; } @@ -4884,7 +4698,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, @@ -4914,7 +4728,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, 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) { @@ -4928,7 +4742,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); /* * Visit clock blocks. @@ -4944,7 +4758,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } 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 @@ -4962,7 +4776,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } 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) { @@ -4971,7 +4785,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } 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) { @@ -4985,7 +4799,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } 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) { @@ -4999,7 +4813,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } 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) { @@ -5013,7 +4827,7 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor, } BT_ASSERT(ctx->current_scope && - ctx->current_scope->parent_scope == NULL); + !ctx->current_scope->parent_scope); break; } default: