symbol.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. unsigned char origin;
  95. u8 sorted_by_name;
  96. u8 loaded;
  97. u8 build_id[BUILD_ID_SIZE];
  98. const char *short_name;
  99. char *long_name;
  100. u16 long_name_len;
  101. u16 short_name_len;
  102. char name[0];
  103. };
  104. struct dso *dso__new(const char *name);
  105. struct dso *dso__new_kernel(const char *name);
  106. void dso__delete(struct dso *self);
  107. bool dso__loaded(const struct dso *self, enum map_type type);
  108. bool dso__sorted_by_name(const struct dso *self, enum map_type type);
  109. static inline void dso__set_loaded(struct dso *self, enum map_type type)
  110. {
  111. self->loaded |= (1 << type);
  112. }
  113. void dso__sort_by_name(struct dso *self, enum map_type type);
  114. extern struct list_head dsos__user, dsos__kernel;
  115. struct dso *__dsos__findnew(struct list_head *head, const char *name);
  116. static inline struct dso *dsos__findnew(const char *name)
  117. {
  118. return __dsos__findnew(&dsos__user, name);
  119. }
  120. int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
  121. int dso__load_vmlinux_path(struct dso *self, struct map *map,
  122. symbol_filter_t filter);
  123. int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
  124. symbol_filter_t filter);
  125. void dsos__fprintf(FILE *fp);
  126. size_t dsos__fprintf_buildid(FILE *fp, bool with_hits);
  127. size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
  128. size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
  129. char dso__symtab_origin(const struct dso *self);
  130. void dso__set_long_name(struct dso *self, char *name);
  131. void dso__set_build_id(struct dso *self, void *build_id);
  132. void dso__read_running_kernel_build_id(struct dso *self);
  133. struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
  134. struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
  135. const char *name);
  136. int filename__read_build_id(const char *filename, void *bf, size_t size);
  137. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  138. bool dsos__read_build_ids(bool with_hits);
  139. int build_id__sprintf(const u8 *self, int len, char *bf);
  140. int kallsyms__parse(const char *filename, void *arg,
  141. int (*process_symbol)(void *arg, const char *name,
  142. char type, u64 start));
  143. int symbol__init(void);
  144. bool symbol_type__is_a(char symbol_type, enum map_type map_type);
  145. #endif /* __PERF_SYMBOL */