X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fmetadata%2Fctf-visitor-generate-io-struct.c;h=6e828fcd13059b20f466a53eb07f4ea7cf59a23a;hp=cda3329be4455be450b31d611ce0c8e0dee23690;hb=d86d62f815e8fce21a7efb2cc0811720d62b0c11;hpb=c2b59caccd2c0590557b49779fb4858be7e44493 diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index cda3329b..6e828fcd 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) { @@ -119,7 +136,7 @@ int get_unary_uuid(struct cds_list_head *head, uuid_t *uuid) assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN); assert(i == 0); src_string = node->u.unary_expression.u.string; - ret = uuid_parse(node->u.unary_expression.u.string, *uuid); + ret = uuid_parse(src_string, *uuid); } return ret; } @@ -726,7 +743,7 @@ struct declaration *ctf_declaration_struct_visit(FILE *fd, ret = ctf_struct_declaration_list_visit(fd, depth + 1, iter, struct_declaration, trace); if (ret) - goto error; + goto error_free_declaration; } if (name) { ret = register_struct_declaration(g_quark_from_string(name), @@ -736,8 +753,9 @@ struct declaration *ctf_declaration_struct_visit(FILE *fd, } return &struct_declaration->p; } -error: +error_free_declaration: struct_declaration->p.declaration_free(&struct_declaration->p); +error: return NULL; } @@ -1092,7 +1110,7 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth, struct ctf_trace *trace) { struct ctf_node *expression; - uint64_t alignment, size; + uint64_t alignment = 1, size = 0; int byte_order = trace->byte_order; int signedness = 0; int has_alignment = 0, has_size = 0; @@ -1247,7 +1265,8 @@ struct declaration *ctf_declaration_floating_point_visit(FILE *fd, int depth, struct ctf_trace *trace) { struct ctf_node *expression; - uint64_t alignment, exp_dig, mant_dig, byte_order = trace->byte_order; + uint64_t alignment = 1, exp_dig = 0, mant_dig = 0, + byte_order = trace->byte_order; int has_alignment = 0, has_exp_dig = 0, has_mant_dig = 0; struct declaration_float *float_declaration; @@ -1548,6 +1567,36 @@ 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; @@ -1791,6 +1840,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; @@ -1896,7 +1946,18 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru ret = -EPERM; goto error; } else { - trace->byte_order = byte_order; + if (byte_order != trace->byte_order) { + trace->byte_order = byte_order; + /* + * We need to restart + * construction of the + * intermediate representation. + */ + trace->field_mask = 0; + CTF_TRACE_SET_FIELD(trace, byte_order); + ret = -EINTR; + goto error; + } } CTF_TRACE_SET_FIELD(trace, byte_order); } else if (!strcmp(left, "packet.header")) { @@ -1986,10 +2047,13 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace return 0; error: - if (trace->packet_header_decl) + if (trace->packet_header_decl) { declaration_unref(&trace->packet_header_decl->p); + trace->packet_header_decl = NULL; + } g_ptr_array_free(trace->streams, TRUE); free_declaration_scope(trace->declaration_scope); + trace->declaration_scope = NULL; return ret; } @@ -2045,9 +2109,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, @@ -2060,6 +2126,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;