symbol.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. #define DEBUG_CACHE_DIR ".debug"
  11. #ifdef HAVE_CPLUS_DEMANGLE
  12. extern char *cplus_demangle(const char *, int);
  13. static inline char *bfd_demangle(void __used *v, const char *c, int i)
  14. {
  15. return cplus_demangle(c, i);
  16. }
  17. #else
  18. #ifdef NO_DEMANGLE
  19. static inline char *bfd_demangle(void __used *v, const char __used *c,
  20. int __used i)
  21. {
  22. return NULL;
  23. }
  24. #else
  25. #include <bfd.h>
  26. #endif
  27. #endif
  28. int hex2u64(const char *ptr, u64 *val);
  29. char *strxfrchar(char *s, char from, char to);
  30. /*
  31. * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
  32. * for newer versions we can use mmap to reduce memory usage:
  33. */
  34. #ifdef LIBELF_NO_MMAP
  35. # define PERF_ELF_C_READ_MMAP ELF_C_READ
  36. #else
  37. # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
  38. #endif
  39. #ifndef DMGL_PARAMS
  40. #define DMGL_PARAMS (1 << 0) /* Include function args */
  41. #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
  42. #endif
  43. #define BUILD_ID_SIZE 20
  44. struct symbol {
  45. struct rb_node rb_node;
  46. u64 start;
  47. u64 end;
  48. u16 namelen;
  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. full_paths,
  62. show_cpu_utilization;
  63. const char *vmlinux_name,
  64. *field_sep;
  65. const char *default_guest_vmlinux_name,
  66. *default_guest_kallsyms,
  67. *default_guest_modules;
  68. const char *guestmount;
  69. const char *dso_list_str,
  70. *comm_list_str,
  71. *sym_list_str,
  72. *col_width_list_str;
  73. struct strlist *dso_list,
  74. *comm_list,
  75. *sym_list;
  76. };
  77. extern struct symbol_conf symbol_conf;
  78. static inline void *symbol__priv(struct symbol *self)
  79. {
  80. return ((void *)self) - symbol_conf.priv_size;
  81. }
  82. struct ref_reloc_sym {
  83. const char *name;
  84. u64 addr;
  85. u64 unrelocated_addr;
  86. };
  87. struct map_symbol {
  88. struct map *map;
  89. struct symbol *sym;
  90. };
  91. struct addr_location {
  92. struct thread *thread;
  93. struct map *map;
  94. struct symbol *sym;
  95. u64 addr;
  96. char level;
  97. bool filtered;
  98. unsigned int cpumode;
  99. };
  100. enum dso_kernel_type {
  101. DSO_TYPE_USER = 0,
  102. DSO_TYPE_KERNEL,
  103. DSO_TYPE_GUEST_KERNEL
  104. };
  105. struct dso {
  106. struct list_head node;
  107. struct rb_root symbols[MAP__NR_TYPES];
  108. struct rb_root symbol_names[MAP__NR_TYPES];
  109. u8 adjust_symbols:1;
  110. u8 slen_calculated:1;
  111. u8 has_build_id:1;
  112. enum dso_kernel_type kernel;
  113. u8 hit:1;
  114. u8 annotate_warned:1;
  115. unsigned char origin;
  116. u8 sorted_by_name;
  117. u8 loaded;
  118. u8 build_id[BUILD_ID_SIZE];
  119. const char *short_name;
  120. char *long_name;
  121. u16 long_name_len;
  122. u16 short_name_len;
  123. char name[0];
  124. };
  125. struct dso *dso__new(const char *name);
  126. struct dso *dso__new_kernel(const char *name);
  127. void dso__delete(struct dso *self);
  128. bool dso__loaded(const struct dso *self, enum map_type type);
  129. bool dso__sorted_by_name(const struct dso *self, enum map_type type);
  130. static inline void dso__set_loaded(struct dso *self, enum map_type type)
  131. {
  132. self->loaded |= (1 << type);
  133. }
  134. void dso__sort_by_name(struct dso *self, enum map_type type);
  135. struct dso *__dsos__findnew(struct list_head *head, const char *name);
  136. int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
  137. int dso__load_vmlinux_path(struct dso *self, struct map *map,
  138. symbol_filter_t filter);
  139. int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
  140. symbol_filter_t filter);
  141. int machine__load_kallsyms(struct machine *self, const char *filename,
  142. enum map_type type, symbol_filter_t filter);
  143. int machine__load_vmlinux_path(struct machine *self, enum map_type type,
  144. symbol_filter_t filter);
  145. size_t __dsos__fprintf(struct list_head *head, FILE *fp);
  146. size_t machine__fprintf_dsos_buildid(struct machine *self, FILE *fp, bool with_hits);
  147. size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp);
  148. size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits);
  149. size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
  150. size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
  151. enum dso_origin {
  152. DSO__ORIG_KERNEL = 0,
  153. DSO__ORIG_GUEST_KERNEL,
  154. DSO__ORIG_JAVA_JIT,
  155. DSO__ORIG_BUILD_ID_CACHE,
  156. DSO__ORIG_FEDORA,
  157. DSO__ORIG_UBUNTU,
  158. DSO__ORIG_BUILDID,
  159. DSO__ORIG_DSO,
  160. DSO__ORIG_GUEST_KMODULE,
  161. DSO__ORIG_KMODULE,
  162. DSO__ORIG_NOT_FOUND,
  163. };
  164. char dso__symtab_origin(const struct dso *self);
  165. void dso__set_long_name(struct dso *self, char *name);
  166. void dso__set_build_id(struct dso *self, void *build_id);
  167. void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine);
  168. struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
  169. struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
  170. const char *name);
  171. int filename__read_build_id(const char *filename, void *bf, size_t size);
  172. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  173. bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
  174. int build_id__sprintf(const u8 *self, int len, char *bf);
  175. int kallsyms__parse(const char *filename, void *arg,
  176. int (*process_symbol)(void *arg, const char *name,
  177. char type, u64 start));
  178. int __machine__create_kernel_maps(struct machine *self, struct dso *kernel);
  179. int machine__create_kernel_maps(struct machine *self);
  180. int machines__create_kernel_maps(struct rb_root *self, pid_t pid);
  181. int machines__create_guest_kernel_maps(struct rb_root *self);
  182. int symbol__init(void);
  183. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  184. size_t machine__fprintf_vmlinux_path(struct machine *self, FILE *fp);
  185. #endif /* __PERF_SYMBOL */