1b2441318SGreg 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>
7c1529738SArnaldo Carvalho de Melo #include "util/map_symbol.h"
83dfed910SArnaldo Carvalho de Melo
979b6bb73SArnaldo Carvalho de Melo struct maps;
103dfed910SArnaldo Carvalho de Melo struct perf_sample;
113dfed910SArnaldo Carvalho de Melo struct thread;
1271ad0f5eSJiri Olsa
1371ad0f5eSJiri Olsa struct unwind_entry {
14c1529738SArnaldo Carvalho de Melo struct map_symbol ms;
1571ad0f5eSJiri Olsa u64 ip;
1671ad0f5eSJiri Olsa };
1771ad0f5eSJiri Olsa
1871ad0f5eSJiri Olsa typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
1971ad0f5eSJiri Olsa
20f83c0415SHe Kuang struct unwind_libunwind_ops {
2179b6bb73SArnaldo Carvalho de Melo int (*prepare_access)(struct maps *maps);
2279b6bb73SArnaldo Carvalho de Melo void (*flush_access)(struct maps *maps);
2379b6bb73SArnaldo Carvalho de Melo void (*finish_access)(struct maps *maps);
24f83c0415SHe Kuang int (*get_entries)(unwind_entry_cb_t cb, void *arg,
25f83c0415SHe Kuang struct thread *thread,
26*fa7095c5SJames Clark struct perf_sample *data, int max_stack, bool best_effort);
27f83c0415SHe Kuang };
28f83c0415SHe Kuang
299ff125d1SJiri Olsa #ifdef HAVE_DWARF_UNWIND_SUPPORT
30*fa7095c5SJames Clark /*
31*fa7095c5SJames Clark * When best_effort is set, don't report errors and fail silently. This could
32*fa7095c5SJames Clark * be expanded in the future to be more permissive about things other than
33*fa7095c5SJames Clark * error messages.
34*fa7095c5SJames Clark */
3571ad0f5eSJiri Olsa int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
3671ad0f5eSJiri Olsa struct thread *thread,
37*fa7095c5SJames Clark struct perf_sample *data, int max_stack,
38*fa7095c5SJames Clark bool best_effort);
399ff125d1SJiri Olsa /* libunwind specific */
409ff125d1SJiri Olsa #ifdef HAVE_LIBUNWIND_SUPPORT
41eeb118c5SHe Kuang #ifndef LIBUNWIND__ARCH_REG_ID
42eeb118c5SHe Kuang #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
43eeb118c5SHe Kuang #endif
4478ff1d6dSHe Kuang
45eeb118c5SHe Kuang int LIBUNWIND__ARCH_REG_ID(int regnum);
4679b6bb73SArnaldo Carvalho de Melo int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized);
4779b6bb73SArnaldo Carvalho de Melo void unwind__flush_access(struct maps *maps);
4879b6bb73SArnaldo Carvalho de Melo void unwind__finish_access(struct maps *maps);
4966f066d8SNamhyung Kim #else
unwind__prepare_access(struct maps * maps __maybe_unused,struct map * map __maybe_unused,bool * initialized __maybe_unused)5079b6bb73SArnaldo Carvalho de Melo static inline int unwind__prepare_access(struct maps *maps __maybe_unused,
51a2873325SJiri Olsa struct map *map __maybe_unused,
52a2873325SJiri Olsa bool *initialized __maybe_unused)
5366f066d8SNamhyung Kim {
5466f066d8SNamhyung Kim return 0;
5566f066d8SNamhyung Kim }
5666f066d8SNamhyung Kim
unwind__flush_access(struct maps * maps __maybe_unused)5779b6bb73SArnaldo Carvalho de Melo static inline void unwind__flush_access(struct maps *maps __maybe_unused) {}
unwind__finish_access(struct maps * maps __maybe_unused)5879b6bb73SArnaldo Carvalho de Melo static inline void unwind__finish_access(struct maps *maps __maybe_unused) {}
599ff125d1SJiri Olsa #endif
6071ad0f5eSJiri Olsa #else
6171ad0f5eSJiri Olsa static inline int
unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,void * arg __maybe_unused,struct thread * thread __maybe_unused,struct perf_sample * data __maybe_unused,int max_stack __maybe_unused,bool best_effort __maybe_unused)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,
66*fa7095c5SJames Clark int max_stack __maybe_unused,
67*fa7095c5SJames Clark bool best_effort __maybe_unused)
6871ad0f5eSJiri Olsa {
6971ad0f5eSJiri Olsa return 0;
7071ad0f5eSJiri Olsa }
7166f066d8SNamhyung Kim
unwind__prepare_access(struct maps * maps __maybe_unused,struct map * map __maybe_unused,bool * initialized __maybe_unused)7279b6bb73SArnaldo Carvalho de Melo static inline int unwind__prepare_access(struct maps *maps __maybe_unused,
73a2873325SJiri Olsa struct map *map __maybe_unused,
74a2873325SJiri Olsa bool *initialized __maybe_unused)
7566f066d8SNamhyung Kim {
7666f066d8SNamhyung Kim return 0;
7766f066d8SNamhyung Kim }
7866f066d8SNamhyung Kim
unwind__flush_access(struct maps * maps __maybe_unused)7979b6bb73SArnaldo Carvalho de Melo static inline void unwind__flush_access(struct maps *maps __maybe_unused) {}
unwind__finish_access(struct maps * maps __maybe_unused)8079b6bb73SArnaldo Carvalho de Melo static inline void unwind__finish_access(struct maps *maps __maybe_unused) {}
819ff125d1SJiri Olsa #endif /* HAVE_DWARF_UNWIND_SUPPORT */
8271ad0f5eSJiri Olsa #endif /* __UNWIND_H */
83