symbol.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _PERF_SYMBOL_
  2. #define _PERF_SYMBOL_ 1
  3. #include <linux/types.h>
  4. #include "types.h"
  5. #include <linux/list.h>
  6. #include <linux/rbtree.h>
  7. #include "module.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. u64 obj_start;
  44. u64 hist_sum;
  45. u64 *hist;
  46. struct module *module;
  47. void *priv;
  48. char name[0];
  49. };
  50. struct dso {
  51. struct list_head node;
  52. struct rb_root syms;
  53. struct symbol *(*find_symbol)(struct dso *, u64 ip);
  54. unsigned int sym_priv_size;
  55. unsigned char adjust_symbols;
  56. unsigned char slen_calculated;
  57. unsigned char origin;
  58. char name[0];
  59. };
  60. extern const char *sym_hist_filter;
  61. typedef int (*symbol_filter_t)(struct dso *self, struct symbol *sym);
  62. struct dso *dso__new(const char *name, unsigned int sym_priv_size);
  63. void dso__delete(struct dso *self);
  64. static inline void *dso__sym_priv(struct dso *self, struct symbol *sym)
  65. {
  66. return ((void *)sym) - self->sym_priv_size;
  67. }
  68. struct symbol *dso__find_symbol(struct dso *self, u64 ip);
  69. int dso__load_kernel(struct dso *self, const char *vmlinux,
  70. symbol_filter_t filter, int verbose, int modules);
  71. int dso__load_modules(struct dso *self, symbol_filter_t filter, int verbose);
  72. int dso__load(struct dso *self, symbol_filter_t filter, int verbose);
  73. struct dso *dsos__findnew(const char *name);
  74. void dsos__fprintf(FILE *fp);
  75. size_t dso__fprintf(struct dso *self, FILE *fp);
  76. char dso__symtab_origin(const struct dso *self);
  77. int load_kernel(void);
  78. void symbol__init(void);
  79. extern struct list_head dsos;
  80. extern struct dso *kernel_dso;
  81. extern struct dso *vdso;
  82. extern struct dso *hypervisor_dso;
  83. extern const char *vmlinux_name;
  84. extern int modules;
  85. #endif /* _PERF_SYMBOL_ */