Allow $app.provider:ctxname in filter, enum, variant identifiers
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Jan 2016 15:14:17 +0000 (10:14 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 12 Feb 2016 22:54:03 +0000 (17:54 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/ust-metadata.c
src/lib/lttng-ctl/filter/filter-lexer.l
src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c

index fc1ea2e7b6a8f1a97b754c5c38a3972acb4badac..cb77e81300f82c6e4d20552ce7f154380389b0f3 100644 (file)
@@ -200,6 +200,24 @@ int print_tabs(struct ust_registry_session *session, size_t nesting)
        return 0;
 }
 
+static
+void sanitize_ctf_identifier(char *out, const char *in)
+{
+       size_t i;
+
+       for (i = 0; i < LTTNG_UST_SYM_NAME_LEN; i++) {
+               switch (in[i]) {
+               case '.':
+               case '$':
+               case ':':
+                       out[i] = '_';
+                       break;
+               default:
+                       out[i] = in[i];
+               }
+       }
+}
+
 /* Called with session registry mutex held. */
 static
 int ust_metadata_enum_statedump(struct ust_registry_session *session,
@@ -213,6 +231,7 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session,
        size_t nr_entries;
        int ret = 0;
        size_t i;
+       char identifier[LTTNG_UST_SYM_NAME_LEN];
 
        rcu_read_lock();
        reg_enum = ust_registry_lookup_enum_by_id(session, enum_name, enum_id);
@@ -248,8 +267,12 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session,
                const struct ustctl_enum_entry *entry = &entries[i];
                int j, len;
 
+               ret = print_tabs(session, nesting);
+               if (ret) {
+                       goto end;
+               }
                ret = lttng_metadata_printf(session,
-                               "                       \"");
+                               "\"");
                if (ret) {
                        goto end;
                }
@@ -294,14 +317,18 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session,
                        goto end;
                }
        }
-       ret = lttng_metadata_printf(session, "          } _%s;\n",
-                       field_name);
+       sanitize_ctf_identifier(identifier, field_name);
+       ret = print_tabs(session, nesting);
+       if (ret) {
+               goto end;
+       }
+       ret = lttng_metadata_printf(session, "} _%s;\n",
+                       identifier);
 end:
        (*iter_field)++;
        return ret;
 }
 
-
 static
 int _lttng_variant_statedump(struct ust_registry_session *session,
                const struct ustctl_field *fields, size_t nr_fields,
@@ -310,6 +337,7 @@ int _lttng_variant_statedump(struct ust_registry_session *session,
        const struct ustctl_field *variant = &fields[*iter_field];
        uint32_t nr_choices, i;
        int ret;
+       char identifier[LTTNG_UST_SYM_NAME_LEN];
 
        if (variant->type.atype != ustctl_atype_variant) {
                ret = -EINVAL;
@@ -317,9 +345,14 @@ int _lttng_variant_statedump(struct ust_registry_session *session,
        }
        nr_choices = variant->type.u.variant.nr_choices;
        (*iter_field)++;
+       sanitize_ctf_identifier(identifier, variant->type.u.variant.tag_name);
+       ret = print_tabs(session, nesting);
+       if (ret) {
+               goto end;
+       }
        ret = lttng_metadata_printf(session,
-                       "               variant <_%s> {\n",
-                       variant->type.u.variant.tag_name);
+                       "variant <_%s> {\n",
+                       identifier);
        if (ret) {
                goto end;
        }
@@ -333,9 +366,11 @@ int _lttng_variant_statedump(struct ust_registry_session *session,
                                fields, nr_fields,
                                iter_field, nesting + 1);
        }
+       sanitize_ctf_identifier(identifier, variant->name);
+       ret = print_tabs(session, nesting);
        ret = lttng_metadata_printf(session,
-                       "               } _%s;\n",
-                       variant->name);
+                       "} _%s;\n",
+                       identifier);
        if (ret) {
                goto end;
        }
index ab887f74c285c0485b962089862bd39d4f5302c1..a45b6e8387c9d0d2ace601b41963bec41221a30b 100644 (file)
@@ -49,7 +49,8 @@ HEXDIGIT                      [0-9A-Fa-f]
 OCTALDIGIT                     [0-7]
 UCHARLOWERCASE                 \\u{HEXDIGIT}{4}
 UCHARUPPERCASE                 \\U{HEXDIGIT}{8}
-ID_NONDIGIT                    {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}
+ID_EXTRA_CHAR                  (":"|".")
+ID_NONDIGIT                    {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}|{ID_EXTRA_CHAR}
 IDENTIFIER                     {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})*
 ESCSEQ                         \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+)
 %%
index d694dcc1609d202ab0dd60a0be65795e5fdf03af..f734b56e3fb4f6bbbd2a9d6609d9222f85f3b379 100644 (file)
@@ -418,36 +418,30 @@ struct ir_op *make_expression(struct filter_parser_ctx *ctx,
                                        side);
        case AST_EXP_GLOBAL_IDENTIFIER:
        {
-               struct filter_node *next;
+               const char *name;
 
-               if (node->u.expression.pre_op == AST_LINK_UNKNOWN) {
-                       fprintf(stderr, "[error] %s: global identifiers need chained identifier \n", __func__);
-                       return NULL;
-               }
-               /* We currently only support $ctx (context) identifiers */
+               /*
+                * We currently only support $ctx (context) and $app
+                * identifiers.
+                */
                if (strncmp(node->u.expression.u.identifier,
-                               "$ctx", strlen("$ctx")) != 0) {
-                       fprintf(stderr, "[error] %s: \"%s\" global identifier is unknown. Only \"$ctx\" currently implemented.\n", __func__, node->u.expression.u.identifier);
-                       return NULL;
-               }
-               next = node->u.expression.next;
-               if (!next) {
-                       fprintf(stderr, "[error] %s: Expecting a context name, e.g. \'$ctx.name\'.\n", __func__);
+                               "$ctx.", strlen("$ctx.")) != 0
+                       && strncmp(node->u.expression.u.identifier,
+                               "$app.", strlen("$app.")) != 0) {
+                       fprintf(stderr, "[error] %s: \"%s\" global identifier is unknown. Only \"$ctx\" and \"$app\" are currently implemented.\n", __func__, node->u.expression.u.identifier);
                        return NULL;
                }
-               if (next->type != NODE_EXPRESSION) {
-                       fprintf(stderr, "[error] %s: Expecting expression.\n", __func__);
+               name = strchr(node->u.expression.u.identifier, '.');
+               if (!name) {
+                       fprintf(stderr, "[error] %s: Expecting '.'\n", __func__);
                        return NULL;
                }
-               if (next->u.expression.type != AST_EXP_IDENTIFIER) {
-                       fprintf(stderr, "[error] %s: Expecting identifier.\n", __func__);
-                       return NULL;
-               }
-               if (next->u.expression.pre_op != AST_LINK_UNKNOWN) {
-                       fprintf(stderr, "[error] %s: dotted and dereferenced identifiers not supported after identifier\n", __func__);
+               name++; /* Skip . */
+               if (!strlen(name)) {
+                       fprintf(stderr, "[error] %s: Expecting a context name, e.g. \'$ctx.name\'.\n", __func__);
                        return NULL;
                }
-               return make_op_load_get_context_ref(next->u.expression.u.identifier,
+               return make_op_load_get_context_ref(node->u.expression.u.identifier,
                                        side);
        }
        case AST_EXP_NESTED:
This page took 0.028659 seconds and 4 git commands to generate.