X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_trigger.c;h=1859a7fa8c46fcd0172ef14a3c2a5cfca18bec65;hp=af58d7b316d604cc3839780fdd22d758b79f64f4;hb=24de704ea32ddb8841624555457b9c46816090b0;hpb=665db06360d2bb830a47a2562ef0ebc28a1d75df diff --git a/src/bin/lttng/commands/add_trigger.c b/src/bin/lttng/commands/add_trigger.c index af58d7b31..1859a7fa8 100644 --- a/src/bin/lttng/commands/add_trigger.c +++ b/src/bin/lttng/commands/add_trigger.c @@ -43,25 +43,17 @@ enum { OPT_USER_ID, OPT_RATE_POLICY, - OPT_ALL, + OPT_NAME, OPT_FILTER, - OPT_EXCLUDE, + OPT_EXCLUDE_NAMES, + OPT_EVENT_NAME, OPT_LOGLEVEL, OPT_LOGLEVEL_ONLY, - OPT_USERSPACE, - OPT_KERNEL, - OPT_LOG4J, - OPT_JUL, - OPT_PYTHON, - - OPT_FUNCTION, - OPT_PROBE, - OPT_USERSPACE_PROBE, - OPT_SYSCALL, - OPT_TRACEPOINT, + OPT_DOMAIN, + OPT_TYPE, + OPT_LOCATION, - OPT_NAME, OPT_MAX_SIZE, OPT_DATA_URL, OPT_CTRL_URL, @@ -72,25 +64,16 @@ enum { }; static const struct argpar_opt_descr event_rule_opt_descrs[] = { - { OPT_ALL, 'a', "all", false }, { OPT_FILTER, 'f', "filter", true }, - { OPT_EXCLUDE, 'x', "exclude", true }, + { OPT_NAME, 'n', "name", true }, + { OPT_EXCLUDE_NAMES, 'x', "exclude-names", true }, { OPT_LOGLEVEL, '\0', "loglevel", true }, { OPT_LOGLEVEL_ONLY, '\0', "loglevel-only", true }, + { OPT_EVENT_NAME, 'E', "event-name", true }, - /* Domains */ - { OPT_USERSPACE, 'u', "userspace", false }, - { OPT_KERNEL, 'k', "kernel", false }, - { OPT_LOG4J, 'l', "log4j", false }, - { OPT_JUL, 'j', "jul", false }, - { OPT_PYTHON, 'p', "python", false }, - - /* Event rule types */ - { OPT_FUNCTION, '\0', "function", true }, - { OPT_PROBE, '\0', "probe", true }, - { OPT_USERSPACE_PROBE, '\0', "userspace-probe", true }, - { OPT_SYSCALL, '\0', "syscall" }, - { OPT_TRACEPOINT, '\0', "tracepoint" }, + { OPT_DOMAIN, 'd', "domain", true }, + { OPT_TYPE, 't', "type", true }, + { OPT_LOCATION, 'L', "location", true }, /* Capture descriptor */ { OPT_CAPTURE, '\0', "capture", true }, @@ -99,36 +82,72 @@ static const struct argpar_opt_descr event_rule_opt_descrs[] = { }; static -bool assign_domain_type(enum lttng_domain_type *dest, - enum lttng_domain_type src) +bool assign_domain_type(enum lttng_domain_type *dest, const char *arg) { bool ret; - if (*dest == LTTNG_DOMAIN_NONE || *dest == src) { - *dest = src; - ret = true; + if (*dest != LTTNG_DOMAIN_NONE) { + ERR("More than one `--domain` was specified."); + goto error; + } + + if (strcmp(arg, "kernel") == 0) { + *dest = LTTNG_DOMAIN_KERNEL; + } else if (strcmp(arg, "user") == 0 || strcmp(arg, "userspace") == 0) { + *dest = LTTNG_DOMAIN_UST; + } else if (strcmp(arg, "jul") == 0) { + *dest = LTTNG_DOMAIN_JUL; + } else if (strcmp(arg, "log4j") == 0) { + *dest = LTTNG_DOMAIN_LOG4J; + } else if (strcmp(arg, "python") == 0) { + *dest = LTTNG_DOMAIN_PYTHON; } else { - ERR("Multiple domains specified."); - ret = false; + ERR("Invalid `--domain` value: %s", arg); + goto error; } + ret = true; + goto end; + +error: + ret = false; + +end: return ret; } static -bool assign_event_rule_type(enum lttng_event_rule_type *dest, - enum lttng_event_rule_type src) +bool assign_event_rule_type(enum lttng_event_rule_type *dest, const char *arg) { bool ret; - if (*dest == LTTNG_EVENT_RULE_TYPE_UNKNOWN || *dest == src) { - *dest = src; - ret = true; + if (*dest != LTTNG_EVENT_RULE_TYPE_UNKNOWN) { + ERR("More than one `--type` was specified."); + goto error; + } + + if (strcmp(arg, "tracepoint") == 0 || strcmp(arg, "logging") == 0) { + *dest = LTTNG_EVENT_RULE_TYPE_TRACEPOINT; + } else if (strcmp (arg, "kprobe") == 0 || strcmp(arg, "kernel-probe") == 0) { + *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE; + } else if (strcmp (arg, "uprobe") == 0 || strcmp(arg, "userspace-probe") == 0) { + *dest = LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE; + } else if (strcmp (arg, "function") == 0) { + *dest = LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION; + } else if (strcmp (arg, "syscall") == 0) { + *dest = LTTNG_EVENT_RULE_TYPE_SYSCALL; } else { - ERR("Multiple event types specified."); - ret = false; + ERR("Invalid `--type` value: %s", arg); + goto error; } + ret = true; + goto end; + +error: + ret = false; + +end: return ret; } @@ -542,22 +561,18 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) struct filter_parser_ctx *parser_ctx = NULL; struct lttng_log_level_rule *log_level_rule = NULL; - /* Was the -a/--all flag provided? */ - bool all_events = false; - - /* Tracepoint name (non-option argument). */ - const char *tracepoint_name = NULL; + /* Tracepoint and syscall options. */ + char *name = NULL; + char *exclude_names = NULL; + char **exclusion_list = NULL; - /* Holds the argument of --probe / --userspace-probe. */ - char *source = NULL; + /* For userspace / kernel probe and function. */ + char *location = NULL; + char *event_name = NULL; /* Filter. */ char *filter = NULL; - /* Exclude. */ - char *exclude = NULL; - char **exclusion_list = NULL; - /* Log level. */ char *loglevel_str = NULL; bool loglevel_only = false; @@ -593,94 +608,54 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) switch (item_opt->descr->id) { /* Domains. */ - case OPT_USERSPACE: - if (!assign_domain_type(&domain_type, LTTNG_DOMAIN_UST)) { - goto error; - } - - break; - case OPT_KERNEL: - if (!assign_domain_type(&domain_type, LTTNG_DOMAIN_KERNEL)) { - goto error; - } - - break; - case OPT_LOG4J: - if (!assign_domain_type(&domain_type, LTTNG_DOMAIN_LOG4J)) { - goto error; - } - - break; - case OPT_JUL: - if (!assign_domain_type(&domain_type, LTTNG_DOMAIN_JUL)) { - goto error; - } - - break; - case OPT_PYTHON: - if (!assign_domain_type(&domain_type, LTTNG_DOMAIN_PYTHON)) { - goto error; - } - - break; - - /* Event rule types */ - case OPT_FUNCTION: - if (!assign_event_rule_type(&event_rule_type, - LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION)) { + case OPT_DOMAIN: + if (!assign_domain_type(&domain_type, + item_opt->arg)) { goto error; } break; - case OPT_PROBE: + case OPT_TYPE: if (!assign_event_rule_type(&event_rule_type, - LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE)) { - goto error; - } - - if (!assign_string(&source, item_opt->arg, "source")) { + item_opt->arg)) { goto error; } break; - case OPT_USERSPACE_PROBE: - if (!assign_event_rule_type(&event_rule_type, - LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE)) { + case OPT_LOCATION: + if (!assign_string(&location, + item_opt->arg, + "--location/-L")) { goto error; } - if (!assign_string(&source, item_opt->arg, "source")) { - goto error; - } - break; - case OPT_SYSCALL: - if (!assign_event_rule_type(&event_rule_type, - LTTNG_EVENT_RULE_TYPE_SYSCALL)) { + case OPT_EVENT_NAME: + if (!assign_string(&event_name, + item_opt->arg, + "--event-name/-E")) { goto error; } break; - case OPT_TRACEPOINT: - if (!assign_event_rule_type(&event_rule_type, - LTTNG_EVENT_RULE_TYPE_TRACEPOINT)) { + case OPT_FILTER: + if (!assign_string(&filter, item_opt->arg, + "--filter/-f")) { goto error; } break; - case OPT_ALL: - all_events = true; - break; - case OPT_FILTER: - if (!assign_string(&filter, item_opt->arg, - "--filter/-f")) { + case OPT_NAME: + if (!assign_string(&name, item_opt->arg, + "--name/-n")) { goto error; } break; - case OPT_EXCLUDE: - if (!assign_string(&exclude, item_opt->arg, - "--exclude/-x")) { + case OPT_EXCLUDE_NAMES: + if (!assign_string(&exclude_names, + item_opt->arg, + "--exclude-names/-x")) { goto error; } @@ -742,17 +717,9 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) (const struct argpar_item_non_opt *) item; - /* - * Don't accept two non-option arguments/tracepoint - * names. - */ - if (tracepoint_name) { - ERR("Unexpected argument '%s'", - item_non_opt->arg); - goto error; - } - - tracepoint_name = item_non_opt->arg; + /* Don't accept non-option arguments. */ + ERR("Unexpected argument '%s'", item_non_opt->arg); + goto error; } } @@ -761,44 +728,70 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } /* - * Option -a is applicable to event rules of type tracepoint and - * syscall, and it is equivalent to using "*" as the tracepoint name. + * Option --name is applicable to event rules of type tracepoint + * and syscall. For tracepoint and syscall rules, if --name is + * omitted, it is implicitly "*". */ - if (all_events) { - switch (event_rule_type) { - case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: - case LTTNG_EVENT_RULE_TYPE_SYSCALL: - break; - default: - ERR("Can't use -a/--all with %s event rules.", - lttng_event_rule_type_str(event_rule_type)); - goto error; + switch (event_rule_type) { + case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: + case LTTNG_EVENT_RULE_TYPE_SYSCALL: + if (!name) { + name = strdup("*"); } + break; - if (tracepoint_name) { - ERR("Can't provide a tracepoint name with -a/--all."); + default: + if (name) { + ERR("Can't use --name with %s event rules.", + lttng_event_rule_type_str( + event_rule_type)); goto error; } - /* In which case, it's equivalent to tracepoint name "*". */ - tracepoint_name = "*"; + if (exclude_names) { + ERR("Can't use --exclude-names/-x with %s event rules.", + lttng_event_rule_type_str( + event_rule_type)); + goto error; + } } /* - * A tracepoint name (or -a, for the event rule types that accept it) - * is required. + * Option --location is only applicable to (and mandatory for) event + * rules of type {k,u}probe and function. + * + * Option --event-name is only applicable to event rules of type probe. + * If omitted, it defaults to the location. */ - if (!tracepoint_name) { - ERR("Need to provide either a tracepoint name or -a/--all."); - goto error; - } + switch (event_rule_type) { + case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE: + case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE: + case LTTNG_EVENT_RULE_TYPE_KERNEL_FUNCTION: + if (!location) { + ERR("Event rule of type %s requires a --location.", + lttng_event_rule_type_str(event_rule_type)); + goto error; + } - /* - * We don't support multiple tracepoint names for now. - */ - if (strchr(tracepoint_name, ',')) { - ERR("Comma separated tracepoint names are not supported."); - goto error; + if (!event_name) { + event_name = strdup(location); + } + + break; + + default: + if (location) { + ERR("Can't use --location with %s event rules.", + lttng_event_rule_type_str(event_rule_type)); + goto error; + } + + if (event_name) { + ERR("Can't use --event-name with %s event rules.", + lttng_event_rule_type_str( + event_rule_type)); + goto error; + } } /* @@ -811,7 +804,7 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) /* Need to specify a domain. */ if (domain_type == LTTNG_DOMAIN_NONE) { - ERR("Please specify a domain (--kernel/--userspace/--jul/--log4j/--python)."); + ERR("Please specify a domain (--domain=(kernel,user,jul,log4j,python))."); goto error; } @@ -852,16 +845,15 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } /* If --exclude/-x was passed, split it into an exclusion list. */ - if (exclude) { + if (exclude_names) { if (domain_type != LTTNG_DOMAIN_UST) { ERR("Event name exclusions are not yet implemented for %s event rules.", get_domain_str(domain_type)); goto error; } - - if (create_exclusion_list_and_validate(tracepoint_name, exclude, - &exclusion_list) != 0) { + if (create_exclusion_list_and_validate(name, + exclude_names, &exclusion_list) != 0) { ERR("Failed to create exclusion list."); goto error; } @@ -886,10 +878,10 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) /* Set pattern. */ event_rule_status = lttng_event_rule_tracepoint_set_pattern( - res.er, tracepoint_name); + res.er, name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set tracepoint event rule's pattern to '%s'.", - tracepoint_name); + name); goto error; } @@ -965,8 +957,8 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) int ret; enum lttng_event_rule_status event_rule_status; - - ret = parse_kernel_probe_opts(source, &kernel_probe_location); + ret = parse_kernel_probe_opts( + location, &kernel_probe_location); if (ret) { ERR("Failed to parse kernel probe location."); goto error; @@ -979,9 +971,12 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - event_rule_status = lttng_event_rule_kernel_probe_set_event_name(res.er, tracepoint_name); + event_rule_status = + lttng_event_rule_kernel_probe_set_event_name( + res.er, event_name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { - ERR("Failed to set kprobe event rule's name to '%s'.", tracepoint_name); + ERR("Failed to set kprobe event rule's name to '%s'.", + event_name); goto error; } @@ -993,7 +988,7 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) enum lttng_event_rule_status event_rule_status; ret = parse_userspace_probe_opts( - source, &userspace_probe_location); + location, &userspace_probe_location); if (ret) { ERR("Failed to parse user space probe location."); goto error; @@ -1005,11 +1000,12 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) goto error; } - event_rule_status = lttng_event_rule_userspace_probe_set_event_name( - res.er, tracepoint_name); + event_rule_status = + lttng_event_rule_userspace_probe_set_event_name( + res.er, event_name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set user space probe event rule's name to '%s'.", - tracepoint_name); + event_name); goto error; } @@ -1026,10 +1022,10 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv) } event_rule_status = lttng_event_rule_syscall_set_pattern( - res.er, tracepoint_name); + res.er, name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to set syscall event rule's pattern to '%s'.", - tracepoint_name); + name); goto error; } @@ -1067,9 +1063,12 @@ end: free(error); argpar_state_destroy(state); free(filter); - free(exclude); + free(name); + free(exclude_names); free(loglevel_str); - free(source); + free(location); + free(event_name); + strutils_free_null_terminated_array_of_strings(exclusion_list); lttng_kernel_probe_location_destroy(kernel_probe_location); lttng_userspace_probe_location_destroy(userspace_probe_location);