]> asedeno.scripts.mit.edu Git - linux.git/blob
6499b22b158b
[linux.git] /
1 // SPDX-License-Identifier: GPL-2.0
2 #include "unwind.h"
3 #include "map.h"
4 #include "thread.h"
5 #include "session.h"
6 #include "debug.h"
7 #include "env.h"
8 #include "callchain.h"
9
10 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
11 struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
12 struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
13
14 static void unwind__register_ops(struct map_groups *mg,
15                           struct unwind_libunwind_ops *ops)
16 {
17         mg->unwind_libunwind_ops = ops;
18 }
19
20 int unwind__prepare_access(struct map_groups *mg, struct map *map,
21                            bool *initialized)
22 {
23         const char *arch;
24         enum dso_type dso_type;
25         struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
26         int err;
27
28         if (!dwarf_callchain_users)
29                 return 0;
30
31         if (mg->addr_space) {
32                 pr_debug("unwind: thread map already set, dso=%s\n",
33                          map->dso->name);
34                 if (initialized)
35                         *initialized = true;
36                 return 0;
37         }
38
39         /* env->arch is NULL for live-mode (i.e. perf top) */
40         if (!mg->machine->env || !mg->machine->env->arch)
41                 goto out_register;
42
43         dso_type = dso__type(map->dso, mg->machine);
44         if (dso_type == DSO__TYPE_UNKNOWN)
45                 return 0;
46
47         arch = perf_env__arch(mg->machine->env);
48
49         if (!strcmp(arch, "x86")) {
50                 if (dso_type != DSO__TYPE_64BIT)
51                         ops = x86_32_unwind_libunwind_ops;
52         } else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
53                 if (dso_type == DSO__TYPE_64BIT)
54                         ops = arm64_unwind_libunwind_ops;
55         }
56
57         if (!ops) {
58                 pr_err("unwind: target platform=%s is not supported\n", arch);
59                 return 0;
60         }
61 out_register:
62         unwind__register_ops(mg, ops);
63
64         err = mg->unwind_libunwind_ops->prepare_access(mg);
65         if (initialized)
66                 *initialized = err ? false : true;
67         return err;
68 }
69
70 void unwind__flush_access(struct map_groups *mg)
71 {
72         if (mg->unwind_libunwind_ops)
73                 mg->unwind_libunwind_ops->flush_access(mg);
74 }
75
76 void unwind__finish_access(struct map_groups *mg)
77 {
78         if (mg->unwind_libunwind_ops)
79                 mg->unwind_libunwind_ops->finish_access(mg);
80 }
81
82 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
83                          struct thread *thread,
84                          struct perf_sample *data, int max_stack)
85 {
86         if (thread->mg->unwind_libunwind_ops)
87                 return thread->mg->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);
88         return 0;
89 }