X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-generate-io-struct.c;h=70fd5df200c388be088871ce37d97c594a8a2f37;hp=f0e5b4744667d7a1e8a52f638082ba32e4727f9a;hb=e7682217ca3c8d08ce6d14808b3b3b0ed2ba1b23;hpb=0d72513f59db3db1306602a34c15c0afda5526eb diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index f0e5b474..70fd5df2 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -104,6 +104,23 @@ int get_unary_unsigned(struct cds_list_head *head, uint64_t *value) return 0; } +static +int get_unary_signed(struct cds_list_head *head, int64_t *value) +{ + struct ctf_node *node; + int i = 0; + + cds_list_for_each_entry(node, head, siblings) { + assert(node->type == NODE_UNARY_EXPRESSION); + assert(node->u.unary_expression.type == UNARY_UNSIGNED_CONSTANT); + assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN); + assert(i == 0); + *value = node->u.unary_expression.u.signed_constant; + i++; + } + return 0; +} + static int get_unary_uuid(struct cds_list_head *head, uuid_t *uuid) { @@ -1093,7 +1110,7 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, struct ctf_trace *trace) { struct ctf_node *expression; - uint64_t alignment = 1, size; + uint64_t alignment = 1, size = 0; int byte_order = trace->byte_order; int signedness = 0; int has_alignment = 0, has_size = 0; @@ -1217,10 +1234,26 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, return NULL; } g_free(s_right); + } else if (!strcmp(left->u.unary_expression.u.string, "map")) { + char *s_right; + + if (right->u.unary_expression.type != UNARY_STRING) { + fprintf(fd, "[error] %s: map: expecting identifier\n", + __func__); + return NULL; + } + s_right = concatenate_unary_strings(&expression->u.ctf_expression.right); + if (!s_right) { + fprintf(fd, "[error] %s: unexpected unary expression for integer map\n", __func__); + g_free(s_right); + return NULL; + } + /* TODO: lookup */ + } else { - fprintf(fd, "[error] %s: unknown attribute name %s\n", + fprintf(fd, "[warning] %s: unknown attribute name %s\n", __func__, left->u.unary_expression.u.string); - return NULL; + /* Fall-through after warning */ } } if (!has_size) { @@ -1294,9 +1327,9 @@ struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth, } has_alignment = 1; } else { - fprintf(fd, "[error] %s: unknown attribute name %s\n", + fprintf(fd, "[warning] %s: unknown attribute name %s\n", __func__, left->u.unary_expression.u.string); - return NULL; + /* Fall-through after warning */ } } if (!has_mant_dig) { @@ -1345,9 +1378,9 @@ struct declaration *ctf_declaration_string_visit(FILE *fd, int depth, } encoding_c = right->u.unary_expression.u.string; } else { - fprintf(fd, "[error] %s: unknown attribute name %s\n", + fprintf(fd, "[warning] %s: unknown attribute name %s\n", __func__, left->u.unary_expression.u.string); - return NULL; + /* Fall-through after warning */ } } if (encoding_c && !strcmp(encoding_c, "ASCII")) @@ -1550,10 +1583,39 @@ int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru goto error; } event->fields_decl = container_of(declaration, struct declaration_struct, p); + } else if (!strcmp(left, "loglevel.identifier")) { + char *right; + + if (CTF_EVENT_FIELD_IS_SET(event, loglevel_identifier)) { + fprintf(fd, "[error] %s: identifier already declared in event declaration\n", __func__); + ret = -EPERM; + goto error; + } + right = concatenate_unary_strings(&node->u.ctf_expression.right); + if (!right) { + fprintf(fd, "[error] %s: unexpected unary expression for event identifier\n", __func__); + ret = -EINVAL; + goto error; + } + event->loglevel_identifier = g_quark_from_string(right); + g_free(right); + CTF_EVENT_SET_FIELD(event, loglevel_identifier); + } else if (!strcmp(left, "loglevel.value")) { + if (CTF_EVENT_FIELD_IS_SET(event, loglevel_value)) { + fprintf(fd, "[error] %s: loglevel value already declared in event declaration\n", __func__); + ret = -EPERM; + goto error; + } + ret = get_unary_signed(&node->u.ctf_expression.right, &event->loglevel_value); + if (ret) { + fprintf(fd, "[error] %s: unexpected unary expression for event loglevel value\n", __func__); + ret = -EINVAL; + goto error; + } + CTF_EVENT_SET_FIELD(event, loglevel_value); } else { - fprintf(fd, "[error] %s: attribute \"%s\" is unknown in event declaration.\n", __func__, left); - ret = -EINVAL; - goto error; + fprintf(fd, "[warning] %s: attribute \"%s\" is unknown in event declaration.\n", __func__, left); + /* Fall-through after warning */ } error: g_free(left); @@ -1736,9 +1798,8 @@ int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, str } stream->packet_context_decl = container_of(declaration, struct declaration_struct, p); } else { - fprintf(fd, "[error] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__, left); - ret = -EINVAL; - goto error; + fprintf(fd, "[warning] %s: attribute \"%s\" is unknown in stream declaration.\n", __func__, left); + /* Fall-through after warning */ } error: @@ -1793,6 +1854,7 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node, if (trace->streams->len <= stream->stream_id) g_ptr_array_set_size(trace->streams, stream->stream_id + 1); g_ptr_array_index(trace->streams, stream->stream_id) = stream; + stream->trace = trace; return 0; @@ -1934,9 +1996,7 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru } trace->packet_header_decl = container_of(declaration, struct declaration_struct, p); } else { - fprintf(fd, "[error] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__, left); - ret = -EINVAL; - goto error; + fprintf(fd, "[warning] %s: attribute \"%s\" is unknown in trace declaration.\n", __func__, left); } error: @@ -1957,7 +2017,6 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace int ret = 0; struct ctf_node *iter; -restart: if (trace->declaration_scope) return -EEXIST; trace->declaration_scope = new_declaration_scope(trace->root_declaration_scope); @@ -2007,10 +2066,6 @@ error: g_ptr_array_free(trace->streams, TRUE); free_declaration_scope(trace->declaration_scope); trace->declaration_scope = NULL; - /* byte order changed while creating types, retry. */ - if (ret == -EINTR) { - goto restart; - } return ret; } @@ -2066,9 +2121,11 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, struct ctf_node *iter; printf_verbose("CTF visitor: metadata construction... "); - trace->root_declaration_scope = new_declaration_scope(NULL); trace->byte_order = byte_order; +retry: + trace->root_declaration_scope = new_declaration_scope(NULL); + switch (node->type) { case NODE_ROOT: cds_list_for_each_entry(iter, &node->u.root.declaration_list, @@ -2081,6 +2138,15 @@ int ctf_visitor_construct_metadata(FILE *fd, int depth, struct ctf_node *node, } cds_list_for_each_entry(iter, &node->u.root.trace, siblings) { ret = ctf_trace_visit(fd, depth + 1, iter, trace); + if (ret == -EINTR) { + free_declaration_scope(trace->root_declaration_scope); + /* + * Need to restart creation of type + * definitions, aliases and + * trace header declarations. + */ + goto retry; + } if (ret) { fprintf(fd, "[error] %s: trace declaration error\n", __func__); goto error;