X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_trigger.cpp;h=8619a822161eda44fbe2f61aceb7dedae8c07781;hb=ff0a1009ba5fdd3d76f0faa9dcf2f8d4745b6082;hp=b1985e95c9100f89fba780ee42552baaffd18b2a;hpb=e776cf47dcf2cd7ab154392f30eb015f6a6f2866;p=lttng-tools.git diff --git a/src/bin/lttng/commands/add_trigger.cpp b/src/bin/lttng/commands/add_trigger.cpp index b1985e95c..8619a8221 100644 --- a/src/bin/lttng/commands/add_trigger.cpp +++ b/src/bin/lttng/commands/add_trigger.cpp @@ -10,23 +10,23 @@ #include #include -#include "../command.h" -#include "../loglevel.h" -#include "../uprobe.h" +#include "../command.hpp" +#include "../loglevel.hpp" +#include "../uprobe.hpp" #include "common/argpar/argpar.h" -#include "common/argpar-utils/argpar-utils.h" -#include "common/dynamic-array.h" -#include "common/mi-lttng.h" -#include "common/string-utils/string-utils.h" -#include "common/utils.h" -#include +#include "common/argpar-utils/argpar-utils.hpp" +#include "common/dynamic-array.hpp" +#include "common/mi-lttng.hpp" +#include "common/string-utils/string-utils.hpp" +#include "common/utils.hpp" +#include /* For lttng_event_rule_type_str(). */ -#include +#include #include -#include "common/filter/filter-ast.h" -#include "common/filter/filter-ir.h" -#include "common/dynamic-array.h" +#include "common/filter/filter-ast.hpp" +#include "common/filter/filter-ir.hpp" +#include "common/dynamic-array.hpp" #if (LTTNG_SYMBOL_NAME_LEN == 256) #define LTTNG_SYMBOL_NAME_LEN_SCANF_IS_A_BROKEN_API "255" @@ -355,7 +355,7 @@ static int parse_kernel_probe_opts(const char *source, PERROR("Failed to copy kernel probe location symbol name."); goto error; } - offset = strtoul(s_hex, NULL, 0); + offset = strtoull(s_hex, NULL, 0); *location = lttng_kernel_probe_location_symbol_create( symbol_name, offset); @@ -401,7 +401,7 @@ static int parse_kernel_probe_opts(const char *source, goto error; } - address = strtoul(s_hex, NULL, 0); + address = strtoull(s_hex, NULL, 0); *location = lttng_kernel_probe_location_address_create(address); if (!*location) { ERR("Failed to create symbol kernel probe location."); @@ -640,6 +640,7 @@ void destroy_event_expr(void *ptr) lttng_event_expr_destroy((lttng_event_expr *) ptr); } +namespace { struct parse_event_rule_res { /* Owned by this. */ struct lttng_event_rule *er; @@ -647,6 +648,7 @@ struct parse_event_rule_res { /* Array of `struct lttng_event_expr *` */ struct lttng_dynamic_pointer_array capture_descriptors; }; +} /* namespace */ static struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv, @@ -659,7 +661,7 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv, int consumed_args = -1; struct lttng_kernel_probe_location *kernel_probe_location = NULL; struct lttng_userspace_probe_location *userspace_probe_location = NULL; - struct parse_event_rule_res res = { 0 }; + struct parse_event_rule_res res = {}; struct lttng_event_expr *event_expr = NULL; struct filter_parser_ctx *parser_ctx = NULL; struct lttng_log_level_rule *log_level_rule = NULL; @@ -697,8 +699,9 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, - argc_offset, *argv, false, NULL); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + argc_offset, *argv, false, NULL, NULL); + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -786,6 +789,8 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv, event_expr = ir_op_root_to_event_expr( parser_ctx->ir_root, arg); + filter_parser_ctx_free(parser_ctx); + parser_ctx = nullptr; if (!event_expr) { /* * ir_op_root_to_event_expr has printed @@ -1403,17 +1408,31 @@ end: return c; } +namespace { struct condition_descr { const char *name; struct lttng_condition *(*handler) (int *argc, const char ***argv, int argc_offset); }; +} /* namespace */ static const struct condition_descr condition_descrs[] = { { "event-rule-matches", handle_condition_event }, }; +static +void print_valid_condition_names(void) +{ + unsigned int i; + + ERR("Valid condition names are:"); + + for (i = 0; i < ARRAY_SIZE(condition_descrs); ++i) { + ERR(" %s", condition_descrs[i].name); + } +} + static struct lttng_condition *parse_condition(const char *condition_name, int *argc, const char ***argv, int argc_offset, int orig_arg_index, @@ -1433,6 +1452,7 @@ struct lttng_condition *parse_condition(const char *condition_name, int *argc, if (!descr) { ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown condition name '%s'", orig_arg_index + 1, orig_arg, condition_name); + print_valid_condition_names(); goto error; } @@ -1547,9 +1567,10 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, - argc_offset, *argv, false, + argc_offset, *argv, false, NULL, "While parsing `notify` action:"); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -1653,9 +1674,10 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, argc_offset, - *argv, false, + *argv, false, NULL, "While parsing `%s` action:", action_name); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -1813,8 +1835,9 @@ struct lttng_action *handle_action_snapshot_session(int *argc, enum parse_next_item_status status; status = parse_next_item(argpar_iter, &argpar_item, argc_offset, - *argv, false, "While parsing `snapshot` action:"); - if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + *argv, false, NULL, "While parsing `snapshot` action:"); + if (status == PARSE_NEXT_ITEM_STATUS_ERROR || + status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -2082,11 +2105,13 @@ end: return action; } +namespace { struct action_descr { const char *name; struct lttng_action *(*handler) (int *argc, const char ***argv, int argc_offset); }; +} /* namespace */ static const struct action_descr action_descrs[] = { @@ -2097,6 +2122,18 @@ struct action_descr action_descrs[] = { { "snapshot-session", handle_action_snapshot_session }, }; +static +void print_valid_action_names(void) +{ + unsigned int i; + + ERR("Valid action names are:"); + + for (i = 0; i < ARRAY_SIZE(condition_descrs); ++i) { + ERR(" %s", action_descrs[i].name); + } +} + static struct lttng_action *parse_action(const char *action_name, int *argc, const char ***argv, int argc_offset, int orig_arg_index, @@ -2114,8 +2151,9 @@ struct lttng_action *parse_action(const char *action_name, int *argc, } if (!descr) { - ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown action name: %s", + ERR(WHILE_PARSING_ARG_N_ARG_FMT "Unknown action name '%s'", orig_arg_index + 1, orig_arg, action_name); + print_valid_action_names(); goto error; } @@ -2160,6 +2198,7 @@ int cmd_add_trigger(int argc, const char **argv) struct lttng_dynamic_pointer_array actions; struct argpar_iter *argpar_iter = NULL; const struct argpar_item *argpar_item = NULL; + const struct argpar_error *argpar_error = NULL; struct lttng_action *action_list = NULL; struct lttng_action *action = NULL; struct lttng_trigger *trigger = NULL; @@ -2211,8 +2250,22 @@ int cmd_add_trigger(int argc, const char **argv) } status = parse_next_item(argpar_iter, &argpar_item, - argc - my_argc, my_argv, true, NULL); + argc - my_argc, my_argv, true, &argpar_error, NULL); if (status == PARSE_NEXT_ITEM_STATUS_ERROR) { + + if (argpar_error_type(argpar_error) == + ARGPAR_ERROR_TYPE_MISSING_OPT_ARG) { + int opt_id = argpar_error_opt_descr(argpar_error, NULL)->id; + + if (opt_id == OPT_CONDITION) { + print_valid_condition_names(); + } else if (opt_id == OPT_ACTION) { + print_valid_action_names(); + } + } + + goto error; + } else if (status == PARSE_NEXT_ITEM_STATUS_ERROR_MEMORY) { goto error; } else if (status == PARSE_NEXT_ITEM_STATUS_END) { break; @@ -2432,6 +2485,7 @@ end: } cleanup: + argpar_error_destroy(argpar_error); argpar_iter_destroy(argpar_iter); argpar_item_destroy(argpar_item); lttng_dynamic_pointer_array_reset(&actions);