symbol.h 5.7 KB

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