symbol.h 6.5 KB

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