symbol.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 "../perf.h"
  8. #include <linux/list.h>
  9. #include <linux/rbtree.h>
  10. #include <stdio.h>
  11. #include <byteswap.h>
  12. #include <libgen.h>
  13. #include "build-id.h"
  14. #ifdef LIBELF_SUPPORT
  15. #include <libelf.h>
  16. #include <gelf.h>
  17. #include <elf.h>
  18. #endif
  19. #include "dso.h"
  20. #ifdef HAVE_CPLUS_DEMANGLE
  21. extern char *cplus_demangle(const char *, int);
  22. static inline char *bfd_demangle(void __maybe_unused *v, const char *c, int i)
  23. {
  24. return cplus_demangle(c, i);
  25. }
  26. #else
  27. #ifdef NO_DEMANGLE
  28. static inline char *bfd_demangle(void __maybe_unused *v,
  29. const char __maybe_unused *c,
  30. int __maybe_unused i)
  31. {
  32. return NULL;
  33. }
  34. #else
  35. #define PACKAGE 'perf'
  36. #include <bfd.h>
  37. #endif
  38. #endif
  39. /*
  40. * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
  41. * for newer versions we can use mmap to reduce memory usage:
  42. */
  43. #ifdef LIBELF_MMAP
  44. # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
  45. #else
  46. # define PERF_ELF_C_READ_MMAP ELF_C_READ
  47. #endif
  48. #ifndef DMGL_PARAMS
  49. #define DMGL_PARAMS (1 << 0) /* Include function args */
  50. #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
  51. #endif
  52. /** struct symbol - symtab entry
  53. *
  54. * @ignore - resolvable but tools ignore it (e.g. idle routines)
  55. */
  56. struct symbol {
  57. struct rb_node rb_node;
  58. u64 start;
  59. u64 end;
  60. u16 namelen;
  61. u8 binding;
  62. bool ignore;
  63. char name[0];
  64. };
  65. void symbol__delete(struct symbol *sym);
  66. void symbols__delete(struct rb_root *symbols);
  67. static inline size_t symbol__size(const struct symbol *sym)
  68. {
  69. return sym->end - sym->start + 1;
  70. }
  71. struct strlist;
  72. struct symbol_conf {
  73. unsigned short priv_size;
  74. unsigned short nr_events;
  75. bool try_vmlinux_path,
  76. show_kernel_path,
  77. use_modules,
  78. sort_by_name,
  79. show_nr_samples,
  80. show_total_period,
  81. use_callchain,
  82. exclude_other,
  83. show_cpu_utilization,
  84. initialized,
  85. kptr_restrict,
  86. annotate_asm_raw,
  87. annotate_src;
  88. const char *vmlinux_name,
  89. *kallsyms_name,
  90. *source_prefix,
  91. *field_sep;
  92. const char *default_guest_vmlinux_name,
  93. *default_guest_kallsyms,
  94. *default_guest_modules;
  95. const char *guestmount;
  96. const char *dso_list_str,
  97. *comm_list_str,
  98. *sym_list_str,
  99. *col_width_list_str;
  100. struct strlist *dso_list,
  101. *comm_list,
  102. *sym_list,
  103. *dso_from_list,
  104. *dso_to_list,
  105. *sym_from_list,
  106. *sym_to_list;
  107. const char *symfs;
  108. };
  109. extern struct symbol_conf symbol_conf;
  110. static inline void *symbol__priv(struct symbol *sym)
  111. {
  112. return ((void *)sym) - symbol_conf.priv_size;
  113. }
  114. struct ref_reloc_sym {
  115. const char *name;
  116. u64 addr;
  117. u64 unrelocated_addr;
  118. };
  119. struct map_symbol {
  120. struct map *map;
  121. struct symbol *sym;
  122. bool unfolded;
  123. bool has_children;
  124. };
  125. struct addr_map_symbol {
  126. struct map *map;
  127. struct symbol *sym;
  128. u64 addr;
  129. u64 al_addr;
  130. };
  131. struct branch_info {
  132. struct addr_map_symbol from;
  133. struct addr_map_symbol to;
  134. struct branch_flags flags;
  135. };
  136. struct addr_location {
  137. struct thread *thread;
  138. struct map *map;
  139. struct symbol *sym;
  140. u64 addr;
  141. char level;
  142. bool filtered;
  143. u8 cpumode;
  144. s32 cpu;
  145. };
  146. struct symsrc {
  147. char *name;
  148. int fd;
  149. enum dso_binary_type type;
  150. #ifdef LIBELF_SUPPORT
  151. Elf *elf;
  152. GElf_Ehdr ehdr;
  153. Elf_Scn *opdsec;
  154. size_t opdidx;
  155. GElf_Shdr opdshdr;
  156. Elf_Scn *symtab;
  157. GElf_Shdr symshdr;
  158. Elf_Scn *dynsym;
  159. size_t dynsym_idx;
  160. GElf_Shdr dynshdr;
  161. bool adjust_symbols;
  162. #endif
  163. };
  164. void symsrc__destroy(struct symsrc *ss);
  165. int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
  166. enum dso_binary_type type);
  167. bool symsrc__has_symtab(struct symsrc *ss);
  168. bool symsrc__possibly_runtime(struct symsrc *ss);
  169. int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
  170. int dso__load_vmlinux(struct dso *dso, struct map *map,
  171. const char *vmlinux, symbol_filter_t filter);
  172. int dso__load_vmlinux_path(struct dso *dso, struct map *map,
  173. symbol_filter_t filter);
  174. int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
  175. symbol_filter_t filter);
  176. struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
  177. u64 addr);
  178. struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
  179. const char *name);
  180. int filename__read_build_id(const char *filename, void *bf, size_t size);
  181. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  182. int kallsyms__parse(const char *filename, void *arg,
  183. int (*process_symbol)(void *arg, const char *name,
  184. char type, u64 start));
  185. int filename__read_debuglink(const char *filename, char *debuglink,
  186. size_t size);
  187. int symbol__init(void);
  188. void symbol__exit(void);
  189. void symbol__elf_init(void);
  190. struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
  191. size_t symbol__fprintf_symname_offs(const struct symbol *sym,
  192. const struct addr_location *al, FILE *fp);
  193. size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
  194. size_t symbol__fprintf(struct symbol *sym, FILE *fp);
  195. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  196. int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
  197. struct symsrc *runtime_ss, symbol_filter_t filter,
  198. int kmodule);
  199. int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
  200. struct map *map, symbol_filter_t filter);
  201. void symbols__insert(struct rb_root *symbols, struct symbol *sym);
  202. void symbols__fixup_duplicate(struct rb_root *symbols);
  203. void symbols__fixup_end(struct rb_root *symbols);
  204. void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
  205. #endif /* __PERF_SYMBOL */