xref: /openbmc/linux/tools/perf/util/unwind.h (revision a2873325ffb21cecca8032673eb698cb4d778dc6)
171ad0f5eSJiri Olsa #ifndef __UNWIND_H
271ad0f5eSJiri Olsa #define __UNWIND_H
371ad0f5eSJiri Olsa 
4d944c4eeSBorislav Petkov #include <linux/types.h>
571ad0f5eSJiri Olsa #include "event.h"
671ad0f5eSJiri Olsa #include "symbol.h"
766f066d8SNamhyung Kim #include "thread.h"
871ad0f5eSJiri Olsa 
971ad0f5eSJiri Olsa struct unwind_entry {
1071ad0f5eSJiri Olsa 	struct map	*map;
1171ad0f5eSJiri Olsa 	struct symbol	*sym;
1271ad0f5eSJiri Olsa 	u64		ip;
1371ad0f5eSJiri Olsa };
1471ad0f5eSJiri Olsa 
1571ad0f5eSJiri Olsa typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
1671ad0f5eSJiri Olsa 
17f83c0415SHe Kuang struct unwind_libunwind_ops {
18f83c0415SHe Kuang 	int (*prepare_access)(struct thread *thread);
19f83c0415SHe Kuang 	void (*flush_access)(struct thread *thread);
20f83c0415SHe Kuang 	void (*finish_access)(struct thread *thread);
21f83c0415SHe Kuang 	int (*get_entries)(unwind_entry_cb_t cb, void *arg,
22f83c0415SHe Kuang 			   struct thread *thread,
23f83c0415SHe Kuang 			   struct perf_sample *data, int max_stack);
24f83c0415SHe Kuang };
25f83c0415SHe Kuang 
269ff125d1SJiri Olsa #ifdef HAVE_DWARF_UNWIND_SUPPORT
2771ad0f5eSJiri Olsa int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
2871ad0f5eSJiri Olsa 			struct thread *thread,
2937676af1SArnaldo Carvalho de Melo 			struct perf_sample *data, int max_stack);
309ff125d1SJiri Olsa /* libunwind specific */
319ff125d1SJiri Olsa #ifdef HAVE_LIBUNWIND_SUPPORT
32eeb118c5SHe Kuang #ifndef LIBUNWIND__ARCH_REG_ID
33eeb118c5SHe Kuang #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
34eeb118c5SHe Kuang #endif
3578ff1d6dSHe Kuang 
3678ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_SP
3778ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP
3878ff1d6dSHe Kuang #endif
3978ff1d6dSHe Kuang 
4078ff1d6dSHe Kuang #ifndef LIBUNWIND__ARCH_REG_IP
4178ff1d6dSHe Kuang #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP
4278ff1d6dSHe Kuang #endif
4378ff1d6dSHe Kuang 
44eeb118c5SHe Kuang int LIBUNWIND__ARCH_REG_ID(int regnum);
45*a2873325SJiri Olsa int unwind__prepare_access(struct thread *thread, struct map *map,
46*a2873325SJiri Olsa 			   bool *initialized);
47380b5143SNamhyung Kim void unwind__flush_access(struct thread *thread);
4866f066d8SNamhyung Kim void unwind__finish_access(struct thread *thread);
4966f066d8SNamhyung Kim #else
50d64ec10eSHe Kuang static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
51*a2873325SJiri Olsa 					 struct map *map __maybe_unused,
52*a2873325SJiri Olsa 					 bool *initialized __maybe_unused)
5366f066d8SNamhyung Kim {
5466f066d8SNamhyung Kim 	return 0;
5566f066d8SNamhyung Kim }
5666f066d8SNamhyung Kim 
57380b5143SNamhyung Kim static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
5866f066d8SNamhyung Kim static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
599ff125d1SJiri Olsa #endif
6071ad0f5eSJiri Olsa #else
6171ad0f5eSJiri Olsa static inline int
621d037ca1SIrina Tirdea unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
631d037ca1SIrina Tirdea 		    void *arg __maybe_unused,
641d037ca1SIrina Tirdea 		    struct thread *thread __maybe_unused,
6537676af1SArnaldo Carvalho de Melo 		    struct perf_sample *data __maybe_unused,
6637676af1SArnaldo Carvalho de Melo 		    int max_stack __maybe_unused)
6771ad0f5eSJiri Olsa {
6871ad0f5eSJiri Olsa 	return 0;
6971ad0f5eSJiri Olsa }
7066f066d8SNamhyung Kim 
71d64ec10eSHe Kuang static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
72*a2873325SJiri Olsa 					 struct map *map __maybe_unused,
73*a2873325SJiri Olsa 					 bool *initialized __maybe_unused)
7466f066d8SNamhyung Kim {
7566f066d8SNamhyung Kim 	return 0;
7666f066d8SNamhyung Kim }
7766f066d8SNamhyung Kim 
78380b5143SNamhyung Kim static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
7966f066d8SNamhyung Kim static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
809ff125d1SJiri Olsa #endif /* HAVE_DWARF_UNWIND_SUPPORT */
8171ad0f5eSJiri Olsa #endif /* __UNWIND_H */
82