blob: 1073e2d8b79740fb4a1c9656b9cc4058b5c84299 [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>
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -03008#include <stdbool.h>
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -03009#include "types.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020010
11enum map_type {
12 MAP__FUNCTION = 0,
13 MAP__VARIABLE,
14};
15
16#define MAP__NR_TYPES (MAP__VARIABLE + 1)
17
Arnaldo Carvalho de Melo3846df22010-02-22 16:15:39 -030018extern const char *map_type__name[MAP__NR_TYPES];
19
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020020struct dso;
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020021struct ip_callchain;
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020022struct ref_reloc_sym;
23struct map_groups;
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030024struct machine;
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -020025struct perf_evsel;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020026
27struct map {
28 union {
29 struct rb_node rb_node;
30 struct list_head node;
31 };
32 u64 start;
33 u64 end;
Arnaldo Carvalho de Melo0a1eae32010-08-02 19:45:23 -030034 u8 /* enum map_type */ type;
35 bool referenced;
Arnaldo Carvalho de Melo31d68e72012-03-27 12:55:57 -030036 bool erange_warned;
Arnaldo Carvalho de Melo5c0541d2010-04-29 15:25:23 -030037 u32 priv;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020038 u64 pgoff;
Adrian Hunter91767532014-01-29 16:14:36 +020039 u64 reloc;
Stephane Eranian5c5e8542013-08-21 12:10:25 +020040 u32 maj, min; /* only valid for MMAP2 record */
41 u64 ino; /* only valid for MMAP2 record */
42 u64 ino_generation;/* only valid for MMAP2 record */
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020043
44 /* ip -> dso rip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020045 u64 (*map_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020046 /* dso rip -> ip */
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020047 u64 (*unmap_ip)(struct map *, u64);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020048
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020049 struct dso *dso;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080050 struct map_groups *groups;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020051};
52
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020053struct kmap {
54 struct ref_reloc_sym *ref_reloc_sym;
55 struct map_groups *kmaps;
56};
57
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080058struct map_groups {
Arnaldo Carvalho de Melo23346f22010-04-27 21:17:50 -030059 struct rb_root maps[MAP__NR_TYPES];
60 struct list_head removed_maps[MAP__NR_TYPES];
61 struct machine *machine;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +080062};
63
Arnaldo Carvalho de Melo93d57312014-03-21 17:57:01 -030064struct map_groups *map_groups__new(void);
65void map_groups__delete(struct map_groups *mg);
66
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -030067static inline struct kmap *map__kmap(struct map *map)
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020068{
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -030069 return (struct kmap *)(map + 1);
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -020070}
71
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020072static inline u64 map__map_ip(struct map *map, u64 ip)
73{
74 return ip - map->start + map->pgoff;
75}
76
77static inline u64 map__unmap_ip(struct map *map, u64 ip)
78{
79 return ip + map->start - map->pgoff;
80}
81
Irina Tirdea1d037ca2012-09-11 01:15:03 +030082static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020083{
84 return ip;
85}
86
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020087
Kirill Smelkovee11b902010-02-07 11:46:15 -020088/* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020089u64 map__rip_2objdump(struct map *map, u64 rip);
Kirill Smelkov7a2b6202010-02-03 16:52:07 -020090
Adrian Hunter1d5077b2013-10-14 13:43:44 +030091/* objdump address -> memory address */
92u64 map__objdump_2mem(struct map *map, u64 ip);
93
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020094struct symbol;
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020095
Masami Hiramatsueb948e52014-02-06 05:32:25 +000096/* map__for_each_symbol - iterate over the symbols in the given map
97 *
98 * @map: the 'struct map *' in which symbols itereated
99 * @pos: the 'struct symbol *' to use as a loop cursor
100 * @n: the 'struct rb_node *' to use as a temporary storage
101 * Note: caller must ensure map->dso is not NULL (map is loaded).
102 */
103#define map__for_each_symbol(map, pos, n) \
104 dso__for_each_symbol(map->dso, pos, n, map->type)
105
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200106typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
107
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300108void map__init(struct map *map, enum map_type type,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200109 u64 start, u64 end, u64 pgoff, struct dso *dso);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800110struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
Stephane Eranian5c5e8542013-08-21 12:10:25 +0200111 u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
112 u64 ino_gen,
113 char *filename, enum map_type type);
Namhyung Kime5a18452012-08-06 13:41:20 +0900114struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300115void map__delete(struct map *map);
116struct map *map__clone(struct map *map);
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200117int map__overlap(struct map *l, struct map *r);
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300118size_t map__fprintf(struct map *map, FILE *fp);
Akihiro Nagai547a92e2012-01-30 13:42:57 +0900119size_t map__fprintf_dsoname(struct map *map, FILE *fp);
Adrian Huntercc8fae12013-12-06 09:42:57 +0200120int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
121 FILE *fp);
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200122
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300123int map__load(struct map *map, symbol_filter_t filter);
124struct symbol *map__find_symbol(struct map *map,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200125 u64 addr, symbol_filter_t filter);
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300126struct symbol *map__find_symbol_by_name(struct map *map, const char *name,
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200127 symbol_filter_t filter);
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300128void map__fixup_start(struct map *map);
129void map__fixup_end(struct map *map);
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200130
Arnaldo Carvalho de Melo237a7e02013-01-24 21:59:59 -0300131void map__reloc_vmlinux(struct map *map);
Arnaldo Carvalho de Melo9de89fe2010-02-03 16:52:00 -0200132
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300133size_t __map_groups__fprintf_maps(struct map_groups *mg,
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300134 enum map_type type, int verbose, FILE *fp);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300135void maps__insert(struct rb_root *maps, struct map *map);
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300136void maps__remove(struct rb_root *maps, struct map *map);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300137struct map *maps__find(struct rb_root *maps, u64 addr);
Adrian Hunter8e0cf962013-08-07 14:38:51 +0300138struct map *maps__first(struct rb_root *maps);
139struct map *maps__next(struct map *map);
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300140void map_groups__init(struct map_groups *mg);
141void map_groups__exit(struct map_groups *mg);
142int map_groups__clone(struct map_groups *mg,
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300143 struct map_groups *parent, enum map_type type);
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300144size_t map_groups__fprintf(struct map_groups *mg, int verbose, FILE *fp);
145size_t map_groups__fprintf_maps(struct map_groups *mg, int verbose, FILE *fp);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300146
Arnaldo Carvalho de Melo743eb862011-11-28 07:56:39 -0200147int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
148 u64 addr);
149
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300150static inline void map_groups__insert(struct map_groups *mg, struct map *map)
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300151{
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300152 maps__insert(&mg->maps[map->type], map);
153 map->groups = mg;
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300154}
155
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300156static inline void map_groups__remove(struct map_groups *mg, struct map *map)
Arnaldo Carvalho de Melo076c6e452010-08-02 18:18:28 -0300157{
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300158 maps__remove(&mg->maps[map->type], map);
Arnaldo Carvalho de Melo076c6e452010-08-02 18:18:28 -0300159}
160
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300161static inline struct map *map_groups__find(struct map_groups *mg,
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300162 enum map_type type, u64 addr)
163{
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300164 return maps__find(&mg->maps[type], addr);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300165}
166
Adrian Hunter8e0cf962013-08-07 14:38:51 +0300167static inline struct map *map_groups__first(struct map_groups *mg,
168 enum map_type type)
169{
170 return maps__first(&mg->maps[type]);
171}
172
173static inline struct map *map_groups__next(struct map *map)
174{
175 return maps__next(map);
176}
177
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300178struct symbol *map_groups__find_symbol(struct map_groups *mg,
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300179 enum map_type type, u64 addr,
Arnaldo Carvalho de Melo7e5e1b142010-03-26 12:30:40 -0300180 struct map **mapp,
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300181 symbol_filter_t filter);
182
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300183struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
Arnaldo Carvalho de Melo7e5e1b142010-03-26 12:30:40 -0300184 enum map_type type,
185 const char *name,
186 struct map **mapp,
187 symbol_filter_t filter);
188
Arnaldo Carvalho de Melo4e987712013-10-14 13:43:38 +0300189struct addr_map_symbol;
190
191int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter);
192
Arnaldo Carvalho de Melo7e5e1b142010-03-26 12:30:40 -0300193static inline
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300194struct symbol *map_groups__find_function_by_name(struct map_groups *mg,
Arnaldo Carvalho de Melo7e5e1b142010-03-26 12:30:40 -0300195 const char *name, struct map **mapp,
196 symbol_filter_t filter)
197{
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300198 return map_groups__find_symbol_by_name(mg, MAP__FUNCTION, name, mapp, filter);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300199}
200
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300201int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -0300202 int verbose, FILE *fp);
203
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300204struct map *map_groups__find_by_name(struct map_groups *mg,
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300205 enum map_type type, const char *name);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800206
Arnaldo Carvalho de Melo98dfd552011-08-23 14:31:30 -0300207void map_groups__flush(struct map_groups *mg);
Arnaldo Carvalho de Melo4b8cf842010-03-25 19:58:58 -0300208
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -0200209#endif /* __PERF_MAP_H */