blob: 8a44a1569a21bc2a20eb0c96c70112b3f818ec02 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Olsa71ad0f52012-08-07 15:20:46 +02002#ifndef __UNWIND_H
3#define __UNWIND_H
4
Arnaldo Carvalho de Melo3dfed912017-04-19 13:28:30 -03005#include <linux/compiler.h>
Borislav Petkovd944c4e2014-04-25 21:31:02 +02006#include <linux/types.h>
Arnaldo Carvalho de Melo3dfed912017-04-19 13:28:30 -03007
8struct map;
9struct perf_sample;
10struct symbol;
11struct thread;
Jiri Olsa71ad0f52012-08-07 15:20:46 +020012
13struct unwind_entry {
14 struct map *map;
15 struct symbol *sym;
16 u64 ip;
17};
18
19typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
20
He Kuangf83c0412016-06-03 03:33:12 +000021struct unwind_libunwind_ops {
22 int (*prepare_access)(struct thread *thread);
23 void (*flush_access)(struct thread *thread);
24 void (*finish_access)(struct thread *thread);
25 int (*get_entries)(unwind_entry_cb_t cb, void *arg,
26 struct thread *thread,
27 struct perf_sample *data, int max_stack);
28};
29
Jiri Olsa9ff125d2014-01-07 13:47:28 +010030#ifdef HAVE_DWARF_UNWIND_SUPPORT
Jiri Olsa71ad0f52012-08-07 15:20:46 +020031int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
Jiri Olsa71ad0f52012-08-07 15:20:46 +020032 struct thread *thread,
Arnaldo Carvalho de Melo37676af2013-11-13 17:40:36 -030033 struct perf_sample *data, int max_stack);
Jiri Olsa9ff125d2014-01-07 13:47:28 +010034/* libunwind specific */
35#ifdef HAVE_LIBUNWIND_SUPPORT
He Kuangeeb118c2016-06-03 03:33:20 +000036#ifndef LIBUNWIND__ARCH_REG_ID
37#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
38#endif
He Kuang78ff1d62016-06-22 06:57:02 +000039
40#ifndef LIBUNWIND__ARCH_REG_SP
41#define LIBUNWIND__ARCH_REG_SP PERF_REG_SP
42#endif
43
44#ifndef LIBUNWIND__ARCH_REG_IP
45#define LIBUNWIND__ARCH_REG_IP PERF_REG_IP
46#endif
47
He Kuangeeb118c2016-06-03 03:33:20 +000048int LIBUNWIND__ARCH_REG_ID(int regnum);
Jiri Olsaa2873322016-07-04 14:16:22 +020049int unwind__prepare_access(struct thread *thread, struct map *map,
50 bool *initialized);
Namhyung Kim380b5142014-10-06 09:46:01 +090051void unwind__flush_access(struct thread *thread);
Namhyung Kim66f066d82014-10-06 09:46:00 +090052void unwind__finish_access(struct thread *thread);
53#else
He Kuangd64ec102016-06-03 03:33:19 +000054static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
Jiri Olsaa2873322016-07-04 14:16:22 +020055 struct map *map __maybe_unused,
56 bool *initialized __maybe_unused)
Namhyung Kim66f066d82014-10-06 09:46:00 +090057{
58 return 0;
59}
60
Namhyung Kim380b5142014-10-06 09:46:01 +090061static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
Namhyung Kim66f066d82014-10-06 09:46:00 +090062static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
Jiri Olsa9ff125d2014-01-07 13:47:28 +010063#endif
Jiri Olsa71ad0f52012-08-07 15:20:46 +020064#else
65static inline int
Irina Tirdea1d037ca2012-09-11 01:15:03 +030066unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
67 void *arg __maybe_unused,
Irina Tirdea1d037ca2012-09-11 01:15:03 +030068 struct thread *thread __maybe_unused,
Arnaldo Carvalho de Melo37676af2013-11-13 17:40:36 -030069 struct perf_sample *data __maybe_unused,
70 int max_stack __maybe_unused)
Jiri Olsa71ad0f52012-08-07 15:20:46 +020071{
72 return 0;
73}
Namhyung Kim66f066d82014-10-06 09:46:00 +090074
He Kuangd64ec102016-06-03 03:33:19 +000075static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
Jiri Olsaa2873322016-07-04 14:16:22 +020076 struct map *map __maybe_unused,
77 bool *initialized __maybe_unused)
Namhyung Kim66f066d82014-10-06 09:46:00 +090078{
79 return 0;
80}
81
Namhyung Kim380b5142014-10-06 09:46:01 +090082static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
Namhyung Kim66f066d82014-10-06 09:46:00 +090083static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
Jiri Olsa9ff125d2014-01-07 13:47:28 +010084#endif /* HAVE_DWARF_UNWIND_SUPPORT */
Jiri Olsa71ad0f52012-08-07 15:20:46 +020085#endif /* __UNWIND_H */