blob: 2031278cc06aeebd83faae683a0c5232b8b8ebce [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>
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -03007#include <stdio.h>
8#include "types.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -02009
10enum map_type {
11 MAP__FUNCTION = 0,
12 MAP__VARIABLE,
13};
14
15#define MAP__NR_TYPES (MAP__VARIABLE + 1)
16
Arnaldo Carvalho de Melo3846df22010-02-22 16:15:39 -030017extern const char *map_type__name[MAP__NR_TYPES];
18
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020019struct dso;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020020struct ref_reloc_sym;
21struct map_groups;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020022
23struct 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 Smelkov7a2b6202010-02-03 16:52:07 -020032
33 /* ip -> dso rip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020034 u64 (*map_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020035 /* dso rip -> ip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020036 u64 (*unmap_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020037
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020038 struct dso *dso;
39};
40
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020041struct kmap {
42 struct ref_reloc_sym *ref_reloc_sym;
43 struct map_groups *kmaps;
44};
45
46static inline struct kmap *map__kmap(struct map *self)
47{
48 return (struct kmap *)(self + 1);
49}
50
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020051static inline u64 map__map_ip(struct map *map, u64 ip)
52{
53 return ip - map->start + map->pgoff;
54}
55
56static inline u64 map__unmap_ip(struct map *map, u64 ip)
57{
58 return ip + map->start - map->pgoff;
59}
60
61static inline u64 identity__map_ip(struct map *map __used, u64 ip)
62{
63 return ip;
64}
65
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020066
Kirill Smelkovee11b902010-02-07 11:46:15 -020067/* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020068u64 map__rip_2objdump(struct map *map, u64 rip);
Kirill Smelkovee11b902010-02-07 11:46:15 -020069u64 map__objdump_2ip(struct map *map, u64 addr);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020070
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020071struct symbol;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020072
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);
Arnaldo Carvalho de Melob177f632010-03-25 19:58:57 -030077struct 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 Melo4a58e612009-12-27 21:37:00 -020079void 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 Melo4b8cf842010-03-25 19:58:58 -030094struct map_groups {
95 struct rb_root maps[MAP__NR_TYPES];
96 struct list_head removed_maps[MAP__NR_TYPES];
97};
98
99size_t __map_groups__fprintf_maps(struct map_groups *self,
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300100 enum map_type type, int verbose, FILE *fp);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300101void maps__insert(struct rb_root *maps, struct map *map);
102struct map *maps__find(struct rb_root *maps, u64 addr);
103void map_groups__init(struct map_groups *self);
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300104int map_groups__clone(struct map_groups *self,
105 struct map_groups *parent, enum map_type type);
106size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp);
107size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300108
109static inline void map_groups__insert(struct map_groups *self, struct map *map)
110{
111 maps__insert(&self->maps[map->type], map);
112}
113
114static inline struct map *map_groups__find(struct map_groups *self,
115 enum map_type type, u64 addr)
116{
117 return maps__find(&self->maps[type], addr);
118}
119
120struct symbol *map_groups__find_symbol(struct map_groups *self,
121 enum map_type type, u64 addr,
Arnaldo Carvalho de Melo7e5e1b12010-03-26 12:30:40 -0300122 struct map **mapp,
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300123 symbol_filter_t filter);
124
Arnaldo Carvalho de Melo7e5e1b12010-03-26 12:30:40 -0300125struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
126 enum map_type type,
127 const char *name,
128 struct map **mapp,
129 symbol_filter_t filter);
130
131static inline
132struct symbol *map_groups__find_function(struct map_groups *self, u64 addr,
133 struct map **mapp, symbol_filter_t filter)
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300134{
Arnaldo Carvalho de Melo7e5e1b12010-03-26 12:30:40 -0300135 return map_groups__find_symbol(self, MAP__FUNCTION, addr, mapp, filter);
136}
137
138static inline
139struct symbol *map_groups__find_function_by_name(struct map_groups *self,
140 const char *name, struct map **mapp,
141 symbol_filter_t filter)
142{
143 return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300144}
145
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300146int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
147 int verbose, FILE *fp);
148
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300149struct map *map_groups__find_by_name(struct map_groups *self,
150 enum map_type type, const char *name);
151int __map_groups__create_kernel_maps(struct map_groups *self,
152 struct map *vmlinux_maps[MAP__NR_TYPES],
153 struct dso *kernel);
154int map_groups__create_kernel_maps(struct map_groups *self,
155 struct map *vmlinux_maps[MAP__NR_TYPES]);
156struct map *map_groups__new_module(struct map_groups *self, u64 start,
157 const char *filename);
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300158void map_groups__flush(struct map_groups *self);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300159
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200160#endif /* __PERF_MAP_H */