lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87ty0b3qpo.fsf@sejong.aot.lge.com>
Date:	Mon, 23 Apr 2012 15:30:27 +0900
From:	Namhyung Kim <namhyung.kim@....com>
To:	Arnaldo Carvalho de Melo <acme@...radead.org>
Cc:	Ingo Molnar <mingo@...nel.org>, linux-kernel@...r.kernel.org,
	Arnaldo Carvalho de Melo <acme@...hat.com>,
	David Ahern <dsahern@...il.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Mike Galbraith <efault@....de>,
	Paul Mackerras <paulus@...ba.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Stephane Eranian <eranian@...gle.com>
Subject: Re: [PATCH 02/13] perf annotate: Parse instruction

Hi,

On Thu, 19 Apr 2012 17:33:57 -0300, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@...hat.com>
>
> For lines with instructions find the name and operands, breaking those
> tokens for consumption by the browser.
>

Just a minor nit below...


> Cc: David Ahern <dsahern@...il.com>
> Cc: Frederic Weisbecker <fweisbec@...il.com>
> Cc: Mike Galbraith <efault@....de>
> Cc: Namhyung Kim <namhyung@...il.com>
> Cc: Paul Mackerras <paulus@...ba.org>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: Stephane Eranian <eranian@...gle.com>
> Link: http://lkml.kernel.org/n/tip-6aazb9f5o3d9zi28e6rruv12@git.kernel.org
> Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
> ---
>  tools/perf/util/annotate.c |   65 +++++++++++++++++++++++++++++++++++++++++++-
>  tools/perf/util/annotate.h |    3 ++
>  2 files changed, 67 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index ef1d57d..a72585a 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -80,16 +80,50 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,
>  
>  static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
>  {
> -	struct disasm_line *dl = malloc(sizeof(*dl) + privsize);
> +	struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);
>  
>  	if (dl != NULL) {
>  		dl->offset = offset;
>  		dl->line = strdup(line);
>  		if (dl->line == NULL)
>  			goto out_delete;
> +
> +		if (offset != -1) {

To avoid deep nesting, how about this:

	if (dl == NULL)
		return NULL;

	<snip>

	if (offset == -1)
		return dl;

Thanks,
Namhyung


> +			char *name = dl->line, tmp;
> +
> +			while (isspace(name[0]))
> +				++name;
> +
> +			if (name[0] == '\0')
> +				goto out_delete;
> +
> +			dl->operands = name + 1;
> +
> +			while (dl->operands[0] != '\0' &&
> +			       !isspace(dl->operands[0]))
> +				++dl->operands;
> +
> +			tmp = dl->operands[0];
> +			dl->operands[0] = '\0';
> +			dl->name = strdup(name);
> +
> +			if (dl->name == NULL)
> +				goto out_free_line;
> +
> +			dl->operands[0] = tmp;
> +
> +			if (dl->operands[0] != '\0') {
> +				dl->operands++;
> +				while (isspace(dl->operands[0]))
> +					++dl->operands;
> +			}
> +		}
>  	}
>  
>  	return dl;
> +
> +out_free_line:
> +	free(dl->line);
>  out_delete:
>  	free(dl);
>  	return NULL;
> @@ -98,6 +132,7 @@ out_delete:
>  void disasm_line__free(struct disasm_line *dl)
>  {
>  	free(dl->line);
> +	free(dl->name);
>  	free(dl);
>  }
>  
> @@ -591,6 +626,34 @@ void disasm__purge(struct list_head *head)
>  	}
>  }
>  
> +static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
> +{
> +	size_t printed;
> +
> +	if (dl->offset == -1)
> +		return fprintf(fp, "%s\n", dl->line);
> +
> +	printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name);
> +
> +	if (dl->operands[0] != '\0') {
> +		printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
> +				   dl->operands);
> +	}
> +
> +	return printed + fprintf(fp, "\n");
> +}
> +
> +size_t disasm__fprintf(struct list_head *head, FILE *fp)
> +{
> +	struct disasm_line *pos;
> +	size_t printed = 0;
> +
> +	list_for_each_entry(pos, head, node)
> +		printed += disasm_line__fprintf(pos, fp);
> +
> +	return printed;
> +}
> +
>  int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
>  			 bool print_lines, bool full_paths, int min_pcnt,
>  			 int max_lines)
> diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
> index 8bb68bb..dd7636d 100644
> --- a/tools/perf/util/annotate.h
> +++ b/tools/perf/util/annotate.h
> @@ -11,10 +11,13 @@ struct disasm_line {
>  	struct list_head node;
>  	s64		 offset;
>  	char		 *line;
> +	char		 *name;
> +	char		 *operands;
>  };
>  
>  void disasm_line__free(struct disasm_line *dl);
>  struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
> +size_t disasm__fprintf(struct list_head *head, FILE *fp);
>  
>  struct sym_hist {
>  	u64		sum;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ