symbol.h 4.2 KB

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