perf tools: Check recorded kernel version when finding vmlinux
[deliverable/linux.git] / tools / perf / util / symbol.h
CommitLineData
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>
4383db88 14#include "build-id.h"
0776eb59 15#include "event.h"
972f393b 16#include "util.h"
a2928c42 17
89fe808a 18#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
19#include <libelf.h>
20#include <gelf.h>
b68e2f91 21#endif
eec185ab 22#include <elf.h>
b68e2f91 23
cdd059d7
JO
24#include "dso.h"
25
89fe808a 26#ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
247648e3
ACM
27extern char *cplus_demangle(const char *, int);
28
1d037ca1 29static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i)
247648e3
ACM
30{
31 return cplus_demangle(c, i);
32}
33#else
34#ifdef NO_DEMANGLE
1d037ca1
IT
35static inline char *bfd_demangle(void __maybe_unused *v,
36 const char __maybe_unused *c,
37 int __maybe_unused i)
247648e3
ACM
38{
39 return NULL;
40}
41#else
3ce711a6 42#define PACKAGE 'perf'
247648e3
ACM
43#include <bfd.h>
44#endif
45#endif
46
84087126
MR
47/*
48 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
49 * for newer versions we can use mmap to reduce memory usage:
50 */
89fe808a 51#ifdef HAVE_LIBELF_MMAP_SUPPORT
84087126 52# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
29a0fc9b
NK
53#else
54# define PERF_ELF_C_READ_MMAP ELF_C_READ
84087126
MR
55#endif
56
99ca4233
MH
57#ifdef HAVE_LIBELF_SUPPORT
58extern Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
59 GElf_Shdr *shp, const char *name, size_t *idx);
60#endif
61
247648e3
ACM
62#ifndef DMGL_PARAMS
63#define DMGL_PARAMS (1 << 0) /* Include function args */
64#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
65#endif
66
171b3be9
ACM
67/** struct symbol - symtab entry
68 *
69 * @ignore - resolvable but tools ignore it (e.g. idle routines)
70 */
a2928c42
ACM
71struct symbol {
72 struct rb_node rb_node;
9cffa8d5
PM
73 u64 start;
74 u64 end;
fefb0b94 75 u16 namelen;
c408fedf 76 u8 binding;
171b3be9 77 bool ignore;
a2928c42
ACM
78 char name[0];
79};
80
aeafcbaf 81void symbol__delete(struct symbol *sym);
cdd059d7 82void symbols__delete(struct rb_root *symbols);
628ada0c 83
eb948e50
MH
84/* symbols__for_each_entry - iterate over symbols (rb_root)
85 *
86 * @symbols: the rb_root of symbols
87 * @pos: the 'struct symbol *' to use as a loop cursor
88 * @nd: the 'struct rb_node *' to use as a temporary storage
89 */
90#define symbols__for_each_entry(symbols, pos, nd) \
91 for (nd = rb_first(symbols); \
92 nd && (pos = rb_entry(nd, struct symbol, rb_node)); \
93 nd = rb_next(nd))
94
1b2e2df4
ACM
95static inline size_t symbol__size(const struct symbol *sym)
96{
97 return sym->end - sym->start + 1;
98}
99
655000e7
ACM
100struct strlist;
101
b32d133a
ACM
102struct symbol_conf {
103 unsigned short priv_size;
d04b35f8 104 unsigned short nr_events;
b32d133a 105 bool try_vmlinux_path,
fc2be696 106 ignore_vmlinux,
0bc8d205 107 show_kernel_path,
79406cd7 108 use_modules,
d599db3f
ACM
109 sort_by_name,
110 show_nr_samples,
3f2728bd 111 show_total_period,
d599db3f 112 use_callchain,
f8be1c8c 113 cumulate_callchain,
f7d87444 114 exclude_other,
85e00b55 115 show_cpu_utilization,
ec80fde7 116 initialized,
3e6a2a7f
SE
117 kptr_restrict,
118 annotate_asm_raw,
6e1f601a 119 annotate_src,
328ccdac 120 event_group,
f2148330 121 demangle,
c8302367
JO
122 filter_relative,
123 show_hist_headers;
c410a338 124 const char *vmlinux_name,
b226a5a7 125 *kallsyms_name,
9ed7e1b8 126 *source_prefix,
c410a338 127 *field_sep;
a1645ce1
ZY
128 const char *default_guest_vmlinux_name,
129 *default_guest_kallsyms,
130 *default_guest_modules;
131 const char *guestmount;
edb7c60e 132 const char *dso_list_str,
655000e7
ACM
133 *comm_list_str,
134 *sym_list_str,
135 *col_width_list_str;
136 struct strlist *dso_list,
137 *comm_list,
a68c2c58
SE
138 *sym_list,
139 *dso_from_list,
140 *dso_to_list,
141 *sym_from_list,
142 *sym_to_list;
ec5761ea 143 const char *symfs;
b32d133a
ACM
144};
145
75be6cf4 146extern struct symbol_conf symbol_conf;
972f393b
ACM
147
148static inline int __symbol__join_symfs(char *bf, size_t size, const char *path)
149{
150 return path__join(bf, size, symbol_conf.symfs, path);
151}
152
153#define symbol__join_symfs(bf, path) __symbol__join_symfs(bf, sizeof(bf), path)
154
3f067dca
ACM
155extern int vmlinux_path__nr_entries;
156extern char **vmlinux_path;
00a192b3 157
aeafcbaf 158static inline void *symbol__priv(struct symbol *sym)
00a192b3 159{
aeafcbaf 160 return ((void *)sym) - symbol_conf.priv_size;
00a192b3
ACM
161}
162
9de89fe7
ACM
163struct ref_reloc_sym {
164 const char *name;
165 u64 addr;
166 u64 unrelocated_addr;
167};
168
59fd5306
ACM
169struct map_symbol {
170 struct map *map;
171 struct symbol *sym;
0f0cbf7a
ACM
172 bool unfolded;
173 bool has_children;
59fd5306
ACM
174};
175
b5387528
RAV
176struct addr_map_symbol {
177 struct map *map;
178 struct symbol *sym;
179 u64 addr;
a68c2c58 180 u64 al_addr;
b5387528
RAV
181};
182
183struct branch_info {
184 struct addr_map_symbol from;
185 struct addr_map_symbol to;
186 struct branch_flags flags;
187};
188
98a3b32c
SE
189struct mem_info {
190 struct addr_map_symbol iaddr;
191 struct addr_map_symbol daddr;
192 union perf_mem_data_src data_src;
193};
194
1ed091c4 195struct addr_location {
cc22e575 196 struct machine *machine;
1ed091c4
ACM
197 struct thread *thread;
198 struct map *map;
199 struct symbol *sym;
200 u64 addr;
201 char level;
b3cef7f6 202 u8 filtered;
f60f3593
AS
203 u8 cpumode;
204 s32 cpu;
a1645ce1
ZY
205};
206
b68e2f91
CS
207struct symsrc {
208 char *name;
209 int fd;
210 enum dso_binary_type type;
211
89fe808a 212#ifdef HAVE_LIBELF_SUPPORT
b68e2f91
CS
213 Elf *elf;
214 GElf_Ehdr ehdr;
215
216 Elf_Scn *opdsec;
217 size_t opdidx;
218 GElf_Shdr opdshdr;
219
220 Elf_Scn *symtab;
221 GElf_Shdr symshdr;
222
223 Elf_Scn *dynsym;
224 size_t dynsym_idx;
225 GElf_Shdr dynshdr;
226
227 bool adjust_symbols;
c6d8f2a4 228 bool is_64_bit;
b68e2f91
CS
229#endif
230};
231
232void symsrc__destroy(struct symsrc *ss);
233int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
234 enum dso_binary_type type);
d26cd12b 235bool symsrc__has_symtab(struct symsrc *ss);
3aafe5ae 236bool symsrc__possibly_runtime(struct symsrc *ss);
b68e2f91 237
aeafcbaf
ACM
238int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
239int dso__load_vmlinux(struct dso *dso, struct map *map,
5230fb7d
ACM
240 const char *vmlinux, bool vmlinux_allocated,
241 symbol_filter_t filter);
aeafcbaf 242int dso__load_vmlinux_path(struct dso *dso, struct map *map,
9de89fe7 243 symbol_filter_t filter);
aeafcbaf 244int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
9de89fe7 245 symbol_filter_t filter);
cdd059d7 246
aeafcbaf
ACM
247struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
248 u64 addr);
249struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
79406cd7 250 const char *name);
a2928c42 251
9c00a81b
AH
252struct symbol *dso__first_symbol(struct dso *dso, enum map_type type);
253struct symbol *dso__next_symbol(struct symbol *sym);
254
2b5b8bb2
AH
255enum dso_type dso__type_fd(int fd);
256
2643ce11 257int filename__read_build_id(const char *filename, void *bf, size_t size);
f1617b40 258int sysfs__read_build_id(const char *filename, void *bf, size_t size);
316d70d6
AH
259int modules__parse(const char *filename, void *arg,
260 int (*process_module)(void *arg, const char *name,
261 u64 start));
e5a1845f
NK
262int filename__read_debuglink(const char *filename, char *debuglink,
263 size_t size);
2643ce11 264
0a7e6d1b
NK
265struct perf_session_env;
266int symbol__init(struct perf_session_env *env);
d65a458b 267void symbol__exit(void);
166ccc9c 268void symbol__elf_init(void);
e5a1845f 269struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
a978f2ab
AN
270size_t symbol__fprintf_symname_offs(const struct symbol *sym,
271 const struct addr_location *al, FILE *fp);
547a92e0 272size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
cdd059d7 273size_t symbol__fprintf(struct symbol *sym, FILE *fp);
36a3e646 274bool symbol_type__is_a(char symbol_type, enum map_type map_type);
3f067dca
ACM
275bool symbol__restricted_filename(const char *filename,
276 const char *restricted_filename);
82d1deb0 277bool symbol__is_idle(struct symbol *sym);
36a3e646 278
261360b6
CS
279int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
280 struct symsrc *runtime_ss, symbol_filter_t filter,
281 int kmodule);
a44f605b
CS
282int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
283 struct map *map, symbol_filter_t filter);
e5a1845f
NK
284
285void symbols__insert(struct rb_root *symbols, struct symbol *sym);
286void symbols__fixup_duplicate(struct rb_root *symbols);
287void symbols__fixup_end(struct rb_root *symbols);
288void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
289
8e0cf965
AH
290typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data);
291int file__read_maps(int fd, bool exe, mapfn_t mapfn, void *data,
292 bool *is_64_bit);
293
afba19d9
AH
294#define PERF_KCORE_EXTRACT "/tmp/perf-kcore-XXXXXX"
295
296struct kcore_extract {
297 char *kcore_filename;
298 u64 addr;
299 u64 offs;
300 u64 len;
301 char extract_filename[sizeof(PERF_KCORE_EXTRACT)];
302 int fd;
303};
304
305int kcore_extract__create(struct kcore_extract *kce);
306void kcore_extract__delete(struct kcore_extract *kce);
307
fc1b691d
AH
308int kcore_copy(const char *from_dir, const char *to_dir);
309int compare_proc_modules(const char *from, const char *to);
310
3bfe5f81
DA
311int setup_list(struct strlist **list, const char *list_str,
312 const char *list_name);
313
8b40f521 314#endif /* __PERF_SYMBOL */
This page took 0.21989 seconds and 5 git commands to generate.