symbol.h revision 4eb881eab369a68754cb352bd8c73cd363757d28
1#ifndef __PERF_SYMBOL 2#define __PERF_SYMBOL 1 3 4/* ANDROID_CHANGE_BEGIN */ 5#ifndef __APPLE__ 6#include <features.h> // Suppress kernel-name space pollution in <linux/types.h> below 7# include <linux/types.h> 8#endif 9/* ANDROID_CHANGE_END */ 10#include <stdbool.h> 11#include <stdint.h> 12#include "map.h" 13/* ANDROID_CHANGE_BEGIN */ 14#if 0 15#include <linux/list.h> 16#include <linux/rbtree.h> 17#else 18#include "include/linux/list.h" 19#include "include/linux/rbtree.h" 20#endif 21/* ANDROID_CHANGE_END */ 22#include <stdio.h> 23 24#ifdef HAVE_CPLUS_DEMANGLE 25extern char *cplus_demangle(const char *, int); 26 27static inline char *bfd_demangle(void __used *v, const char *c, int i) 28{ 29 return cplus_demangle(c, i); 30} 31#else 32#ifdef NO_DEMANGLE 33static inline char *bfd_demangle(void __used *v, const char __used *c, 34 int __used i) 35{ 36 return NULL; 37} 38#else 39#include <bfd.h> 40#endif 41#endif 42 43int hex2u64(const char *ptr, u64 *val); 44char *strxfrchar(char *s, char from, char to); 45 46/* 47 * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP; 48 * for newer versions we can use mmap to reduce memory usage: 49 */ 50#ifdef LIBELF_NO_MMAP 51# define PERF_ELF_C_READ_MMAP ELF_C_READ 52#else 53# define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP 54#endif 55 56#ifndef DMGL_PARAMS 57#define DMGL_PARAMS (1 << 0) /* Include function args */ 58#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */ 59#endif 60 61#define BUILD_ID_SIZE 20 62 63/** struct symbol - symtab entry 64 * 65 * @ignore - resolvable but tools ignore it (e.g. idle routines) 66 */ 67struct symbol { 68 struct rb_node rb_node; 69 u64 start; 70 u64 end; 71 u16 namelen; 72 u8 binding; 73 bool ignore; 74 char name[0]; 75}; 76 77void symbol__delete(struct symbol *sym); 78 79struct strlist; 80 81struct symbol_conf { 82 unsigned short priv_size; 83 bool try_vmlinux_path, 84 use_modules, 85 sort_by_name, 86 show_nr_samples, 87 use_callchain, 88 exclude_other, 89 show_cpu_utilization, 90 initialized, 91 kptr_restrict; 92 const char *vmlinux_name, 93 *kallsyms_name, 94 *source_prefix, 95 *field_sep; 96 const char *default_guest_vmlinux_name, 97 *default_guest_kallsyms, 98 *default_guest_modules; 99 const char *guestmount; 100 const char *dso_list_str, 101 *comm_list_str, 102 *sym_list_str, 103 *col_width_list_str; 104 struct strlist *dso_list, 105 *comm_list, 106 *sym_list; 107 const char *symfs; 108}; 109 110extern struct symbol_conf symbol_conf; 111 112static inline void *symbol__priv(struct symbol *sym) 113{ 114 return ((void *)sym) - symbol_conf.priv_size; 115} 116 117struct ref_reloc_sym { 118 const char *name; 119 u64 addr; 120 u64 unrelocated_addr; 121}; 122 123struct map_symbol { 124 struct map *map; 125 struct symbol *sym; 126 bool unfolded; 127 bool has_children; 128}; 129 130struct addr_location { 131 struct thread *thread; 132 struct map *map; 133 struct symbol *sym; 134 u64 addr; 135 char level; 136 bool filtered; 137 u8 cpumode; 138 s32 cpu; 139}; 140 141enum dso_kernel_type { 142 DSO_TYPE_USER = 0, 143 DSO_TYPE_KERNEL, 144 DSO_TYPE_GUEST_KERNEL 145}; 146 147struct dso { 148 struct list_head node; 149 struct rb_root symbols[MAP__NR_TYPES]; 150 struct rb_root symbol_names[MAP__NR_TYPES]; 151 enum dso_kernel_type kernel; 152 u8 adjust_symbols:1; 153 u8 has_build_id:1; 154 u8 hit:1; 155 u8 annotate_warned:1; 156 u8 sname_alloc:1; 157 u8 lname_alloc:1; 158 unsigned char symtab_type; 159 u8 sorted_by_name; 160 u8 loaded; 161 u8 build_id[BUILD_ID_SIZE]; 162 const char *short_name; 163 char *long_name; 164 u16 long_name_len; 165 u16 short_name_len; 166 char name[0]; 167}; 168 169struct dso *dso__new(const char *name); 170struct dso *dso__new_kernel(const char *name); 171void dso__delete(struct dso *dso); 172 173int dso__name_len(const struct dso *dso); 174 175bool dso__loaded(const struct dso *dso, enum map_type type); 176bool dso__sorted_by_name(const struct dso *dso, enum map_type type); 177 178static inline void dso__set_loaded(struct dso *dso, enum map_type type) 179{ 180 dso->loaded |= (1 << type); 181} 182 183void dso__sort_by_name(struct dso *dso, enum map_type type); 184 185struct dso *__dsos__findnew(struct list_head *head, const char *name); 186 187int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter); 188int dso__load_vmlinux(struct dso *dso, struct map *map, 189 const char *vmlinux, symbol_filter_t filter); 190int dso__load_vmlinux_path(struct dso *dso, struct map *map, 191 symbol_filter_t filter); 192int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map, 193 symbol_filter_t filter); 194int machine__load_kallsyms(struct machine *machine, const char *filename, 195 enum map_type type, symbol_filter_t filter); 196int machine__load_vmlinux_path(struct machine *machine, enum map_type type, 197 symbol_filter_t filter); 198 199size_t __dsos__fprintf(struct list_head *head, FILE *fp); 200 201size_t machine__fprintf_dsos_buildid(struct machine *machine, 202 FILE *fp, bool with_hits); 203size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp); 204size_t machines__fprintf_dsos_buildid(struct rb_root *machines, 205 FILE *fp, bool with_hits); 206size_t dso__fprintf_buildid(struct dso *dso, FILE *fp); 207size_t dso__fprintf_symbols_by_name(struct dso *dso, 208 enum map_type type, FILE *fp); 209size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp); 210 211enum symtab_type { 212 SYMTAB__KALLSYMS = 0, 213 SYMTAB__GUEST_KALLSYMS, 214 SYMTAB__JAVA_JIT, 215 SYMTAB__BUILD_ID_CACHE, 216 SYMTAB__FEDORA_DEBUGINFO, 217 SYMTAB__UBUNTU_DEBUGINFO, 218 SYMTAB__BUILDID_DEBUGINFO, 219 SYMTAB__SYSTEM_PATH_DSO, 220 SYMTAB__GUEST_KMODULE, 221 SYMTAB__SYSTEM_PATH_KMODULE, 222 SYMTAB__NOT_FOUND, 223}; 224 225char dso__symtab_origin(const struct dso *dso); 226void dso__set_long_name(struct dso *dso, char *name); 227void dso__set_build_id(struct dso *dso, void *build_id); 228void dso__read_running_kernel_build_id(struct dso *dso, 229 struct machine *machine); 230struct symbol *dso__find_symbol(struct dso *dso, enum map_type type, 231 u64 addr); 232struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type, 233 const char *name); 234 235int filename__read_build_id(const char *filename, void *bf, size_t size); 236int sysfs__read_build_id(const char *filename, void *bf, size_t size); 237bool __dsos__read_build_ids(struct list_head *head, bool with_hits); 238int build_id__sprintf(const u8 *build_id, int len, char *bf); 239int kallsyms__parse(const char *filename, void *arg, 240 int (*process_symbol)(void *arg, const char *name, 241 char type, u64 start, u64 end)); 242 243void machine__destroy_kernel_maps(struct machine *machine); 244int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel); 245int machine__create_kernel_maps(struct machine *machine); 246 247int machines__create_kernel_maps(struct rb_root *machines, pid_t pid); 248int machines__create_guest_kernel_maps(struct rb_root *machines); 249void machines__destroy_guest_kernel_maps(struct rb_root *machines); 250 251int symbol__init(void); 252void symbol__exit(void); 253bool symbol_type__is_a(char symbol_type, enum map_type map_type); 254 255size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp); 256 257#endif /* __PERF_SYMBOL */ 258