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> |
a2928c42 | 12 | |
247648e3 ACM |
13 | #ifdef HAVE_CPLUS_DEMANGLE |
14 | extern char *cplus_demangle(const char *, int); | |
15 | ||
16 | static inline char *bfd_demangle(void __used *v, const char *c, int i) | |
17 | { | |
18 | return cplus_demangle(c, i); | |
19 | } | |
20 | #else | |
21 | #ifdef NO_DEMANGLE | |
22 | static inline char *bfd_demangle(void __used *v, const char __used *c, | |
23 | int __used i) | |
24 | { | |
25 | return NULL; | |
26 | } | |
27 | #else | |
28 | #include <bfd.h> | |
29 | #endif | |
30 | #endif | |
31 | ||
5aab621b ACM |
32 | int hex2u64(const char *ptr, u64 *val); |
33 | char *strxfrchar(char *s, char from, char to); | |
34 | ||
84087126 MR |
35 | /* |
36 | * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; | |
37 | * for newer versions we can use mmap to reduce memory usage: | |
38 | */ | |
39 | #ifdef LIBELF_NO_MMAP | |
40 | # define PERF_ELF_C_READ_MMAP ELF_C_READ | |
41 | #else | |
42 | # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP | |
43 | #endif | |
44 | ||
247648e3 ACM |
45 | #ifndef DMGL_PARAMS |
46 | #define DMGL_PARAMS (1 << 0) /* Include function args */ | |
47 | #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ | |
48 | #endif | |
49 | ||
5aab621b ACM |
50 | #define BUILD_ID_SIZE 20 |
51 | ||
171b3be9 ACM |
52 | /** struct symbol - symtab entry |
53 | * | |
54 | * @ignore - resolvable but tools ignore it (e.g. idle routines) | |
55 | */ | |
a2928c42 ACM |
56 | struct symbol { |
57 | struct rb_node rb_node; | |
9cffa8d5 PM |
58 | u64 start; |
59 | u64 end; | |
fefb0b94 | 60 | u16 namelen; |
c408fedf | 61 | u8 binding; |
171b3be9 | 62 | bool ignore; |
a2928c42 ACM |
63 | char name[0]; |
64 | }; | |
65 | ||
aeafcbaf | 66 | void symbol__delete(struct symbol *sym); |
628ada0c | 67 | |
1b2e2df4 ACM |
68 | static inline size_t symbol__size(const struct symbol *sym) |
69 | { | |
70 | return sym->end - sym->start + 1; | |
71 | } | |
72 | ||
655000e7 ACM |
73 | struct strlist; |
74 | ||
b32d133a ACM |
75 | struct symbol_conf { |
76 | unsigned short priv_size; | |
d04b35f8 | 77 | unsigned short nr_events; |
b32d133a | 78 | bool try_vmlinux_path, |
0bc8d205 | 79 | show_kernel_path, |
79406cd7 | 80 | use_modules, |
d599db3f ACM |
81 | sort_by_name, |
82 | show_nr_samples, | |
3f2728bd | 83 | show_total_period, |
d599db3f | 84 | use_callchain, |
f7d87444 | 85 | exclude_other, |
85e00b55 | 86 | show_cpu_utilization, |
ec80fde7 | 87 | initialized, |
3e6a2a7f SE |
88 | kptr_restrict, |
89 | annotate_asm_raw, | |
90 | annotate_src; | |
c410a338 | 91 | const char *vmlinux_name, |
b226a5a7 | 92 | *kallsyms_name, |
9ed7e1b8 | 93 | *source_prefix, |
c410a338 | 94 | *field_sep; |
a1645ce1 ZY |
95 | const char *default_guest_vmlinux_name, |
96 | *default_guest_kallsyms, | |
97 | *default_guest_modules; | |
98 | const char *guestmount; | |
edb7c60e | 99 | const char *dso_list_str, |
655000e7 ACM |
100 | *comm_list_str, |
101 | *sym_list_str, | |
102 | *col_width_list_str; | |
103 | struct strlist *dso_list, | |
104 | *comm_list, | |
a68c2c58 SE |
105 | *sym_list, |
106 | *dso_from_list, | |
107 | *dso_to_list, | |
108 | *sym_from_list, | |
109 | *sym_to_list; | |
ec5761ea | 110 | const char *symfs; |
b32d133a ACM |
111 | }; |
112 | ||
75be6cf4 | 113 | extern struct symbol_conf symbol_conf; |
00a192b3 | 114 | |
aeafcbaf | 115 | static inline void *symbol__priv(struct symbol *sym) |
00a192b3 | 116 | { |
aeafcbaf | 117 | return ((void *)sym) - symbol_conf.priv_size; |
00a192b3 ACM |
118 | } |
119 | ||
9de89fe7 ACM |
120 | struct ref_reloc_sym { |
121 | const char *name; | |
122 | u64 addr; | |
123 | u64 unrelocated_addr; | |
124 | }; | |
125 | ||
59fd5306 ACM |
126 | struct map_symbol { |
127 | struct map *map; | |
128 | struct symbol *sym; | |
0f0cbf7a ACM |
129 | bool unfolded; |
130 | bool has_children; | |
59fd5306 ACM |
131 | }; |
132 | ||
b5387528 RAV |
133 | struct addr_map_symbol { |
134 | struct map *map; | |
135 | struct symbol *sym; | |
136 | u64 addr; | |
a68c2c58 | 137 | u64 al_addr; |
b5387528 RAV |
138 | }; |
139 | ||
140 | struct branch_info { | |
141 | struct addr_map_symbol from; | |
142 | struct addr_map_symbol to; | |
143 | struct branch_flags flags; | |
144 | }; | |
145 | ||
1ed091c4 ACM |
146 | struct addr_location { |
147 | struct thread *thread; | |
148 | struct map *map; | |
149 | struct symbol *sym; | |
150 | u64 addr; | |
151 | char level; | |
c410a338 | 152 | bool filtered; |
f60f3593 AS |
153 | u8 cpumode; |
154 | s32 cpu; | |
a1645ce1 ZY |
155 | }; |
156 | ||
157 | enum dso_kernel_type { | |
158 | DSO_TYPE_USER = 0, | |
159 | DSO_TYPE_KERNEL, | |
160 | DSO_TYPE_GUEST_KERNEL | |
1ed091c4 ACM |
161 | }; |
162 | ||
a2928c42 ACM |
163 | struct dso { |
164 | struct list_head node; | |
6a4694a4 | 165 | struct rb_root symbols[MAP__NR_TYPES]; |
79406cd7 | 166 | struct rb_root symbol_names[MAP__NR_TYPES]; |
6e406257 | 167 | enum dso_kernel_type kernel; |
8d06367f | 168 | u8 adjust_symbols:1; |
8d06367f | 169 | u8 has_build_id:1; |
88d3d9b7 | 170 | u8 hit:1; |
d06d92b7 | 171 | u8 annotate_warned:1; |
6e406257 ACM |
172 | u8 sname_alloc:1; |
173 | u8 lname_alloc:1; | |
878b439d | 174 | unsigned char symtab_type; |
79406cd7 | 175 | u8 sorted_by_name; |
3610583c | 176 | u8 loaded; |
8d06367f | 177 | u8 build_id[BUILD_ID_SIZE]; |
439d473b ACM |
178 | const char *short_name; |
179 | char *long_name; | |
b63be8d7 ACM |
180 | u16 long_name_len; |
181 | u16 short_name_len; | |
a2928c42 ACM |
182 | char name[0]; |
183 | }; | |
184 | ||
00a192b3 | 185 | struct dso *dso__new(const char *name); |
aeafcbaf | 186 | void dso__delete(struct dso *dso); |
a2928c42 | 187 | |
aeafcbaf | 188 | int dso__name_len(const struct dso *dso); |
8a6c5b26 | 189 | |
aeafcbaf ACM |
190 | bool dso__loaded(const struct dso *dso, enum map_type type); |
191 | bool dso__sorted_by_name(const struct dso *dso, enum map_type type); | |
79406cd7 | 192 | |
aeafcbaf | 193 | static inline void dso__set_loaded(struct dso *dso, enum map_type type) |
8d92c02a | 194 | { |
aeafcbaf | 195 | dso->loaded |= (1 << type); |
8d92c02a ACM |
196 | } |
197 | ||
aeafcbaf | 198 | void dso__sort_by_name(struct dso *dso, enum map_type type); |
3610583c | 199 | |
a89e5abe ACM |
200 | struct dso *__dsos__findnew(struct list_head *head, const char *name); |
201 | ||
aeafcbaf ACM |
202 | int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); |
203 | int dso__load_vmlinux(struct dso *dso, struct map *map, | |
fd930ff9 | 204 | const char *vmlinux, symbol_filter_t filter); |
aeafcbaf | 205 | int dso__load_vmlinux_path(struct dso *dso, struct map *map, |
9de89fe7 | 206 | symbol_filter_t filter); |
aeafcbaf | 207 | int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map, |
9de89fe7 | 208 | symbol_filter_t filter); |
aeafcbaf | 209 | int machine__load_kallsyms(struct machine *machine, const char *filename, |
5c0541d5 | 210 | enum map_type type, symbol_filter_t filter); |
aeafcbaf | 211 | int machine__load_vmlinux_path(struct machine *machine, enum map_type type, |
5c0541d5 ACM |
212 | symbol_filter_t filter); |
213 | ||
1f626bc3 ACM |
214 | size_t __dsos__fprintf(struct list_head *head, FILE *fp); |
215 | ||
aeafcbaf ACM |
216 | size_t machine__fprintf_dsos_buildid(struct machine *machine, |
217 | FILE *fp, bool with_hits); | |
218 | size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); | |
219 | size_t machines__fprintf_dsos_buildid(struct rb_root *machines, | |
220 | FILE *fp, bool with_hits); | |
221 | size_t dso__fprintf_buildid(struct dso *dso, FILE *fp); | |
222 | size_t dso__fprintf_symbols_by_name(struct dso *dso, | |
223 | enum map_type type, FILE *fp); | |
224 | size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); | |
b0a9ab62 | 225 | |
878b439d ACM |
226 | enum symtab_type { |
227 | SYMTAB__KALLSYMS = 0, | |
228 | SYMTAB__GUEST_KALLSYMS, | |
229 | SYMTAB__JAVA_JIT, | |
230 | SYMTAB__BUILD_ID_CACHE, | |
231 | SYMTAB__FEDORA_DEBUGINFO, | |
232 | SYMTAB__UBUNTU_DEBUGINFO, | |
233 | SYMTAB__BUILDID_DEBUGINFO, | |
234 | SYMTAB__SYSTEM_PATH_DSO, | |
235 | SYMTAB__GUEST_KMODULE, | |
236 | SYMTAB__SYSTEM_PATH_KMODULE, | |
237 | SYMTAB__NOT_FOUND, | |
b0a9ab62 ACM |
238 | }; |
239 | ||
aeafcbaf ACM |
240 | char dso__symtab_origin(const struct dso *dso); |
241 | void dso__set_long_name(struct dso *dso, char *name); | |
242 | void dso__set_build_id(struct dso *dso, void *build_id); | |
243 | void dso__read_running_kernel_build_id(struct dso *dso, | |
244 | struct machine *machine); | |
225466f1 | 245 | struct map *dso__new_map(const char *name); |
aeafcbaf ACM |
246 | struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, |
247 | u64 addr); | |
248 | struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, | |
79406cd7 | 249 | const char *name); |
a2928c42 | 250 | |
2643ce11 | 251 | int filename__read_build_id(const char *filename, void *bf, size_t size); |
f1617b40 | 252 | int sysfs__read_build_id(const char *filename, void *bf, size_t size); |
a1645ce1 | 253 | bool __dsos__read_build_ids(struct list_head *head, bool with_hits); |
aeafcbaf | 254 | int build_id__sprintf(const u8 *build_id, int len, char *bf); |
9e201442 ACM |
255 | int kallsyms__parse(const char *filename, void *arg, |
256 | int (*process_symbol)(void *arg, const char *name, | |
3b01a413 | 257 | char type, u64 start, u64 end)); |
2643ce11 | 258 | |
aeafcbaf ACM |
259 | void machine__destroy_kernel_maps(struct machine *machine); |
260 | int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); | |
261 | int machine__create_kernel_maps(struct machine *machine); | |
5c0541d5 | 262 | |
aeafcbaf ACM |
263 | int machines__create_kernel_maps(struct rb_root *machines, pid_t pid); |
264 | int machines__create_guest_kernel_maps(struct rb_root *machines); | |
265 | void machines__destroy_guest_kernel_maps(struct rb_root *machines); | |
a1645ce1 | 266 | |
75be6cf4 | 267 | int symbol__init(void); |
d65a458b | 268 | void symbol__exit(void); |
a978f2ab AN |
269 | size_t symbol__fprintf_symname_offs(const struct symbol *sym, |
270 | const struct addr_location *al, FILE *fp); | |
547a92e0 | 271 | size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp); |
36a3e646 ACM |
272 | bool symbol_type__is_a(char symbol_type, enum map_type map_type); |
273 | ||
aeafcbaf | 274 | size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); |
b0a9ab62 | 275 | |
8b40f521 | 276 | #endif /* __PERF_SYMBOL */ |