Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf annotate: Add dso__debuginfo() helper

It'd be great if it can get the correct debug information using DSO
build-Id not just the path name. Instead of adding new callsites of
debuginfo__new(), let's add dso__debuginfo() which can hide the access
using the pathname and help the future conversion.

Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250816031635.25318-12-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
53a61a6c d69f5654

+15 -5
+2 -2
tools/perf/ui/browsers/annotate.c
··· 1050 1050 case 'T': 1051 1051 annotate_opts.code_with_type ^= 1; 1052 1052 if (browser->dbg == NULL) 1053 - browser->dbg = debuginfo__new(dso__long_name(map__dso(ms->map))); 1053 + browser->dbg = dso__debuginfo(map__dso(ms->map)); 1054 1054 annotate_browser__show(&browser->b, title, help); 1055 1055 annotate_browser__debuginfo_warning(browser); 1056 1056 continue; ··· 1146 1146 ui_helpline__push("Press ESC to exit"); 1147 1147 1148 1148 if (annotate_opts.code_with_type) 1149 - browser.dbg = debuginfo__new(dso__long_name(dso)); 1149 + browser.dbg = dso__debuginfo(dso); 1150 1150 1151 1151 browser.b.width = notes->src->widths.max_line_len; 1152 1152 browser.b.nr_entries = notes->src->nr_entries;
+3 -3
tools/perf/util/annotate.c
··· 1270 1270 apd.addr_fmt_width = annotated_source__addr_fmt_width(&notes->src->source, 1271 1271 notes->src->start); 1272 1272 evsel__get_arch(evsel, &apd.arch); 1273 - apd.dbg = debuginfo__new(filename); 1273 + apd.dbg = dso__debuginfo(dso); 1274 1274 1275 1275 list_for_each_entry(pos, &notes->src->source, node) { 1276 1276 int err; ··· 1375 1375 1376 1376 if (annotate_opts.code_with_type) { 1377 1377 evsel__get_arch(apd->evsel, &apd->arch); 1378 - apd->dbg = debuginfo__new(dso__long_name(map__dso(apd->he->ms.map))); 1378 + apd->dbg = dso__debuginfo(map__dso(apd->he->ms.map)); 1379 1379 } 1380 1380 1381 1381 list_for_each_entry(al, &notes->src->source, node) { ··· 2882 2882 di_cache.dso = dso__get(map__dso(ms->map)); 2883 2883 2884 2884 debuginfo__delete(di_cache.dbg); 2885 - di_cache.dbg = debuginfo__new(dso__long_name(di_cache.dso)); 2885 + di_cache.dbg = dso__debuginfo(di_cache.dso); 2886 2886 } 2887 2887 2888 2888 if (di_cache.dbg == NULL) {
+10
tools/perf/util/dso.h
··· 10 10 #include <stdio.h> 11 11 #include <linux/bitops.h> 12 12 #include "build-id.h" 13 + #include "debuginfo.h" 13 14 #include "mutex.h" 14 15 #include <internal/rc_check.h> 15 16 ··· 914 913 /* Check if dso name is of format "/tmp/perf-%d.map" */ 915 914 bool perf_pid_map_tid(const char *dso_name, int *tid); 916 915 bool is_perf_pid_map_name(const char *dso_name); 916 + 917 + /* 918 + * In the future, we may get debuginfo using build-ID (w/o path). 919 + * Add this helper is for the smooth conversion. 920 + */ 921 + static inline struct debuginfo *dso__debuginfo(struct dso *dso) 922 + { 923 + return debuginfo__new(dso__long_name(dso)); 924 + } 917 925 918 926 #endif /* __PERF_DSO */