All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: acme@kernel.org
Cc: jolsa@kernel.org, linux-kernel@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>
Subject: [PATCH 3/3] perf annotate: Improve handling of corrupted ~/.debug
Date: Fri, 27 Sep 2019 16:35:46 -0700	[thread overview]
Message-ID: <20190927233546.11533-3-andi@firstfloor.org> (raw)
In-Reply-To: <20190927233546.11533-1-andi@firstfloor.org>

From: Andi Kleen <ak@linux.intel.com>

Sometimes ~/.debug can get corrupted and contain files that still
have symbol tables, but which objdump cannot handle. Add a fallback
to read the "original" file in such a case. This might be wrong
too if it's different, but in many cases when profiling
on the same host it will work.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/util/annotate.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 1748f528b6e9..cff5f36786fa 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1638,19 +1638,22 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *
 	return 0;
 }
 
-static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filename_size)
+static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filename_size,
+				     bool *build_id)
 {
 	char linkname[PATH_MAX];
 	char *build_id_filename;
 	char *build_id_path = NULL;
 	char *pos;
 
+	*build_id = false;
 	if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
 	    !dso__is_kcore(dso))
 		return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;
 
 	build_id_filename = dso__build_id_filename(dso, NULL, 0, false);
 	if (build_id_filename) {
+		*build_id = true;
 		__symbol__join_symfs(filename, filename_size, build_id_filename);
 		free(build_id_filename);
 	} else {
@@ -1854,11 +1857,14 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 	int lineno = 0;
 	int nline;
 	pid_t pid;
-	int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename));
+	bool build_id;
+	int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename),
+					    &build_id);
 
 	if (err)
 		return err;
 
+again:
 	pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__,
 		 symfs_filename, sym->name, map->unmap_ip(map, sym->start),
 		 map->unmap_ip(map, sym->end));
@@ -1955,8 +1961,21 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 		nline++;
 	}
 
-	if (nline == 0)
-		pr_err("No output from %s\n", command);
+	if (nline == 0) {
+		pr_err("No objdump output for %s. Corrupted file?\n", symfs_filename);
+		if (build_id) {
+			/*
+			 * It could be that the buildid file is corrupted.
+			 * Try again with the "true" file. This might be wrong
+			 * too, but it's better than nothing.
+			 * We could move the build id file here?
+			 */
+			__symbol__join_symfs(symfs_filename, sizeof(symfs_filename),
+					     dso->long_name);
+			build_id = false;
+			goto again;
+		}
+	}
 
 	/*
 	 * kallsyms does not have symbol sizes so there may a nop at the end.
-- 
2.21.0


  parent reply	other threads:[~2019-09-27 23:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-27 23:35 [PATCH 1/3] perf script brstackinsn: Fix recovery from LBR/binary mismatch Andi Kleen
2019-09-27 23:35 ` [PATCH 2/3] perf jevents: Fix period for Intel fixed counters Andi Kleen
2019-09-30 10:50   ` Arnaldo Carvalho de Melo
2019-10-07 14:49   ` [tip: perf/urgent] " tip-bot2 for Andi Kleen
2019-09-27 23:35 ` Andi Kleen [this message]
2019-09-30 10:50 ` [PATCH 1/3] perf script brstackinsn: Fix recovery from LBR/binary mismatch Arnaldo Carvalho de Melo
2019-10-07 14:49 ` [tip: perf/urgent] " tip-bot2 for Andi Kleen

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=20190927233546.11533-3-andi@firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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.