Commit | Line | Data |
---|---|---|
8b40f521 JK |
1 | #ifndef __PERF_SYMBOL |
2 | #define __PERF_SYMBOL 1 | |
a2928c42 ACM |
3 | |
4 | #include <linux/types.h> | |
e4204992 | 5 | #include <stdbool.h> |
5aab621b ACM |
6 | #include <stdint.h> |
7 | #include "map.h" | |
b5387528 | 8 | #include "../perf.h" |
5da50258 | 9 | #include <linux/list.h> |
43cbcd8a | 10 | #include <linux/rbtree.h> |
5aab621b | 11 | #include <stdio.h> |
8db4841f | 12 | #include <byteswap.h> |
b771a830 | 13 | #include <libgen.h> |
a2928c42 | 14 | |
b68e2f91 CS |
15 | #ifndef NO_LIBELF_SUPPORT |
16 | #include <libelf.h> | |
17 | #include <gelf.h> | |
18 | #include <elf.h> | |
19 | #endif | |
20 | ||
247648e3 ACM |
21 | #ifdef HAVE_CPLUS_DEMANGLE |
22 | extern char *cplus_demangle(const char *, int); | |
23 | ||
24 | static inline char *bfd_demangle(void __used *v, const char *c, int i) | |
25 | { | |
26 | return cplus_demangle(c, i); | |
27 | } | |
28 | #else | |
29 | #ifdef NO_DEMANGLE | |
30 | static inline char *bfd_demangle(void __used *v, const char __used *c, | |
31 | int __used i) | |
32 | { | |
33 | return NULL; | |
34 | } | |
35 | #else | |
36 | #include <bfd.h> | |
37 | #endif | |
38 | #endif | |
39 | ||
5aab621b ACM |
40 | int hex2u64(const char *ptr, u64 *val); |
41 | char *strxfrchar(char *s, char from, char to); | |
42 | ||
84087126 MR |
43 | /* |
44 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | |
45 | * for newer versions we can use mmap to reduce memory usage: | |
46 | */ | |
47 | #ifdef LIBELF_NO_MMAP | |
48 | # define PERF_ELF_C_READ_MMAP ELF_C_READ | |
49 | #else | |
50 | # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP | |
51 | #endif | |
52 | ||
247648e3 ACM |
53 | #ifndef DMGL_PARAMS |
54 | #define DMGL_PARAMS (1 << 0) /* Include function args */ | |
55 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | |
56 | #endif | |
57 | ||
5aab621b ACM |
58 | #define BUILD_ID_SIZE 20 |
59 | ||
171b3be9 ACM |
60 | /** struct symbol - symtab entry |
61 | * | |
62 | * @ignore - resolvable but tools ignore it (e.g. idle routines) | |
63 | */ | |
a2928c42 ACM |
64 | struct symbol { |
65 | struct rb_node rb_node; | |
9cffa8d5 PM |
66 | u64 start; |
67 | u64 end; | |
fefb0b94 | 68 | u16 namelen; |
c408fedf | 69 | u8 binding; |
171b3be9 | 70 | bool ignore; |
a2928c42 ACM |
71 | char name[0]; |
72 | }; | |
73 | ||
aeafcbaf | 74 | void symbol__delete(struct symbol *sym); |
628ada0c | 75 | |
1b2e2df4 ACM |
76 | static inline size_t symbol__size(const struct symbol *sym) |
77 | { | |
78 | return sym->end - sym->start + 1; | |
79 | } | |
80 | ||
655000e7 ACM |
81 | struct strlist; |
82 | ||
b32d133a ACM |
83 | struct symbol_conf { |
84 | unsigned short priv_size; | |
d04b35f8 | 85 | unsigned short nr_events; |
b32d133a | 86 | bool try_vmlinux_path, |
0bc8d205 | 87 | show_kernel_path, |
79406cd7 | 88 | use_modules, |
d599db3f ACM |
89 | sort_by_name, |
90 | show_nr_samples, | |
3f2728bd | 91 | show_total_period, |
d599db3f | 92 | use_callchain, |
f7d87444 | 93 | exclude_other, |
85e00b55 | 94 | show_cpu_utilization, |
ec80fde7 | 95 | initialized, |
3e6a2a7f SE |
96 | kptr_restrict, |
97 | annotate_asm_raw, | |
98 | annotate_src; | |
c410a338 | 99 | const char *vmlinux_name, |
b226a5a7 | 100 | *kallsyms_name, |
9ed7e1b8 | 101 | *source_prefix, |
c410a338 | 102 | *field_sep; |
a1645ce1 ZY |
103 | const char *default_guest_vmlinux_name, |
104 | *default_guest_kallsyms, | |
105 | *default_guest_modules; | |
106 | const char *guestmount; | |
edb7c60e | 107 | const char *dso_list_str, |
655000e7 ACM |
108 | *comm_list_str, |
109 | *sym_list_str, | |
110 | *col_width_list_str; | |
111 | struct strlist *dso_list, | |
112 | *comm_list, | |
a68c2c58 SE |
113 | *sym_list, |
114 | *dso_from_list, | |
115 | *dso_to_list, | |
116 | *sym_from_list, | |
117 | *sym_to_list; | |
ec5761ea | 118 | const char *symfs; |
b32d133a ACM |
119 | }; |
120 | ||
75be6cf4 | 121 | extern struct symbol_conf symbol_conf; |
00a192b3 | 122 | |
aeafcbaf | 123 | static inline void *symbol__priv(struct symbol *sym) |
00a192b3 | 124 | { |
aeafcbaf | 125 | return ((void *)sym) - symbol_conf.priv_size; |
00a192b3 ACM |
126 | } |
127 | ||
9de89fe7 ACM |
128 | struct ref_reloc_sym { |
129 | const char *name; | |
130 | u64 addr; | |
131 | u64 unrelocated_addr; | |
132 | }; | |
133 | ||
59fd5306 ACM |
134 | struct map_symbol { |
135 | struct map *map; | |
136 | struct symbol *sym; | |
0f0cbf7a ACM |
137 | bool unfolded; |
138 | bool has_children; | |
59fd5306 ACM |
139 | }; |
140 | ||
b5387528 RAV |
141 | struct addr_map_symbol { |
142 | struct map *map; | |
143 | struct symbol *sym; | |
144 | u64 addr; | |
a68c2c58 | 145 | u64 al_addr; |
b5387528 RAV |
146 | }; |
147 | ||
148 | struct branch_info { | |
149 | struct addr_map_symbol from; | |
150 | struct addr_map_symbol to; | |
151 | struct branch_flags flags; | |
152 | }; | |
153 | ||
1ed091c4 ACM |
154 | struct addr_location { |
155 | struct thread *thread; | |
156 | struct map *map; | |
157 | struct symbol *sym; | |
158 | u64 addr; | |
159 | char level; | |
c410a338 | 160 | bool filtered; |
f60f3593 AS |
161 | u8 cpumode; |
162 | s32 cpu; | |
a1645ce1 ZY |
163 | }; |
164 | ||
44f24cb3 JO |
165 | enum dso_binary_type { |
166 | DSO_BINARY_TYPE__KALLSYMS = 0, | |
167 | DSO_BINARY_TYPE__GUEST_KALLSYMS, | |
21ea4539 CS |
168 | DSO_BINARY_TYPE__VMLINUX, |
169 | DSO_BINARY_TYPE__GUEST_VMLINUX, | |
44f24cb3 JO |
170 | DSO_BINARY_TYPE__JAVA_JIT, |
171 | DSO_BINARY_TYPE__DEBUGLINK, | |
172 | DSO_BINARY_TYPE__BUILD_ID_CACHE, | |
173 | DSO_BINARY_TYPE__FEDORA_DEBUGINFO, | |
174 | DSO_BINARY_TYPE__UBUNTU_DEBUGINFO, | |
175 | DSO_BINARY_TYPE__BUILDID_DEBUGINFO, | |
176 | DSO_BINARY_TYPE__SYSTEM_PATH_DSO, | |
177 | DSO_BINARY_TYPE__GUEST_KMODULE, | |
178 | DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE, | |
179 | DSO_BINARY_TYPE__NOT_FOUND, | |
180 | }; | |
181 | ||
a1645ce1 ZY |
182 | enum dso_kernel_type { |
183 | DSO_TYPE_USER = 0, | |
184 | DSO_TYPE_KERNEL, | |
185 | DSO_TYPE_GUEST_KERNEL | |
1ed091c4 ACM |
186 | }; |
187 | ||
8db4841f JO |
188 | enum dso_swap_type { |
189 | DSO_SWAP__UNSET, | |
190 | DSO_SWAP__NO, | |
191 | DSO_SWAP__YES, | |
192 | }; | |
193 | ||
4dff624a JO |
194 | #define DSO__DATA_CACHE_SIZE 4096 |
195 | #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1) | |
196 | ||
197 | struct dso_cache { | |
198 | struct rb_node rb_node; | |
199 | u64 offset; | |
200 | u64 size; | |
201 | char data[0]; | |
202 | }; | |
203 | ||
a2928c42 ACM |
204 | struct dso { |
205 | struct list_head node; | |
6a4694a4 | 206 | struct rb_root symbols[MAP__NR_TYPES]; |
79406cd7 | 207 | struct rb_root symbol_names[MAP__NR_TYPES]; |
4dff624a | 208 | struct rb_root cache; |
6e406257 | 209 | enum dso_kernel_type kernel; |
8db4841f | 210 | enum dso_swap_type needs_swap; |
44f24cb3 | 211 | enum dso_binary_type symtab_type; |
949d160b | 212 | enum dso_binary_type data_type; |
8d06367f | 213 | u8 adjust_symbols:1; |
8d06367f | 214 | u8 has_build_id:1; |
88d3d9b7 | 215 | u8 hit:1; |
d06d92b7 | 216 | u8 annotate_warned:1; |
6e406257 ACM |
217 | u8 sname_alloc:1; |
218 | u8 lname_alloc:1; | |
79406cd7 | 219 | u8 sorted_by_name; |
3610583c | 220 | u8 loaded; |
8d06367f | 221 | u8 build_id[BUILD_ID_SIZE]; |
439d473b ACM |
222 | const char *short_name; |
223 | char *long_name; | |
b63be8d7 ACM |
224 | u16 long_name_len; |
225 | u16 short_name_len; | |
a2928c42 ACM |
226 | char name[0]; |
227 | }; | |
228 | ||
b68e2f91 CS |
229 | struct symsrc { |
230 | char *name; | |
231 | int fd; | |
232 | enum dso_binary_type type; | |
233 | ||
234 | #ifndef NO_LIBELF_SUPPORT | |
235 | Elf *elf; | |
236 | GElf_Ehdr ehdr; | |
237 | ||
238 | Elf_Scn *opdsec; | |
239 | size_t opdidx; | |
240 | GElf_Shdr opdshdr; | |
241 | ||
242 | Elf_Scn *symtab; | |
243 | GElf_Shdr symshdr; | |
244 | ||
245 | Elf_Scn *dynsym; | |
246 | size_t dynsym_idx; | |
247 | GElf_Shdr dynshdr; | |
248 | ||
249 | bool adjust_symbols; | |
250 | #endif | |
251 | }; | |
252 | ||
253 | void symsrc__destroy(struct symsrc *ss); | |
254 | int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, | |
255 | enum dso_binary_type type); | |
d26cd12b | 256 | bool symsrc__has_symtab(struct symsrc *ss); |
3aafe5ae | 257 | bool symsrc__possibly_runtime(struct symsrc *ss); |
b68e2f91 | 258 | |
8db4841f JO |
259 | #define DSO__SWAP(dso, type, val) \ |
260 | ({ \ | |
261 | type ____r = val; \ | |
262 | BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \ | |
263 | if (dso->needs_swap == DSO_SWAP__YES) { \ | |
264 | switch (sizeof(____r)) { \ | |
265 | case 2: \ | |
266 | ____r = bswap_16(val); \ | |
267 | break; \ | |
268 | case 4: \ | |
269 | ____r = bswap_32(val); \ | |
270 | break; \ | |
271 | case 8: \ | |
272 | ____r = bswap_64(val); \ | |
273 | break; \ | |
274 | default: \ | |
275 | BUG_ON(1); \ | |
276 | } \ | |
277 | } \ | |
278 | ____r; \ | |
279 | }) | |
280 | ||
00a192b3 | 281 | struct dso *dso__new(const char *name); |
aeafcbaf | 282 | void dso__delete(struct dso *dso); |
a2928c42 | 283 | |
aeafcbaf | 284 | int dso__name_len(const struct dso *dso); |
8a6c5b26 | 285 | |
aeafcbaf ACM |
286 | bool dso__loaded(const struct dso *dso, enum map_type type); |
287 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type); | |
79406cd7 | 288 | |
aeafcbaf | 289 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) |
8d92c02a | 290 | { |
aeafcbaf | 291 | dso->loaded |= (1 << type); |
8d92c02a ACM |
292 | } |
293 | ||
aeafcbaf | 294 | void dso__sort_by_name(struct dso *dso, enum map_type type); |
3610583c | 295 | |
e5a1845f | 296 | void dsos__add(struct list_head *head, struct dso *dso); |
a89e5abe ACM |
297 | struct dso *__dsos__findnew(struct list_head *head, const char *name); |
298 | ||
aeafcbaf ACM |
299 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); |
300 | int dso__load_vmlinux(struct dso *dso, struct map *map, | |
fd930ff9 | 301 | const char *vmlinux, symbol_filter_t filter); |
aeafcbaf | 302 | int dso__load_vmlinux_path(struct dso *dso, struct map *map, |
9de89fe7 | 303 | symbol_filter_t filter); |
aeafcbaf | 304 | int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map, |
9de89fe7 | 305 | symbol_filter_t filter); |
aeafcbaf | 306 | int machine__load_kallsyms(struct machine *machine, const char *filename, |
5c0541d5 | 307 | enum map_type type, symbol_filter_t filter); |
aeafcbaf | 308 | int machine__load_vmlinux_path(struct machine *machine, enum map_type type, |
5c0541d5 ACM |
309 | symbol_filter_t filter); |
310 | ||
1f626bc3 ACM |
311 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); |
312 | ||
aeafcbaf ACM |
313 | size_t machine__fprintf_dsos_buildid(struct machine *machine, |
314 | FILE *fp, bool with_hits); | |
315 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); | |
316 | size_t machines__fprintf_dsos_buildid(struct rb_root *machines, | |
317 | FILE *fp, bool with_hits); | |
318 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp); | |
319 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | |
320 | enum map_type type, FILE *fp); | |
321 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | |
b0a9ab62 | 322 | |
aeafcbaf ACM |
323 | char dso__symtab_origin(const struct dso *dso); |
324 | void dso__set_long_name(struct dso *dso, char *name); | |
325 | void dso__set_build_id(struct dso *dso, void *build_id); | |
e5a1845f | 326 | bool dso__build_id_equal(const struct dso *dso, u8 *build_id); |
aeafcbaf ACM |
327 | void dso__read_running_kernel_build_id(struct dso *dso, |
328 | struct machine *machine); | |
225466f1 | 329 | struct map *dso__new_map(const char *name); |
aeafcbaf ACM |
330 | struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, |
331 | u64 addr); | |
332 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, | |
79406cd7 | 333 | const char *name); |
a2928c42 | 334 | |
2643ce11 | 335 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
f1617b40 | 336 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
a1645ce1 | 337 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); |
aeafcbaf | 338 | int build_id__sprintf(const u8 *build_id, int len, char *bf); |
9e201442 ACM |
339 | int kallsyms__parse(const char *filename, void *arg, |
340 | int (*process_symbol)(void *arg, const char *name, | |
82151520 | 341 | char type, u64 start)); |
e5a1845f NK |
342 | int filename__read_debuglink(const char *filename, char *debuglink, |
343 | size_t size); | |
2643ce11 | 344 | |
aeafcbaf ACM |
345 | void machine__destroy_kernel_maps(struct machine *machine); |
346 | int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); | |
347 | int machine__create_kernel_maps(struct machine *machine); | |
5c0541d5 | 348 | |
aeafcbaf ACM |
349 | int machines__create_kernel_maps(struct rb_root *machines, pid_t pid); |
350 | int machines__create_guest_kernel_maps(struct rb_root *machines); | |
351 | void machines__destroy_guest_kernel_maps(struct rb_root *machines); | |
a1645ce1 | 352 | |
75be6cf4 | 353 | int symbol__init(void); |
d65a458b | 354 | void symbol__exit(void); |
166ccc9c | 355 | void symbol__elf_init(void); |
e5a1845f | 356 | struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); |
a978f2ab AN |
357 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
358 | const struct addr_location *al, FILE *fp); | |
547a92e0 | 359 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); |
36a3e646 ACM |
360 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
361 | ||
aeafcbaf | 362 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
b0a9ab62 | 363 | |
44f24cb3 JO |
364 | int dso__binary_type_file(struct dso *dso, enum dso_binary_type type, |
365 | char *root_dir, char *file, size_t size); | |
949d160b JO |
366 | |
367 | int dso__data_fd(struct dso *dso, struct machine *machine); | |
368 | ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine, | |
369 | u64 offset, u8 *data, ssize_t size); | |
370 | ssize_t dso__data_read_addr(struct dso *dso, struct map *map, | |
371 | struct machine *machine, u64 addr, | |
372 | u8 *data, ssize_t size); | |
f7add556 | 373 | int dso__test_data(void); |
261360b6 CS |
374 | int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, |
375 | struct symsrc *runtime_ss, symbol_filter_t filter, | |
376 | int kmodule); | |
a44f605b CS |
377 | int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, |
378 | struct map *map, symbol_filter_t filter); | |
e5a1845f NK |
379 | |
380 | void symbols__insert(struct rb_root *symbols, struct symbol *sym); | |
381 | void symbols__fixup_duplicate(struct rb_root *symbols); | |
382 | void symbols__fixup_end(struct rb_root *symbols); | |
383 | void __map_groups__fixup_end(struct map_groups *mg, enum map_type type); | |
384 | ||
8b40f521 | 385 | #endif /* __PERF_SYMBOL */ |