summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-09-30 15:04:21 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-09-30 16:30:06 -0400
commit11aad897f6d1a28eae3b7e5b293647c522d65819 (patch)
tree033e594c5e32ee2287b81d42cb3e345b6ab13424
parent16ed3c1e91159e28b02f11f71ff4ce4cbc6f99e4 (diff)
perf annotate: Don't return -1 for error when doing BPF disassembly
Return errno when open_memstream() fails and add two new speciall error codes for when an invalid, non BPF file or one without BTF is passed to symbol__disassemble_bpf(), so that its callers can rely on symbol__strerror_disassemble() to convert that to a human readable error message that can help figure out what is wrong, with hints even. Cc: Russell King - ARM Linux admin <linux@armlinux.org.uk> Cc: Song Liu <songliubraving@fb.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org>, Cc: Will Deacon <will@kernel.org> Link: https://lkml.kernel.org/n/tip-usevw9r2gcipfcrbpaueurw0@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/annotate.c19
-rw-r--r--tools/perf/util/annotate.h2
2 files changed, 17 insertions, 4 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b49ecdd51188..4036c7f7b0fb 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1637,6 +1637,13 @@ int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *
1637 case SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING: 1637 case SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING:
1638 scnprintf(buf, buflen, "Problems while parsing the CPUID in the arch specific initialization."); 1638 scnprintf(buf, buflen, "Problems while parsing the CPUID in the arch specific initialization.");
1639 break; 1639 break;
1640 case SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE:
1641 scnprintf(buf, buflen, "Invalid BPF file: %s.", dso->long_name);
1642 break;
1643 case SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF:
1644 scnprintf(buf, buflen, "The %s BPF file has no BTF section, compile with -g or use pahole -J.",
1645 dso->long_name);
1646 break;
1640 default: 1647 default:
1641 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum); 1648 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
1642 break; 1649 break;
@@ -1719,13 +1726,13 @@ static int symbol__disassemble_bpf(struct symbol *sym,
1719 char tpath[PATH_MAX]; 1726 char tpath[PATH_MAX];
1720 size_t buf_size; 1727 size_t buf_size;
1721 int nr_skip = 0; 1728 int nr_skip = 0;
1722 int ret = -1;
1723 char *buf; 1729 char *buf;
1724 bfd *bfdf; 1730 bfd *bfdf;
1731 int ret;
1725 FILE *s; 1732 FILE *s;
1726 1733
1727 if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO) 1734 if (dso->binary_type != DSO_BINARY_TYPE__BPF_PROG_INFO)
1728 return -1; 1735 return SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE;
1729 1736
1730 pr_debug("%s: handling sym %s addr %" PRIx64 " len %" PRIx64 "\n", __func__, 1737 pr_debug("%s: handling sym %s addr %" PRIx64 " len %" PRIx64 "\n", __func__,
1731 sym->name, sym->start, sym->end - sym->start); 1738 sym->name, sym->start, sym->end - sym->start);
@@ -1738,8 +1745,10 @@ static int symbol__disassemble_bpf(struct symbol *sym,
1738 assert(bfd_check_format(bfdf, bfd_object)); 1745 assert(bfd_check_format(bfdf, bfd_object));
1739 1746
1740 s = open_memstream(&buf, &buf_size); 1747 s = open_memstream(&buf, &buf_size);
1741 if (!s) 1748 if (!s) {
1749 ret = errno;
1742 goto out; 1750 goto out;
1751 }
1743 init_disassemble_info(&info, s, 1752 init_disassemble_info(&info, s,
1744 (fprintf_ftype) fprintf); 1753 (fprintf_ftype) fprintf);
1745 1754
@@ -1748,8 +1757,10 @@ static int symbol__disassemble_bpf(struct symbol *sym,
1748 1757
1749 info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, 1758 info_node = perf_env__find_bpf_prog_info(dso->bpf_prog.env,
1750 dso->bpf_prog.id); 1759 dso->bpf_prog.id);
1751 if (!info_node) 1760 if (!info_node) {
1761 return SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF;
1752 goto out; 1762 goto out;
1763 }
1753 info_linear = info_node->info_linear; 1764 info_linear = info_node->info_linear;
1754 sub_id = dso->bpf_prog.sub_id; 1765 sub_id = dso->bpf_prog.sub_id;
1755 1766
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 116e21f49da6..d76fd0e81f46 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -372,6 +372,8 @@ enum symbol_disassemble_errno {
372 SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF, 372 SYMBOL_ANNOTATE_ERRNO__NO_LIBOPCODES_FOR_BPF,
373 SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING, 373 SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_CPUID_PARSING,
374 SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP, 374 SYMBOL_ANNOTATE_ERRNO__ARCH_INIT_REGEXP,
375 SYMBOL_ANNOTATE_ERRNO__BPF_INVALID_FILE,
376 SYMBOL_ANNOTATE_ERRNO__BPF_MISSING_BTF,
375 377
376 __SYMBOL_ANNOTATE_ERRNO__END, 378 __SYMBOL_ANNOTATE_ERRNO__END,
377}; 379};