symbol.h 6.4 KB

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