perf tools: Cleanup dso debug info access
Namhyung Kim
maintainerv2 cover perf tools: Cleanup dso debug info access
Hello,
This is a preparation for DSO file access cleanup work. IIUC DSO access has three types - symbol table, binary data and debug info. Those information can be placed separately like stripped binaries and split debug files. I've added dbginfo_type to DSO to track location of debug info like others.
I'm sending this out before it grows too much. This patchset focuses on debuginfo open path. Once it looks good to others, I'll update other places accessing DWARF info to use this info and cleanup other file type accesses too.
v2 changes)
* check .zdebug_info section as well
* slightly change the order of debug types
v1: https://lore.kernel.org/r/[email protected]
Thanks,
Namhyung
Namhyung Kim (8):
perf tools: Add dso->dbginfo_type field
perf tools: Factor out dso__find_dbginfo_type() perf tools: Check system path when check debuginfo perf tools: Export dso__get_filename() with type argument perf tools: Add dso__put_filename()
perf tools: Avoid repeated failing search for debuginfo perf tools: Looks symbol file first when check debuginfo perf tools: Update debuginfo__new() to take DSO
tools/perf/util/debuginfo.c | 51 +++++++++----------- tools/perf/util/debuginfo.h | 13 ++++- tools/perf/util/dso.c | 90 +++++++++++++++++++++++++++-------- tools/perf/util/dso.h | 33 +++++++++++++ tools/perf/util/probe-event.c | 4 +- 5 files changed, 137 insertions(+), 54 deletions(-)
Signature · 1 line
2.55.0
Namhyung Kim
maintainerPATCH v2 1/8 perf tools: Add dso->dbginfo_type field
It saves where the debug info is available for the given DSO. It's sometimes different than where binary data or symbol table is located. So let's add a new field to save the info.
--- tools/perf/util/dso.c | 1 + tools/perf/util/dso.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
tools/perf/util/dso.c +1 -0
@@ -1721,6 +1721,7 @@ struct dso *dso__new_id(const char *name, const struct dso_id *id) dso->data.status =DSO_DATA_STATUS_UNKNOWN ; dso->symtab_type =DSO_BINARY_TYPE__NOT_FOUND ; dso->binary_type =DSO_BINARY_TYPE__NOT_FOUND ; + dso->dbginfo_type =DSO_BINARY_TYPE__NOT_FOUND ; dso->is_64_bit = (sizeof (void *) ==8 ); dso->loaded =0 ; dso->rel =0 ;
tools/perf/util/dso.h +16 -0
@@ -328,8 +328,14 @@ DECLARE_RC_STRUCT(dso) {enum dso_load_errno load_errno;u16 long_name_len;u16 short_name_len; +/* +* DSO file data can be spread into multiple places. Distros usually +* place debug info to a separate file. Symbol tables may exist in +* the binary or the debug file. Let's separate them. +*/ enum dso_binary_type symtab_type:8; enum dso_binary_type binary_type:8; + enum dso_binary_type dbginfo_type:8; enum dso_space_type kernel:2; enum dso_swap_type needs_swap:2; bool is_kmod:1;
@@ -997,6 +1003,16 @@ static inline bool dso__is_kallsyms(const struct dso *dso)return is_guest_kallsyms_pid_name (name); } +static inline enum dso_binary_type dso__dbginfo_type (const struct dso *dso) +{ +return RC_CHK_ACCESS (dso)->dbginfo_type; +} + +static inline void dso__set_dbginfo_type (struct dso *dso,enum dso_binary_type bt) +{ +RC_CHK_ACCESS (dso)->dbginfo_type = bt; +} +bool dso__is_object_file (const struct dso *dso);void dso__free_a2l (struct dso *dso);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 1/8] perf tools: Add dso->dbginfo_type field
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
It saves where the debug info is available for the given DSO. It's sometimes different than where binary data or symbol table is located. So let's add a new field to save the info.
Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Namhyung Kim
maintainerPATCH v2 2/8 perf tools: Factor out dso__find_dbginfo_type()
In reply to Namhyung KimIt tries to find a file with working debug info by checking all possible debug types. It checks if the file has one of known debug info sections.
--- tools/perf/util/debuginfo.c | 23 ++++++----------------- tools/perf/util/dso.c | 29 +++++++++++++++++++++++++++++ tools/perf/util/dso.h | 2 ++ 3 files changed, 37 insertions(+), 17 deletions(-)
tools/perf/util/debuginfo.c +6 -17
@@ -93,15 +93,6 @@ static struct debuginfo *__debuginfo__new(const char *path)struct debuginfo *debuginfo__new (const char *path) { -static const enum dso_binary_type distro_dwarf_types[] = { -DSO_BINARY_TYPE__FEDORA_DEBUGINFO , -DSO_BINARY_TYPE__UBUNTU_DEBUGINFO , -DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO , -DSO_BINARY_TYPE__BUILDID_DEBUGINFO , -DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO , -DSO_BINARY_TYPE__NOT_FOUND , - }; -const enum dso_binary_type *type;char buf[PATH_MAX ], nil ='\0' ;struct dso *dso;struct debuginfo *dinfo =NULL ;
@@ -120,14 +111,12 @@ struct debuginfo *debuginfo__new(const char *path)if (filename__read_build_id (path, &bid) >0 )dso__set_build_id (dso, &bid); -for (type = distro_dwarf_types; - !dinfo && *type !=DSO_BINARY_TYPE__NOT_FOUND ; - type++) { -if (dso__read_binary_type_filename (dso, *type, &nil, - buf,PATH_MAX ) <0 ) -continue ; - dinfo =__debuginfo__new (buf); - } +dso__find_dbginfo_type (dso); +if (dso__read_binary_type_filename (dso,dso__dbginfo_type (dso), &nil, + buf,PATH_MAX ) <0 ) + goto out; + + dinfo =__debuginfo__new (buf);dso__put (dso); out:
tools/perf/util/dso.c +29 -0
@@ -2108,3 +2108,32 @@ void dso__set_symsrc_filename(struct dso *dso, char *val)dso__set_has_srcline (dso, true);dso__set_a2l_fails (dso,0 ); } + +void dso__find_dbginfo_type (struct dso *dso) +{ +static const enum dso_binary_type dbginfo_types[] = { +DSO_BINARY_TYPE__FEDORA_DEBUGINFO , +DSO_BINARY_TYPE__UBUNTU_DEBUGINFO , +DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO , +DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO , +DSO_BINARY_TYPE__BUILDID_DEBUGINFO , +DSO_BINARY_TYPE__NOT_FOUND , + }; +const enum dso_binary_type *type; +char buf[PATH_MAX ]; + +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 ) +continue ; + +if (filename__has_section (buf,".debug_info" ) || +filename__has_section (buf,".zdebug_info" )) +break ; + } + +dso__set_dbginfo_type (dso, *type); +}
tools/perf/util/dso.h +2 -0
@@ -1013,6 +1013,8 @@ static inline void dso__set_dbginfo_type(struct dso *dso, enum dso_binary_type bRC_CHK_ACCESS (dso)->dbginfo_type = bt; } +void dso__find_dbginfo_type (struct dso *dso); +bool dso__is_object_file (const struct dso *dso);void dso__free_a2l (struct dso *dso);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 2/8] perf tools: Factor out dso__find_dbginfo_type()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
It tries to find a file with working debug info by checking all possible debug types. It checks if the file has one of known debug info sections.
Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Namhyung Kim
maintainerPATCH v2 3/8 perf tools: Check system path when check debuginfo
In reply to Namhyung KimThe debuginfo__new() has a fallback to try the given path, but it seems that it can check SYSTEM_PATH_DSO type in the dso__find_dbginfo_type() instead.
One corner case would be when dso__new() fails in debuginfo__new() but it should be rare and memory is exhausted. I think it's fine to fail for that case.
--- tools/perf/util/debuginfo.c | 12 +++--------- tools/perf/util/dso.c | 1 + 2 files changed, 4 insertions(+), 9 deletions(-)
tools/perf/util/debuginfo.c +3 -9
@@ -101,7 +101,7 @@ struct debuginfo *debuginfo__new(const char *path)/* Try to open distro debuginfo files */ dso =dso__new (path);if (!dso) - goto out; +return NULL ;/* * Set the build id for DSO_BINARY_TYPE__BUILDID_DEBUGINFO. Don't block
@@ -114,18 +114,12 @@ struct debuginfo *debuginfo__new(const char *path)dso__find_dbginfo_type (dso);if (dso__read_binary_type_filename (dso,dso__dbginfo_type (dso), &nil, buf,PATH_MAX ) <0 ) - goto out; +return NULL ; dinfo =__debuginfo__new (buf);dso__put (dso); -out: -if (dinfo) -return dinfo; - -/* if failed to open all distro debuginfo, open given binary */ -symbol__join_symfs (buf, path); -return __debuginfo__new (buf); +return dinfo; }void debuginfo__delete (struct debuginfo *dbg)
tools/perf/util/dso.c +1 -0
@@ -2117,6 +2117,7 @@ void dso__find_dbginfo_type(struct dso *dso)DSO_BINARY_TYPE__MIXEDUP_UBUNTU_DEBUGINFO ,DSO_BINARY_TYPE__OPENEMBEDDED_DEBUGINFO ,DSO_BINARY_TYPE__BUILDID_DEBUGINFO , +DSO_BINARY_TYPE__SYSTEM_PATH_DSO , DSO_BINARY_TYPE__NOT_FOUND, };const enum dso_binary_type *type;
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 3/8] perf tools: Check system path when check debuginfo
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] perf: skipping libdw fallback on stripped binaries breaks debuginfod --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf: skipping libdw fallback on stripped binaries breaks debuginfod --
commit b8cad86bb3e8eff20f4bbb18f568843350d829d9
Author: Namhyung Kim <[email protected]>
perf tools: Check system path when check debuginfo
This commit refactors debuginfo__new() to check the system path via dso__find_dbginfo_type() rather than using an explicit fallback. The new approach adds DSO_BINARY_TYPE__SYSTEM_PATH_DSO to the debuginfo types list and removes the fallback code in debuginfo__new().
Quoted 4 lines
tools/perf/util/debuginfo.c +0
-0
[ ... ]
tools/perf/util/debuginfo.c struct debuginfo *debuginfo__new(const char *path) · line 117
Quoted 6 lines
tools/perf/util/debuginfo.c +1
-1@@ -114,18 +114,12 @@ struct debuginfo *debuginfo__new(const char *path)dso__find_dbginfo_type (dso);if (dso__read_binary_type_filename (dso,dso__dbginfo_type (dso), &nil, buf,PATH_MAX ) <0 ) - goto out; +return NULL ;
[Severity: High]
Does this skip the libdw fallback entirely for stripped binaries, which could break remote debuginfo resolution via debuginfod?
When running a tool like perf annotate on a stripped binary that lacks local debuginfo files, dso__find_dbginfo_type() checks for debug sections:
tools/perf/util/dso.c:dso__find_dbginfo_type() {
...
if (filename__has_section(buf, ".debug_info") ||
filename__has_section(buf, ".zdebug_info"))
break;
...
}Because stripped binaries fail this section check, their type is marked as DSO_BINARY_TYPE__NOT_FOUND even when DSO_BINARY_TYPE__SYSTEM_PATH_DSO is evaluated.
This causes the dso__read_binary_type_filename() check in debuginfo__new() to fail and return NULL early. By bypassing __debuginfo__new(), this prevents libdw from invoking dwfl_standard_find_debuginfo() to remotely resolve the debuginfo.
Quoted 13 lines
tools/perf/util/debuginfo.c +1
-7dinfo =__debuginfo__new (buf);dso__put (dso); -out: -if (dinfo) -return dinfo; - -/* if failed to open all distro debuginfo, open given binary */ -symbol__join_symfs (buf, path); -return __debuginfo__new (buf); +return dinfo; }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Namhyung Kim
maintainerRe: [PATCH v2 3/8] perf tools: Check system path when check debuginfo
Quoted 41 lines · On Tue, Sep 29, 2026 at 01:23:02AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf: skipping libdw fallback on stripped binaries breaks debuginfod --commit
b8cad86bb3e8eff20f4bbb18f568843350d829d9
Author: Namhyung Kim <[email protected]>perf tools: Check system path when check debuginfo
This commit refactors
debuginfo__new()to check the system path viadso__find_dbginfo_type()rather than using an explicit fallback. The new approach addsDSO_BINARY_TYPE__SYSTEM_PATH_DSOto the debuginfo types list and removes the fallback code indebuginfo__new().Quoted 4 lines
tools/perf/util/debuginfo.c +0
-0[ ... ]
tools/perf/util/debuginfo.c struct debuginfo *debuginfo__new(const char *path) · line 117
Quoted 6 lines
tools/perf/util/debuginfo.c +1
-1@@ -114,18 +114,12 @@ struct debuginfo *debuginfo__new(const char *path)dso__find_dbginfo_type (dso);if (dso__read_binary_type_filename (dso,dso__dbginfo_type (dso), &nil, buf,PATH_MAX ) <0 ) - goto out; +return NULL ;[Severity: High]
Does this skip the libdw fallback entirely for stripped binaries, which could break remote debuginfo resolution via debuginfod?When running a tool like perf annotate on a stripped binary that lacks local debuginfo files,
dso__find_dbginfo_type()checks for debug sections:tools/perf/util/dso.c:dso__find_dbginfo_type() { ... if (filename__has_section(buf, ".debug_info") || filename__has_section(buf, ".zdebug_info")) break; ... }
Quoted 8 lines
Because stripped binaries fail this section check, their type is marked as
DSO_BINARY_TYPE__NOT_FOUNDeven whenDSO_BINARY_TYPE__SYSTEM_PATH_DSOis evaluated.This causes the
dso__read_binary_type_filename()check indebuginfo__new()to fail and return NULL early. By bypassing__debuginfo__new(), this prevents libdw from invokingdwfl_standard_find_debuginfo()to remotely resolve the debuginfo.
I think this is what Arnaldo wanted to add. As we already have debuginfod support, I think it's better to check it explicitly with introducing DSO_BINARY_TYPE__DEBUGINFOD or so.
By checking sections, it would be independent from libdw support which may be useful for minimal systems that only uses external tools like addr2line.
Thanks,
Namhyung
Quoted 17 lines
Quoted 14 lines
tools/perf/util/debuginfo.c +1
-7dinfo =__debuginfo__new (buf);dso__put (dso); -out: -if (dinfo) -return dinfo; - -/* if failed to open all distro debuginfo, open given binary */ -symbol__join_symfs (buf, path); -return __debuginfo__new (buf); +return dinfo; }Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v2 3/8] perf tools: Check system path when check debuginfo
Quoted 46 lines · Namhyung Kim
Quoted 45 lines · On Tue, Sep 29, 2026 at 01:23:02AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] perf: skipping libdw fallback on stripped binaries breaks debuginfod --commit
b8cad86bb3e8eff20f4bbb18f568843350d829d9
Author: Namhyung Kim <[email protected]>perf tools: Check system path when check debuginfo
This commit refactors
debuginfo__new()to check the system path viadso__find_dbginfo_type()rather than using an explicit fallback. The new approach addsDSO_BINARY_TYPE__SYSTEM_PATH_DSOto the debuginfo types list and removes the fallback code indebuginfo__new().Quoted 4 lines
tools/perf/util/debuginfo.c +0
-0[ ... ]
tools/perf/util/debuginfo.c struct debuginfo *debuginfo__new(const char *path) · line 117
Quoted 6 lines
tools/perf/util/debuginfo.c +1
-1@@ -114,18 +114,12 @@ struct debuginfo *debuginfo__new(const char *path)dso__find_dbginfo_type (dso);if (dso__read_binary_type_filename (dso,dso__dbginfo_type (dso), &nil, buf,PATH_MAX ) <0 ) - goto out; +return NULL ;[Severity: High]
Does this skip the libdw fallback entirely for stripped binaries, which could break remote debuginfo resolution via debuginfod?When running a tool like perf annotate on a stripped binary that lacks local debuginfo files,
dso__find_dbginfo_type()checks for debug sections:tools/perf/util/dso.c:dso__find_dbginfo_type() { ... if (filename__has_section(buf, ".debug_info") || filename__has_section(buf, ".zdebug_info")) break; ... }Because stripped binaries fail this section check, their type is marked as
DSO_BINARY_TYPE__NOT_FOUNDeven whenDSO_BINARY_TYPE__SYSTEM_PATH_DSOis evaluated.
Quoted 6 lines
Quoted 4 lines
This causes the
dso__read_binary_type_filename()check indebuginfo__new()to fail and return NULL early. By bypassing__debuginfo__new(), this prevents libdw from invokingdwfl_standard_find_debuginfo()to remotely resolve the debuginfo.I think this is what Arnaldo wanted to add. As we already have
s/wanted/wants/ :-)
Quoted 2 lines
debuginfod support, I think it's better to check it explicitly with introducing
DSO_BINARY_TYPE__DEBUGINFODor so.
Unsure, I'll try to rebase my branch on top of what is being merged, proably after LPC, we'll see.
If this is the only issue Sashiko found, I'll merge it.
- Arnaldo
Quoted 3 lines
By checking sections, it would be independent from libdw support which may be useful for minimal systems that only uses external tools like addr2line.
Namhyung Kim
maintainerPATCH v2 4/8 perf tools: Export dso__get_filename() with type argument
In reply to Namhyung KimThe 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.
--- 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(-)
tools/perf/util/debuginfo.c +11 -6
@@ -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;
tools/perf/util/dso.c +18 -11
@@ -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 ; }
tools/perf/util/dso.h +2 -0
@@ -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);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 4/8] perf tools: Export dso__get_filename() with type argument
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
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 <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Namhyung Kim
maintainerPATCH v2 5/8 perf tools: Add dso__put_filename()
In reply to Namhyung KimIt's a counterpart of the dso__get_filename() as the returned string should be free. Optionally it needs to remove a temporary file if it's decompressed on the fly.
Currently the dso argument is not used, but it's better to pair with the matching dso.
--- tools/perf/util/debuginfo.c | 5 +---- tools/perf/util/dso.c | 27 +++++++++++++-------------- tools/perf/util/dso.h | 2 ++ 3 files changed, 16 insertions(+), 18 deletions(-)
tools/perf/util/debuginfo.c +1 -4
@@ -118,10 +118,7 @@ struct debuginfo *debuginfo__new(const char *path)return NULL ; dinfo =__debuginfo__new (filename); - -if (decomp) -unlink (filename); -free (filename); +dso__put_filename (dso, filename, decomp);dso__put (dso);return dinfo;
tools/perf/util/dso.c +13 -14
@@ -661,6 +661,14 @@ char *dso__get_filename(struct dso *dso, const char *root_dir, bool *decomp,return NULL ; } +void dso__put_filename (struct dso *dso__maybe_unused ,char *filename,bool decomp) +{ +if (decomp) +unlink (filename); + +free (filename); +} +static int __open_dso (struct dso *dso,struct machine *machine)EXCLUSIVE_LOCKS_REQUIRED (_dso__data_open_lock) {
@@ -680,11 +688,8 @@ static int __open_dso(struct dso *dso, struct machine *machine) fd = -errno; } -if (decomp) -unlink (name); - +dso__put_filename (dso, name, decomp);mutex_unlock (dso__lock (dso)); -free (name);return fd; }
@@ -2088,14 +2093,11 @@ struct debuginfo *dso__debuginfo(struct dso *dso)mutex_lock (dso__lock (dso)); name =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); -if (name) +if (name) { dinfo =debuginfo__new (name); - -if (decomp) -unlink (name); - +dso__put_filename (dso, name, decomp); + }mutex_unlock (dso__lock (dso)); -free (name);return dinfo; }
@@ -2135,10 +2137,7 @@ void dso__find_dbginfo_type(struct dso *dso) found =filename__has_section (path,".debug_info" ) ||filename__has_section (path,".zdebug_info" ); -if (decomp) -unlink (path); -free (path); - +dso__put_filename (dso, path, decomp);if (found)break ; }
tools/perf/util/dso.h +2 -0
@@ -841,8 +841,10 @@ 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); +/* returned filename should be freed by dso__put_filename() */ char *dso__get_filename (struct dso *dso,const char *root_dir,bool *decomp,enum dso_binary_type type); +void dso__put_filename (struct dso *dso,char *filename,bool decomp);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);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 5/8] perf tools: Add dso__put_filename()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines
It's a counterpart of the
dso__get_filename()as the returned string should be free. Optionally it needs to remove a temporary file if it's decompressed on the fly.Currently the dso argument is not used, but it's better to pair with the matching dso.
Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Namhyung Kim
maintainerPATCH v2 6/8 perf tools: Avoid repeated failing search for debuginfo
In reply to Namhyung KimIf dso has no debuginfo, dso__find_dbginfo_type() may repeat the same search for available types. Let's add a new field (debuginfo_searched) not to do it.
--- tools/perf/util/dso.c | 4 ++++ tools/perf/util/dso.h | 11 +++++++++++ 2 files changed, 15 insertions(+)
tools/perf/util/dso.c +4 -0
@@ -2129,6 +2129,10 @@ void dso__find_dbginfo_type(struct dso *dso)if (dso__dbginfo_type (dso) !=DSO_BINARY_TYPE__NOT_FOUND )return ; +if (dso__debuginfo_searched (dso)) +return ; +dso__set_debuginfo_searched (dso); +for (type = dbginfo_types; *type !=DSO_BINARY_TYPE__NOT_FOUND ; type++) { path =dso__get_filename (dso,"" , &decomp, *type);if (path ==NULL )
tools/perf/util/dso.h +11 -0
@@ -349,6 +349,7 @@ DECLARE_RC_STRUCT(dso) { u8 short_name_allocated:1; u8 long_name_allocated:1; u8 is_64_bit:1; + u8 debuginfo_searched:1;bool sorted_by_name;bool loaded;u8 rel;
@@ -1019,6 +1020,16 @@ static inline void dso__set_dbginfo_type(struct dso *dso, enum dso_binary_type bvoid dso__find_dbginfo_type (struct dso *dso); +static inline bool dso__debuginfo_searched (const struct dso *dso) +{ +return RC_CHK_ACCESS (dso)->debuginfo_searched; +} + +static inline void dso__set_debuginfo_searched (struct dso *dso) +{ +RC_CHK_ACCESS (dso)->debuginfo_searched =1 ; +} +bool dso__is_object_file (const struct dso *dso);void dso__free_a2l (struct dso *dso);
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 6/8] perf tools: Avoid repeated failing search for debuginfo
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
If dso has no debuginfo,
dso__find_dbginfo_type()may repeat the same search for available types. Let's add a new field (debuginfo_searched) not to do it.Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Namhyung Kim
maintainerPATCH v2 7/8 perf tools: Looks symbol file first when check debuginfo
In reply to Namhyung KimThere's a high chance that the file containing the symbol table also has debug information. Let's check that first before other locations.
--- tools/perf/util/dso.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tools/perf/util/dso.c +14 -0
@@ -2133,6 +2133,20 @@ void dso__find_dbginfo_type(struct dso *dso)return ;dso__set_debuginfo_searched (dso); +/* Maybe debug info is in the same file with the symbol table */ + path =dso__get_filename (dso,"" , &decomp,dso__symtab_type (dso)); +if (path) { + found =filename__has_section (path,".debug_info" ) || +filename__has_section (path,".zdebug_info" ); + +dso__put_filename (dso, path, decomp); +if (found) { +dso__set_dbginfo_type (dso,dso__symtab_type (dso)); +return ; + } + } + +/* Otherwise check distro debug locations */ for (type = dbginfo_types; *type !=DSO_BINARY_TYPE__NOT_FOUND ; type++) { path =dso__get_filename (dso,"" , &decomp, *type);if (path ==NULL )
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 7/8] perf tools: Looks symbol file first when check debuginfo
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 5 lines
There's a high chance that the file containing the symbol table also has debug information. Let's check that first before other locations.
Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Namhyung Kim
maintainerPATCH v2 8/8 perf tools: Update debuginfo__new() to take DSO
In reply to Namhyung KimIt should be the common case to get debuginfo from existing DSOs. Now dso__debuginfo() calls it with its debuginfo type to avoid the unnecessary loop to find the location of debug file.
Update existing function to debuginfo__from_path() for clarity.
--- tools/perf/util/debuginfo.c | 28 ++++++++++++++++++---------- tools/perf/util/debuginfo.h | 13 +++++++++++-- tools/perf/util/dso.c | 11 ++--------- tools/perf/util/probe-event.c | 4 ++-- 4 files changed, 33 insertions(+), 23 deletions(-)
tools/perf/util/debuginfo.c +18 -10
@@ -91,13 +91,27 @@ static struct debuginfo *__debuginfo__new(const char *path)return dbg; } -struct debuginfo *debuginfo__new (const char *path) +struct debuginfo *debuginfo__new (struct dso *dso) +{ +struct debuginfo *dinfo; +char *path; +bool decomp = false; + +dso__find_dbginfo_type (dso); + path =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); +if (path ==NULL ) +return NULL ; + + dinfo =__debuginfo__new (path); +dso__put_filename (dso, path, decomp); +return dinfo; +} + +struct debuginfo *debuginfo__from_path (const char *path) {struct dso *dso;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,13 +126,7 @@ struct debuginfo *debuginfo__new(const char *path)if (filename__read_build_id (path, &bid) >0 )dso__set_build_id (dso, &bid); -dso__find_dbginfo_type (dso); - filename =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); -if (filename ==NULL ) -return NULL ; - - dinfo =__debuginfo__new (filename); -dso__put_filename (dso, filename, decomp); + dinfo =debuginfo__new (dso);dso__put (dso);return dinfo;
tools/perf/util/debuginfo.h +11 -2
@@ -18,8 +18,12 @@ struct debuginfo {const unsigned char *build_id; }; +struct dso ; +/* This also tries to open distro debuginfo */ -struct debuginfo *debuginfo__new (const char *path); +struct debuginfo *debuginfo__from_path (const char *path); +/* Create a debuginfo using information in DSO */ +struct debuginfo *debuginfo__new (struct dso *dso);void debuginfo__delete (struct debuginfo *dbg); int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,
@@ -31,7 +35,12 @@ int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,struct debuginfo { }; -static inline struct debuginfo *debuginfo__new (const char *path__maybe_unused ) +static inline struct debuginfo *debuginfo__from_path (const char *path__maybe_unused ) +{ +return NULL ; +} + +static inline struct debuginfo *debuginfo__new (struct dso *dso__maybe_unused ) {return NULL ; }
tools/perf/util/dso.c +2 -9
@@ -2086,17 +2086,10 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,struct debuginfo *dso__debuginfo (struct dso *dso) { -char *name; -bool decomp = false; -struct debuginfo *dinfo =NULL ; +struct debuginfo *dinfo;mutex_lock (dso__lock (dso)); - - name =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); -if (name) { - dinfo =debuginfo__new (name); -dso__put_filename (dso, name, decomp); - } + dinfo =debuginfo__new (dso);mutex_unlock (dso__lock (dso));return dinfo; }
tools/perf/util/probe-event.c +2 -2
@@ -519,7 +519,7 @@ static struct debuginfo *open_from_debuginfod(struct dso *dso, struct nsinfo *nspr_debug ("Load debuginfo from debuginfod (%s)\n" , path);nsinfo__mountns_enter (nsi, &nsc); - ret =debuginfo__new ((const char *)path); + ret =debuginfo__from_path ((const char *)path);nsinfo__mountns_exit (&nsc);return ret; }
@@ -567,7 +567,7 @@ static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi, path =dso__long_name (dso); }nsinfo__mountns_enter (nsi, &nsc); - ret =debuginfo__new (path); + ret =debuginfo__from_path (path);if (!ret && !silent) {pr_warning ("The %s file has no debug information.\n" , path);if (!module || !strtailcmp (path,".ko" ))
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 8/8] perf tools: Update debuginfo__new() to take DSO
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
It should be the common case to get debuginfo from existing DSOs. Now
dso__debuginfo()calls it with its debuginfo type to avoid the unnecessary loop to find the location of debug file.Update existing function to
debuginfo__from_path()for clarity.Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH v2 8/8] perf tools: Update debuginfo__new() to take DSO
In reply to Namhyung KimQuoted 6 lines · On Mon, 28 Sep 2026 18:11:39 -0700 Namhyung Kim <[email protected]> wrote:
It should be the common case to get debuginfo from existing DSOs. Now
dso__debuginfo()calls it with its debuginfo type to avoid the unnecessary loop to find the location of debug file.Update existing function to
debuginfo__from_path()for clarity.
Looks good to me.
Thanks!
Quoted 141 lines
Reviewed-by Arnaldo Carvalho de Melo <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/util/debuginfo.c | 28 ++++++++++++++++++---------- tools/perf/util/debuginfo.h | 13 +++++++++++-- tools/perf/util/dso.c | 11 ++--------- tools/perf/util/probe-event.c | 4 ++-- 4 files changed, 33 insertions(+), 23 deletions(-)tools/perf/util/debuginfo.c +18
-10@@ -91,13 +91,27 @@ static struct debuginfo *__debuginfo__new(const char *path)return dbg; } -struct debuginfo *debuginfo__new (const char *path) +struct debuginfo *debuginfo__new (struct dso *dso) +{ +struct debuginfo *dinfo; +char *path; +bool decomp = false; + +dso__find_dbginfo_type (dso); + path =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); +if (path ==NULL ) +return NULL ; + + dinfo =__debuginfo__new (path); +dso__put_filename (dso, path, decomp); +return dinfo; +} + +struct debuginfo *debuginfo__from_path (const char *path) {struct dso *dso;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,13 +126,7 @@ struct debuginfo *debuginfo__new(const char *path)if (filename__read_build_id (path, &bid) >0 )dso__set_build_id (dso, &bid); -dso__find_dbginfo_type (dso); - filename =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); -if (filename ==NULL ) -return NULL ; - - dinfo =__debuginfo__new (filename); -dso__put_filename (dso, filename, decomp); + dinfo =debuginfo__new (dso);dso__put (dso);return dinfo;tools/perf/util/debuginfo.h +11
-2@@ -18,8 +18,12 @@ struct debuginfo {const unsigned char *build_id; }; +struct dso ; +/* This also tries to open distro debuginfo */ -struct debuginfo *debuginfo__new (const char *path); +struct debuginfo *debuginfo__from_path (const char *path); +/* Create a debuginfo using information in DSO */ +struct debuginfo *debuginfo__new (struct dso *dso);void debuginfo__delete (struct debuginfo *dbg); int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,@@ -31,7 +35,12 @@ int debuginfo__get_text_offset(struct debuginfo *dbg, Dwarf_Addr *offs,struct debuginfo { }; -static inline struct debuginfo *debuginfo__new (const char *path__maybe_unused ) +static inline struct debuginfo *debuginfo__from_path (const char *path__maybe_unused ) +{ +return NULL ; +} + +static inline struct debuginfo *debuginfo__new (struct dso *dso__maybe_unused ) {return NULL ; }tools/perf/util/dso.c +2
-9@@ -2086,17 +2086,10 @@ const u8 *dso__read_symbol(struct dso *dso, const char *symfs_filename,struct debuginfo *dso__debuginfo (struct dso *dso) { -char *name; -bool decomp = false; -struct debuginfo *dinfo =NULL ; +struct debuginfo *dinfo;mutex_lock (dso__lock (dso)); - - name =dso__get_filename (dso,"" , &decomp,dso__dbginfo_type (dso)); -if (name) { - dinfo =debuginfo__new (name); -dso__put_filename (dso, name, decomp); - } + dinfo =debuginfo__new (dso);mutex_unlock (dso__lock (dso));return dinfo; }tools/perf/util/probe-event.c +2
-2@@ -519,7 +519,7 @@ static struct debuginfo *open_from_debuginfod(struct dso *dso, struct nsinfo *nspr_debug ("Load debuginfo from debuginfod (%s)\n" , path);nsinfo__mountns_enter (nsi, &nsc); - ret =debuginfo__new ((const char *)path); + ret =debuginfo__from_path ((const char *)path);nsinfo__mountns_exit (&nsc);return ret; }@@ -567,7 +567,7 @@ static struct debuginfo *open_debuginfo(const char *module, struct nsinfo *nsi, path =dso__long_name (dso); }nsinfo__mountns_enter (nsi, &nsc); - ret =debuginfo__new (path); + ret =debuginfo__from_path (path);if (!ret && !silent) {pr_warning ("The %s file has no debug information.\n" , path);if (!module || !strtailcmp (path,".ko" ))Signature · 1 line
2.55.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 8 lines · Namhyung Kim
Hello,
This is a preparation for DSO file access cleanup work. IIUC DSO access has three types - symbol table, binary data and debug info. Those information can be placed separately like stripped binaries and split debug files. I've added
dbginfo_typeto DSO to track location of debug info like others.
Quoted 4 lines
I'm sending this out before it grows too much. This patchset focuses on debuginfo open path. Once it looks good to others, I'll update other places accessing DWARF info to use this info and cleanup other file type accesses too.
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo