Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef __UNWIND_H |
| 3 | #define __UNWIND_H |
| 4 | |
| 5 | #include <linux/compiler.h> |
| 6 | #include <linux/types.h> |
| 7 | |
| 8 | struct map; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 9 | struct map_groups; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10 | struct perf_sample; |
| 11 | struct symbol; |
| 12 | struct thread; |
| 13 | |
| 14 | struct unwind_entry { |
| 15 | struct map *map; |
| 16 | struct symbol *sym; |
| 17 | u64 ip; |
| 18 | }; |
| 19 | |
| 20 | typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg); |
| 21 | |
| 22 | struct unwind_libunwind_ops { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 23 | int (*prepare_access)(struct map_groups *mg); |
| 24 | void (*flush_access)(struct map_groups *mg); |
| 25 | void (*finish_access)(struct map_groups *mg); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 26 | int (*get_entries)(unwind_entry_cb_t cb, void *arg, |
| 27 | struct thread *thread, |
| 28 | struct perf_sample *data, int max_stack); |
| 29 | }; |
| 30 | |
| 31 | #ifdef HAVE_DWARF_UNWIND_SUPPORT |
| 32 | int unwind__get_entries(unwind_entry_cb_t cb, void *arg, |
| 33 | struct thread *thread, |
| 34 | struct perf_sample *data, int max_stack); |
| 35 | /* libunwind specific */ |
| 36 | #ifdef HAVE_LIBUNWIND_SUPPORT |
| 37 | #ifndef LIBUNWIND__ARCH_REG_ID |
| 38 | #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum) |
| 39 | #endif |
| 40 | |
| 41 | #ifndef LIBUNWIND__ARCH_REG_SP |
| 42 | #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP |
| 43 | #endif |
| 44 | |
| 45 | #ifndef LIBUNWIND__ARCH_REG_IP |
| 46 | #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP |
| 47 | #endif |
| 48 | |
| 49 | int LIBUNWIND__ARCH_REG_ID(int regnum); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 50 | int unwind__prepare_access(struct map_groups *mg, struct map *map, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 51 | bool *initialized); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 52 | void unwind__flush_access(struct map_groups *mg); |
| 53 | void unwind__finish_access(struct map_groups *mg); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 54 | #else |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 55 | static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 56 | struct map *map __maybe_unused, |
| 57 | bool *initialized __maybe_unused) |
| 58 | { |
| 59 | return 0; |
| 60 | } |
| 61 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 62 | static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {} |
| 63 | static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {} |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 64 | #endif |
| 65 | #else |
| 66 | static inline int |
| 67 | unwind__get_entries(unwind_entry_cb_t cb __maybe_unused, |
| 68 | void *arg __maybe_unused, |
| 69 | struct thread *thread __maybe_unused, |
| 70 | struct perf_sample *data __maybe_unused, |
| 71 | int max_stack __maybe_unused) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 76 | static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 77 | struct map *map __maybe_unused, |
| 78 | bool *initialized __maybe_unused) |
| 79 | { |
| 80 | return 0; |
| 81 | } |
| 82 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 83 | static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {} |
| 84 | static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {} |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 85 | #endif /* HAVE_DWARF_UNWIND_SUPPORT */ |
| 86 | #endif /* __UNWIND_H */ |