blob: 3a7d00c20d86227f18943833408c9957680a9de6 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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
8struct map;
David Brazdil0f672f62019-12-10 10:32:29 +00009struct map_groups;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000010struct perf_sample;
11struct symbol;
12struct thread;
13
14struct unwind_entry {
15 struct map *map;
16 struct symbol *sym;
17 u64 ip;
18};
19
20typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
21
22struct unwind_libunwind_ops {
David Brazdil0f672f62019-12-10 10:32:29 +000023 int (*prepare_access)(struct map_groups *mg);
24 void (*flush_access)(struct map_groups *mg);
25 void (*finish_access)(struct map_groups *mg);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000026 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
32int 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
49int LIBUNWIND__ARCH_REG_ID(int regnum);
David Brazdil0f672f62019-12-10 10:32:29 +000050int unwind__prepare_access(struct map_groups *mg, struct map *map,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000051 bool *initialized);
David Brazdil0f672f62019-12-10 10:32:29 +000052void unwind__flush_access(struct map_groups *mg);
53void unwind__finish_access(struct map_groups *mg);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000054#else
David Brazdil0f672f62019-12-10 10:32:29 +000055static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000056 struct map *map __maybe_unused,
57 bool *initialized __maybe_unused)
58{
59 return 0;
60}
61
David Brazdil0f672f62019-12-10 10:32:29 +000062static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {}
63static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000064#endif
65#else
66static inline int
67unwind__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 Brazdil0f672f62019-12-10 10:32:29 +000076static inline int unwind__prepare_access(struct map_groups *mg __maybe_unused,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000077 struct map *map __maybe_unused,
78 bool *initialized __maybe_unused)
79{
80 return 0;
81}
82
David Brazdil0f672f62019-12-10 10:32:29 +000083static inline void unwind__flush_access(struct map_groups *mg __maybe_unused) {}
84static inline void unwind__finish_access(struct map_groups *mg __maybe_unused) {}
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000085#endif /* HAVE_DWARF_UNWIND_SUPPORT */
86#endif /* __UNWIND_H */