1 #include "unwind.h" 2 #include "thread.h" 3 #include "session.h" 4 #include "debug.h" 5 #include "arch/common.h" 6 7 struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops; 8 struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops; 9 10 static void unwind__register_ops(struct thread *thread, 11 struct unwind_libunwind_ops *ops) 12 { 13 thread->unwind_libunwind_ops = ops; 14 } 15 16 int unwind__prepare_access(struct thread *thread, struct map *map) 17 { 18 const char *arch; 19 enum dso_type dso_type; 20 struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops; 21 22 if (thread->addr_space) { 23 pr_debug("unwind: thread map already set, dso=%s\n", 24 map->dso->name); 25 return 0; 26 } 27 28 /* env->arch is NULL for live-mode (i.e. perf top) */ 29 if (!thread->mg->machine->env || !thread->mg->machine->env->arch) 30 goto out_register; 31 32 dso_type = dso__type(map->dso, thread->mg->machine); 33 if (dso_type == DSO__TYPE_UNKNOWN) 34 return 0; 35 36 arch = normalize_arch(thread->mg->machine->env->arch); 37 38 if (!strcmp(arch, "x86")) { 39 if (dso_type != DSO__TYPE_64BIT) 40 ops = x86_32_unwind_libunwind_ops; 41 } 42 43 if (!ops) { 44 pr_err("unwind: target platform=%s is not supported\n", arch); 45 return -1; 46 } 47 out_register: 48 unwind__register_ops(thread, ops); 49 50 return thread->unwind_libunwind_ops->prepare_access(thread); 51 } 52 53 void unwind__flush_access(struct thread *thread) 54 { 55 if (thread->unwind_libunwind_ops) 56 thread->unwind_libunwind_ops->flush_access(thread); 57 } 58 59 void unwind__finish_access(struct thread *thread) 60 { 61 if (thread->unwind_libunwind_ops) 62 thread->unwind_libunwind_ops->finish_access(thread); 63 } 64 65 int unwind__get_entries(unwind_entry_cb_t cb, void *arg, 66 struct thread *thread, 67 struct perf_sample *data, int max_stack) 68 { 69 if (thread->unwind_libunwind_ops) 70 return thread->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack); 71 return 0; 72 } 73