Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 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> |
| 7 | #include <linux/types.h> |
| 8 | |
| 9 | enum map_type { |
| 10 | MAP__FUNCTION = 0, |
| 11 | MAP__VARIABLE, |
| 12 | }; |
| 13 | |
| 14 | #define MAP__NR_TYPES (MAP__VARIABLE + 1) |
| 15 | |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame^] | 16 | extern const char *map_type__name[MAP__NR_TYPES]; |
| 17 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 18 | struct dso; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 19 | struct ref_reloc_sym; |
| 20 | struct map_groups; |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 21 | |
| 22 | struct map { |
| 23 | union { |
| 24 | struct rb_node rb_node; |
| 25 | struct list_head node; |
| 26 | }; |
| 27 | u64 start; |
| 28 | u64 end; |
| 29 | enum map_type type; |
| 30 | u64 pgoff; |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 31 | |
| 32 | /* ip -> dso rip */ |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 33 | u64 (*map_ip)(struct map *, u64); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 34 | /* dso rip -> ip */ |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 35 | u64 (*unmap_ip)(struct map *, u64); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 36 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 37 | struct dso *dso; |
| 38 | }; |
| 39 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 40 | struct kmap { |
| 41 | struct ref_reloc_sym *ref_reloc_sym; |
| 42 | struct map_groups *kmaps; |
| 43 | }; |
| 44 | |
| 45 | static inline struct kmap *map__kmap(struct map *self) |
| 46 | { |
| 47 | return (struct kmap *)(self + 1); |
| 48 | } |
| 49 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 50 | static inline u64 map__map_ip(struct map *map, u64 ip) |
| 51 | { |
| 52 | return ip - map->start + map->pgoff; |
| 53 | } |
| 54 | |
| 55 | static inline u64 map__unmap_ip(struct map *map, u64 ip) |
| 56 | { |
| 57 | return ip + map->start - map->pgoff; |
| 58 | } |
| 59 | |
| 60 | static inline u64 identity__map_ip(struct map *map __used, u64 ip) |
| 61 | { |
| 62 | return ip; |
| 63 | } |
| 64 | |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 65 | |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 66 | /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */ |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 67 | u64 map__rip_2objdump(struct map *map, u64 rip); |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 68 | u64 map__objdump_2ip(struct map *map, u64 addr); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 69 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 70 | struct symbol; |
| 71 | struct mmap_event; |
| 72 | |
| 73 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
| 74 | |
| 75 | void map__init(struct map *self, enum map_type type, |
| 76 | u64 start, u64 end, u64 pgoff, struct dso *dso); |
| 77 | struct map *map__new(struct mmap_event *event, enum map_type, |
| 78 | char *cwd, int cwdlen); |
| 79 | void map__delete(struct map *self); |
| 80 | struct map *map__clone(struct map *self); |
| 81 | int map__overlap(struct map *l, struct map *r); |
| 82 | size_t map__fprintf(struct map *self, FILE *fp); |
| 83 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 84 | int map__load(struct map *self, symbol_filter_t filter); |
| 85 | struct symbol *map__find_symbol(struct map *self, |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 86 | u64 addr, symbol_filter_t filter); |
| 87 | struct symbol *map__find_symbol_by_name(struct map *self, const char *name, |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 88 | symbol_filter_t filter); |
| 89 | void map__fixup_start(struct map *self); |
| 90 | void map__fixup_end(struct map *self); |
| 91 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 92 | void map__reloc_vmlinux(struct map *self); |
| 93 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 94 | #endif /* __PERF_MAP_H */ |