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