symbol.h 6.2 KB

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