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