perf parse-events: Report BPF errors

Setting the parse_events_error directly doesn't increment num_errors
causing the error message not to be displayed. Use the
parse_events__handle_error function that sets num_errors and handle
multiple errors.

Committer notes:

Ian provided a before/after upon request:

Before:

  $ /tmp/perf/perf record -e /tmp/perf/util/parse-events.o
  Run 'perf list' for a list of valid events

  Usage: perf record [<options>] [<command>]
     or: perf record [<options>] -- <command> [<options>]

     -e, --event <event>   event selector. use 'perf list' to list available event

After:

  $ /tmp/perf/perf record -e /tmp/perf/util/parse-events.o
  event syntax error: '/tmp/perf/util/parse-events.o'
                      \___ Failed to load /tmp/perf/util/parse-events.o: BPF object format invalid

  (add -v to see detail)
  Run 'perf list' for a list of valid events

  Usage: perf record [<options>] [<command>]
     or: perf record [<options>] -- <command> [<options>]

     -e, --event <event>   event selector. use 'perf list' to list available events

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: bpf@vger.kernel.org
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@chromium.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: netdev@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Yonghong Song <yhs@fb.com>
Link: http://lore.kernel.org/lkml/20200707211449.3868944-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Ian Rogers 2020-07-07 14:14:49 -07:00 committed by Arnaldo Carvalho de Melo
parent 7eeb9855c1
commit 5f634c8e40

View File

@ -767,8 +767,8 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
return 0;
errout:
parse_state->error->help = strdup("(add -v to see detail)");
parse_state->error->str = strdup(errbuf);
parse_events__handle_error(parse_state->error, 0,
strdup(errbuf), strdup("(add -v to see detail)"));
return err;
}
@ -784,36 +784,38 @@ parse_events_config_bpf(struct parse_events_state *parse_state,
return 0;
list_for_each_entry(term, head_config, list) {
char errbuf[BUFSIZ];
int err;
if (term->type_term != PARSE_EVENTS__TERM_TYPE_USER) {
snprintf(errbuf, sizeof(errbuf),
"Invalid config term for BPF object");
errbuf[BUFSIZ - 1] = '\0';
parse_state->error->idx = term->err_term;
parse_state->error->str = strdup(errbuf);
parse_events__handle_error(parse_state->error, term->err_term,
strdup("Invalid config term for BPF object"),
NULL);
return -EINVAL;
}
err = bpf__config_obj(obj, term, parse_state->evlist, &error_pos);
if (err) {
char errbuf[BUFSIZ];
int idx;
bpf__strerror_config_obj(obj, term, parse_state->evlist,
&error_pos, err, errbuf,
sizeof(errbuf));
parse_state->error->help = strdup(
if (err == -BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE)
idx = term->err_val;
else
idx = term->err_term + error_pos;
parse_events__handle_error(parse_state->error, idx,
strdup(errbuf),
strdup(
"Hint:\tValid config terms:\n"
" \tmap:[<arraymap>].value<indices>=[value]\n"
" \tmap:[<eventmap>].event<indices>=[event]\n"
"\n"
" \twhere <indices> is something like [0,3...5] or [all]\n"
" \t(add -v to see detail)");
parse_state->error->str = strdup(errbuf);
if (err == -BPF_LOADER_ERRNO__OBJCONF_MAP_VALUE)
parse_state->error->idx = term->err_val;
else
parse_state->error->idx = term->err_term + error_pos;
" \t(add -v to see detail)"));
return err;
}
}
@ -877,8 +879,8 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
-err, errbuf,
sizeof(errbuf));
parse_state->error->help = strdup("(add -v to see detail)");
parse_state->error->str = strdup(errbuf);
parse_events__handle_error(parse_state->error, 0,
strdup(errbuf), strdup("(add -v to see detail)"));
return err;
}