treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
[linux-block.git] / tools / perf / util / dwarf-aux.h
CommitLineData
1a59d1b8 1/* SPDX-License-Identifier: GPL-2.0-or-later */
e0d153c6
MH
2#ifndef _DWARF_AUX_H
3#define _DWARF_AUX_H
4/*
5 * dwarf-aux.h : libdw auxiliary interfaces
e0d153c6
MH
6 */
7
8#include <dwarf.h>
9#include <elfutils/libdw.h>
10#include <elfutils/libdwfl.h>
11#include <elfutils/version.h>
12
13/* Find the realpath of the target file */
3938bad4 14const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname);
e0d153c6
MH
15
16/* Get DW_AT_comp_dir (should be NULL with older gcc) */
3938bad4 17const char *cu_get_comp_dir(Dwarf_Die *cu_die);
e0d153c6
MH
18
19/* Get a line number and file name for given address */
3938bad4
ACM
20int cu_find_lineinfo(Dwarf_Die *cudie, unsigned long addr,
21 const char **fname, int *lineno);
e0d153c6 22
221d0611 23/* Walk on funcitons at given address */
3938bad4
ACM
24int cu_walk_functions_at(Dwarf_Die *cu_die, Dwarf_Addr addr,
25 int (*callback)(Dwarf_Die *, void *), void *data);
221d0611 26
d5a00296
MH
27/* Get DW_AT_linkage_name (should be NULL for C binary) */
28const char *die_get_linkage_name(Dwarf_Die *dw_die);
29
0dbb1cac 30/* Ensure that this DIE is a subprogram and definition (not declaration) */
3938bad4 31bool die_is_func_def(Dwarf_Die *dw_die);
0dbb1cac 32
e1ecbbc3 33/* Ensure that this DIE is an instance of a subprogram */
3938bad4 34bool die_is_func_instance(Dwarf_Die *dw_die);
e1ecbbc3 35
e0d153c6 36/* Compare diename and tname */
3938bad4 37bool die_compare_name(Dwarf_Die *dw_die, const char *tname);
e0d153c6 38
4c859351 39/* Matching diename with glob pattern */
3938bad4 40bool die_match_name(Dwarf_Die *dw_die, const char *glob);
4c859351 41
e0d153c6 42/* Get callsite line number of inline-function instance */
3938bad4 43int die_get_call_lineno(Dwarf_Die *in_die);
e0d153c6 44
b0e9cb28 45/* Get callsite file name of inlined function instance */
3938bad4 46const char *die_get_call_file(Dwarf_Die *in_die);
b0e9cb28 47
e0d153c6 48/* Get type die */
3938bad4 49Dwarf_Die *die_get_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem);
e0d153c6
MH
50
51/* Get a type die, but skip qualifiers and typedef */
3938bad4 52Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem);
e0d153c6
MH
53
54/* Check whether the DIE is signed or not */
3938bad4 55bool die_is_signed_type(Dwarf_Die *tp_die);
e0d153c6
MH
56
57/* Get data_member_location offset */
3938bad4 58int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs);
e0d153c6
MH
59
60/* Return values for die_find_child() callbacks */
61enum {
62 DIE_FIND_CB_END = 0, /* End of Search */
63 DIE_FIND_CB_CHILD = 1, /* Search only children */
64 DIE_FIND_CB_SIBLING = 2, /* Search only siblings */
65 DIE_FIND_CB_CONTINUE = 3, /* Search children and siblings */
66};
67
68/* Search child DIEs */
3938bad4
ACM
69Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
70 int (*callback)(Dwarf_Die *, void *),
71 void *data, Dwarf_Die *die_mem);
e0d153c6
MH
72
73/* Search a non-inlined function including given address */
3938bad4
ACM
74Dwarf_Die *die_find_realfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
75 Dwarf_Die *die_mem);
e0d153c6 76
d4c537e6
NR
77/* Search a non-inlined function with tail call at given address */
78Dwarf_Die *die_find_tailfunc(Dwarf_Die *cu_die, Dwarf_Addr addr,
79 Dwarf_Die *die_mem);
80
e08cfd4b 81/* Search the top inlined function including given address */
3938bad4
ACM
82Dwarf_Die *die_find_top_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
83 Dwarf_Die *die_mem);
e08cfd4b
MH
84
85/* Search the deepest inlined function including given address */
3938bad4
ACM
86Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
87 Dwarf_Die *die_mem);
e0d153c6 88
db0d2c64 89/* Walk on the instances of given DIE */
3938bad4
ACM
90int die_walk_instances(Dwarf_Die *in_die,
91 int (*callback)(Dwarf_Die *, void *), void *data);
db0d2c64 92
e0d153c6
MH
93/* Walker on lines (Note: line number will not be sorted) */
94typedef int (* line_walk_callback_t) (const char *fname, int lineno,
95 Dwarf_Addr addr, void *data);
96
97/*
98 * Walk on lines inside given DIE. If the DIE is a subprogram, walk only on
99 * the lines inside the subprogram, otherwise the DIE must be a CU DIE.
100 */
3938bad4 101int die_walk_lines(Dwarf_Die *rt_die, line_walk_callback_t callback, void *data);
e0d153c6
MH
102
103/* Find a variable called 'name' at given address */
3938bad4
ACM
104Dwarf_Die *die_find_variable_at(Dwarf_Die *sp_die, const char *name,
105 Dwarf_Addr addr, Dwarf_Die *die_mem);
e0d153c6
MH
106
107/* Find a member called 'name' */
3938bad4
ACM
108Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
109 Dwarf_Die *die_mem);
e0d153c6
MH
110
111/* Get the name of given variable DIE */
3938bad4 112int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf);
e0d153c6
MH
113
114/* Get the name and type of given variable DIE, stored as "type\tname" */
3938bad4
ACM
115int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf);
116int die_get_var_range(Dwarf_Die *sp_die, Dwarf_Die *vr_die, struct strbuf *buf);
6243b9dc
RB
117
118/* Check if target program is compiled with optimization */
119bool die_is_optimized_target(Dwarf_Die *cu_die);
120
121/* Use next address after prologue as probe location */
122void die_skip_prologue(Dwarf_Die *sp_die, Dwarf_Die *cu_die,
123 Dwarf_Addr *entrypc);
124
e0d153c6 125#endif