perf tools: Rename maps__next
[linux-2.6-block.git] / tools / perf / util / map.h
CommitLineData
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
12enum map_type {
13 MAP__FUNCTION = 0,
14 MAP__VARIABLE,
15};
16
17#define MAP__NR_TYPES (MAP__VARIABLE + 1)
18
3846df2e
ACM
19extern const char *map_type__name[MAP__NR_TYPES];
20
4a58e611 21struct dso;
743eb868 22struct ip_callchain;
9de89fe7
ACM
23struct ref_reloc_sym;
24struct map_groups;
23346f21 25struct machine;
743eb868 26struct perf_evsel;
4a58e611
ACM
27
28struct 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
56struct kmap {
57 struct ref_reloc_sym *ref_reloc_sym;
58 struct map_groups *kmaps;
59};
60
a1645ce1 61struct 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 68struct map_groups *map_groups__new(struct machine *machine);
93d5731d 69void map_groups__delete(struct map_groups *mg);
29ce3612 70bool map_groups__empty(struct map_groups *mg);
93d5731d 71
a26ca671
ACM
72static 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
79void map_groups__put(struct map_groups *mg);
80
ba92732e
WN
81struct kmap *map__kmap(struct map *map);
82struct map_groups *map__kmaps(struct map *map);
9de89fe7 83
4a58e611
ACM
84static inline u64 map__map_ip(struct map *map, u64 ip)
85{
86 return ip - map->start + map->pgoff;
87}
88
89static inline u64 map__unmap_ip(struct map *map, u64 ip)
90{
91 return ip + map->start - map->pgoff;
92}
93
1d037ca1 94static 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 101u64 map__rip_2objdump(struct map *map, u64 rip);
7a2b6209 102
1d5077bd
AH
103/* objdump address -> memory address */
104u64 map__objdump_2mem(struct map *map, u64 ip);
105
4a58e611 106struct symbol;
5835edda 107struct 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
135typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
136
031b84c4 137int arch__compare_symbol_names(const char *namea, const char *nameb);
237a7e04 138void map__init(struct map *map, enum map_type type,
4a58e611 139 u64 start, u64 end, u64 pgoff, struct dso *dso);
2a03068c 140struct 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 144struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
237a7e04
ACM
145void map__delete(struct map *map);
146struct map *map__clone(struct map *map);
4a58e611 147int map__overlap(struct map *l, struct map *r);
237a7e04 148size_t map__fprintf(struct map *map, FILE *fp);
547a92e0 149size_t map__fprintf_dsoname(struct map *map, FILE *fp);
cc8fae1d
AH
150int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
151 FILE *fp);
4a58e611 152
237a7e04
ACM
153int map__load(struct map *map, symbol_filter_t filter);
154struct symbol *map__find_symbol(struct map *map,
4a58e611 155 u64 addr, symbol_filter_t filter);
237a7e04 156struct symbol *map__find_symbol_by_name(struct map *map, const char *name,
4a58e611 157 symbol_filter_t filter);
237a7e04
ACM
158void map__fixup_start(struct map *map);
159void map__fixup_end(struct map *map);
4a58e611 160
237a7e04 161void map__reloc_vmlinux(struct map *map);
9de89fe7 162
acebd408
JO
163size_t __map_groups__fprintf_maps(struct map_groups *mg, enum map_type type,
164 FILE *fp);
4b8cf846 165void maps__insert(struct rb_root *maps, struct map *map);
98dfd55d 166void maps__remove(struct rb_root *maps, struct map *map);
4b8cf846 167struct map *maps__find(struct rb_root *maps, u64 addr);
8e0cf965 168struct map *maps__first(struct rb_root *maps);
4d4dee9a 169struct map *map__next(struct map *map);
11246c70 170void map_groups__init(struct map_groups *mg, struct machine *machine);
98dfd55d
ACM
171void map_groups__exit(struct map_groups *mg);
172int map_groups__clone(struct map_groups *mg,
c6e718ff 173 struct map_groups *parent, enum map_type type);
acebd408 174size_t map_groups__fprintf(struct map_groups *mg, FILE *fp);
4b8cf846 175
743eb868
ACM
176int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
177 u64 addr);
178
98dfd55d 179static 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 185static 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 190static 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
196static 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
202static inline struct map *map_groups__next(struct map *map)
203{
4d4dee9a 204 return map__next(map);
8e0cf965
AH
205}
206
98dfd55d 207struct 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 212struct 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
218struct addr_map_symbol;
219
220int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter);
221
7e5e1b14 222static inline
98dfd55d 223struct 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 230int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
acebd408 231 FILE *fp);
c6e718ff 232
98dfd55d 233struct map *map_groups__find_by_name(struct map_groups *mg,
4b8cf846 234 enum map_type type, const char *name);
a1645ce1 235
98dfd55d 236void map_groups__flush(struct map_groups *mg);
4b8cf846 237
4a58e611 238#endif /* __PERF_MAP_H */