[PATCH v6 7/8] perf: disasm: prefer debugging files in build-id cache

From: Changbin Du
Date: Fri Aug 16 2024 - 07:00:34 EST


The build-id cache might have both debugging and non-debugging files. Here
we prefer the debugging version for annotation.

Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Signed-off-by: Changbin Du <changbin.du@xxxxxxxxxx>
---
tools/perf/util/disasm.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 6af9fbec3a95..5f66b3632770 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -1162,18 +1162,25 @@ static int dso__disassemble_filename(struct dso *dso, char *filename, size_t fil
!dso__is_kcore(dso))
return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX;

- build_id_filename = dso__build_id_filename(dso, NULL, 0, false);
- if (build_id_filename) {
- __symbol__join_symfs(filename, filename_size, build_id_filename);
- free(build_id_filename);
- } else {
- if (dso__has_build_id(dso))
- return ENOMEM;
- return fallback_filename(dso, filename, filename_size);
- }
+ /* Prefer debugging file if exists, otherwise non-debugging one is used. */
+ for (int i = 0; i < 2; i++) {
+ build_id_filename = dso__build_id_filename(dso, NULL, 0, !i);
+ if (build_id_filename) {
+ __symbol__join_symfs(filename, filename_size, build_id_filename);
+ free(build_id_filename);
+ } else {
+ if (dso__has_build_id(dso))
+ return ENOMEM;
+ return fallback_filename(dso, filename, filename_size);
+ }

- if (access(filename, R_OK))
- return fallback_filename(dso, filename, filename_size);
+ if (!access(filename, R_OK))
+ break;
+ else if (i != 0) {
+ /* nor debugging or non-debugging is found */
+ return fallback_filename(dso, filename, filename_size);
+ }
+ }

if (dso__is_kcore(dso) || dso__is_vdso(dso))
goto fallback;
--
2.34.1