symbol.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifdef HAVE_CPLUS_DEMANGLE
  10. extern char *cplus_demangle(const char *, int);
  11. static inline char *bfd_demangle(void __used *v, const char *c, int i)
  12. {
  13. return cplus_demangle(c, i);
  14. }
  15. #else
  16. #ifdef NO_DEMANGLE
  17. static inline char *bfd_demangle(void __used *v, const char __used *c,
  18. int __used i)
  19. {
  20. return NULL;
  21. }
  22. #else
  23. #include <bfd.h>
  24. #endif
  25. #endif
  26. /*
  27. * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
  28. * for newer versions we can use mmap to reduce memory usage:
  29. */
  30. #ifdef LIBELF_NO_MMAP
  31. # define PERF_ELF_C_READ_MMAP ELF_C_READ
  32. #else
  33. # define PERF_ELF_C_READ_MMAP ELF_C_READ_MMAP
  34. #endif
  35. #ifndef DMGL_PARAMS
  36. #define DMGL_PARAMS (1 << 0) /* Include function args */
  37. #define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
  38. #endif
  39. struct symbol {
  40. struct rb_node rb_node;
  41. u64 start;
  42. u64 end;
  43. char name[0];
  44. };
  45. struct strlist;
  46. struct symbol_conf {
  47. unsigned short priv_size;
  48. bool try_vmlinux_path,
  49. use_modules,
  50. sort_by_name,
  51. show_nr_samples,
  52. use_callchain,
  53. exclude_other;
  54. const char *vmlinux_name,
  55. *field_sep;
  56. char *dso_list_str,
  57. *comm_list_str,
  58. *sym_list_str,
  59. *col_width_list_str;
  60. struct strlist *dso_list,
  61. *comm_list,
  62. *sym_list;
  63. };
  64. extern struct symbol_conf symbol_conf;
  65. static inline void *symbol__priv(struct symbol *self)
  66. {
  67. return ((void *)self) - symbol_conf.priv_size;
  68. }
  69. struct addr_location {
  70. struct thread *thread;
  71. struct map *map;
  72. struct symbol *sym;
  73. u64 addr;
  74. char level;
  75. bool filtered;
  76. };
  77. struct dso {
  78. struct list_head node;
  79. struct rb_root symbols[MAP__NR_TYPES];
  80. struct rb_root symbol_names[MAP__NR_TYPES];
  81. u8 adjust_symbols:1;
  82. u8 slen_calculated:1;
  83. u8 has_build_id:1;
  84. u8 kernel:1;
  85. unsigned char origin;
  86. u8 sorted_by_name;
  87. u8 loaded;
  88. u8 build_id[BUILD_ID_SIZE];
  89. u16 long_name_len;
  90. const char *short_name;
  91. char *long_name;
  92. char name[0];
  93. };
  94. struct dso *dso__new(const char *name);
  95. void dso__delete(struct dso *self);
  96. bool dso__loaded(const struct dso *self, enum map_type type);
  97. bool dso__sorted_by_name(const struct dso *self, enum map_type type);
  98. void dso__sort_by_name(struct dso *self, enum map_type type);
  99. struct perf_session;
  100. struct dso *dsos__findnew(const char *name);
  101. int dso__load(struct dso *self, struct map *map, struct perf_session *session,
  102. symbol_filter_t filter);
  103. void dsos__fprintf(FILE *fp);
  104. size_t dsos__fprintf_buildid(FILE *fp);
  105. size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
  106. size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
  107. char dso__symtab_origin(const struct dso *self);
  108. void dso__set_build_id(struct dso *self, void *build_id);
  109. struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
  110. struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
  111. const char *name);
  112. int filename__read_build_id(const char *filename, void *bf, size_t size);
  113. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  114. bool dsos__read_build_ids(void);
  115. int build_id__sprintf(u8 *self, int len, char *bf);
  116. int symbol__init(void);
  117. int perf_session__create_kernel_maps(struct perf_session *self);
  118. extern struct list_head dsos__user, dsos__kernel;
  119. extern struct dso *vdso;
  120. #endif /* __PERF_SYMBOL */