Commit | Line | Data |
---|---|---|
4a58e611 ACM |
1 | #ifndef __PERF_MAP_H |
2 | #define __PERF_MAP_H | |
3 | ||
848cbd25 | 4 | #include <linux/atomic.h> |
4a58e611 ACM |
5 | #include <linux/compiler.h> |
6 | #include <linux/list.h> | |
7 | #include <linux/rbtree.h> | |
4b8cf846 | 8 | #include <stdio.h> |
23346f21 | 9 | #include <stdbool.h> |
d944c4ee | 10 | #include <linux/types.h> |
4a58e611 ACM |
11 | |
12 | enum map_type { | |
13 | MAP__FUNCTION = 0, | |
14 | MAP__VARIABLE, | |
15 | }; | |
16 | ||
17 | #define MAP__NR_TYPES (MAP__VARIABLE + 1) | |
18 | ||
3846df2e ACM |
19 | extern const char *map_type__name[MAP__NR_TYPES]; |
20 | ||
4a58e611 | 21 | struct dso; |
743eb868 | 22 | struct ip_callchain; |
9de89fe7 ACM |
23 | struct ref_reloc_sym; |
24 | struct map_groups; | |
23346f21 | 25 | struct machine; |
743eb868 | 26 | struct perf_evsel; |
4a58e611 ACM |
27 | |
28 | struct map { | |
29 | union { | |
30 | struct rb_node rb_node; | |
31 | struct list_head node; | |
32 | }; | |
33 | u64 start; | |
34 | u64 end; | |
0a1eae39 ACM |
35 | u8 /* enum map_type */ type; |
36 | bool referenced; | |
31d68e7b | 37 | bool erange_warned; |
5c0541d5 | 38 | u32 priv; |
7ef80703 DZ |
39 | u32 prot; |
40 | u32 flags; | |
4a58e611 | 41 | u64 pgoff; |
9176753d | 42 | u64 reloc; |
5c5e854b SE |
43 | u32 maj, min; /* only valid for MMAP2 record */ |
44 | u64 ino; /* only valid for MMAP2 record */ | |
45 | u64 ino_generation;/* only valid for MMAP2 record */ | |
7a2b6209 KS |
46 | |
47 | /* ip -> dso rip */ | |
4a58e611 | 48 | u64 (*map_ip)(struct map *, u64); |
7a2b6209 | 49 | /* dso rip -> ip */ |
4a58e611 | 50 | u64 (*unmap_ip)(struct map *, u64); |
7a2b6209 | 51 | |
4a58e611 | 52 | struct dso *dso; |
a1645ce1 | 53 | struct map_groups *groups; |
4a58e611 ACM |
54 | }; |
55 | ||
9de89fe7 ACM |
56 | struct kmap { |
57 | struct ref_reloc_sym *ref_reloc_sym; | |
58 | struct map_groups *kmaps; | |
59 | }; | |
60 | ||
a1645ce1 | 61 | struct map_groups { |
23346f21 ACM |
62 | struct rb_root maps[MAP__NR_TYPES]; |
63 | struct list_head removed_maps[MAP__NR_TYPES]; | |
64 | struct machine *machine; | |
848cbd25 | 65 | atomic_t refcnt; |
a1645ce1 ZY |
66 | }; |
67 | ||
11246c70 | 68 | struct map_groups *map_groups__new(struct machine *machine); |
93d5731d | 69 | void map_groups__delete(struct map_groups *mg); |
29ce3612 | 70 | bool map_groups__empty(struct map_groups *mg); |
93d5731d | 71 | |
a26ca671 ACM |
72 | static inline struct map_groups *map_groups__get(struct map_groups *mg) |
73 | { | |
848cbd25 ACM |
74 | if (mg) |
75 | atomic_inc(&mg->refcnt); | |
a26ca671 ACM |
76 | return mg; |
77 | } | |
78 | ||
79 | void map_groups__put(struct map_groups *mg); | |
80 | ||
ba92732e WN |
81 | struct kmap *map__kmap(struct map *map); |
82 | struct map_groups *map__kmaps(struct map *map); | |
9de89fe7 | 83 | |
4a58e611 ACM |
84 | static inline u64 map__map_ip(struct map *map, u64 ip) |
85 | { | |
86 | return ip - map->start + map->pgoff; | |
87 | } | |
88 | ||
89 | static inline u64 map__unmap_ip(struct map *map, u64 ip) | |
90 | { | |
91 | return ip + map->start - map->pgoff; | |
92 | } | |
93 | ||
1d037ca1 | 94 | static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip) |
4a58e611 ACM |
95 | { |
96 | return ip; | |
97 | } | |
98 | ||
7a2b6209 | 99 | |
ee11b90b | 100 | /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */ |
7a2b6209 | 101 | u64 map__rip_2objdump(struct map *map, u64 rip); |
7a2b6209 | 102 | |
1d5077bd AH |
103 | /* objdump address -> memory address */ |
104 | u64 map__objdump_2mem(struct map *map, u64 ip); | |
105 | ||
4a58e611 | 106 | struct symbol; |
5835edda | 107 | struct thread; |
4a58e611 | 108 | |
eb948e50 MH |
109 | /* map__for_each_symbol - iterate over the symbols in the given map |
110 | * | |
111 | * @map: the 'struct map *' in which symbols itereated | |
112 | * @pos: the 'struct symbol *' to use as a loop cursor | |
113 | * @n: the 'struct rb_node *' to use as a temporary storage | |
114 | * Note: caller must ensure map->dso is not NULL (map is loaded). | |
115 | */ | |
116 | #define map__for_each_symbol(map, pos, n) \ | |
117 | dso__for_each_symbol(map->dso, pos, n, map->type) | |
118 | ||
0a3873a8 ACM |
119 | /* map__for_each_symbol_with_name - iterate over the symbols in the given map |
120 | * that have the given name | |
121 | * | |
122 | * @map: the 'struct map *' in which symbols itereated | |
123 | * @sym_name: the symbol name | |
124 | * @pos: the 'struct symbol *' to use as a loop cursor | |
125 | * @filter: to use when loading the DSO | |
126 | */ | |
127 | #define __map__for_each_symbol_by_name(map, sym_name, pos, filter) \ | |
128 | for (pos = map__find_symbol_by_name(map, sym_name, filter); \ | |
031b84c4 | 129 | pos && arch__compare_symbol_names(pos->name, sym_name) == 0; \ |
0a3873a8 ACM |
130 | pos = symbol__next_by_name(pos)) |
131 | ||
132 | #define map__for_each_symbol_by_name(map, sym_name, pos) \ | |
133 | __map__for_each_symbol_by_name(map, sym_name, (pos), NULL) | |
134 | ||
4a58e611 ACM |
135 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
136 | ||
031b84c4 | 137 | int arch__compare_symbol_names(const char *namea, const char *nameb); |
237a7e04 | 138 | void map__init(struct map *map, enum map_type type, |
4a58e611 | 139 | u64 start, u64 end, u64 pgoff, struct dso *dso); |
2a03068c | 140 | struct map *map__new(struct machine *machine, u64 start, u64 len, |
5c5e854b | 141 | u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino, |
7ef80703 | 142 | u64 ino_gen, u32 prot, u32 flags, |
5835edda | 143 | char *filename, enum map_type type, struct thread *thread); |
e5a1845f | 144 | struct map *map__new2(u64 start, struct dso *dso, enum map_type type); |
237a7e04 ACM |
145 | void map__delete(struct map *map); |
146 | struct map *map__clone(struct map *map); | |
4a58e611 | 147 | int map__overlap(struct map *l, struct map *r); |
237a7e04 | 148 | size_t map__fprintf(struct map *map, FILE *fp); |
547a92e0 | 149 | size_t map__fprintf_dsoname(struct map *map, FILE *fp); |
cc8fae1d AH |
150 | int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, |
151 | FILE *fp); | |
4a58e611 | 152 | |
237a7e04 ACM |
153 | int map__load(struct map *map, symbol_filter_t filter); |
154 | struct symbol *map__find_symbol(struct map *map, | |
4a58e611 | 155 | u64 addr, symbol_filter_t filter); |
237a7e04 | 156 | struct symbol *map__find_symbol_by_name(struct map *map, const char *name, |
4a58e611 | 157 | symbol_filter_t filter); |
237a7e04 ACM |
158 | void map__fixup_start(struct map *map); |
159 | void map__fixup_end(struct map *map); | |
4a58e611 | 160 | |
237a7e04 | 161 | void map__reloc_vmlinux(struct map *map); |
9de89fe7 | 162 | |
acebd408 JO |
163 | size_t __map_groups__fprintf_maps(struct map_groups *mg, enum map_type type, |
164 | FILE *fp); | |
4b8cf846 | 165 | void maps__insert(struct rb_root *maps, struct map *map); |
98dfd55d | 166 | void maps__remove(struct rb_root *maps, struct map *map); |
4b8cf846 | 167 | struct map *maps__find(struct rb_root *maps, u64 addr); |
8e0cf965 | 168 | struct map *maps__first(struct rb_root *maps); |
4d4dee9a | 169 | struct map *map__next(struct map *map); |
11246c70 | 170 | void map_groups__init(struct map_groups *mg, struct machine *machine); |
98dfd55d ACM |
171 | void map_groups__exit(struct map_groups *mg); |
172 | int map_groups__clone(struct map_groups *mg, | |
c6e718ff | 173 | struct map_groups *parent, enum map_type type); |
acebd408 | 174 | size_t map_groups__fprintf(struct map_groups *mg, FILE *fp); |
4b8cf846 | 175 | |
743eb868 ACM |
176 | int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name, |
177 | u64 addr); | |
178 | ||
98dfd55d | 179 | static inline void map_groups__insert(struct map_groups *mg, struct map *map) |
4b8cf846 | 180 | { |
98dfd55d ACM |
181 | maps__insert(&mg->maps[map->type], map); |
182 | map->groups = mg; | |
4b8cf846 ACM |
183 | } |
184 | ||
98dfd55d | 185 | static inline void map_groups__remove(struct map_groups *mg, struct map *map) |
076c6e45 | 186 | { |
98dfd55d | 187 | maps__remove(&mg->maps[map->type], map); |
076c6e45 ACM |
188 | } |
189 | ||
98dfd55d | 190 | static inline struct map *map_groups__find(struct map_groups *mg, |
4b8cf846 ACM |
191 | enum map_type type, u64 addr) |
192 | { | |
98dfd55d | 193 | return maps__find(&mg->maps[type], addr); |
4b8cf846 ACM |
194 | } |
195 | ||
8e0cf965 AH |
196 | static inline struct map *map_groups__first(struct map_groups *mg, |
197 | enum map_type type) | |
198 | { | |
199 | return maps__first(&mg->maps[type]); | |
200 | } | |
201 | ||
202 | static inline struct map *map_groups__next(struct map *map) | |
203 | { | |
4d4dee9a | 204 | return map__next(map); |
8e0cf965 AH |
205 | } |
206 | ||
98dfd55d | 207 | struct symbol *map_groups__find_symbol(struct map_groups *mg, |
4b8cf846 | 208 | enum map_type type, u64 addr, |
7e5e1b14 | 209 | struct map **mapp, |
4b8cf846 ACM |
210 | symbol_filter_t filter); |
211 | ||
98dfd55d | 212 | struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg, |
7e5e1b14 ACM |
213 | enum map_type type, |
214 | const char *name, | |
215 | struct map **mapp, | |
216 | symbol_filter_t filter); | |
217 | ||
4e987712 ACM |
218 | struct addr_map_symbol; |
219 | ||
220 | int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter); | |
221 | ||
7e5e1b14 | 222 | static inline |
98dfd55d | 223 | struct symbol *map_groups__find_function_by_name(struct map_groups *mg, |
7e5e1b14 ACM |
224 | const char *name, struct map **mapp, |
225 | symbol_filter_t filter) | |
4b8cf846 | 226 | { |
98dfd55d | 227 | return map_groups__find_symbol_by_name(mg, MAP__FUNCTION, name, mapp, filter); |
4b8cf846 ACM |
228 | } |
229 | ||
98dfd55d | 230 | int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map, |
acebd408 | 231 | FILE *fp); |
c6e718ff | 232 | |
98dfd55d | 233 | struct map *map_groups__find_by_name(struct map_groups *mg, |
4b8cf846 | 234 | enum map_type type, const char *name); |
a1645ce1 | 235 | |
98dfd55d | 236 | void map_groups__flush(struct map_groups *mg); |
4b8cf846 | 237 | |
4a58e611 | 238 | #endif /* __PERF_MAP_H */ |