Skip to content

Commit 8cb0aa4

Browse files
mhiramathitachiacmel
authored andcommitted
perf probe: Check the orphaned -x option
To avoid probing in unintended binary, the orphaned -x option must be checked and warned. Without this patch, following command sets up the probe in the kernel. ----- # perf probe -a strcpy -x ./perf Added new event: probe:strcpy (on strcpy) You can now use it in all perf tools, such as: perf record -e probe:strcpy -aR sleep 1 ----- But in this case, it seems that the user may want to probe in the perf binary. With this patch, perf-probe correctly handles the orphaned -x. ----- # perf probe -a strcpy -x ./perf Error: -x/-m must follow the probe definitions. ... ----- Reported-by: Jiri Olsa <jolsa@redhat.com> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/20150401102541.17137.75477.stgit@localhost.localdomain Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7afb3fa commit 8cb0aa4

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎tools/perf/builtin-probe.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static struct {
5656
bool mod_events;
5757
bool uprobes;
5858
bool quiet;
59+
bool target_used;
5960
int nevents;
6061
struct perf_probe_event events[MAX_PROBES];
6162
struct strlist *dellist;
@@ -82,6 +83,7 @@ static int parse_probe_event(const char *str)
8283
pev->target = strdup(params.target);
8384
if (!pev->target)
8485
return -ENOMEM;
86+
params.target_used = true;
8587
}
8688

8789
/* Parse a perf-probe command into event */
@@ -107,6 +109,7 @@ static int set_target(const char *ptr)
107109
params.target = strdup(ptr);
108110
if (!params.target)
109111
return -ENOMEM;
112+
params.target_used = false;
110113

111114
found = 1;
112115
buf = ptr + (strlen(ptr) - 3);
@@ -207,6 +210,7 @@ static int opt_set_target(const struct option *opt, const char *str,
207210
}
208211
free(params.target);
209212
params.target = tmp;
213+
params.target_used = false;
210214
ret = 0;
211215
}
212216

@@ -491,6 +495,12 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
491495
}
492496

493497
if (params.nevents) {
498+
/* Ensure the last given target is used */
499+
if (params.target && !params.target_used) {
500+
pr_warning(" Error: -x/-m must follow the probe definitions.\n");
501+
usage_with_options(probe_usage, options);
502+
}
503+
494504
ret = add_perf_probe_events(params.events, params.nevents,
495505
params.max_probe_points,
496506
params.force_add);

0 commit comments

Comments
 (0)