perf intel-pt: Add lookahead callback
[linux/fpc-iii.git] / tools / perf / util / unwind-libunwind.c
blobc0811977d7d542c613bd489c6e8f636aeb75a2ff
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"
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;
14 static void unwind__register_ops(struct thread *thread,
15 struct unwind_libunwind_ops *ops)
17 thread->unwind_libunwind_ops = ops;
20 int unwind__prepare_access(struct thread *thread, struct map *map,
21 bool *initialized)
23 const char *arch;
24 enum dso_type dso_type;
25 struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
26 int err;
28 if (!dwarf_callchain_users)
29 return 0;
31 if (thread->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;
39 /* env->arch is NULL for live-mode (i.e. perf top) */
40 if (!thread->mg->machine->env || !thread->mg->machine->env->arch)
41 goto out_register;
43 dso_type = dso__type(map->dso, thread->mg->machine);
44 if (dso_type == DSO__TYPE_UNKNOWN)
45 return 0;
47 arch = perf_env__arch(thread->mg->machine->env);
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;
57 if (!ops) {
58 pr_err("unwind: target platform=%s is not supported\n", arch);
59 return 0;
61 out_register:
62 unwind__register_ops(thread, ops);
64 err = thread->unwind_libunwind_ops->prepare_access(thread);
65 if (initialized)
66 *initialized = err ? false : true;
67 return err;
70 void unwind__flush_access(struct thread *thread)
72 if (!dwarf_callchain_users)
73 return;
75 if (thread->unwind_libunwind_ops)
76 thread->unwind_libunwind_ops->flush_access(thread);
79 void unwind__finish_access(struct thread *thread)
81 if (!dwarf_callchain_users)
82 return;
84 if (thread->unwind_libunwind_ops)
85 thread->unwind_libunwind_ops->finish_access(thread);
88 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
89 struct thread *thread,
90 struct perf_sample *data, int max_stack)
92 if (thread->unwind_libunwind_ops)
93 return thread->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);
94 return 0;