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,
Masami Hiramatsu <mhiramat@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH v2 4/8] perf tools: Export dso__get_filename() with type argument
Date: Mon, 28 Sep 2026 18:11:35 -0700 [thread overview]
Message-ID: <20260929011139.53242-5-namhyung@kernel.org> (raw)
In-Reply-To: <20260929011139.53242-1-namhyung@kernel.org>
The dso__get_filename() returns a new string of filepath for the given
binary type. It handles chroot and decompressed kernel modules so that
callers can read the file contents. Thus it'd be better to use it to
check available binary types.
Add a type argument to handle a different path for symbol or debug info.
Reviewed-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/debuginfo.c | 17 +++++++++++------
tools/perf/util/dso.c | 29 ++++++++++++++++++-----------
tools/perf/util/dso.h | 2 ++
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/tools/perf/util/debuginfo.c b/tools/perf/util/debuginfo.c
index 2669d5f5ee6121d4..38e9299765182bd7 100644
--- a/tools/perf/util/debuginfo.c
+++ b/tools/perf/util/debuginfo.c
@@ -93,10 +93,11 @@ static struct debuginfo *__debuginfo__new(const char *path)
struct debuginfo *debuginfo__new(const char *path)
{
- char buf[PATH_MAX], nil = '\0';
struct dso *dso;
- struct debuginfo *dinfo = NULL;
- struct build_id bid = { .size = 0};
+ struct debuginfo *dinfo;
+ struct build_id bid = { .size = 0 };
+ char *filename;
+ bool decomp = false;
/* Try to open distro debuginfo files */
dso = dso__new(path);
@@ -112,11 +113,15 @@ struct debuginfo *debuginfo__new(const char *path)
dso__set_build_id(dso, &bid);
dso__find_dbginfo_type(dso);
- if (dso__read_binary_type_filename(dso, dso__dbginfo_type(dso), &nil,
- buf, PATH_MAX) < 0)
+ filename = dso__get_filename(dso, "", &decomp, dso__dbginfo_type(dso));
+ if (filename == NULL)
return NULL;
- dinfo = __debuginfo__new(buf);
+ dinfo = __debuginfo__new(filename);
+
+ if (decomp)
+ unlink(filename);
+ free(filename);
dso__put(dso);
return dinfo;
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index ceebb32d0a48a96f..7fd6b64583d8b61a 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -590,8 +590,8 @@ char *dso__filename_with_chroot(const struct dso *dso, const char *filename)
return filename_with_chroot(nsinfo__pid(dso__nsinfo_const(dso)), filename);
}
-static char *dso__get_filename(struct dso *dso, const char *root_dir,
- bool *decomp)
+char *dso__get_filename(struct dso *dso, const char *root_dir, bool *decomp,
+ enum dso_binary_type type)
{
char *name = malloc(PATH_MAX);
@@ -600,8 +600,7 @@ static char *dso__get_filename(struct dso *dso, const char *root_dir,
if (name == NULL)
return NULL;
- if (dso__read_binary_type_filename(dso, dso__binary_type(dso),
- root_dir, name, PATH_MAX))
+ if (dso__read_binary_type_filename(dso, type, root_dir, name, PATH_MAX))
goto out;
if (!is_regular_file(name)) {
@@ -671,7 +670,8 @@ static int __open_dso(struct dso *dso, struct machine *machine)
mutex_lock(dso__lock(dso));
- name = dso__get_filename(dso, machine ? machine->root_dir : "", &decomp);
+ name = dso__get_filename(dso, machine ? machine->root_dir : "", &decomp,
+ dso__binary_type(dso));
if (name) {
fd = do_open(name);
} else {
@@ -2087,7 +2087,7 @@ struct debuginfo *dso__debuginfo(struct dso *dso)
mutex_lock(dso__lock(dso));
- name = dso__get_filename(dso, "", &decomp);
+ name = dso__get_filename(dso, "", &decomp, dso__dbginfo_type(dso));
if (name)
dinfo = debuginfo__new(name);
@@ -2121,18 +2121,25 @@ void dso__find_dbginfo_type(struct dso *dso)
DSO_BINARY_TYPE__NOT_FOUND,
};
const enum dso_binary_type *type;
- char buf[PATH_MAX];
+ char *path;
+ bool found, decomp = false;
if (dso__dbginfo_type(dso) != DSO_BINARY_TYPE__NOT_FOUND)
return;
for (type = dbginfo_types; *type != DSO_BINARY_TYPE__NOT_FOUND; type++) {
- if (dso__read_binary_type_filename(dso, *type, "",
- buf, PATH_MAX) < 0)
+ path = dso__get_filename(dso, "", &decomp, *type);
+ if (path == NULL)
continue;
- if (filename__has_section(buf, ".debug_info") ||
- filename__has_section(buf, ".zdebug_info"))
+ found = filename__has_section(path, ".debug_info") ||
+ filename__has_section(path, ".zdebug_info");
+
+ if (decomp)
+ unlink(path);
+ free(path);
+
+ if (found)
break;
}
diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h
index a152957322f6b31c..94cc7ea89ceb5bd9 100644
--- a/tools/perf/util/dso.h
+++ b/tools/perf/util/dso.h
@@ -841,6 +841,8 @@ 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,
const char *root_dir, char *filename, size_t size);
+char *dso__get_filename(struct dso *dso, const char *root_dir, bool *decomp,
+ enum dso_binary_type type);
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);
--
2.55.0
next prev parent reply other threads:[~2026-09-29 1:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 1:11 [PATCH v2 0/8] perf tools: Cleanup dso debug info access Namhyung Kim
2026-09-29 1:11 ` [PATCH v2 1/8] perf tools: Add dso->dbginfo_type field Namhyung Kim
2026-09-29 1:11 ` [PATCH v2 2/8] perf tools: Factor out dso__find_dbginfo_type() Namhyung Kim
2026-09-29 1:11 ` [PATCH v2 3/8] perf tools: Check system path when check debuginfo Namhyung Kim
2026-09-29 1:11 ` Namhyung Kim [this message]
2026-09-29 1:11 ` [PATCH v2 5/8] perf tools: Add dso__put_filename() Namhyung Kim
2026-09-29 1:11 ` [PATCH v2 6/8] perf tools: Avoid repeated failing search for debuginfo Namhyung Kim
2026-09-29 1:11 ` [PATCH v2 7/8] perf tools: Looks symbol file first when check debuginfo Namhyung Kim
2026-09-29 1:11 ` [PATCH v2 8/8] perf tools: Update debuginfo__new() to take DSO Namhyung Kim
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=20260929011139.53242-5-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--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=mhiramat@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®