symbol.h 7.1 KB

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