symbol.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifndef __PERF_SYMBOL
  2. #define __PERF_SYMBOL 1
  3. #include <linux/types.h>
  4. #include <stdbool.h>
  5. #include "types.h"
  6. #include <linux/list.h>
  7. #include <linux/rbtree.h>
  8. #include "event.h"
  9. #define DEBUG_CACHE_DIR ".debug"
  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. /*
  28. * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
  29. * for newer versions we can use mmap to reduce memory usage:
  30. */
  31. #ifdef LIBELF_NO_MMAP
  32. # define PERF_ELF_C_READ_MMAP ELF_C_READ
  33. #else
  34. # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
  35. #endif
  36. #ifndef DMGL_PARAMS
  37. #define DMGL_PARAMS (1 << 0) /* Include function args */
  38. #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
  39. #endif
  40. struct symbol {
  41. struct rb_node rb_node;
  42. u64 start;
  43. u64 end;
  44. char name[0];
  45. };
  46. void symbol__delete(struct symbol *self);
  47. struct strlist;
  48. struct symbol_conf {
  49. unsigned short priv_size;
  50. bool try_vmlinux_path,
  51. use_modules,
  52. sort_by_name,
  53. show_nr_samples,
  54. use_callchain,
  55. exclude_other,
  56. full_paths;
  57. const char *vmlinux_name,
  58. *field_sep;
  59. char *dso_list_str,
  60. *comm_list_str,
  61. *sym_list_str,
  62. *col_width_list_str;
  63. struct strlist *dso_list,
  64. *comm_list,
  65. *sym_list;
  66. };
  67. extern struct symbol_conf symbol_conf;
  68. static inline void *symbol__priv(struct symbol *self)
  69. {
  70. return ((void *)self) - symbol_conf.priv_size;
  71. }
  72. struct ref_reloc_sym {
  73. const char *name;
  74. u64 addr;
  75. u64 unrelocated_addr;
  76. };
  77. struct addr_location {
  78. struct thread *thread;
  79. struct map *map;
  80. struct symbol *sym;
  81. u64 addr;
  82. char level;
  83. bool filtered;
  84. };
  85. struct dso {
  86. struct list_head node;
  87. struct rb_root symbols[MAP__NR_TYPES];
  88. struct rb_root symbol_names[MAP__NR_TYPES];
  89. u8 adjust_symbols:1;
  90. u8 slen_calculated:1;
  91. u8 has_build_id:1;
  92. u8 kernel:1;
  93. u8 hit:1;
  94. u8 annotate_warned:1;
  95. unsigned char origin;
  96. u8 sorted_by_name;
  97. u8 loaded;
  98. u8 build_id[BUILD_ID_SIZE];
  99. const char *short_name;
  100. char *long_name;
  101. u16 long_name_len;
  102. u16 short_name_len;
  103. char name[0];
  104. };
  105. struct dso *dso__new(const char *name);
  106. struct dso *dso__new_kernel(const char *name);
  107. void dso__delete(struct dso *self);
  108. bool dso__loaded(const struct dso *self, enum map_type type);
  109. bool dso__sorted_by_name(const struct dso *self, enum map_type type);
  110. static inline void dso__set_loaded(struct dso *self, enum map_type type)
  111. {
  112. self->loaded |= (1 << type);
  113. }
  114. void dso__sort_by_name(struct dso *self, enum map_type type);
  115. extern struct list_head dsos__user, dsos__kernel;
  116. struct dso *__dsos__findnew(struct list_head *head, const char *name);
  117. static inline struct dso *dsos__findnew(const char *name)
  118. {
  119. return __dsos__findnew(&dsos__user, name);
  120. }
  121. int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
  122. int dso__load_vmlinux_path(struct dso *self, struct map *map,
  123. symbol_filter_t filter);
  124. int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
  125. symbol_filter_t filter);
  126. void dsos__fprintf(FILE *fp);
  127. size_t dsos__fprintf_buildid(FILE *fp, bool with_hits);
  128. size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
  129. size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
  130. enum dso_origin {
  131. DSO__ORIG_KERNEL = 0,
  132. DSO__ORIG_JAVA_JIT,
  133. DSO__ORIG_BUILD_ID_CACHE,
  134. DSO__ORIG_FEDORA,
  135. DSO__ORIG_UBUNTU,
  136. DSO__ORIG_BUILDID,
  137. DSO__ORIG_DSO,
  138. DSO__ORIG_KMODULE,
  139. DSO__ORIG_NOT_FOUND,
  140. };
  141. char dso__symtab_origin(const struct dso *self);
  142. void dso__set_long_name(struct dso *self, char *name);
  143. void dso__set_build_id(struct dso *self, void *build_id);
  144. void dso__read_running_kernel_build_id(struct dso *self);
  145. struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
  146. struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
  147. const char *name);
  148. int filename__read_build_id(const char *filename, void *bf, size_t size);
  149. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  150. bool dsos__read_build_ids(bool with_hits);
  151. int build_id__sprintf(const u8 *self, int len, char *bf);
  152. int kallsyms__parse(const char *filename, void *arg,
  153. int (*process_symbol)(void *arg, const char *name,
  154. char type, u64 start));
  155. int symbol__init(void);
  156. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  157. size_t vmlinux_path__fprintf(FILE *fp);
  158. #endif /* __PERF_SYMBOL */