2 #define __PERF_SYMBOL 1
4 #include <linux/types.h>
9 #include <linux/list.h>
10 #include <linux/rbtree.h>
21 #ifdef HAVE_CPLUS_DEMANGLE
22 extern char *cplus_demangle(const char *, int);
24 static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i)
26 return cplus_demangle(c, i);
30 static inline char *bfd_demangle(void __maybe_unused *v,
31 const char __maybe_unused *c,
37 #define PACKAGE 'perf'
42 int hex2u64(const char *ptr, u64 *val);
43 char *strxfrchar(char *s, char from, char to);
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:
50 # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
52 # define PERF_ELF_C_READ_MMAP ELF_C_READ
56 #define DMGL_PARAMS (1 << 0) /* Include function args */
57 #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
60 #define BUILD_ID_SIZE 20
62 /** struct symbol - symtab entry
64 * @ignore - resolvable but tools ignore it (e.g. idle routines)
67 struct rb_node rb_node;
76 void symbol__delete(struct symbol *sym);
78 static inline size_t symbol__size(const struct symbol *sym)
80 return sym->end - sym->start + 1;
86 unsigned short priv_size;
87 unsigned short nr_events;
88 bool try_vmlinux_path,
101 const char *vmlinux_name,
105 const char *default_guest_vmlinux_name,
106 *default_guest_kallsyms,
107 *default_guest_modules;
108 const char *guestmount;
109 const char *dso_list_str,
113 struct strlist *dso_list,
123 extern struct symbol_conf symbol_conf;
125 static inline void *symbol__priv(struct symbol *sym)
127 return ((void *)sym) - symbol_conf.priv_size;
130 struct ref_reloc_sym {
133 u64 unrelocated_addr;
143 struct addr_map_symbol {
151 struct addr_map_symbol from;
152 struct addr_map_symbol to;
153 struct branch_flags flags;
156 struct addr_location {
157 struct thread *thread;
167 enum dso_binary_type {
168 DSO_BINARY_TYPE__KALLSYMS = 0,
169 DSO_BINARY_TYPE__GUEST_KALLSYMS,
170 DSO_BINARY_TYPE__VMLINUX,
171 DSO_BINARY_TYPE__GUEST_VMLINUX,
172 DSO_BINARY_TYPE__JAVA_JIT,
173 DSO_BINARY_TYPE__DEBUGLINK,
174 DSO_BINARY_TYPE__BUILD_ID_CACHE,
175 DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
176 DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
177 DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
178 DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
179 DSO_BINARY_TYPE__GUEST_KMODULE,
180 DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
181 DSO_BINARY_TYPE__NOT_FOUND,
184 enum dso_kernel_type {
187 DSO_TYPE_GUEST_KERNEL
196 #define DSO__DATA_CACHE_SIZE 4096
197 #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
200 struct rb_node rb_node;
207 struct list_head node;
208 struct rb_root symbols[MAP__NR_TYPES];
209 struct rb_root symbol_names[MAP__NR_TYPES];
210 struct rb_root cache;
211 enum dso_kernel_type kernel;
212 enum dso_swap_type needs_swap;
213 enum dso_binary_type symtab_type;
214 enum dso_binary_type data_type;
218 u8 annotate_warned:1;
223 u8 build_id[BUILD_ID_SIZE];
224 const char *short_name;
234 enum dso_binary_type type;
236 #ifdef LIBELF_SUPPORT
255 void symsrc__destroy(struct symsrc *ss);
256 int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
257 enum dso_binary_type type);
258 bool symsrc__has_symtab(struct symsrc *ss);
259 bool symsrc__possibly_runtime(struct symsrc *ss);
261 #define DSO__SWAP(dso, type, val) \
264 BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
265 if (dso->needs_swap == DSO_SWAP__YES) { \
266 switch (sizeof(____r)) { \
268 ____r = bswap_16(val); \
271 ____r = bswap_32(val); \
274 ____r = bswap_64(val); \
283 struct dso *dso__new(const char *name);
284 void dso__delete(struct dso *dso);
286 int dso__name_len(const struct dso *dso);
288 bool dso__loaded(const struct dso *dso, enum map_type type);
289 bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
291 static inline void dso__set_loaded(struct dso *dso, enum map_type type)
293 dso->loaded |= (1 << type);
296 void dso__sort_by_name(struct dso *dso, enum map_type type);
298 void dsos__add(struct list_head *head, struct dso *dso);
299 struct dso *dsos__find(struct list_head *head, const char *name);
300 struct dso *__dsos__findnew(struct list_head *head, const char *name);
302 int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
303 int dso__load_vmlinux(struct dso *dso, struct map *map,
304 const char *vmlinux, symbol_filter_t filter);
305 int dso__load_vmlinux_path(struct dso *dso, struct map *map,
306 symbol_filter_t filter);
307 int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
308 symbol_filter_t filter);
309 int machine__load_kallsyms(struct machine *machine, const char *filename,
310 enum map_type type, symbol_filter_t filter);
311 int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
312 symbol_filter_t filter);
314 size_t __dsos__fprintf(struct list_head *head, FILE *fp);
316 size_t machine__fprintf_dsos_buildid(struct machine *machine,
317 FILE *fp, bool with_hits);
318 size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
319 size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
320 FILE *fp, bool with_hits);
321 size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
322 size_t dso__fprintf_symbols_by_name(struct dso *dso,
323 enum map_type type, FILE *fp);
324 size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
326 char dso__symtab_origin(const struct dso *dso);
327 void dso__set_long_name(struct dso *dso, char *name);
328 void dso__set_build_id(struct dso *dso, void *build_id);
329 bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
330 void dso__read_running_kernel_build_id(struct dso *dso,
331 struct machine *machine);
332 struct map *dso__new_map(const char *name);
333 struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
335 struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
338 int filename__read_build_id(const char *filename, void *bf, size_t size);
339 int sysfs__read_build_id(const char *filename, void *bf, size_t size);
340 bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
341 int build_id__sprintf(const u8 *build_id, int len, char *bf);
342 int kallsyms__parse(const char *filename, void *arg,
343 int (*process_symbol)(void *arg, const char *name,
344 char type, u64 start));
345 int filename__read_debuglink(const char *filename, char *debuglink,
348 void machine__destroy_kernel_maps(struct machine *machine);
349 int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
350 int machine__create_kernel_maps(struct machine *machine);
352 int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
353 int machines__create_guest_kernel_maps(struct rb_root *machines);
354 void machines__destroy_guest_kernel_maps(struct rb_root *machines);
356 int symbol__init(void);
357 void symbol__exit(void);
358 void symbol__elf_init(void);
359 struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
360 size_t symbol__fprintf_symname_offs(const struct symbol *sym,
361 const struct addr_location *al, FILE *fp);
362 size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
363 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
365 size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
367 int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
368 char *root_dir, char *file, size_t size);
370 int dso__data_fd(struct dso *dso, struct machine *machine);
371 ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
372 u64 offset, u8 *data, ssize_t size);
373 ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
374 struct machine *machine, u64 addr,
375 u8 *data, ssize_t size);
376 int dso__test_data(void);
377 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
378 struct symsrc *runtime_ss, symbol_filter_t filter,
380 int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
381 struct map *map, symbol_filter_t filter);
383 void symbols__insert(struct rb_root *symbols, struct symbol *sym);
384 void symbols__fixup_duplicate(struct rb_root *symbols);
385 void symbols__fixup_end(struct rb_root *symbols);
386 void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
388 #endif /* __PERF_SYMBOL */