diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2010-03-25 18:58:58 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-03-26 03:52:58 -0400 |
commit | 4b8cf84624e9a58a21aaac3d064222092ae234e0 (patch) | |
tree | b3730987728f9280612fedbf24db50142e8ed253 /tools/perf/util/map.c | |
parent | b177f63f5226e75280855bbcd106e677250778bd (diff) |
perf symbols: Move map related routines to map.c
Thru series of refactorings functions were being renamed but not
moved to map.c to reduce patch noise, now lets have them in the
same place so that use of the symbol system by tools can be
constrained to building and linking fewer source files:
symbol.c, map.c and rbtree.c.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1269557941-15617-3-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/map.c')
-rw-r--r-- | tools/perf/util/map.c | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index a9b42273675d..9f2963f9ee9a 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
@@ -1,8 +1,9 @@ | |||
1 | #include "symbol.h" | 1 | #include "symbol.h" |
2 | #include <limits.h> | ||
2 | #include <stdlib.h> | 3 | #include <stdlib.h> |
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <stdio.h> | 5 | #include <stdio.h> |
5 | #include "debug.h" | 6 | #include "map.h" |
6 | 7 | ||
7 | const char *map_type__name[MAP__NR_TYPES] = { | 8 | const char *map_type__name[MAP__NR_TYPES] = { |
8 | [MAP__FUNCTION] = "Functions", | 9 | [MAP__FUNCTION] = "Functions", |
@@ -232,3 +233,84 @@ u64 map__objdump_2ip(struct map *map, u64 addr) | |||
232 | map->unmap_ip(map, addr); /* RIP -> IP */ | 233 | map->unmap_ip(map, addr); /* RIP -> IP */ |
233 | return ip; | 234 | return ip; |
234 | } | 235 | } |
236 | |||
237 | struct symbol *map_groups__find_symbol(struct map_groups *self, | ||
238 | enum map_type type, u64 addr, | ||
239 | symbol_filter_t filter) | ||
240 | { | ||
241 | struct map *map = map_groups__find(self, type, addr); | ||
242 | |||
243 | if (map != NULL) | ||
244 | return map__find_symbol(map, map->map_ip(map, addr), filter); | ||
245 | |||
246 | return NULL; | ||
247 | } | ||
248 | |||
249 | static u64 map__reloc_map_ip(struct map *map, u64 ip) | ||
250 | { | ||
251 | return ip + (s64)map->pgoff; | ||
252 | } | ||
253 | |||
254 | static u64 map__reloc_unmap_ip(struct map *map, u64 ip) | ||
255 | { | ||
256 | return ip - (s64)map->pgoff; | ||
257 | } | ||
258 | |||
259 | void map__reloc_vmlinux(struct map *self) | ||
260 | { | ||
261 | struct kmap *kmap = map__kmap(self); | ||
262 | s64 reloc; | ||
263 | |||
264 | if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr) | ||
265 | return; | ||
266 | |||
267 | reloc = (kmap->ref_reloc_sym->unrelocated_addr - | ||
268 | kmap->ref_reloc_sym->addr); | ||
269 | |||
270 | if (!reloc) | ||
271 | return; | ||
272 | |||
273 | self->map_ip = map__reloc_map_ip; | ||
274 | self->unmap_ip = map__reloc_unmap_ip; | ||
275 | self->pgoff = reloc; | ||
276 | } | ||
277 | |||
278 | void maps__insert(struct rb_root *maps, struct map *map) | ||
279 | { | ||
280 | struct rb_node **p = &maps->rb_node; | ||
281 | struct rb_node *parent = NULL; | ||
282 | const u64 ip = map->start; | ||
283 | struct map *m; | ||
284 | |||
285 | while (*p != NULL) { | ||
286 | parent = *p; | ||
287 | m = rb_entry(parent, struct map, rb_node); | ||
288 | if (ip < m->start) | ||
289 | p = &(*p)->rb_left; | ||
290 | else | ||
291 | p = &(*p)->rb_right; | ||
292 | } | ||
293 | |||
294 | rb_link_node(&map->rb_node, parent, p); | ||
295 | rb_insert_color(&map->rb_node, maps); | ||
296 | } | ||
297 | |||
298 | struct map *maps__find(struct rb_root *maps, u64 ip) | ||
299 | { | ||
300 | struct rb_node **p = &maps->rb_node; | ||
301 | struct rb_node *parent = NULL; | ||
302 | struct map *m; | ||
303 | |||
304 | while (*p != NULL) { | ||
305 | parent = *p; | ||
306 | m = rb_entry(parent, struct map, rb_node); | ||
307 | if (ip < m->start) | ||
308 | p = &(*p)->rb_left; | ||
309 | else if (ip > m->end) | ||
310 | p = &(*p)->rb_right; | ||
311 | else | ||
312 | return m; | ||
313 | } | ||
314 | |||
315 | return NULL; | ||
316 | } | ||