symbol.h 6.0 KB

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