UUID field should be optional, as specified by CTF spec
[babeltrace.git] / formats / ctf / metadata / ctf-visitor-generate-io-struct.c
index bfb6031d39509d35ff235490fbdcf6d1bf1361c6..4b399613585ebb81b9aa49d25c23583690483003 100644 (file)
 #include <assert.h>
 #include <glib.h>
 #include <inttypes.h>
 #include <assert.h>
 #include <glib.h>
 #include <inttypes.h>
-#include <endian.h>
 #include <errno.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/list.h>
 #include <babeltrace/types.h>
 #include <babeltrace/ctf/metadata.h>
 #include <errno.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/list.h>
 #include <babeltrace/types.h>
 #include <babeltrace/ctf/metadata.h>
-#include <uuid/uuid.h>
+#include <babeltrace/uuid.h>
+#include <babeltrace/endian.h>
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
 #include "ctf-ast.h"
 #include "ctf-scanner.h"
 #include "ctf-parser.h"
 #include "ctf-ast.h"
@@ -51,6 +51,20 @@ static
 int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
                     struct declaration_scope *parent_declaration_scope, struct ctf_trace *trace);
 
 int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
                     struct declaration_scope *parent_declaration_scope, struct ctf_trace *trace);
 
+static
+int is_unary_string(struct bt_list_head *head)
+{
+       struct ctf_node *node;
+
+       bt_list_for_each_entry(node, head, siblings) {
+               if (node->type != NODE_UNARY_EXPRESSION)
+                       return 0;
+               if (node->u.unary_expression.type != UNARY_STRING)
+                       return 0;
+       }
+       return 1;
+}
+
 /*
  * String returned must be freed by the caller using g_free.
  */
 /*
  * String returned must be freed by the caller using g_free.
  */
@@ -133,6 +147,20 @@ GQuark get_map_clock_name_value(struct bt_list_head *head)
        return g_quark_from_string(name);
 }
 
        return g_quark_from_string(name);
 }
 
+static
+int is_unary_unsigned(struct bt_list_head *head)
+{
+       struct ctf_node *node;
+
+       bt_list_for_each_entry(node, head, siblings) {
+               if (node->type != NODE_UNARY_EXPRESSION)
+                       return 0;
+               if (node->u.unary_expression.type != UNARY_UNSIGNED_CONSTANT)
+                       return 0;
+       }
+       return 1;
+}
+
 static
 int get_unary_unsigned(struct bt_list_head *head, uint64_t *value)
 {
 static
 int get_unary_unsigned(struct bt_list_head *head, uint64_t *value)
 {
@@ -150,6 +178,20 @@ int get_unary_unsigned(struct bt_list_head *head, uint64_t *value)
        return 0;
 }
 
        return 0;
 }
 
+static
+int is_unary_signed(struct bt_list_head *head)
+{
+       struct ctf_node *node;
+
+       bt_list_for_each_entry(node, head, siblings) {
+               if (node->type != NODE_UNARY_EXPRESSION)
+                       return 0;
+               if (node->u.unary_expression.type != UNARY_SIGNED_CONSTANT)
+                       return 0;
+       }
+       return 1;
+}
+
 static
 int get_unary_signed(struct bt_list_head *head, int64_t *value)
 {
 static
 int get_unary_signed(struct bt_list_head *head, int64_t *value)
 {
@@ -178,7 +220,7 @@ int get_unary_signed(struct bt_list_head *head, int64_t *value)
 }
 
 static
 }
 
 static
-int get_unary_uuid(struct bt_list_head *head, uuid_t *uuid)
+int get_unary_uuid(struct bt_list_head *head, unsigned char *uuid)
 {
        struct ctf_node *node;
        int i = 0;
 {
        struct ctf_node *node;
        int i = 0;
@@ -192,13 +234,13 @@ int get_unary_uuid(struct bt_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;
                assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN);
                assert(i == 0);
                src_string = node->u.unary_expression.u.string;
-               ret = uuid_parse(src_string, *uuid);
+               ret = babeltrace_uuid_parse(src_string, uuid);
        }
        return ret;
 }
 
 static
        }
        return ret;
 }
 
 static
-struct ctf_stream_class *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id)
+struct ctf_stream_declaration *trace_stream_lookup(struct ctf_trace *trace, uint64_t stream_id)
 {
        if (trace->streams->len <= stream_id)
                return NULL;
 {
        if (trace->streams->len <= stream_id)
                return NULL;
@@ -1543,7 +1585,7 @@ struct declaration *ctf_type_specifier_list_visit(FILE *fd,
 }
 
 static
 }
 
 static
-int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_event *event, struct ctf_trace *trace)
+int ctf_event_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_event_declaration *event, struct ctf_trace *trace)
 {
        int ret = 0;
 
 {
        int ret = 0;
 
@@ -1699,9 +1741,9 @@ int ctf_event_visit(FILE *fd, int depth, struct ctf_node *node,
 {
        int ret = 0;
        struct ctf_node *iter;
 {
        int ret = 0;
        struct ctf_node *iter;
-       struct ctf_event *event;
+       struct ctf_event_declaration *event;
 
 
-       event = g_new0(struct ctf_event, 1);
+       event = g_new0(struct ctf_event_declaration, 1);
        event->declaration_scope = new_declaration_scope(parent_declaration_scope);
        event->loglevel = -1;
        bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
        event->declaration_scope = new_declaration_scope(parent_declaration_scope);
        event->loglevel = -1;
        bt_list_for_each_entry(iter, &node->u.event.declaration_list, siblings) {
@@ -1759,7 +1801,7 @@ error:
 
  
 static
 
  
 static
-int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream_class *stream, struct ctf_trace *trace)
+int ctf_stream_declaration_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_stream_declaration *stream, struct ctf_trace *trace)
 {
        int ret = 0;
 
 {
        int ret = 0;
 
@@ -1885,9 +1927,9 @@ int ctf_stream_visit(FILE *fd, int depth, struct ctf_node *node,
 {
        int ret = 0;
        struct ctf_node *iter;
 {
        int ret = 0;
        struct ctf_node *iter;
-       struct ctf_stream_class *stream;
+       struct ctf_stream_declaration *stream;
 
 
-       stream = g_new0(struct ctf_stream_class, 1);
+       stream = g_new0(struct ctf_stream_declaration, 1);
        stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
        stream->events_by_id = g_ptr_array_new();
        stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
        stream->declaration_scope = new_declaration_scope(parent_declaration_scope);
        stream->events_by_id = g_ptr_array_new();
        stream->event_quark_to_id = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -1993,16 +2035,16 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru
                        }
                        CTF_TRACE_SET_FIELD(trace, minor);
                } else if (!strcmp(left, "uuid")) {
                        }
                        CTF_TRACE_SET_FIELD(trace, minor);
                } else if (!strcmp(left, "uuid")) {
-                       uuid_t uuid;
+                       unsigned char uuid[BABELTRACE_UUID_LEN];
 
 
-                       ret = get_unary_uuid(&node->u.ctf_expression.right, &uuid);
+                       ret = get_unary_uuid(&node->u.ctf_expression.right, uuid);
                        if (ret) {
                                fprintf(fd, "[error] %s: unexpected unary expression for trace uuid\n", __func__);
                                ret = -EINVAL;
                                goto error;
                        }
                        if (CTF_TRACE_FIELD_IS_SET(trace, uuid)
                        if (ret) {
                                fprintf(fd, "[error] %s: unexpected unary expression for trace uuid\n", __func__);
                                ret = -EINVAL;
                                goto error;
                        }
                        if (CTF_TRACE_FIELD_IS_SET(trace, uuid)
-                               && uuid_compare(uuid, trace->uuid)) {
+                               && babeltrace_uuid_compare(uuid, trace->uuid)) {
                                fprintf(fd, "[error] %s: uuid mismatch\n", __func__);
                                ret = -EPERM;
                                goto error;
                                fprintf(fd, "[error] %s: uuid mismatch\n", __func__);
                                ret = -EPERM;
                                goto error;
@@ -2101,11 +2143,6 @@ int ctf_trace_visit(FILE *fd, int depth, struct ctf_node *node, struct ctf_trace
                fprintf(fd, "[error] %s: missing minor field in trace declaration\n", __func__);
                goto error;
        }
                fprintf(fd, "[error] %s: missing minor field in trace declaration\n", __func__);
                goto error;
        }
-       if (!CTF_TRACE_FIELD_IS_SET(trace, uuid)) {
-               ret = -EPERM;
-               fprintf(fd, "[error] %s: missing uuid field in trace declaration\n", __func__);
-               goto error;
-       }
        if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
                ret = -EPERM;
                fprintf(fd, "[error] %s: missing byte_order field in trace declaration\n", __func__);
        if (!CTF_TRACE_FIELD_IS_SET(trace, byte_order)) {
                ret = -EPERM;
                fprintf(fd, "[error] %s: missing byte_order field in trace declaration\n", __func__);
@@ -2393,7 +2430,7 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                        }
                        strncpy(env->procname, right, TRACER_ENV_LEN);
                        env->procname[TRACER_ENV_LEN - 1] = '\0';
                        }
                        strncpy(env->procname, right, TRACER_ENV_LEN);
                        env->procname[TRACER_ENV_LEN - 1] = '\0';
-                       printf_verbose("env.procname = %s\n", env->procname);
+                       printf_verbose("env.procname = \"%s\"\n", env->procname);
                } else if (!strcmp(left, "domain")) {
                        char *right;
 
                } else if (!strcmp(left, "domain")) {
                        char *right;
 
@@ -2408,7 +2445,7 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                        }
                        strncpy(env->domain, right, TRACER_ENV_LEN);
                        env->domain[TRACER_ENV_LEN - 1] = '\0';
                        }
                        strncpy(env->domain, right, TRACER_ENV_LEN);
                        env->domain[TRACER_ENV_LEN - 1] = '\0';
-                       printf_verbose("env.domain = %s\n", env->domain);
+                       printf_verbose("env.domain = \"%s\"\n", env->domain);
                } else if (!strcmp(left, "sysname")) {
                        char *right;
 
                } else if (!strcmp(left, "sysname")) {
                        char *right;
 
@@ -2423,8 +2460,8 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                        }
                        strncpy(env->sysname, right, TRACER_ENV_LEN);
                        env->sysname[TRACER_ENV_LEN - 1] = '\0';
                        }
                        strncpy(env->sysname, right, TRACER_ENV_LEN);
                        env->sysname[TRACER_ENV_LEN - 1] = '\0';
-                       printf_verbose("env.sysname = %s\n", env->sysname);
-               } else if (!strcmp(left, "release")) {
+                       printf_verbose("env.sysname = \"%s\"\n", env->sysname);
+               } else if (!strcmp(left, "kernel_release")) {
                        char *right;
 
                        if (env->release[0]) {
                        char *right;
 
                        if (env->release[0]) {
@@ -2438,8 +2475,8 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                        }
                        strncpy(env->release, right, TRACER_ENV_LEN);
                        env->release[TRACER_ENV_LEN - 1] = '\0';
                        }
                        strncpy(env->release, right, TRACER_ENV_LEN);
                        env->release[TRACER_ENV_LEN - 1] = '\0';
-                       printf_verbose("env.release = %s\n", env->release);
-               } else if (!strcmp(left, "version")) {
+                       printf_verbose("env.release = \"%s\"\n", env->release);
+               } else if (!strcmp(left, "kernel_version")) {
                        char *right;
 
                        if (env->version[0]) {
                        char *right;
 
                        if (env->version[0]) {
@@ -2453,9 +2490,30 @@ int ctf_env_declaration_visit(FILE *fd, int depth, struct ctf_node *node,
                        }
                        strncpy(env->version, right, TRACER_ENV_LEN);
                        env->version[TRACER_ENV_LEN - 1] = '\0';
                        }
                        strncpy(env->version, right, TRACER_ENV_LEN);
                        env->version[TRACER_ENV_LEN - 1] = '\0';
-                       printf_verbose("env.version = %s\n", env->version);
+                       printf_verbose("env.version = \"%s\"\n", env->version);
                } else {
                } else {
-                       printf_verbose("%s: attribute \"%s\" is unknown in environment declaration.\n", __func__, left);
+                       if (is_unary_string(&node->u.ctf_expression.right)) {
+                               char *right;
+
+                               right = concatenate_unary_strings(&node->u.ctf_expression.right);
+                               printf_verbose("env.%s = \"%s\"\n", left, right);
+                       } else if (is_unary_unsigned(&node->u.ctf_expression.right)) {
+                               uint64_t v;
+                               int ret;
+
+                               ret = get_unary_unsigned(&node->u.ctf_expression.right, &v);
+                               assert(ret == 0);
+                               printf_verbose("env.%s = %" PRIu64 "\n", left, v);
+                       } else if (is_unary_signed(&node->u.ctf_expression.right)) {
+                               int64_t v;
+                               int ret;
+
+                               ret = get_unary_signed(&node->u.ctf_expression.right, &v);
+                               assert(ret == 0);
+                               printf_verbose("env.%s = %" PRId64 "\n", left, v);
+                       } else {
+                               printf_verbose("%s: attribute \"%s\" has unknown type.\n", __func__, left);
+                       }
                }
 
 error:
                }
 
 error:
This page took 0.026777 seconds and 4 git commands to generate.