symbol.h 6.3 KB

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