xref: /linux/tools/perf/util/map.h (revision 5499b45190237ca90dd2ac86395cf464fe1f4cc7)
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 
16 extern const char *map_type__name[MAP__NR_TYPES];
17 
18 struct dso;
19 struct ref_reloc_sym;
20 struct map_groups;
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;
31 
32 	/* ip -> dso rip */
33 	u64			(*map_ip)(struct map *, u64);
34 	/* dso rip -> ip */
35 	u64			(*unmap_ip)(struct map *, u64);
36 
37 	struct dso		*dso;
38 };
39 
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 
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 
65 
66 /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
67 u64 map__rip_2objdump(struct map *map, u64 rip);
68 u64 map__objdump_2ip(struct map *map, u64 addr);
69 
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 
84 int map__load(struct map *self, symbol_filter_t filter);
85 struct symbol *map__find_symbol(struct map *self,
86 				u64 addr, symbol_filter_t filter);
87 struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
88 					symbol_filter_t filter);
89 void map__fixup_start(struct map *self);
90 void map__fixup_end(struct map *self);
91 
92 void map__reloc_vmlinux(struct map *self);
93 
94 #endif /* __PERF_MAP_H */
95