diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2015-04-01 06:25:42 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-04-10 09:21:30 -0400 |
commit | 8cb0aa4c2db395b143cd5165586dc17677960002 (patch) | |
tree | fc15a499e0f56b1ef24436d247f3b04c2128e57d /tools | |
parent | 7afb3fab390871b1d20b1dbb94e03b8a3861cb0d (diff) |
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-probe.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 2df23e177da5..f7b1af67e9f6 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c | |||
@@ -56,6 +56,7 @@ static struct { | |||
56 | bool mod_events; | 56 | bool mod_events; |
57 | bool uprobes; | 57 | bool uprobes; |
58 | bool quiet; | 58 | bool quiet; |
59 | bool target_used; | ||
59 | int nevents; | 60 | int nevents; |
60 | struct perf_probe_event events[MAX_PROBES]; | 61 | struct perf_probe_event events[MAX_PROBES]; |
61 | struct strlist *dellist; | 62 | struct strlist *dellist; |
@@ -82,6 +83,7 @@ static int parse_probe_event(const char *str) | |||
82 | pev->target = strdup(params.target); | 83 | pev->target = strdup(params.target); |
83 | if (!pev->target) | 84 | if (!pev->target) |
84 | return -ENOMEM; | 85 | return -ENOMEM; |
86 | params.target_used = true; | ||
85 | } | 87 | } |
86 | 88 | ||
87 | /* Parse a perf-probe command into event */ | 89 | /* Parse a perf-probe command into event */ |
@@ -107,6 +109,7 @@ static int set_target(const char *ptr) | |||
107 | params.target = strdup(ptr); | 109 | params.target = strdup(ptr); |
108 | if (!params.target) | 110 | if (!params.target) |
109 | return -ENOMEM; | 111 | return -ENOMEM; |
112 | params.target_used = false; | ||
110 | 113 | ||
111 | found = 1; | 114 | found = 1; |
112 | buf = ptr + (strlen(ptr) - 3); | 115 | buf = ptr + (strlen(ptr) - 3); |
@@ -207,6 +210,7 @@ static int opt_set_target(const struct option *opt, const char *str, | |||
207 | } | 210 | } |
208 | free(params.target); | 211 | free(params.target); |
209 | params.target = tmp; | 212 | params.target = tmp; |
213 | params.target_used = false; | ||
210 | ret = 0; | 214 | ret = 0; |
211 | } | 215 | } |
212 | 216 | ||
@@ -491,6 +495,12 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) | |||
491 | } | 495 | } |
492 | 496 | ||
493 | if (params.nevents) { | 497 | 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 | |||
494 | ret = add_perf_probe_events(params.events, params.nevents, | 504 | ret = add_perf_probe_events(params.events, params.nevents, |
495 | params.max_probe_points, | 505 | params.max_probe_points, |
496 | params.force_add); | 506 | params.force_add); |