Commit d81fa63b authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf parse-events: Populate error column for BPF/tracepoint events

Follow convention from parse_events_terms__num/str and pass the
YYLTYPE for the location.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20230627181030.95608-12-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b30d4f0b
...@@ -124,7 +124,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void), ...@@ -124,7 +124,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void),
parse_state.error = &parse_error; parse_state.error = &parse_error;
INIT_LIST_HEAD(&parse_state.list); INIT_LIST_HEAD(&parse_state.list);
err = parse_events_load_bpf_obj(&parse_state, &parse_state.list, obj, NULL); err = parse_events_load_bpf_obj(&parse_state, &parse_state.list, obj, NULL, NULL);
parse_events_error__exit(&parse_error); parse_events_error__exit(&parse_error);
if (err == -ENODATA) { if (err == -ENODATA) {
pr_debug("Failed to add events selected by BPF, debuginfo package not installed\n"); pr_debug("Failed to add events selected by BPF, debuginfo package not installed\n");
......
...@@ -499,7 +499,7 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name, ...@@ -499,7 +499,7 @@ int parse_events_add_cache(struct list_head *list, int *idx, const char *name,
#ifdef HAVE_LIBTRACEEVENT #ifdef HAVE_LIBTRACEEVENT
static void tracepoint_error(struct parse_events_error *e, int err, static void tracepoint_error(struct parse_events_error *e, int err,
const char *sys, const char *name) const char *sys, const char *name, int column)
{ {
const char *str; const char *str;
char help[BUFSIZ]; char help[BUFSIZ];
...@@ -526,18 +526,19 @@ static void tracepoint_error(struct parse_events_error *e, int err, ...@@ -526,18 +526,19 @@ static void tracepoint_error(struct parse_events_error *e, int err,
} }
tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name); tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
parse_events_error__handle(e, 0, strdup(str), strdup(help)); parse_events_error__handle(e, column, strdup(str), strdup(help));
} }
static int add_tracepoint(struct list_head *list, int *idx, static int add_tracepoint(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name, const char *sys_name, const char *evt_name,
struct parse_events_error *err, struct parse_events_error *err,
struct list_head *head_config) struct list_head *head_config, void *loc_)
{ {
YYLTYPE *loc = loc_;
struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, (*idx)++); struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, (*idx)++);
if (IS_ERR(evsel)) { if (IS_ERR(evsel)) {
tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name); tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name, loc->first_column);
return PTR_ERR(evsel); return PTR_ERR(evsel);
} }
...@@ -556,7 +557,7 @@ static int add_tracepoint(struct list_head *list, int *idx, ...@@ -556,7 +557,7 @@ static int add_tracepoint(struct list_head *list, int *idx,
static int add_tracepoint_multi_event(struct list_head *list, int *idx, static int add_tracepoint_multi_event(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name, const char *sys_name, const char *evt_name,
struct parse_events_error *err, struct parse_events_error *err,
struct list_head *head_config) struct list_head *head_config, YYLTYPE *loc)
{ {
char *evt_path; char *evt_path;
struct dirent *evt_ent; struct dirent *evt_ent;
...@@ -565,13 +566,13 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx, ...@@ -565,13 +566,13 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
evt_path = get_events_file(sys_name); evt_path = get_events_file(sys_name);
if (!evt_path) { if (!evt_path) {
tracepoint_error(err, errno, sys_name, evt_name); tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
return -1; return -1;
} }
evt_dir = opendir(evt_path); evt_dir = opendir(evt_path);
if (!evt_dir) { if (!evt_dir) {
put_events_file(evt_path); put_events_file(evt_path);
tracepoint_error(err, errno, sys_name, evt_name); tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
return -1; return -1;
} }
...@@ -588,11 +589,11 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx, ...@@ -588,11 +589,11 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
found++; found++;
ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name, ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name,
err, head_config); err, head_config, loc);
} }
if (!found) { if (!found) {
tracepoint_error(err, ENOENT, sys_name, evt_name); tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column);
ret = -1; ret = -1;
} }
...@@ -604,19 +605,19 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx, ...@@ -604,19 +605,19 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
static int add_tracepoint_event(struct list_head *list, int *idx, static int add_tracepoint_event(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name, const char *sys_name, const char *evt_name,
struct parse_events_error *err, struct parse_events_error *err,
struct list_head *head_config) struct list_head *head_config, YYLTYPE *loc)
{ {
return strpbrk(evt_name, "*?") ? return strpbrk(evt_name, "*?") ?
add_tracepoint_multi_event(list, idx, sys_name, evt_name, add_tracepoint_multi_event(list, idx, sys_name, evt_name,
err, head_config) : err, head_config, loc) :
add_tracepoint(list, idx, sys_name, evt_name, add_tracepoint(list, idx, sys_name, evt_name,
err, head_config); err, head_config, loc);
} }
static int add_tracepoint_multi_sys(struct list_head *list, int *idx, static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
const char *sys_name, const char *evt_name, const char *sys_name, const char *evt_name,
struct parse_events_error *err, struct parse_events_error *err,
struct list_head *head_config) struct list_head *head_config, YYLTYPE *loc)
{ {
struct dirent *events_ent; struct dirent *events_ent;
DIR *events_dir; DIR *events_dir;
...@@ -624,7 +625,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx, ...@@ -624,7 +625,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
events_dir = tracing_events__opendir(); events_dir = tracing_events__opendir();
if (!events_dir) { if (!events_dir) {
tracepoint_error(err, errno, sys_name, evt_name); tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
return -1; return -1;
} }
...@@ -640,7 +641,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx, ...@@ -640,7 +641,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
continue; continue;
ret = add_tracepoint_event(list, idx, events_ent->d_name, ret = add_tracepoint_event(list, idx, events_ent->d_name,
evt_name, err, head_config); evt_name, err, head_config, loc);
} }
closedir(events_dir); closedir(events_dir);
...@@ -653,6 +654,7 @@ struct __add_bpf_event_param { ...@@ -653,6 +654,7 @@ struct __add_bpf_event_param {
struct parse_events_state *parse_state; struct parse_events_state *parse_state;
struct list_head *list; struct list_head *list;
struct list_head *head_config; struct list_head *head_config;
YYLTYPE *loc;
}; };
static int add_bpf_event(const char *group, const char *event, int fd, struct bpf_object *obj, static int add_bpf_event(const char *group, const char *event, int fd, struct bpf_object *obj,
...@@ -679,7 +681,7 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bp ...@@ -679,7 +681,7 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bp
err = parse_events_add_tracepoint(&new_evsels, &parse_state->idx, group, err = parse_events_add_tracepoint(&new_evsels, &parse_state->idx, group,
event, parse_state->error, event, parse_state->error,
param->head_config); param->head_config, param->loc);
if (err) { if (err) {
struct evsel *evsel, *tmp; struct evsel *evsel, *tmp;
...@@ -706,12 +708,14 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bp ...@@ -706,12 +708,14 @@ static int add_bpf_event(const char *group, const char *event, int fd, struct bp
int parse_events_load_bpf_obj(struct parse_events_state *parse_state, int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
struct list_head *list, struct list_head *list,
struct bpf_object *obj, struct bpf_object *obj,
struct list_head *head_config) struct list_head *head_config,
void *loc)
{ {
int err; int err;
char errbuf[BUFSIZ]; char errbuf[BUFSIZ];
struct __add_bpf_event_param param = {parse_state, list, head_config}; struct __add_bpf_event_param param = {parse_state, list, head_config, loc};
static bool registered_unprobe_atexit = false; static bool registered_unprobe_atexit = false;
YYLTYPE test_loc = {.first_column = -1};
if (IS_ERR(obj) || !obj) { if (IS_ERR(obj) || !obj) {
snprintf(errbuf, sizeof(errbuf), snprintf(errbuf, sizeof(errbuf),
...@@ -742,6 +746,9 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state, ...@@ -742,6 +746,9 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
goto errout; goto errout;
} }
if (!param.loc)
param.loc = &test_loc;
err = bpf__foreach_event(obj, add_bpf_event, &param); err = bpf__foreach_event(obj, add_bpf_event, &param);
if (err) { if (err) {
snprintf(errbuf, sizeof(errbuf), snprintf(errbuf, sizeof(errbuf),
...@@ -751,7 +758,7 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state, ...@@ -751,7 +758,7 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
return 0; return 0;
errout: errout:
parse_events_error__handle(parse_state->error, 0, parse_events_error__handle(parse_state->error, param.loc->first_column,
strdup(errbuf), strdup("(add -v to see detail)")); strdup(errbuf), strdup("(add -v to see detail)"));
return err; return err;
} }
...@@ -839,11 +846,13 @@ int parse_events_load_bpf(struct parse_events_state *parse_state, ...@@ -839,11 +846,13 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
struct list_head *list, struct list_head *list,
char *bpf_file_name, char *bpf_file_name,
bool source, bool source,
struct list_head *head_config) struct list_head *head_config,
void *loc_)
{ {
int err; int err;
struct bpf_object *obj; struct bpf_object *obj;
LIST_HEAD(obj_head_config); LIST_HEAD(obj_head_config);
YYLTYPE *loc = loc_;
if (head_config) if (head_config)
split_bpf_config_terms(head_config, &obj_head_config); split_bpf_config_terms(head_config, &obj_head_config);
...@@ -863,12 +872,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state, ...@@ -863,12 +872,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
-err, errbuf, -err, errbuf,
sizeof(errbuf)); sizeof(errbuf));
parse_events_error__handle(parse_state->error, 0, parse_events_error__handle(parse_state->error, loc->first_column,
strdup(errbuf), strdup("(add -v to see detail)")); strdup(errbuf), strdup("(add -v to see detail)"));
return err; return err;
} }
err = parse_events_load_bpf_obj(parse_state, list, obj, head_config); err = parse_events_load_bpf_obj(parse_state, list, obj, head_config, loc);
if (err) if (err)
return err; return err;
err = parse_events_config_bpf(parse_state, obj, &obj_head_config); err = parse_events_config_bpf(parse_state, obj, &obj_head_config);
...@@ -885,9 +894,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state, ...@@ -885,9 +894,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
int parse_events_load_bpf_obj(struct parse_events_state *parse_state, int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
struct list_head *list __maybe_unused, struct list_head *list __maybe_unused,
struct bpf_object *obj __maybe_unused, struct bpf_object *obj __maybe_unused,
struct list_head *head_config __maybe_unused) struct list_head *head_config __maybe_unused,
void *loc_)
{ {
parse_events_error__handle(parse_state->error, 0, YYLTYPE *loc = loc_;
parse_events_error__handle(parse_state->error, loc->first_column,
strdup("BPF support is not compiled"), strdup("BPF support is not compiled"),
strdup("Make sure libbpf-devel is available at build time.")); strdup("Make sure libbpf-devel is available at build time."));
return -ENOTSUP; return -ENOTSUP;
...@@ -897,9 +909,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state, ...@@ -897,9 +909,12 @@ int parse_events_load_bpf(struct parse_events_state *parse_state,
struct list_head *list __maybe_unused, struct list_head *list __maybe_unused,
char *bpf_file_name __maybe_unused, char *bpf_file_name __maybe_unused,
bool source __maybe_unused, bool source __maybe_unused,
struct list_head *head_config __maybe_unused) struct list_head *head_config __maybe_unused,
void *loc_)
{ {
parse_events_error__handle(parse_state->error, 0, YYLTYPE *loc = loc_;
parse_events_error__handle(parse_state->error, loc->first_column,
strdup("BPF support is not compiled"), strdup("BPF support is not compiled"),
strdup("Make sure libbpf-devel is available at build time.")); strdup("Make sure libbpf-devel is available at build time."));
return -ENOTSUP; return -ENOTSUP;
...@@ -1441,8 +1456,9 @@ static int get_config_chgs(struct perf_pmu *pmu, struct list_head *head_config, ...@@ -1441,8 +1456,9 @@ static int get_config_chgs(struct perf_pmu *pmu, struct list_head *head_config,
int parse_events_add_tracepoint(struct list_head *list, int *idx, int parse_events_add_tracepoint(struct list_head *list, int *idx,
const char *sys, const char *event, const char *sys, const char *event,
struct parse_events_error *err, struct parse_events_error *err,
struct list_head *head_config) struct list_head *head_config, void *loc_)
{ {
YYLTYPE *loc = loc_;
#ifdef HAVE_LIBTRACEEVENT #ifdef HAVE_LIBTRACEEVENT
if (head_config) { if (head_config) {
struct perf_event_attr attr; struct perf_event_attr attr;
...@@ -1454,17 +1470,17 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, ...@@ -1454,17 +1470,17 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx,
if (strpbrk(sys, "*?")) if (strpbrk(sys, "*?"))
return add_tracepoint_multi_sys(list, idx, sys, event, return add_tracepoint_multi_sys(list, idx, sys, event,
err, head_config); err, head_config, loc);
else else
return add_tracepoint_event(list, idx, sys, event, return add_tracepoint_event(list, idx, sys, event,
err, head_config); err, head_config, loc);
#else #else
(void)list; (void)list;
(void)idx; (void)idx;
(void)sys; (void)sys;
(void)event; (void)event;
(void)head_config; (void)head_config;
parse_events_error__handle(err, 0, strdup("unsupported tracepoint"), parse_events_error__handle(err, loc->first_column, strdup("unsupported tracepoint"),
strdup("libtraceevent is necessary for tracepoint support")); strdup("libtraceevent is necessary for tracepoint support"));
return -1; return -1;
#endif #endif
......
...@@ -169,18 +169,20 @@ int parse_events_name(struct list_head *list, const char *name); ...@@ -169,18 +169,20 @@ int parse_events_name(struct list_head *list, const char *name);
int parse_events_add_tracepoint(struct list_head *list, int *idx, int parse_events_add_tracepoint(struct list_head *list, int *idx,
const char *sys, const char *event, const char *sys, const char *event,
struct parse_events_error *error, struct parse_events_error *error,
struct list_head *head_config); struct list_head *head_config, void *loc);
int parse_events_load_bpf(struct parse_events_state *parse_state, int parse_events_load_bpf(struct parse_events_state *parse_state,
struct list_head *list, struct list_head *list,
char *bpf_file_name, char *bpf_file_name,
bool source, bool source,
struct list_head *head_config); struct list_head *head_config,
void *loc);
/* Provide this function for perf test */ /* Provide this function for perf test */
struct bpf_object; struct bpf_object;
int parse_events_load_bpf_obj(struct parse_events_state *parse_state, int parse_events_load_bpf_obj(struct parse_events_state *parse_state,
struct list_head *list, struct list_head *list,
struct bpf_object *obj, struct bpf_object *obj,
struct list_head *head_config); struct list_head *head_config,
void *loc);
int parse_events_add_numeric(struct parse_events_state *parse_state, int parse_events_add_numeric(struct parse_events_state *parse_state,
struct list_head *list, struct list_head *list,
u32 type, u64 config, u32 type, u64 config,
......
...@@ -567,7 +567,7 @@ tracepoint_name opt_event_config ...@@ -567,7 +567,7 @@ tracepoint_name opt_event_config
error->idx = @1.first_column; error->idx = @1.first_column;
err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
error, $2); error, $2, &@1);
parse_events_terms__delete($2); parse_events_terms__delete($2);
free($1.sys); free($1.sys);
...@@ -640,7 +640,7 @@ PE_BPF_OBJECT opt_event_config ...@@ -640,7 +640,7 @@ PE_BPF_OBJECT opt_event_config
list = alloc_list(); list = alloc_list();
if (!list) if (!list)
YYNOMEM; YYNOMEM;
err = parse_events_load_bpf(parse_state, list, $1, false, $2); err = parse_events_load_bpf(parse_state, list, $1, false, $2, &@1);
parse_events_terms__delete($2); parse_events_terms__delete($2);
free($1); free($1);
if (err) { if (err) {
...@@ -658,7 +658,7 @@ PE_BPF_SOURCE opt_event_config ...@@ -658,7 +658,7 @@ PE_BPF_SOURCE opt_event_config
list = alloc_list(); list = alloc_list();
if (!list) if (!list)
YYNOMEM; YYNOMEM;
err = parse_events_load_bpf(_parse_state, list, $1, true, $2); err = parse_events_load_bpf(_parse_state, list, $1, true, $2, &@1);
parse_events_terms__delete($2); parse_events_terms__delete($2);
if (err) { if (err) {
free(list); free(list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment