symbol.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. char name[0];
  49. };
  50. void symbol__delete(struct symbol *self);
  51. struct strlist;
  52. struct symbol_conf {
  53. unsigned short priv_size;
  54. bool try_vmlinux_path,
  55. use_modules,
  56. sort_by_name,
  57. show_nr_samples,
  58. use_callchain,
  59. exclude_other,
  60. full_paths;
  61. const char *vmlinux_name,
  62. *field_sep;
  63. char *dso_list_str,
  64. *comm_list_str,
  65. *sym_list_str,
  66. *col_width_list_str;
  67. struct strlist *dso_list,
  68. *comm_list,
  69. *sym_list;
  70. };
  71. extern struct symbol_conf symbol_conf;
  72. static inline void *symbol__priv(struct symbol *self)
  73. {
  74. return ((void *)self) - symbol_conf.priv_size;
  75. }
  76. struct ref_reloc_sym {
  77. const char *name;
  78. u64 addr;
  79. u64 unrelocated_addr;
  80. };
  81. struct map_symbol {
  82. struct map *map;
  83. struct symbol *sym;
  84. };
  85. struct addr_location {
  86. struct thread *thread;
  87. struct map *map;
  88. struct symbol *sym;
  89. u64 addr;
  90. char level;
  91. bool filtered;
  92. };
  93. struct dso {
  94. struct list_head node;
  95. struct rb_root symbols[MAP__NR_TYPES];
  96. struct rb_root symbol_names[MAP__NR_TYPES];
  97. u8 adjust_symbols:1;
  98. u8 slen_calculated:1;
  99. u8 has_build_id:1;
  100. u8 kernel:1;
  101. u8 hit:1;
  102. u8 annotate_warned:1;
  103. unsigned char origin;
  104. u8 sorted_by_name;
  105. u8 loaded;
  106. u8 build_id[BUILD_ID_SIZE];
  107. const char *short_name;
  108. char *long_name;
  109. u16 long_name_len;
  110. u16 short_name_len;
  111. char name[0];
  112. };
  113. struct dso *dso__new(const char *name);
  114. struct dso *dso__new_kernel(const char *name);
  115. void dso__delete(struct dso *self);
  116. bool dso__loaded(const struct dso *self, enum map_type type);
  117. bool dso__sorted_by_name(const struct dso *self, enum map_type type);
  118. static inline void dso__set_loaded(struct dso *self, enum map_type type)
  119. {
  120. self->loaded |= (1 << type);
  121. }
  122. void dso__sort_by_name(struct dso *self, enum map_type type);
  123. extern struct list_head dsos__user, dsos__kernel;
  124. struct dso *__dsos__findnew(struct list_head *head, const char *name);
  125. static inline struct dso *dsos__findnew(const char *name)
  126. {
  127. return __dsos__findnew(&dsos__user, name);
  128. }
  129. int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
  130. int dso__load_vmlinux_path(struct dso *self, struct map *map,
  131. symbol_filter_t filter);
  132. int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
  133. symbol_filter_t filter);
  134. void dsos__fprintf(FILE *fp);
  135. size_t dsos__fprintf_buildid(FILE *fp, bool with_hits);
  136. size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
  137. size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
  138. enum dso_origin {
  139. DSO__ORIG_KERNEL = 0,
  140. DSO__ORIG_JAVA_JIT,
  141. DSO__ORIG_BUILD_ID_CACHE,
  142. DSO__ORIG_FEDORA,
  143. DSO__ORIG_UBUNTU,
  144. DSO__ORIG_BUILDID,
  145. DSO__ORIG_DSO,
  146. DSO__ORIG_KMODULE,
  147. DSO__ORIG_NOT_FOUND,
  148. };
  149. char dso__symtab_origin(const struct dso *self);
  150. void dso__set_long_name(struct dso *self, char *name);
  151. void dso__set_build_id(struct dso *self, void *build_id);
  152. void dso__read_running_kernel_build_id(struct dso *self);
  153. struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
  154. struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
  155. const char *name);
  156. int filename__read_build_id(const char *filename, void *bf, size_t size);
  157. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  158. bool dsos__read_build_ids(bool with_hits);
  159. int build_id__sprintf(const u8 *self, int len, char *bf);
  160. int kallsyms__parse(const char *filename, void *arg,
  161. int (*process_symbol)(void *arg, const char *name,
  162. char type, u64 start));
  163. int symbol__init(void);
  164. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  165. size_t vmlinux_path__fprintf(FILE *fp);
  166. #endif /* __PERF_SYMBOL */