Skip to content

Commit 8d0cf13

Browse files
namhyungSasha Levin
authored andcommitted
perf tools: Get debug info of DSO properly
[ Upstream commit 069e603 ] The dso__debuginfo() just used the path name to open the file but it may be outdated. It should check build-ID and use the file in the build-ID cache if available rather than just using the path name. Let's factor out dso__get_filename() to avoid code duplicate. Fixes: 53a61a6 ("perf annotate: Add dso__debuginfo() helper") Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: James Clark <james.clark@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 82b1f2b commit 8d0cf13

2 files changed

Lines changed: 50 additions & 24 deletions

File tree

tools/perf/util/dso.c

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool dso__is_object_file(const struct dso *dso)
111111

112112
int dso__read_binary_type_filename(const struct dso *dso,
113113
enum dso_binary_type type,
114-
char *root_dir, char *filename, size_t size)
114+
const char *root_dir, char *filename, size_t size)
115115
{
116116
char build_id_hex[SBUILD_ID_SIZE];
117117
int ret = 0;
@@ -563,20 +563,15 @@ char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
563563
return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename);
564564
}
565565

566-
static int __open_dso(struct dso *dso, struct machine *machine)
567-
EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
566+
static char *dso__get_filename(struct dso *dso, const char *root_dir,
567+
bool *decomp)
568568
{
569-
int fd = -EINVAL;
570-
char *root_dir = (char *)"";
571569
char *name = malloc(PATH_MAX);
572-
bool decomp = false;
573570

574-
if (!name)
575-
return -ENOMEM;
571+
*decomp = false;
576572

577-
mutex_lock(dso__lock(dso));
578-
if (machine)
579-
root_dir = machine->root_dir;
573+
if (name == NULL)
574+
return NULL;
580575

581576
if (dso__read_binary_type_filename(dso, dso__binary_type(dso),
582577
root_dir, name, PATH_MAX))
@@ -601,20 +596,38 @@ static int __open_dso(struct dso *dso, struct machine *machine)
601596
size_t len = sizeof(newpath);
602597

603598
if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
604-
fd = -(*dso__load_errno(dso));
599+
errno = *dso__load_errno(dso);
605600
goto out;
606601
}
607602

608-
decomp = true;
603+
*decomp = true;
609604
strcpy(name, newpath);
610605
}
606+
return name;
607+
608+
out:
609+
free(name);
610+
return NULL;
611+
}
611612

612-
fd = do_open(name);
613+
static int __open_dso(struct dso *dso, struct machine *machine)
614+
EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
615+
{
616+
int fd = -EINVAL;
617+
char *name;
618+
bool decomp = false;
619+
620+
mutex_lock(dso__lock(dso));
621+
622+
name = dso__get_filename(dso, machine ? machine->root_dir : "", &decomp);
623+
if (name)
624+
fd = do_open(name);
625+
else
626+
fd = -errno;
613627

614628
if (decomp)
615629
unlink(name);
616630

617-
out:
618631
mutex_unlock(dso__lock(dso));
619632
free(name);
620633
return fd;
@@ -1910,3 +1923,23 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
19101923
return __dso__read_symbol(dso, symfs_filename, start, len,
19111924
out_buf, out_buf_len, is_64bit);
19121925
}
1926+
1927+
struct debuginfo *dso__debuginfo(struct dso *dso)
1928+
{
1929+
char *name;
1930+
bool decomp = false;
1931+
struct debuginfo *dinfo = NULL;
1932+
1933+
mutex_lock(dso__lock(dso));
1934+
1935+
name = dso__get_filename(dso, "", &decomp);
1936+
if (name)
1937+
dinfo = debuginfo__new(name);
1938+
1939+
if (decomp)
1940+
unlink(name);
1941+
1942+
mutex_unlock(dso__lock(dso));
1943+
free(name);
1944+
return dinfo;
1945+
}

tools/perf/util/dso.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
766766

767767
char dso__symtab_origin(const struct dso *dso);
768768
int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
769-
char *root_dir, char *filename, size_t size);
769+
const char *root_dir, char *filename, size_t size);
770770
bool is_kernel_module(const char *pathname, int cpumode);
771771
bool dso__needs_decompress(struct dso *dso);
772772
int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
@@ -915,14 +915,7 @@ u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
915915
bool perf_pid_map_tid(const char *dso_name, int *tid);
916916
bool is_perf_pid_map_name(const char *dso_name);
917917

918-
/*
919-
* In the future, we may get debuginfo using build-ID (w/o path).
920-
* Add this helper is for the smooth conversion.
921-
*/
922-
static inline struct debuginfo *dso__debuginfo(struct dso *dso)
923-
{
924-
return debuginfo__new(dso__long_name(dso));
925-
}
918+
struct debuginfo *dso__debuginfo(struct dso *dso);
926919

927920
const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
928921
const struct map *map, const struct symbol *sym,

0 commit comments

Comments
 (0)