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