Skip to content

Commit 069e603

Browse files
namhyungacmel
authored andcommitted
perf tools: Get debug info of DSO properly
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 <[email protected]> Signed-off-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: James Clark <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b42c4df commit 069e603

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
@@ -112,7 +112,7 @@ bool dso__is_object_file(const struct dso *dso)
112112

113113
int dso__read_binary_type_filename(const struct dso *dso,
114114
enum dso_binary_type type,
115-
char *root_dir, char *filename, size_t size)
115+
const char *root_dir, char *filename, size_t size)
116116
{
117117
char build_id_hex[SBUILD_ID_SIZE];
118118
int ret = 0;
@@ -561,20 +561,15 @@ char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
561561
return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename);
562562
}
563563

564-
static int __open_dso(struct dso *dso, struct machine *machine)
565-
EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
564+
static char *dso__get_filename(struct dso *dso, const char *root_dir,
565+
bool *decomp)
566566
{
567-
int fd = -EINVAL;
568-
char *root_dir = (char *)"";
569567
char *name = malloc(PATH_MAX);
570-
bool decomp = false;
571568

572-
if (!name)
573-
return -ENOMEM;
569+
*decomp = false;
574570

575-
mutex_lock(dso__lock(dso));
576-
if (machine)
577-
root_dir = machine->root_dir;
571+
if (name == NULL)
572+
return NULL;
578573

579574
if (dso__read_binary_type_filename(dso, dso__binary_type(dso),
580575
root_dir, name, PATH_MAX))
@@ -599,20 +594,38 @@ static int __open_dso(struct dso *dso, struct machine *machine)
599594
size_t len = sizeof(newpath);
600595

601596
if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
602-
fd = -(*dso__load_errno(dso));
597+
errno = *dso__load_errno(dso);
603598
goto out;
604599
}
605600

606-
decomp = true;
601+
*decomp = true;
607602
strcpy(name, newpath);
608603
}
604+
return name;
605+
606+
out:
607+
free(name);
608+
return NULL;
609+
}
609610

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

612626
if (decomp)
613627
unlink(name);
614628

615-
out:
616629
mutex_unlock(dso__lock(dso));
617630
free(name);
618631
return fd;
@@ -1916,3 +1929,23 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
19161929
return __dso__read_symbol(dso, symfs_filename, start, len,
19171930
out_buf, out_buf_len, is_64bit);
19181931
}
1932+
1933+
struct debuginfo *dso__debuginfo(struct dso *dso)
1934+
{
1935+
char *name;
1936+
bool decomp = false;
1937+
struct debuginfo *dinfo = NULL;
1938+
1939+
mutex_lock(dso__lock(dso));
1940+
1941+
name = dso__get_filename(dso, "", &decomp);
1942+
if (name)
1943+
dinfo = debuginfo__new(name);
1944+
1945+
if (decomp)
1946+
unlink(name);
1947+
1948+
mutex_unlock(dso__lock(dso));
1949+
free(name);
1950+
return dinfo;
1951+
}

tools/perf/util/dso.h

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

785785
char dso__symtab_origin(const struct dso *dso);
786786
int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
787-
char *root_dir, char *filename, size_t size);
787+
const char *root_dir, char *filename, size_t size);
788788
bool is_kernel_module(const char *pathname, int cpumode);
789789
bool dso__needs_decompress(struct dso *dso);
790790
int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
@@ -933,14 +933,7 @@ u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
933933
bool perf_pid_map_tid(const char *dso_name, int *tid);
934934
bool is_perf_pid_map_name(const char *dso_name);
935935

936-
/*
937-
* In the future, we may get debuginfo using build-ID (w/o path).
938-
* Add this helper is for the smooth conversion.
939-
*/
940-
static inline struct debuginfo *dso__debuginfo(struct dso *dso)
941-
{
942-
return debuginfo__new(dso__long_name(dso));
943-
}
936+
struct debuginfo *dso__debuginfo(struct dso *dso);
944937

945938
const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
946939
const struct map *map, const struct symbol *sym,

0 commit comments

Comments
 (0)