symbol.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. #endif
  18. #include <elf.h>
  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. event_group,
  89. demangle;
  90. const char *vmlinux_name,
  91. *kallsyms_name,
  92. *source_prefix,
  93. *field_sep;
  94. const char *default_guest_vmlinux_name,
  95. *default_guest_kallsyms,
  96. *default_guest_modules;
  97. const char *guestmount;
  98. const char *dso_list_str,
  99. *comm_list_str,
  100. *sym_list_str,
  101. *col_width_list_str;
  102. struct strlist *dso_list,
  103. *comm_list,
  104. *sym_list,
  105. *dso_from_list,
  106. *dso_to_list,
  107. *sym_from_list,
  108. *sym_to_list;
  109. const char *symfs;
  110. };
  111. extern struct symbol_conf symbol_conf;
  112. extern int vmlinux_path__nr_entries;
  113. extern char **vmlinux_path;
  114. static inline void *symbol__priv(struct symbol *sym)
  115. {
  116. return ((void *)sym) - symbol_conf.priv_size;
  117. }
  118. struct ref_reloc_sym {
  119. const char *name;
  120. u64 addr;
  121. u64 unrelocated_addr;
  122. };
  123. struct map_symbol {
  124. struct map *map;
  125. struct symbol *sym;
  126. bool unfolded;
  127. bool has_children;
  128. };
  129. struct addr_map_symbol {
  130. struct map *map;
  131. struct symbol *sym;
  132. u64 addr;
  133. u64 al_addr;
  134. };
  135. struct branch_info {
  136. struct addr_map_symbol from;
  137. struct addr_map_symbol to;
  138. struct branch_flags flags;
  139. };
  140. struct mem_info {
  141. struct addr_map_symbol iaddr;
  142. struct addr_map_symbol daddr;
  143. union perf_mem_data_src data_src;
  144. };
  145. struct addr_location {
  146. struct thread *thread;
  147. struct map *map;
  148. struct symbol *sym;
  149. u64 addr;
  150. char level;
  151. bool filtered;
  152. u8 cpumode;
  153. s32 cpu;
  154. };
  155. struct symsrc {
  156. char *name;
  157. int fd;
  158. enum dso_binary_type type;
  159. #ifdef LIBELF_SUPPORT
  160. Elf *elf;
  161. GElf_Ehdr ehdr;
  162. Elf_Scn *opdsec;
  163. size_t opdidx;
  164. GElf_Shdr opdshdr;
  165. Elf_Scn *symtab;
  166. GElf_Shdr symshdr;
  167. Elf_Scn *dynsym;
  168. size_t dynsym_idx;
  169. GElf_Shdr dynshdr;
  170. bool adjust_symbols;
  171. #endif
  172. };
  173. void symsrc__destroy(struct symsrc *ss);
  174. int symsrc__init(struct symsrc *ss, struct dso *dso, const char *name,
  175. enum dso_binary_type type);
  176. bool symsrc__has_symtab(struct symsrc *ss);
  177. bool symsrc__possibly_runtime(struct symsrc *ss);
  178. int dso__load(struct dso *dso, struct map *map, symbol_filter_t filter);
  179. int dso__load_vmlinux(struct dso *dso, struct map *map,
  180. const char *vmlinux, symbol_filter_t filter);
  181. int dso__load_vmlinux_path(struct dso *dso, struct map *map,
  182. symbol_filter_t filter);
  183. int dso__load_kallsyms(struct dso *dso, const char *filename, struct map *map,
  184. symbol_filter_t filter);
  185. struct symbol *dso__find_symbol(struct dso *dso, enum map_type type,
  186. u64 addr);
  187. struct symbol *dso__find_symbol_by_name(struct dso *dso, enum map_type type,
  188. const char *name);
  189. int filename__read_build_id(const char *filename, void *bf, size_t size);
  190. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  191. int kallsyms__parse(const char *filename, void *arg,
  192. int (*process_symbol)(void *arg, const char *name,
  193. char type, u64 start));
  194. int filename__read_debuglink(const char *filename, char *debuglink,
  195. size_t size);
  196. int symbol__init(void);
  197. void symbol__exit(void);
  198. void symbol__elf_init(void);
  199. struct symbol *symbol__new(u64 start, u64 len, u8 binding, const char *name);
  200. size_t symbol__fprintf_symname_offs(const struct symbol *sym,
  201. const struct addr_location *al, FILE *fp);
  202. size_t symbol__fprintf_symname(const struct symbol *sym, FILE *fp);
  203. size_t symbol__fprintf(struct symbol *sym, FILE *fp);
  204. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  205. bool symbol__restricted_filename(const char *filename,
  206. const char *restricted_filename);
  207. int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss,
  208. struct symsrc *runtime_ss, symbol_filter_t filter,
  209. int kmodule);
  210. int dso__synthesize_plt_symbols(struct dso *dso, struct symsrc *ss,
  211. struct map *map, symbol_filter_t filter);
  212. void symbols__insert(struct rb_root *symbols, struct symbol *sym);
  213. void symbols__fixup_duplicate(struct rb_root *symbols);
  214. void symbols__fixup_end(struct rb_root *symbols);
  215. void __map_groups__fixup_end(struct map_groups *mg, enum map_type type);
  216. #endif /* __PERF_SYMBOL */