symbol.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. struct strlist;
  59. struct symbol_conf {
  60. unsigned short priv_size;
  61. unsigned short nr_events;
  62. bool try_vmlinux_path,
  63. show_kernel_path,
  64. use_modules,
  65. sort_by_name,
  66. show_nr_samples,
  67. show_total_period,
  68. use_callchain,
  69. exclude_other,
  70. show_cpu_utilization,
  71. initialized,
  72. kptr_restrict,
  73. annotate_asm_raw,
  74. annotate_src;
  75. const char *vmlinux_name,
  76. *kallsyms_name,
  77. *source_prefix,
  78. *field_sep;
  79. const char *default_guest_vmlinux_name,
  80. *default_guest_kallsyms,
  81. *default_guest_modules;
  82. const char *guestmount;
  83. const char *dso_list_str,
  84. *comm_list_str,
  85. *sym_list_str,
  86. *col_width_list_str;
  87. struct strlist *dso_list,
  88. *comm_list,
  89. *sym_list,
  90. *dso_from_list,
  91. *dso_to_list,
  92. *sym_from_list,
  93. *sym_to_list;
  94. const char *symfs;
  95. };
  96. extern struct symbol_conf symbol_conf;
  97. static inline void *symbol__priv(struct symbol *sym)
  98. {
  99. return ((void *)sym) - symbol_conf.priv_size;
  100. }
  101. struct ref_reloc_sym {
  102. const char *name;
  103. u64 addr;
  104. u64 unrelocated_addr;
  105. };
  106. struct map_symbol {
  107. struct map *map;
  108. struct symbol *sym;
  109. bool unfolded;
  110. bool has_children;
  111. };
  112. struct addr_map_symbol {
  113. struct map *map;
  114. struct symbol *sym;
  115. u64 addr;
  116. u64 al_addr;
  117. };
  118. struct branch_info {
  119. struct addr_map_symbol from;
  120. struct addr_map_symbol to;
  121. struct branch_flags flags;
  122. };
  123. struct addr_location {
  124. struct thread *thread;
  125. struct map *map;
  126. struct symbol *sym;
  127. u64 addr;
  128. char level;
  129. bool filtered;
  130. u8 cpumode;
  131. s32 cpu;
  132. };
  133. enum dso_kernel_type {
  134. DSO_TYPE_USER = 0,
  135. DSO_TYPE_KERNEL,
  136. DSO_TYPE_GUEST_KERNEL
  137. };
  138. struct dso {
  139. struct list_head node;
  140. struct rb_root symbols[MAP__NR_TYPES];
  141. struct rb_root symbol_names[MAP__NR_TYPES];
  142. enum dso_kernel_type kernel;
  143. u8 adjust_symbols:1;
  144. u8 has_build_id:1;
  145. u8 hit:1;
  146. u8 annotate_warned:1;
  147. u8 sname_alloc:1;
  148. u8 lname_alloc:1;
  149. unsigned char symtab_type;
  150. u8 sorted_by_name;
  151. u8 loaded;
  152. u8 build_id[BUILD_ID_SIZE];
  153. const char *short_name;
  154. char *long_name;
  155. u16 long_name_len;
  156. u16 short_name_len;
  157. char name[0];
  158. };
  159. struct dso *dso__new(const char *name);
  160. void dso__delete(struct dso *dso);
  161. int dso__name_len(const struct dso *dso);
  162. bool dso__loaded(const struct dso *dso, enum map_type type);
  163. bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
  164. static inline void dso__set_loaded(struct dso *dso, enum map_type type)
  165. {
  166. dso->loaded |= (1 << type);
  167. }
  168. void dso__sort_by_name(struct dso *dso, enum map_type type);
  169. struct dso *__dsos__findnew(struct list_head *head, const char *name);
  170. int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
  171. int dso__load_vmlinux(struct dso *dso, struct map *map,
  172. const char *vmlinux, symbol_filter_t filter);
  173. int dso__load_vmlinux_path(struct dso *dso, struct map *map,
  174. symbol_filter_t filter);
  175. int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
  176. symbol_filter_t filter);
  177. int machine__load_kallsyms(struct machine *machine, const char *filename,
  178. enum map_type type, symbol_filter_t filter);
  179. int machine__load_vmlinux_path(struct machine *machine, enum map_type type,
  180. symbol_filter_t filter);
  181. size_t __dsos__fprintf(struct list_head *head, FILE *fp);
  182. size_t machine__fprintf_dsos_buildid(struct machine *machine,
  183. FILE *fp, bool with_hits);
  184. size_t machines__fprintf_dsos(struct rb_root *machines, FILE *fp);
  185. size_t machines__fprintf_dsos_buildid(struct rb_root *machines,
  186. FILE *fp, bool with_hits);
  187. size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
  188. size_t dso__fprintf_symbols_by_name(struct dso *dso,
  189. enum map_type type, FILE *fp);
  190. size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
  191. enum symtab_type {
  192. SYMTAB__KALLSYMS = 0,
  193. SYMTAB__GUEST_KALLSYMS,
  194. SYMTAB__JAVA_JIT,
  195. SYMTAB__BUILD_ID_CACHE,
  196. SYMTAB__FEDORA_DEBUGINFO,
  197. SYMTAB__UBUNTU_DEBUGINFO,
  198. SYMTAB__BUILDID_DEBUGINFO,
  199. SYMTAB__SYSTEM_PATH_DSO,
  200. SYMTAB__GUEST_KMODULE,
  201. SYMTAB__SYSTEM_PATH_KMODULE,
  202. SYMTAB__NOT_FOUND,
  203. };
  204. char dso__symtab_origin(const struct dso *dso);
  205. void dso__set_long_name(struct dso *dso, char *name);
  206. void dso__set_build_id(struct dso *dso, void *build_id);
  207. void dso__read_running_kernel_build_id(struct dso *dso,
  208. struct machine *machine);
  209. struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
  210. u64 addr);
  211. struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
  212. const char *name);
  213. int filename__read_build_id(const char *filename, void *bf, size_t size);
  214. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  215. bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
  216. int build_id__sprintf(const u8 *build_id, int len, char *bf);
  217. int kallsyms__parse(const char *filename, void *arg,
  218. int (*process_symbol)(void *arg, const char *name,
  219. char type, u64 start, u64 end));
  220. void machine__destroy_kernel_maps(struct machine *machine);
  221. int __machine__create_kernel_maps(struct machine *machine, struct dso *kernel);
  222. int machine__create_kernel_maps(struct machine *machine);
  223. int machines__create_kernel_maps(struct rb_root *machines, pid_t pid);
  224. int machines__create_guest_kernel_maps(struct rb_root *machines);
  225. void machines__destroy_guest_kernel_maps(struct rb_root *machines);
  226. int symbol__init(void);
  227. void symbol__exit(void);
  228. size_t symbol__fprintf_symname_offs(const struct symbol *sym,
  229. const struct addr_location *al, FILE *fp);
  230. size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
  231. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  232. size_t machine__fprintf_vmlinux_path(struct machine *machine, FILE *fp);
  233. #endif /* __PERF_SYMBOL */