xref: /linux/tools/perf/util/libdw.h (revision c7decec2f2d2ab0366567f9e30c0e1418cece43f)
188c51002SIan Rogers /* SPDX-License-Identifier: GPL-2.0 */
288c51002SIan Rogers #ifndef PERF_LIBDW_H
388c51002SIan Rogers #define PERF_LIBDW_H
488c51002SIan Rogers 
588c51002SIan Rogers #include <linux/types.h>
688c51002SIan Rogers 
788c51002SIan Rogers struct dso;
888c51002SIan Rogers struct inline_node;
988c51002SIan Rogers struct symbol;
1088c51002SIan Rogers 
1188c51002SIan Rogers #ifdef HAVE_LIBDW_SUPPORT
1288c51002SIan Rogers /*
1388c51002SIan Rogers  * libdw__addr2line - Convert address to source location using libdw
1488c51002SIan Rogers  * @addr: Address to resolve
1588c51002SIan Rogers  * @file: Pointer to return filename (caller must free)
1688c51002SIan Rogers  * @line_nr: Pointer to return line number
1788c51002SIan Rogers  * @dso: The dso struct
1888c51002SIan Rogers  * @unwind_inlines: Whether to unwind inline function calls
1988c51002SIan Rogers  * @node: Inline node list to append to
2088c51002SIan Rogers  * @sym: The symbol associated with the address
2188c51002SIan Rogers  *
2288c51002SIan Rogers  * This function initializes a Dwfl context for the DSO if not already present,
2388c51002SIan Rogers  * finds the source line information for the given address, and optionally
2488c51002SIan Rogers  * resolves inline function call chains.
2588c51002SIan Rogers  *
2688c51002SIan Rogers  * Returns 1 on success (found), 0 on failure (not found).
2788c51002SIan Rogers  */
28*b7a2b011SIan Rogers int libdw__addr2line(u64 addr, char **file,
2988c51002SIan Rogers 		     unsigned int *line_nr, struct dso *dso,
3088c51002SIan Rogers 		     bool unwind_inlines, struct inline_node *node,
3188c51002SIan Rogers 		     struct symbol *sym);
3288c51002SIan Rogers 
3388c51002SIan Rogers /*
34*b7a2b011SIan Rogers  * dso__free_libdw - Free libdw resources associated with the DSO
3588c51002SIan Rogers  * @dso: The dso to free resources for
3688c51002SIan Rogers  *
3788c51002SIan Rogers  * This function cleans up the Dwfl context used for addr2line lookups.
3888c51002SIan Rogers  */
39*b7a2b011SIan Rogers void dso__free_libdw(struct dso *dso);
4088c51002SIan Rogers 
4188c51002SIan Rogers #else /* HAVE_LIBDW_SUPPORT */
4288c51002SIan Rogers 
libdw__addr2line(u64 addr __maybe_unused,char ** file __maybe_unused,unsigned int * line_nr __maybe_unused,struct dso * dso __maybe_unused,bool unwind_inlines __maybe_unused,struct inline_node * node __maybe_unused,struct symbol * sym __maybe_unused)43*b7a2b011SIan Rogers static inline int libdw__addr2line(u64 addr __maybe_unused, char **file __maybe_unused,
4488c51002SIan Rogers 				   unsigned int *line_nr __maybe_unused,
4588c51002SIan Rogers 				   struct dso *dso __maybe_unused,
4688c51002SIan Rogers 				   bool unwind_inlines __maybe_unused,
4788c51002SIan Rogers 				   struct inline_node *node __maybe_unused,
4888c51002SIan Rogers 				   struct symbol *sym __maybe_unused)
4988c51002SIan Rogers {
5088c51002SIan Rogers 	return 0;
5188c51002SIan Rogers }
5288c51002SIan Rogers 
dso__free_libdw(struct dso * dso __maybe_unused)53*b7a2b011SIan Rogers static inline void dso__free_libdw(struct dso *dso __maybe_unused)
5488c51002SIan Rogers {
5588c51002SIan Rogers }
5688c51002SIan Rogers #endif /* HAVE_LIBDW_SUPPORT */
5788c51002SIan Rogers 
5888c51002SIan Rogers #endif /* PERF_LIBDW_H */
59