xref: /kernel/linux/linux-6.6/tools/perf/util/unwind.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __UNWIND_H
362306a36Sopenharmony_ci#define __UNWIND_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/compiler.h>
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci#include "util/map_symbol.h"
862306a36Sopenharmony_ci
962306a36Sopenharmony_cistruct maps;
1062306a36Sopenharmony_cistruct perf_sample;
1162306a36Sopenharmony_cistruct thread;
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistruct unwind_entry {
1462306a36Sopenharmony_ci	struct map_symbol ms;
1562306a36Sopenharmony_ci	u64		  ip;
1662306a36Sopenharmony_ci};
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_citypedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct unwind_libunwind_ops {
2162306a36Sopenharmony_ci	int (*prepare_access)(struct maps *maps);
2262306a36Sopenharmony_ci	void (*flush_access)(struct maps *maps);
2362306a36Sopenharmony_ci	void (*finish_access)(struct maps *maps);
2462306a36Sopenharmony_ci	int (*get_entries)(unwind_entry_cb_t cb, void *arg,
2562306a36Sopenharmony_ci			   struct thread *thread,
2662306a36Sopenharmony_ci			   struct perf_sample *data, int max_stack, bool best_effort);
2762306a36Sopenharmony_ci};
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci#ifdef HAVE_DWARF_UNWIND_SUPPORT
3062306a36Sopenharmony_ci/*
3162306a36Sopenharmony_ci * When best_effort is set, don't report errors and fail silently. This could
3262306a36Sopenharmony_ci * be expanded in the future to be more permissive about things other than
3362306a36Sopenharmony_ci * error messages.
3462306a36Sopenharmony_ci */
3562306a36Sopenharmony_ciint unwind__get_entries(unwind_entry_cb_t cb, void *arg,
3662306a36Sopenharmony_ci			struct thread *thread,
3762306a36Sopenharmony_ci			struct perf_sample *data, int max_stack,
3862306a36Sopenharmony_ci			bool best_effort);
3962306a36Sopenharmony_ci/* libunwind specific */
4062306a36Sopenharmony_ci#ifdef HAVE_LIBUNWIND_SUPPORT
4162306a36Sopenharmony_ci#ifndef LIBUNWIND__ARCH_REG_ID
4262306a36Sopenharmony_ci#define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
4362306a36Sopenharmony_ci#endif
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ciint LIBUNWIND__ARCH_REG_ID(int regnum);
4662306a36Sopenharmony_ciint unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized);
4762306a36Sopenharmony_civoid unwind__flush_access(struct maps *maps);
4862306a36Sopenharmony_civoid unwind__finish_access(struct maps *maps);
4962306a36Sopenharmony_ci#else
5062306a36Sopenharmony_cistatic inline int unwind__prepare_access(struct maps *maps __maybe_unused,
5162306a36Sopenharmony_ci					 struct map *map __maybe_unused,
5262306a36Sopenharmony_ci					 bool *initialized __maybe_unused)
5362306a36Sopenharmony_ci{
5462306a36Sopenharmony_ci	return 0;
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_cistatic inline void unwind__flush_access(struct maps *maps __maybe_unused) {}
5862306a36Sopenharmony_cistatic inline void unwind__finish_access(struct maps *maps __maybe_unused) {}
5962306a36Sopenharmony_ci#endif
6062306a36Sopenharmony_ci#else
6162306a36Sopenharmony_cistatic inline int
6262306a36Sopenharmony_ciunwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
6362306a36Sopenharmony_ci		    void *arg __maybe_unused,
6462306a36Sopenharmony_ci		    struct thread *thread __maybe_unused,
6562306a36Sopenharmony_ci		    struct perf_sample *data __maybe_unused,
6662306a36Sopenharmony_ci		    int max_stack __maybe_unused,
6762306a36Sopenharmony_ci		    bool best_effort __maybe_unused)
6862306a36Sopenharmony_ci{
6962306a36Sopenharmony_ci	return 0;
7062306a36Sopenharmony_ci}
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_cistatic inline int unwind__prepare_access(struct maps *maps __maybe_unused,
7362306a36Sopenharmony_ci					 struct map *map __maybe_unused,
7462306a36Sopenharmony_ci					 bool *initialized __maybe_unused)
7562306a36Sopenharmony_ci{
7662306a36Sopenharmony_ci	return 0;
7762306a36Sopenharmony_ci}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistatic inline void unwind__flush_access(struct maps *maps __maybe_unused) {}
8062306a36Sopenharmony_cistatic inline void unwind__finish_access(struct maps *maps __maybe_unused) {}
8162306a36Sopenharmony_ci#endif /* HAVE_DWARF_UNWIND_SUPPORT */
8262306a36Sopenharmony_ci#endif /* __UNWIND_H */
83