public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Taeung Song <treeze.taeung@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Wang Nan <wangnan0@huawei.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Taeung Song <treeze.taeung@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH 3/4] perf annotate: Change the method counting line numbers
Date: Wed, 22 Feb 2017 19:08:22 +0900	[thread overview]
Message-ID: <1487758103-7953-4-git-send-email-treeze.taeung@gmail.com> (raw)
In-Reply-To: <1487758103-7953-1-git-send-email-treeze.taeung@gmail.com>

Currently line numbers are wrong due to
just counting according to output of 'objdump -S'

So remove needless local variables (line_nr, lineno)
and get correct line numbers according to each address
in symbol__get_source_line().

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/util/annotate.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 9d0aa50..acd500b 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -812,7 +812,7 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp)
 }
 
 static struct disasm_line *disasm_line__new(s64 offset, char *line,
-					    size_t privsize, int line_nr,
+					    size_t privsize,
 					    struct arch *arch,
 					    struct map *map)
 {
@@ -821,7 +821,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line,
 	if (dl != NULL) {
 		dl->offset = offset;
 		dl->line = strdup(line);
-		dl->line_nr = line_nr;
+
 		if (dl->line == NULL)
 			goto out_delete;
 
@@ -1133,8 +1133,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
  */
 static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
 				      struct arch *arch,
-				      FILE *file, size_t privsize,
-				      int *line_nr)
+				      FILE *file, size_t privsize)
 {
 	struct annotation *notes = symbol__annotation(sym);
 	struct disasm_line *dl;
@@ -1188,9 +1187,8 @@ static int symbol__parse_objdump_line(struct symbol *sym, struct map *map,
 			parsed_line = tmp2 + 1;
 	}
 
-	dl = disasm_line__new(offset, parsed_line, privsize, *line_nr, arch, map);
+	dl = disasm_line__new(offset, parsed_line, privsize, arch, map);
 	free(line);
-	(*line_nr)++;
 
 	if (dl == NULL)
 		return -1;
@@ -1338,7 +1336,6 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na
 	struct kcore_extract kce;
 	bool delete_extract = false;
 	int stdout_fd[2];
-	int lineno = 0;
 	int nline;
 	pid_t pid;
 	int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename));
@@ -1460,8 +1457,7 @@ int symbol__disassemble(struct symbol *sym, struct map *map, const char *arch_na
 
 	nline = 0;
 	while (!feof(file)) {
-		if (symbol__parse_objdump_line(sym, map, arch, file, privsize,
-			    &lineno) < 0)
+		if (symbol__parse_objdump_line(sym, map, arch, file, privsize) < 0)
 			break;
 		nline++;
 	}
@@ -1631,6 +1627,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 	for (i = 0; i < len; i++) {
 		u64 offset;
 		double percent_max = 0.0;
+		struct disasm_line *dl;
 
 		src_line->nr_pcnt = nr_pcnt;
 
@@ -1645,6 +1642,19 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 		offset = start + i;
 		src_line->path = get_srcline(map->dso, offset, NULL, false);
 		insert_source_line(&tmp_root, src_line);
+
+		if (!strcmp(src_line->path, SRCLINE_UNKNOWN))
+			goto next;
+
+		list_for_each_entry(dl, &notes->src->source, node) {
+			if ((dl->offset + start) == offset) {
+				char *sep = strchr(src_line->path, ':');
+
+				if (sep)
+					dl->line_nr = strtoul(++sep, NULL, 0);
+			}
+		}
+	next:
 		src_line = (void *)src_line + sizeof_src_line;
 	}
 
-- 
2.7.4

  parent reply	other threads:[~2017-02-22 10:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-22 10:08 [PATCH 0/4] perf annotate: Fixes for line numbers and Introduce source_code Taeung Song
2017-02-22 10:08 ` [PATCH 1/4] perf annotate: Remove needless regular expression for filename:linenr Taeung Song
2017-02-22 10:47   ` Namhyung Kim
2017-02-22 16:00     ` Taeung Song
2017-02-22 10:08 ` [PATCH 2/4] perf annotate: Align filename:linenr and more correct summary Taeung Song
2017-02-22 11:12   ` Namhyung Kim
2017-02-22 11:22   ` Namhyung Kim
2017-02-22 16:31     ` Taeung Song
2017-02-22 10:08 ` Taeung Song [this message]
2017-02-22 10:08 ` [PATCH 4/4] perf annotate: Introduce source_code to collect actual code Taeung Song
2017-02-22 11:27   ` Namhyung Kim
2017-02-22 16:41     ` Taeung Song
2017-02-24  5:57   ` Ravi Bangoria

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=1487758103-7953-4-git-send-email-treeze.taeung@gmail.com \
    --to=treeze.taeung@gmail.com \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=wangnan0@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox