blob: b756368076c6ce4478ccb18ccdd61bd45e2fd408 [file] [log] [blame]
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02001#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
9enum map_type {
10 MAP__FUNCTION = 0,
11 MAP__VARIABLE,
12};
13
14#define MAP__NR_TYPES (MAP__VARIABLE + 1)
15
Arnaldo Carvalho de Melo3846df22010-02-22 16:15:39 -030016extern const char *map_type__name[MAP__NR_TYPES];
17
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020018struct dso;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020019struct ref_reloc_sym;
20struct map_groups;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020021
22struct 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 Smelkov7a2b6202010-02-03 16:52:07 -020031
32 /* ip -> dso rip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020033 u64 (*map_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020034 /* dso rip -> ip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020035 u64 (*unmap_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020036
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020037 struct dso *dso;
38};
39
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020040struct kmap {
41 struct ref_reloc_sym *ref_reloc_sym;
42 struct map_groups *kmaps;
43};
44
45static inline struct kmap *map__kmap(struct map *self)
46{
47 return (struct kmap *)(self + 1);
48}
49
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020050static inline u64 map__map_ip(struct map *map, u64 ip)
51{
52 return ip - map->start + map->pgoff;
53}
54
55static inline u64 map__unmap_ip(struct map *map, u64 ip)
56{
57 return ip + map->start - map->pgoff;
58}
59
60static inline u64 identity__map_ip(struct map *map __used, u64 ip)
61{
62 return ip;
63}
64
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020065
Kirill Smelkovee11b902010-02-07 11:46:15 -020066/* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020067u64 map__rip_2objdump(struct map *map, u64 rip);
Kirill Smelkovee11b902010-02-07 11:46:15 -020068u64 map__objdump_2ip(struct map *map, u64 addr);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020069
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020070struct symbol;
71struct mmap_event;
72
73typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
74
75void map__init(struct map *self, enum map_type type,
76 u64 start, u64 end, u64 pgoff, struct dso *dso);
77struct map *map__new(struct mmap_event *event, enum map_type,
78 char *cwd, int cwdlen);
79void map__delete(struct map *self);
80struct map *map__clone(struct map *self);
81int map__overlap(struct map *l, struct map *r);
82size_t map__fprintf(struct map *self, FILE *fp);
83
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020084int map__load(struct map *self, symbol_filter_t filter);
85struct symbol *map__find_symbol(struct map *self,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020086 u64 addr, symbol_filter_t filter);
87struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020088 symbol_filter_t filter);
89void map__fixup_start(struct map *self);
90void map__fixup_end(struct map *self);
91
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020092void map__reloc_vmlinux(struct map *self);
93
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020094#endif /* __PERF_MAP_H */