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