All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
To: Franck Bui-Huu <vagabon.xyz@gmail.com>
Cc: acme@ghostprotocols.net, linux-kernel@vger.kernel.org,
	2nddept-manager@sdl.hitachi.co.jp
Subject: Re: [PATCH 6/6] perf-probe: handle gracefully some stupid and buggy line syntaxes
Date: Tue, 21 Dec 2010 22:10:59 +0900	[thread overview]
Message-ID: <4D10A763.4080209@hitachi.com> (raw)
In-Reply-To: <1292854685-8230-7-git-send-email-fbuihuu@gmail.com>

(2010/12/20 23:18), Franck Bui-Huu wrote:
> From: Franck Bui-Huu <fbuihuu@gmail.com>
> 
> Currently perf-probe doesn't handle those incorrect syntaxes
> 
>    $ perf probe -L sched.c:++13
>    $ perf probe -L sched.c:-+13
>    $ perf probe -L sched.c:10000000000000000000000000000+13
> 
> This patches rewrites parse_line_range_desc() to handle them.

OK, without this patch, perf probe accepted that as "0+13".
With this, perf probe rejects it as an invalid input.

Thank you!

> 
> As a bonus side, it reports more usefull error messages instead of:
> "Tailing with invalid character...".
> 
> Signed-off-by: Franck Bui-Huu <fbuihuu@gmail.com>

Acked-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>

> ---
>  tools/perf/util/probe-event.c |   92 ++++++++++++++++++++++++++--------------
>  1 files changed, 60 insertions(+), 32 deletions(-)
> 
> diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
> index 1e81936..469ad35 100644
> --- a/tools/perf/util/probe-event.c
> +++ b/tools/perf/util/probe-event.c
> @@ -539,6 +539,19 @@ int show_available_vars(struct perf_probe_event *pevs __unused,
>  }
>  #endif
>  
> +static int parse_line_num(char **ptr, int *val, const char *what)
> +{
> +	const char *start = *ptr;
> +
> +	errno = 0;
> +	*val = strtol(*ptr, ptr, 0);
> +	if (errno || *ptr == start) {
> +		semantic_error("'%s' is not a valid number.\n", what);
> +		return -EINVAL;
> +	}
> +	return 0;
> +}
> +
>  /*
>   * Stuff 'lr' according to the line range described by 'arg'.
>   * The line range syntax is described by:
> @@ -548,50 +561,65 @@ int show_available_vars(struct perf_probe_event *pevs __unused,
>   */
>  int parse_line_range_desc(const char *arg, struct line_range *lr)
>  {
> -	const char *ptr;
> -	char *tmp;
> +	char *range, *name = strdup(arg);
> +	int err;
> +
> +	if (!name)
> +		return -ENOMEM;
> +
> +	lr->start = 0;
> +	lr->end = INT_MAX;
> +
> +	range = strchr(name, ':');
> +	if (range) {
> +		*range++ = '\0';
> +
> +		err = parse_line_num(&range, &lr->start, "start line");
> +		if (err)
> +			goto err;
> +
> +		if (*range == '+' || *range == '-') {
> +			const char c = *range++;
> +
> +			err = parse_line_num(&range, &lr->end, "end line");
> +			if (err)
> +				goto err;
> +
> +			if (c == '+') {
> +				lr->end += lr->start;
> +				/*
> +				 * Adjust the number of lines here.
> +				 * If the number of lines == 1, the
> +				 * the end of line should be equal to
> +				 * the start of line.
> +				 */
> +				lr->end--;
> +			}
> +		}
>  
> -	ptr = strchr(arg, ':');
> -	if (ptr) {
> -		lr->start = (int)strtoul(ptr + 1, &tmp, 0);
> -		if (*tmp == '+') {
> -			lr->end = lr->start + (int)strtoul(tmp + 1, &tmp, 0);
> -			lr->end--;	/*
> -					 * Adjust the number of lines here.
> -					 * If the number of lines == 1, the
> -					 * the end of line should be equal to
> -					 * the start of line.
> -					 */
> -		} else if (*tmp == '-')
> -			lr->end = (int)strtoul(tmp + 1, &tmp, 0);
> -		else
> -			lr->end = INT_MAX;
>  		pr_debug("Line range is %d to %d\n", lr->start, lr->end);
> +
> +		err = -EINVAL;
>  		if (lr->start > lr->end) {
>  			semantic_error("Start line must be smaller"
>  				       " than end line.\n");
> -			return -EINVAL;
> +			goto err;
>  		}
> -		if (*tmp != '\0') {
> -			semantic_error("Tailing with invalid character '%d'.\n",
> -				       *tmp);
> -			return -EINVAL;
> +		if (*range != '\0') {
> +			semantic_error("Tailing with invalid str '%s'.\n", range);
> +			goto err;
>  		}
> -		tmp = strndup(arg, (ptr - arg));
> -	} else {
> -		tmp = strdup(arg);
> -		lr->end = INT_MAX;
>  	}
>  
> -	if (tmp == NULL)
> -		return -ENOMEM;
> -
> -	if (strchr(tmp, '.'))
> -		lr->file = tmp;
> +	if (strchr(name, '.'))
> +		lr->file = name;
>  	else
> -		lr->function = tmp;
> +		lr->function = name;
>  
>  	return 0;
> +err:
> +	free(name);
> +	return err;
>  }
>  
>  /* Check the name is good for event/group */


-- 
Masami HIRAMATSU
2nd Dept. Linux Technology Center
Hitachi, Ltd., Systems Development Laboratory
E-mail: masami.hiramatsu.pt@hitachi.com

  reply	other threads:[~2010-12-21 13:11 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-20 14:17 [PATCH 0/6] Minor cleanups & fixes for perf-probe(1) Franck Bui-Huu
2010-12-20 14:18 ` [PATCH 1/6] perf-tools: make perf-probe -L display the absolute path of the dumped file Franck Bui-Huu
2010-12-21  5:30   ` Masami Hiramatsu
2010-12-22 11:30   ` [tip:perf/core] perf probe: Make " tip-bot for Franck Bui-Huu
2010-12-20 14:18 ` [PATCH 2/6] perf-probe: rewrite show_one_line() to make it simpler Franck Bui-Huu
2010-12-21  8:55   ` Masami Hiramatsu
2010-12-22 11:30   ` [tip:perf/core] perf probe: Rewrite " tip-bot for Franck Bui-Huu
2010-12-20 14:18 ` [PATCH 3/6] perf-probe: clean up redundant tests in show_line_range() Franck Bui-Huu
2010-12-21  9:47   ` Masami Hiramatsu
2010-12-22 11:31   ` [tip:perf/core] perf probe: Clean " tip-bot for Franck Bui-Huu
2010-12-20 14:18 ` [PATCH 4/6] perf-probe: Fix line range description since a single file is allowed Franck Bui-Huu
2010-12-22 11:31   ` [tip:perf/core] perf probe: " tip-bot for Franck Bui-Huu
2010-12-20 14:18 ` [PATCH 5/6] perf-probe: don't always consider EOF as an error when listing source code Franck Bui-Huu
2010-12-21 11:54   ` Masami Hiramatsu
2010-12-22 11:31   ` [tip:perf/core] perf probe: Don't " tip-bot for Franck Bui-Huu
2010-12-22 13:14     ` Franck Bui-Huu
2010-12-22 14:43       ` Arnaldo Carvalho de Melo
2010-12-22 16:37         ` Franck Bui-Huu
2010-12-25  8:58           ` [tip:perf/core] perf probe: Fix wrong warning in __show_one_line() if read(1) errors happen tip-bot for Franck Bui-Huu
2010-12-26 14:11             ` Masami Hiramatsu
2010-12-20 14:18 ` [PATCH 6/6] perf-probe: handle gracefully some stupid and buggy line syntaxes Franck Bui-Huu
2010-12-21 13:10   ` Masami Hiramatsu [this message]
2010-12-22 11:32   ` [tip:perf/core] perf probe: Handle " tip-bot for Franck Bui-Huu
2010-12-21 13:11 ` [PATCH 0/6] Minor cleanups & fixes for perf-probe(1) Masami Hiramatsu
2010-12-21 18:01   ` Franck Bui-Huu
2010-12-21 21:05     ` Arnaldo Carvalho de Melo
2010-12-22 13:11       ` Franck Bui-Huu
2010-12-24  0:36         ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D10A763.4080209@hitachi.com \
    --to=masami.hiramatsu.pt@hitachi.com \
    --cc=2nddept-manager@sdl.hitachi.co.jp \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vagabon.xyz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.