xref: /openbmc/linux/tools/perf/util/unwind.h (revision b24413180f5600bcb3bb70fbed5cf186b60864bd)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
271ad0f5eSJiri Olsa #ifndef __UNWIND_H
371ad0f5eSJiri Olsa #define __UNWIND_H
471ad0f5eSJiri Olsa 
53dfed910SArnaldo Carvalho de Melo #include <linux/compiler.h>
6d944c4eeSBorislav Petkov #include <linux/types.h>
73dfed910SArnaldo Carvalho de Melo 
83dfed910SArnaldo Carvalho de Melo struct map;
93dfed910SArnaldo Carvalho de Melo struct perf_sample;
103dfed910SArnaldo Carvalho de Melo struct symbol;
113dfed910SArnaldo Carvalho de Melo struct thread;
1271ad0f5eSJiri Olsa 
1371ad0f5eSJiri Olsa struct unwind_entry {
1471ad0f5eSJiri Olsa 	struct map	*map;
1571ad0f5eSJiri Olsa 	struct symbol	*sym;
1671ad0f5eSJiri Olsa 	u64		ip;
1771ad0f5eSJiri Olsa };
1871ad0f5eSJiri Olsa 
1971ad0f5eSJiri Olsa typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
2071ad0f5eSJiri Olsa 
21f83c0415SHe Kuang struct unwind_libunwind_ops {
22f83c0415SHe Kuang 	int (*prepare_access)(struct thread *thread);
23f83c0415SHe Kuang 	void (*flush_access)(struct thread *thread);
24f83c0415SHe Kuang 	void (*finish_access)(struct thread *thread);
25f83c0415SHe Kuang 	int (*get_entries)(unwind_entry_cb_t cb, void *arg,
26f83c0415SHe Kuang 			   struct thread *thread,
27f83c0415SHe Kuang 			   struct perf_sample *data, int max_stack);
28f83c0415SHe Kuang };
29f83c0415SHe Kuang 
309ff125d1SJiri Olsa #ifdef HAVE_DWARF_UNWIND_SUPPORT
3171ad0f5eSJiri Olsa int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
3271ad0f5eSJiri Olsa 			struct thread *thread,
3337676af1SArnaldo Carvalho de Melo 			struct perf_sample *data, int max_stack);
349ff125d1SJiri Olsa /* libunwind specific */
359ff125d1SJiri Olsa #ifdef HAVE_LIBUNWIND_SUPPORT
36eeb118c5SHe Kuang #ifndef LIBUNWIND__ARCH_REG_ID
37eeb118c5SHe Kuang #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
38eeb118c5SHe Kuang #endif
3978ff1d6dSHe Kuang 
4078ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_SP
4178ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP
4278ff1d6dSHe Kuang #endif
4378ff1d6dSHe Kuang 
4478ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_IP
4578ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP
4678ff1d6dSHe Kuang #endif
4778ff1d6dSHe Kuang 
48eeb118c5SHe Kuang int LIBUNWIND__ARCH_REG_ID(int regnum);
49a2873325SJiri Olsa int unwind__prepare_access(struct thread *thread, struct map *map,
50a2873325SJiri Olsa 			   bool *initialized);
51380b5143SNamhyung Kim void unwind__flush_access(struct thread *thread);
5266f066d8SNamhyung Kim void unwind__finish_access(struct thread *thread);
5366f066d8SNamhyung Kim #else
54d64ec10eSHe Kuang static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
55a2873325SJiri Olsa 					 struct map *map __maybe_unused,
56a2873325SJiri Olsa 					 bool *initialized __maybe_unused)
5766f066d8SNamhyung Kim {
5866f066d8SNamhyung Kim 	return 0;
5966f066d8SNamhyung Kim }
6066f066d8SNamhyung Kim 
61380b5143SNamhyung Kim static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
6266f066d8SNamhyung Kim static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
639ff125d1SJiri Olsa #endif
6471ad0f5eSJiri Olsa #else
6571ad0f5eSJiri Olsa static inline int
661d037ca1SIrina Tirdea unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
671d037ca1SIrina Tirdea 		    void *arg __maybe_unused,
681d037ca1SIrina Tirdea 		    struct thread *thread __maybe_unused,
6937676af1SArnaldo Carvalho de Melo 		    struct perf_sample *data __maybe_unused,
7037676af1SArnaldo Carvalho de Melo 		    int max_stack __maybe_unused)
7171ad0f5eSJiri Olsa {
7271ad0f5eSJiri Olsa 	return 0;
7371ad0f5eSJiri Olsa }
7466f066d8SNamhyung Kim 
75d64ec10eSHe Kuang static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
76a2873325SJiri Olsa 					 struct map *map __maybe_unused,
77a2873325SJiri Olsa 					 bool *initialized __maybe_unused)
7866f066d8SNamhyung Kim {
7966f066d8SNamhyung Kim 	return 0;
8066f066d8SNamhyung Kim }
8166f066d8SNamhyung Kim 
82380b5143SNamhyung Kim static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
8366f066d8SNamhyung Kim static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
849ff125d1SJiri Olsa #endif /* HAVE_DWARF_UNWIND_SUPPORT */
8571ad0f5eSJiri Olsa #endif /* __UNWIND_H */
86