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> |
4383db88 | 14 | #include "build-id.h" |
a2928c42 | 15 | |
29a0fc9b | 16 | #ifdef LIBELF_SUPPORT |
b68e2f91 CS |
17 | #include <libelf.h> |
18 | #include <gelf.h> | |
19 | #include <elf.h> | |
20 | #endif | |
21 | ||
cdd059d7 JO |
22 | #include "dso.h" |
23 | ||
247648e3 ACM |
24 | #ifdef HAVE_CPLUS_DEMANGLE |
25 | extern char *cplus_demangle(const char *, int); | |
26 | ||
1d037ca1 | 27 | static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i) |
247648e3 ACM |
28 | { |
29 | return cplus_demangle(c, i); | |
30 | } | |
31 | #else | |
32 | #ifdef NO_DEMANGLE | |
1d037ca1 IT |
33 | static inline char *bfd_demangle(void __maybe_unused *v, |
34 | const char __maybe_unused *c, | |
35 | int __maybe_unused i) | |
247648e3 ACM |
36 | { |
37 | return NULL; | |
38 | } | |
39 | #else | |
3ce711a6 | 40 | #define PACKAGE 'perf' |
247648e3 ACM |
41 | #include <bfd.h> |
42 | #endif | |
43 | #endif | |
44 | ||
84087126 MR |
45 | /* |
46 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | |
47 | * for newer versions we can use mmap to reduce memory usage: | |
48 | */ | |
29a0fc9b | 49 | #ifdef LIBELF_MMAP |
84087126 | 50 | # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP |
29a0fc9b NK |
51 | #else |
52 | # define PERF_ELF_C_READ_MMAP ELF_C_READ | |
84087126 MR |
53 | #endif |
54 | ||
247648e3 ACM |
55 | #ifndef DMGL_PARAMS |
56 | #define DMGL_PARAMS (1 << 0) /* Include function args */ | |
57 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | |
58 | #endif | |
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); |
cdd059d7 | 75 | void symbols__delete(struct rb_root *symbols); |
628ada0c | 76 | |
1b2e2df4 ACM |
77 | static inline size_t symbol__size(const struct symbol *sym) |
78 | { | |
79 | return sym->end - sym->start + 1; | |
80 | } | |
81 | ||
655000e7 ACM |
82 | struct strlist; |
83 | ||
b32d133a ACM |
84 | struct symbol_conf { |
85 | unsigned short priv_size; | |
d04b35f8 | 86 | unsigned short nr_events; |
b32d133a | 87 | bool try_vmlinux_path, |
0bc8d205 | 88 | show_kernel_path, |
79406cd7 | 89 | use_modules, |
d599db3f ACM |
90 | sort_by_name, |
91 | show_nr_samples, | |
3f2728bd | 92 | show_total_period, |
d599db3f | 93 | use_callchain, |
f7d87444 | 94 | exclude_other, |
85e00b55 | 95 | show_cpu_utilization, |
ec80fde7 | 96 | initialized, |
3e6a2a7f SE |
97 | kptr_restrict, |
98 | annotate_asm_raw, | |
99 | annotate_src; | |
c410a338 | 100 | const char *vmlinux_name, |
b226a5a7 | 101 | *kallsyms_name, |
9ed7e1b8 | 102 | *source_prefix, |
c410a338 | 103 | *field_sep; |
a1645ce1 ZY |
104 | const char *default_guest_vmlinux_name, |
105 | *default_guest_kallsyms, | |
106 | *default_guest_modules; | |
107 | const char *guestmount; | |
edb7c60e | 108 | const char *dso_list_str, |
655000e7 ACM |
109 | *comm_list_str, |
110 | *sym_list_str, | |
111 | *col_width_list_str; | |
112 | struct strlist *dso_list, | |
113 | *comm_list, | |
a68c2c58 SE |
114 | *sym_list, |
115 | *dso_from_list, | |
116 | *dso_to_list, | |
117 | *sym_from_list, | |
118 | *sym_to_list; | |
ec5761ea | 119 | const char *symfs; |
b32d133a ACM |
120 | }; |
121 | ||
75be6cf4 | 122 | extern struct symbol_conf symbol_conf; |
00a192b3 | 123 | |
aeafcbaf | 124 | static inline void *symbol__priv(struct symbol *sym) |
00a192b3 | 125 | { |
aeafcbaf | 126 | return ((void *)sym) - symbol_conf.priv_size; |
00a192b3 ACM |
127 | } |
128 | ||
9de89fe7 ACM |
129 | struct ref_reloc_sym { |
130 | const char *name; | |
131 | u64 addr; | |
132 | u64 unrelocated_addr; | |
133 | }; | |
134 | ||
59fd5306 ACM |
135 | struct map_symbol { |
136 | struct map *map; | |
137 | struct symbol *sym; | |
0f0cbf7a ACM |
138 | bool unfolded; |
139 | bool has_children; | |
59fd5306 ACM |
140 | }; |
141 | ||
b5387528 RAV |
142 | struct addr_map_symbol { |
143 | struct map *map; | |
144 | struct symbol *sym; | |
145 | u64 addr; | |
a68c2c58 | 146 | u64 al_addr; |
b5387528 RAV |
147 | }; |
148 | ||
149 | struct branch_info { | |
150 | struct addr_map_symbol from; | |
151 | struct addr_map_symbol to; | |
152 | struct branch_flags flags; | |
153 | }; | |
154 | ||
1ed091c4 ACM |
155 | struct addr_location { |
156 | struct thread *thread; | |
157 | struct map *map; | |
158 | struct symbol *sym; | |
159 | u64 addr; | |
160 | char level; | |
c410a338 | 161 | bool filtered; |
f60f3593 AS |
162 | u8 cpumode; |
163 | s32 cpu; | |
a1645ce1 ZY |
164 | }; |
165 | ||
b68e2f91 CS |
166 | struct symsrc { |
167 | char *name; | |
168 | int fd; | |
169 | enum dso_binary_type type; | |
170 | ||
29a0fc9b | 171 | #ifdef LIBELF_SUPPORT |
b68e2f91 CS |
172 | Elf *elf; |
173 | GElf_Ehdr ehdr; | |
174 | ||
175 | Elf_Scn *opdsec; | |
176 | size_t opdidx; | |
177 | GElf_Shdr opdshdr; | |
178 | ||
179 | Elf_Scn *symtab; | |
180 | GElf_Shdr symshdr; | |
181 | ||
182 | Elf_Scn *dynsym; | |
183 | size_t dynsym_idx; | |
184 | GElf_Shdr dynshdr; | |
185 | ||
186 | bool adjust_symbols; | |
187 | #endif | |
188 | }; | |
189 | ||
190 | void symsrc__destroy(struct symsrc *ss); | |
191 | int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name, | |
192 | enum dso_binary_type type); | |
d26cd12b | 193 | bool symsrc__has_symtab(struct symsrc *ss); |
3aafe5ae | 194 | bool symsrc__possibly_runtime(struct symsrc *ss); |
b68e2f91 | 195 | |
aeafcbaf ACM |
196 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); |
197 | int dso__load_vmlinux(struct dso *dso, struct map *map, | |
fd930ff9 | 198 | const char *vmlinux, symbol_filter_t filter); |
aeafcbaf | 199 | int dso__load_vmlinux_path(struct dso *dso, struct map *map, |
9de89fe7 | 200 | symbol_filter_t filter); |
aeafcbaf | 201 | int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map, |
9de89fe7 | 202 | symbol_filter_t filter); |
aeafcbaf | 203 | int machine__load_kallsyms(struct machine *machine, const char *filename, |
5c0541d5 | 204 | enum map_type type, symbol_filter_t filter); |
aeafcbaf | 205 | int machine__load_vmlinux_path(struct machine *machine, enum map_type type, |
5c0541d5 ACM |
206 | symbol_filter_t filter); |
207 | ||
aeafcbaf ACM |
208 | size_t machine__fprintf_dsos_buildid(struct machine *machine, |
209 | FILE *fp, bool with_hits); | |
210 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); | |
211 | size_t machines__fprintf_dsos_buildid(struct rb_root *machines, | |
212 | FILE *fp, bool with_hits); | |
cdd059d7 | 213 | |
aeafcbaf ACM |
214 | struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, |
215 | u64 addr); | |
216 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, | |
79406cd7 | 217 | const char *name); |
a2928c42 | 218 | |
2643ce11 | 219 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
f1617b40 | 220 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
9e201442 ACM |
221 | int kallsyms__parse(const char *filename, void *arg, |
222 | int (*process_symbol)(void *arg, const char *name, | |
82151520 | 223 | char type, u64 start)); |
e5a1845f NK |
224 | int filename__read_debuglink(const char *filename, char *debuglink, |
225 | size_t size); | |
2643ce11 | 226 | |
aeafcbaf ACM |
227 | void machine__destroy_kernel_maps(struct machine *machine); |
228 | int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); | |
229 | int machine__create_kernel_maps(struct machine *machine); | |
5c0541d5 | 230 | |
aeafcbaf ACM |
231 | int machines__create_kernel_maps(struct rb_root *machines, pid_t pid); |
232 | int machines__create_guest_kernel_maps(struct rb_root *machines); | |
233 | void machines__destroy_guest_kernel_maps(struct rb_root *machines); | |
a1645ce1 | 234 | |
75be6cf4 | 235 | int symbol__init(void); |
d65a458b | 236 | void symbol__exit(void); |
166ccc9c | 237 | void symbol__elf_init(void); |
e5a1845f | 238 | struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name); |
a978f2ab AN |
239 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
240 | const struct addr_location *al, FILE *fp); | |
547a92e0 | 241 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); |
cdd059d7 | 242 | size_t symbol__fprintf(struct symbol *sym, FILE *fp); |
36a3e646 ACM |
243 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
244 | ||
aeafcbaf | 245 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
b0a9ab62 | 246 | |
f7add556 | 247 | int dso__test_data(void); |
261360b6 CS |
248 | int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, |
249 | struct symsrc *runtime_ss, symbol_filter_t filter, | |
250 | int kmodule); | |
a44f605b CS |
251 | int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss, |
252 | struct map *map, symbol_filter_t filter); | |
e5a1845f NK |
253 | |
254 | void symbols__insert(struct rb_root *symbols, struct symbol *sym); | |
255 | void symbols__fixup_duplicate(struct rb_root *symbols); | |
256 | void symbols__fixup_end(struct rb_root *symbols); | |
257 | void __map_groups__fixup_end(struct map_groups *mg, enum map_type type); | |
258 | ||
8b40f521 | 259 | #endif /* __PERF_SYMBOL */ |