perf symbols: Save DSO loading errno to better report errors
Before, when some problem happened while trying to load the kernel symtab, 'perf top' would show: ┌─Warning:───────────────────────────┐ │The vmlinux file can't be used. │ │Kernel samples will not be resolved.│ │ │ │ │ │Press any key... │ └────────────────────────────────────┘ Now, it reports: # perf top --vmlinux /dev/null ┌─Warning:───────────────────────────────────────────┐ │The /tmp/passwd file can't be used: Invalid ELF file│ │Kernel samples will not be resolved. │ │ │ │ │ │Press any key... │ └────────────────────────────────────────────────────┘ This is possible because we now register the reason for not being able to load the symtab in the dso->load_errno member, and provide a dso__strerror_load() routine to format this error into a strerror like string with a short reason for the error while loading. That can be just forwarding the dso__strerror_load() call to strerror_r(), or, for a separate errno range providing a custom message. Reported-by: Ingo Molnar <mingo@kernel.org> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Borislav Petkov <bp@suse.de> Cc: David Ahern <dsahern@gmail.com> Cc: Don Zickus <dzickus@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-u5rb5uq63xqhkfb8uv2lxd5u@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
@@ -1137,3 +1137,36 @@ enum dso_type dso__type(struct dso *dso, struct machine *machine)
|
||||
|
||||
return dso__type_fd(fd);
|
||||
}
|
||||
|
||||
int dso__strerror_load(struct dso *dso, char *buf, size_t buflen)
|
||||
{
|
||||
int idx, errnum = dso->load_errno;
|
||||
/*
|
||||
* This must have a same ordering as the enum dso_load_errno.
|
||||
*/
|
||||
static const char *dso_load__error_str[] = {
|
||||
"Internal tools/perf/ library error",
|
||||
"Invalid ELF file",
|
||||
"Can not read build id",
|
||||
"Mismatching build id",
|
||||
"Decompression failure",
|
||||
};
|
||||
|
||||
BUG_ON(buflen == 0);
|
||||
|
||||
if (errnum >= 0) {
|
||||
const char *err = strerror_r(errnum, buf, buflen);
|
||||
|
||||
if (err != buf)
|
||||
scnprintf(buf, buflen, "%s", err);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (errnum < __DSO_LOAD_ERRNO__START || errnum >= __DSO_LOAD_ERRNO__END)
|
||||
return -1;
|
||||
|
||||
idx = errnum - __DSO_LOAD_ERRNO__START;
|
||||
scnprintf(buf, buflen, "%s", dso_load__error_str[idx]);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user