Skip to content

Commit dc8d6ab

Browse files
acmelIngo Molnar
authored andcommitted
perf symbols: Use only --vmlinux if specified
Found while analysing a perf.data file collected on an ARM machine where an explicitely specified vmlinux was being disregarded. Reported-by: Jamie Iles <jamie.iles@picochip.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> LKML-Reference: <1263904574-30732-2-git-send-email-acme@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent f162f87 commit dc8d6ab

1 file changed

Lines changed: 41 additions & 26 deletions

File tree

‎tools/perf/util/symbol.c‎

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ static int dso__load_vmlinux(struct dso *self, struct map *map,
15721572
return -1;
15731573

15741574
dso__set_loaded(self, map->type);
1575-
err = dso__load_sym(self, map, session, self->long_name, fd, filter, 1, 0);
1575+
err = dso__load_sym(self, map, session, vmlinux, fd, filter, 1, 0);
15761576
close(fd);
15771577

15781578
return err;
@@ -1584,6 +1584,26 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,
15841584
int err;
15851585
const char *kallsyms_filename = NULL;
15861586
char *kallsyms_allocated_filename = NULL;
1587+
/*
1588+
* Step 1: if the user specified a vmlinux filename, use it and only
1589+
* it, reporting errors to the user if it cannot be used.
1590+
*
1591+
* For instance, try to analyse an ARM perf.data file _without_ a
1592+
* build-id, or if the user specifies the wrong path to the right
1593+
* vmlinux file, obviously we can't fallback to another vmlinux (a
1594+
* x86_86 one, on the machine where analysis is being performed, say),
1595+
* or worse, /proc/kallsyms.
1596+
*
1597+
* If the specified file _has_ a build-id and there is a build-id
1598+
* section in the perf.data file, we will still do the expected
1599+
* validation in dso__load_vmlinux and will bail out if they don't
1600+
* match.
1601+
*/
1602+
if (symbol_conf.vmlinux_name != NULL) {
1603+
err = dso__load_vmlinux(self, map, session,
1604+
symbol_conf.vmlinux_name, filter);
1605+
goto out_try_fixup;
1606+
}
15871607

15881608
if (vmlinux_path != NULL) {
15891609
int i;
@@ -1618,46 +1638,41 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,
16181638
goto do_kallsyms;
16191639
}
16201640
}
1621-
1641+
/*
1642+
* Now look if we have it on the build-id cache in
1643+
* $HOME/.debug/[kernel.kallsyms].
1644+
*/
16221645
build_id__sprintf(self->build_id, sizeof(self->build_id),
16231646
sbuild_id);
16241647

16251648
if (asprintf(&kallsyms_allocated_filename,
16261649
"%s/.debug/[kernel.kallsyms]/%s",
1627-
getenv("HOME"), sbuild_id) != -1) {
1628-
if (access(kallsyms_filename, F_OK)) {
1629-
kallsyms_filename = kallsyms_allocated_filename;
1630-
goto do_kallsyms;
1631-
}
1650+
getenv("HOME"), sbuild_id) == -1)
1651+
return -1;
1652+
1653+
if (access(kallsyms_filename, F_OK)) {
16321654
free(kallsyms_allocated_filename);
1633-
kallsyms_allocated_filename = NULL;
1655+
return -1;
16341656
}
16351657

1636-
goto do_vmlinux;
1637-
}
1638-
1639-
if (self->long_name[0] == '[') {
1658+
kallsyms_filename = kallsyms_allocated_filename;
1659+
} else {
1660+
/*
1661+
* Last resort, if we don't have a build-id and couldn't find
1662+
* any vmlinux file, try the running kernel kallsyms table.
1663+
*/
16401664
kallsyms_filename = "/proc/kallsyms";
1641-
goto do_kallsyms;
16421665
}
16431666

1644-
do_vmlinux:
1645-
err = dso__load_vmlinux(self, map, session, self->long_name, filter);
1646-
if (err <= 0) {
1647-
if (self->has_build_id)
1648-
return -1;
1649-
1650-
pr_info("The file %s cannot be used, "
1651-
"trying to use /proc/kallsyms...", self->long_name);
16521667
do_kallsyms:
1653-
err = dso__load_kallsyms(self, kallsyms_filename, map, session, filter);
1654-
if (err > 0 && kallsyms_filename == NULL)
1655-
dso__set_long_name(self, strdup("[kernel.kallsyms]"));
1656-
free(kallsyms_allocated_filename);
1657-
}
1668+
err = dso__load_kallsyms(self, kallsyms_filename, map, session, filter);
1669+
free(kallsyms_allocated_filename);
16581670

1671+
out_try_fixup:
16591672
if (err > 0) {
16601673
out_fixup:
1674+
if (kallsyms_filename == NULL)
1675+
dso__set_long_name(self, strdup("[kernel.kallsyms]"));
16611676
map__fixup_start(map);
16621677
map__fixup_end(map);
16631678
}

0 commit comments

Comments
 (0)