From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Ian Rogers <irogers@google.com>,
James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-perf-users@vger.kernel.org
Subject: [PATCH] perf tools: Get debug info of DSO properly
Date: Tue, 13 Jan 2026 15:37:57 -0800 [thread overview]
Message-ID: <20260113233757.62347-1-namhyung@kernel.org> (raw)
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: 53a61a6ca279165d ("perf annotate: Add dso__debuginfo() helper")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/dso.c | 63 ++++++++++++++++++++++++++++++++-----------
tools/perf/util/dso.h | 11 ++------
2 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 06980844c014ec9b..922fcc2f798baa57 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -112,7 +112,7 @@ bool dso__is_object_file(const struct dso *dso)
int dso__read_binary_type_filename(const struct dso *dso,
enum dso_binary_type type,
- char *root_dir, char *filename, size_t size)
+ const char *root_dir, char *filename, size_t size)
{
char build_id_hex[SBUILD_ID_SIZE];
int ret = 0;
@@ -564,20 +564,15 @@ char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename);
}
-static int __open_dso(struct dso *dso, struct machine *machine)
- EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
+static char *dso__get_filename(struct dso *dso, const char *root_dir,
+ bool *decomp)
{
- int fd = -EINVAL;
- char *root_dir = (char *)"";
char *name = malloc(PATH_MAX);
- bool decomp = false;
- if (!name)
- return -ENOMEM;
+ *decomp = false;
- mutex_lock(dso__lock(dso));
- if (machine)
- root_dir = machine->root_dir;
+ if (name == NULL)
+ return NULL;
if (dso__read_binary_type_filename(dso, dso__binary_type(dso),
root_dir, name, PATH_MAX))
@@ -602,20 +597,38 @@ static int __open_dso(struct dso *dso, struct machine *machine)
size_t len = sizeof(newpath);
if (dso__decompress_kmodule_path(dso, name, newpath, len) < 0) {
- fd = -(*dso__load_errno(dso));
+ errno = *dso__load_errno(dso);
goto out;
}
- decomp = true;
+ *decomp = true;
strcpy(name, newpath);
}
+ return name;
+
+out:
+ free(name);
+ return NULL;
+}
- fd = do_open(name);
+static int __open_dso(struct dso *dso, struct machine *machine)
+ EXCLUSIVE_LOCKS_REQUIRED(_dso__data_open_lock)
+{
+ int fd = -EINVAL;
+ char *name;
+ bool decomp = false;
+
+ mutex_lock(dso__lock(dso));
+
+ name = dso__get_filename(dso, machine ? machine->root_dir : "", &decomp);
+ if (name)
+ fd = do_open(name);
+ else
+ fd = -errno;
if (decomp)
unlink(name);
-out:
mutex_unlock(dso__lock(dso));
free(name);
return fd;
@@ -1912,3 +1925,23 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
return __dso__read_symbol(dso, symfs_filename, start, len,
out_buf, out_buf_len, is_64bit);
}
+
+struct debuginfo *dso__debuginfo(struct dso *dso)
+{
+ char *name;
+ bool decomp = false;
+ struct debuginfo *dinfo = NULL;
+
+ mutex_lock(dso__lock(dso));
+
+ name = dso__get_filename(dso, "", &decomp);
+ if (name)
+ dinfo = debuginfo__new(name);
+
+ if (decomp)
+ unlink(name);
+
+ mutex_unlock(dso__lock(dso));
+ free(name);
+ return dinfo;
+}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index 4aee23775054cf83..3dd7d0fc00797f37 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -777,7 +777,7 @@ int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
char dso__symtab_origin(const struct dso *dso);
int dso__read_binary_type_filename(const struct dso *dso, enum dso_binary_type type,
- char *root_dir, char *filename, size_t size);
+ const char *root_dir, char *filename, size_t size);
bool is_kernel_module(const char *pathname, int cpumode);
bool dso__needs_decompress(struct dso *dso);
int dso__decompress_kmodule_fd(struct dso *dso, const char *name);
@@ -926,14 +926,7 @@ u64 dso__findnew_global_type(struct dso *dso, u64 addr, u64 offset);
bool perf_pid_map_tid(const char *dso_name, int *tid);
bool is_perf_pid_map_name(const char *dso_name);
-/*
- * In the future, we may get debuginfo using build-ID (w/o path).
- * Add this helper is for the smooth conversion.
- */
-static inline struct debuginfo *dso__debuginfo(struct dso *dso)
-{
- return debuginfo__new(dso__long_name(dso));
-}
+struct debuginfo *dso__debuginfo(struct dso *dso);
const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,
const struct map *map, const struct symbol *sym,
--
2.52.0.457.g6b5491de43-goog
next reply other threads:[~2026-01-13 23:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-13 23:37 Namhyung Kim [this message]
2026-01-14 0:45 ` [PATCH] perf tools: Get debug info of DSO properly Ian Rogers
2026-01-14 19:12 ` Ian Rogers
2026-01-20 20:23 ` Arnaldo Carvalho de Melo
2026-01-20 20:36 ` Ian Rogers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260113233757.62347-1-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.