hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/tools/perf/util/unwind-libdw.c
....@@ -5,22 +5,39 @@
55 #include <inttypes.h>
66 #include <errno.h>
77 #include "debug.h"
8
+#include "dso.h"
89 #include "unwind.h"
910 #include "unwind-libdw.h"
1011 #include "machine.h"
12
+#include "map.h"
13
+#include "symbol.h"
1114 #include "thread.h"
1215 #include <linux/types.h>
16
+#include <linux/zalloc.h>
1317 #include "event.h"
1418 #include "perf_regs.h"
1519 #include "callchain.h"
16
-#include "util.h"
1720
1821 static char *debuginfo_path;
1922
23
+static int __find_debuginfo(Dwfl_Module *mod __maybe_unused, void **userdata,
24
+ const char *modname __maybe_unused, Dwarf_Addr base __maybe_unused,
25
+ const char *file_name, const char *debuglink_file __maybe_unused,
26
+ GElf_Word debuglink_crc __maybe_unused, char **debuginfo_file_name)
27
+{
28
+ const struct dso *dso = *userdata;
29
+
30
+ assert(dso);
31
+ if (dso->symsrc_filename && strcmp (file_name, dso->symsrc_filename))
32
+ *debuginfo_file_name = strdup(dso->symsrc_filename);
33
+ return -1;
34
+}
35
+
2036 static const Dwfl_Callbacks offline_callbacks = {
21
- .find_debuginfo = dwfl_standard_find_debuginfo,
37
+ .find_debuginfo = __find_debuginfo,
2238 .debuginfo_path = &debuginfo_path,
2339 .section_address = dwfl_offline_section_address,
40
+ // .find_elf is not set as we use dwfl_report_elf() instead.
2441 };
2542
2643 static int __report_module(struct addr_location *al, u64 ip,
....@@ -50,9 +67,22 @@
5067 }
5168
5269 if (!mod)
53
- mod = dwfl_report_elf(ui->dwfl, dso->short_name,
54
- (dso->symsrc_filename ? dso->symsrc_filename : dso->long_name), -1, al->map->start - al->map->pgoff,
55
- false);
70
+ mod = dwfl_report_elf(ui->dwfl, dso->short_name, dso->long_name, -1,
71
+ al->map->start - al->map->pgoff, false);
72
+ if (!mod) {
73
+ char filename[PATH_MAX];
74
+
75
+ if (dso__build_id_filename(dso, filename, sizeof(filename), false))
76
+ mod = dwfl_report_elf(ui->dwfl, dso->short_name, filename, -1,
77
+ al->map->start - al->map->pgoff, false);
78
+ }
79
+
80
+ if (mod) {
81
+ void **userdatap;
82
+
83
+ dwfl_module_info(mod, &userdatap, NULL, NULL, NULL, NULL, NULL, NULL);
84
+ *userdatap = dso;
85
+ }
5686
5787 return mod && dwfl_addrmodule(ui->dwfl, ip) == mod ? 0 : -1;
5888 }
....@@ -77,9 +107,10 @@
77107 if (__report_module(&al, ip, ui))
78108 return -1;
79109
80
- e->ip = ip;
81
- e->map = al.map;
82
- e->sym = al.sym;
110
+ e->ip = ip;
111
+ e->ms.maps = al.maps;
112
+ e->ms.map = al.map;
113
+ e->ms.sym = al.sym;
83114
84115 pr_debug("unwind: %s:ip = 0x%" PRIx64 " (0x%" PRIx64 ")\n",
85116 al.sym ? al.sym->name : "''",
....@@ -196,7 +227,7 @@
196227 struct unwind_info *ui, ui_buf = {
197228 .sample = data,
198229 .thread = thread,
199
- .machine = thread->mg->machine,
230
+ .machine = thread->maps->machine,
200231 .cb = cb,
201232 .arg = arg,
202233 .max_stack = max_stack,