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> |
Arnaldo Carvalho de Melo | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame^] | 7 | #include <stdio.h> |
| 8 | #include "types.h" |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 9 | |
| 10 | enum map_type { |
| 11 | MAP__FUNCTION = 0, |
| 12 | MAP__VARIABLE, |
| 13 | }; |
| 14 | |
| 15 | #define MAP__NR_TYPES (MAP__VARIABLE + 1) |
| 16 | |
Arnaldo Carvalho de Melo | 3846df2 | 2010-02-22 16:15:39 -0300 | [diff] [blame] | 17 | extern const char *map_type__name[MAP__NR_TYPES]; |
| 18 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 19 | struct dso; |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 20 | struct ref_reloc_sym; |
| 21 | struct map_groups; |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 22 | |
| 23 | struct map { |
| 24 | union { |
| 25 | struct rb_node rb_node; |
| 26 | struct list_head node; |
| 27 | }; |
| 28 | u64 start; |
| 29 | u64 end; |
| 30 | enum map_type type; |
| 31 | u64 pgoff; |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 32 | |
| 33 | /* ip -> dso rip */ |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 34 | u64 (*map_ip)(struct map *, u64); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 35 | /* dso rip -> ip */ |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 36 | u64 (*unmap_ip)(struct map *, u64); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 37 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 38 | struct dso *dso; |
| 39 | }; |
| 40 | |
Arnaldo Carvalho de Melo | 9de89fe | 2010-02-03 16:52:00 -0200 | [diff] [blame] | 41 | struct kmap { |
| 42 | struct ref_reloc_sym *ref_reloc_sym; |
| 43 | struct map_groups *kmaps; |
| 44 | }; |
| 45 | |
| 46 | static inline struct kmap *map__kmap(struct map *self) |
| 47 | { |
| 48 | return (struct kmap *)(self + 1); |
| 49 | } |
| 50 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 51 | static inline u64 map__map_ip(struct map *map, u64 ip) |
| 52 | { |
| 53 | return ip - map->start + map->pgoff; |
| 54 | } |
| 55 | |
| 56 | static inline u64 map__unmap_ip(struct map *map, u64 ip) |
| 57 | { |
| 58 | return ip + map->start - map->pgoff; |
| 59 | } |
| 60 | |
| 61 | static inline u64 identity__map_ip(struct map *map __used, u64 ip) |
| 62 | { |
| 63 | return ip; |
| 64 | } |
| 65 | |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 66 | |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 67 | /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */ |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 68 | u64 map__rip_2objdump(struct map *map, u64 rip); |
Kirill Smelkov | ee11b90 | 2010-02-07 11:46:15 -0200 | [diff] [blame] | 69 | u64 map__objdump_2ip(struct map *map, u64 addr); |
Kirill Smelkov | 7a2b620 | 2010-02-03 16:52:07 -0200 | [diff] [blame] | 70 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 71 | struct symbol; |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 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); |
Arnaldo Carvalho de Melo | b177f63 | 2010-03-25 19:58:57 -0300 | [diff] [blame] | 77 | struct map *map__new(u64 start, u64 len, u64 pgoff, u32 pid, char *filename, |
| 78 | enum map_type type, char *cwd, int cwdlen); |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 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 | 4b8cf84 | 2010-03-25 19:58:58 -0300 | [diff] [blame^] | 94 | struct map_groups { |
| 95 | struct rb_root maps[MAP__NR_TYPES]; |
| 96 | struct list_head removed_maps[MAP__NR_TYPES]; |
| 97 | }; |
| 98 | |
| 99 | size_t __map_groups__fprintf_maps(struct map_groups *self, |
| 100 | enum map_type type, FILE *fp); |
| 101 | void maps__insert(struct rb_root *maps, struct map *map); |
| 102 | struct map *maps__find(struct rb_root *maps, u64 addr); |
| 103 | void map_groups__init(struct map_groups *self); |
| 104 | size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp); |
| 105 | |
| 106 | static inline void map_groups__insert(struct map_groups *self, struct map *map) |
| 107 | { |
| 108 | maps__insert(&self->maps[map->type], map); |
| 109 | } |
| 110 | |
| 111 | static inline struct map *map_groups__find(struct map_groups *self, |
| 112 | enum map_type type, u64 addr) |
| 113 | { |
| 114 | return maps__find(&self->maps[type], addr); |
| 115 | } |
| 116 | |
| 117 | struct symbol *map_groups__find_symbol(struct map_groups *self, |
| 118 | enum map_type type, u64 addr, |
| 119 | symbol_filter_t filter); |
| 120 | |
| 121 | static inline struct symbol *map_groups__find_function(struct map_groups *self, |
| 122 | u64 addr, |
| 123 | symbol_filter_t filter) |
| 124 | { |
| 125 | return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter); |
| 126 | } |
| 127 | |
| 128 | struct map *map_groups__find_by_name(struct map_groups *self, |
| 129 | enum map_type type, const char *name); |
| 130 | int __map_groups__create_kernel_maps(struct map_groups *self, |
| 131 | struct map *vmlinux_maps[MAP__NR_TYPES], |
| 132 | struct dso *kernel); |
| 133 | int map_groups__create_kernel_maps(struct map_groups *self, |
| 134 | struct map *vmlinux_maps[MAP__NR_TYPES]); |
| 135 | struct map *map_groups__new_module(struct map_groups *self, u64 start, |
| 136 | const char *filename); |
| 137 | |
Arnaldo Carvalho de Melo | 4a58e61 | 2009-12-27 21:37:00 -0200 | [diff] [blame] | 138 | #endif /* __PERF_MAP_H */ |