From: Mathieu Desnoyers Date: Tue, 26 Jan 2016 15:14:17 +0000 (-0500) Subject: Allow $app.provider:ctxname in filter, enum, variant identifiers X-Git-Tag: v2.8.0-rc1~174 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a1f68b22f074a74a905abd109811d25cb39e9b3b;p=lttng-tools.git Allow $app.provider:ctxname in filter, enum, variant identifiers Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index fc1ea2e7b..cb77e8130 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -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; } diff --git a/src/lib/lttng-ctl/filter/filter-lexer.l b/src/lib/lttng-ctl/filter/filter-lexer.l index ab887f74c..a45b6e838 100644 --- a/src/lib/lttng-ctl/filter/filter-lexer.l +++ b/src/lib/lttng-ctl/filter/filter-lexer.l @@ -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}+) %% diff --git a/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c b/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c index d694dcc16..f734b56e3 100644 --- a/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c +++ b/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c @@ -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: