symbol.h 6.7 KB

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