aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/annotate.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-07-29 15:27:18 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-08-01 17:18:16 -0400
commitee51d851392e1fe3e8be30b3c5847f34da343424 (patch)
tree995d0ca1d366d17876e5b8d32daef596941dacaa /tools/perf/util/annotate.c
parent5cb725a9723aebb248106ff7f8c6c7253b24bbb1 (diff)
perf annotate: Introduce strerror for handling symbol__disassemble() errors
We were just using pr_error() which makes it difficult for non stdio UIs to provide errors using its widgets, as they need to somehow catch what was passed to pr_error(). Fix it by introducing a __strerror() interface like the ones used elsewhere, for instance target__strerror(). This is just the initial step, more work will be done, but first some error handling bugs noticed while working on this need to be dealt with. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-dgd22zl2xg7x4vcnoa83jxfb@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/annotate.c')
-rw-r--r--tools/perf/util/annotate.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 4f47b6069197..4982ed487e96 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1123,6 +1123,45 @@ static void delete_last_nop(struct symbol *sym)
1123 } 1123 }
1124} 1124}
1125 1125
1126int symbol__strerror_disassemble(struct symbol *sym __maybe_unused, struct map *map,
1127 int errnum, char *buf, size_t buflen)
1128{
1129 struct dso *dso = map->dso;
1130
1131 BUG_ON(buflen == 0);
1132
1133 if (errnum >= 0) {
1134 str_error_r(errnum, buf, buflen);
1135 return 0;
1136 }
1137
1138 switch (errnum) {
1139 case SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX: {
1140 char bf[SBUILD_ID_SIZE + 15] = " with build id ";
1141 char *build_id_msg = NULL;
1142
1143 if (dso->has_build_id) {
1144 build_id__sprintf(dso->build_id,
1145 sizeof(dso->build_id), bf + 15);
1146 build_id_msg = bf;
1147 }
1148 scnprintf(buf, buflen,
1149 "No vmlinux file%s\nwas found in the path.\n\n"
1150 "Note that annotation using /proc/kcore requires CAP_SYS_RAWIO capability.\n\n"
1151 "Please use:\n\n"
1152 " perf buildid-cache -vu vmlinux\n\n"
1153 "or:\n\n"
1154 " --vmlinux vmlinux\n", build_id_msg ?: "");
1155 }
1156 break;
1157 default:
1158 scnprintf(buf, buflen, "Internal error: Invalid %d error code\n", errnum);
1159 break;
1160 }
1161
1162 return 0;
1163}
1164
1126int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize) 1165int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize)
1127{ 1166{
1128 struct dso *dso = map->dso; 1167 struct dso *dso = map->dso;
@@ -1143,11 +1182,8 @@ int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize)
1143 symbol__join_symfs(symfs_filename, filename); 1182 symbol__join_symfs(symfs_filename, filename);
1144 1183
1145 if (filename == NULL) { 1184 if (filename == NULL) {
1146 if (dso->has_build_id) { 1185 if (dso->has_build_id)
1147 pr_err("Can't annotate %s: not enough memory\n", 1186 return ENOMEM;
1148 sym->name);
1149 return -ENOMEM;
1150 }
1151 goto fallback; 1187 goto fallback;
1152 } else if (dso__is_kcore(dso)) { 1188 } else if (dso__is_kcore(dso)) {
1153 goto fallback; 1189 goto fallback;
@@ -1168,27 +1204,7 @@ fallback:
1168 1204
1169 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && 1205 if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS &&
1170 !dso__is_kcore(dso)) { 1206 !dso__is_kcore(dso)) {
1171 char bf[SBUILD_ID_SIZE + 15] = " with build id "; 1207 err = SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;
1172 char *build_id_msg = NULL;
1173
1174 if (dso->annotate_warned)
1175 goto out_free_filename;
1176
1177 if (dso->has_build_id) {
1178 build_id__sprintf(dso->build_id,
1179 sizeof(dso->build_id), bf + 15);
1180 build_id_msg = bf;
1181 }
1182 err = -ENOENT;
1183 dso->annotate_warned = 1;
1184 pr_err("Can't annotate %s:\n\n"
1185 "No vmlinux file%s\nwas found in the path.\n\n"
1186 "Note that annotation using /proc/kcore requires CAP_SYS_RAWIO capability.\n\n"
1187 "Please use:\n\n"
1188 " perf buildid-cache -vu vmlinux\n\n"
1189 "or:\n\n"
1190 " --vmlinux vmlinux\n",
1191 sym->name, build_id_msg ?: "");
1192 goto out_free_filename; 1208 goto out_free_filename;
1193 } 1209 }
1194 1210