From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754244AbbDJGwH (ORCPT ); Fri, 10 Apr 2015 02:52:07 -0400 Received: from mail4.hitachi.co.jp ([133.145.228.5]:42336 "EHLO mail4.hitachi.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752088AbbDJGwE (ORCPT ); Fri, 10 Apr 2015 02:52:04 -0400 Message-ID: <5527730D.8030508@hitachi.com> Date: Fri, 10 Apr 2015 15:51:57 +0900 From: Masami Hiramatsu Organization: Hitachi, Ltd., Japan User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Arnaldo Carvalho de Melo CC: Peter Zijlstra , Linux Kernel Mailing List , David Ahern , namhyung@kernel.org, Jiri Olsa , Ingo Molnar Subject: Re: [PATCH perf/core 2/2] perf-probe: Check the orphaned -x option References: <20150331133348.GF9438@kernel.org> <20150401102541.17137.75477.stgit@localhost.localdomain> In-Reply-To: <20150401102541.17137.75477.stgit@localhost.localdomain> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ping? (2015/04/01 19:25), Masami Hiramatsu wrote: > 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 > Signed-off-by: Masami Hiramatsu > --- > tools/perf/builtin-probe.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c > index 2df23e1..f7b1af6 100644 > --- a/tools/perf/builtin-probe.c > +++ b/tools/perf/builtin-probe.c > @@ -56,6 +56,7 @@ static struct { > bool mod_events; > bool uprobes; > bool quiet; > + bool target_used; > int nevents; > struct perf_probe_event events[MAX_PROBES]; > struct strlist *dellist; > @@ -82,6 +83,7 @@ static int parse_probe_event(const char *str) > pev->target = strdup(params.target); > if (!pev->target) > return -ENOMEM; > + params.target_used = true; > } > > /* Parse a perf-probe command into event */ > @@ -107,6 +109,7 @@ static int set_target(const char *ptr) > params.target = strdup(ptr); > if (!params.target) > return -ENOMEM; > + params.target_used = false; > > found = 1; > buf = ptr + (strlen(ptr) - 3); > @@ -207,6 +210,7 @@ static int opt_set_target(const struct option *opt, const char *str, > } > free(params.target); > params.target = tmp; > + params.target_used = false; > ret = 0; > } > > @@ -491,6 +495,12 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused) > } > > if (params.nevents) { > + /* Ensure the last given target is used */ > + if (params.target && !params.target_used) { > + pr_warning(" Error: -x/-m must follow the probe definitions.\n"); > + usage_with_options(probe_usage, options); > + } > + > ret = add_perf_probe_events(params.events, params.nevents, > params.max_probe_points, > params.force_add); > > -- Masami HIRAMATSU Linux Technology Research Center, System Productivity Research Dept. Center for Technology Innovation - Systems Engineering Hitachi, Ltd., Research & Development Group E-mail: masami.hiramatsu.pt@hitachi.com