symbol.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. extern unsigned int symbol__priv_size;
  46. static inline void *symbol__priv(struct symbol *self)
  47. {
  48. return ((void *)self) - symbol__priv_size;
  49. }
  50. struct dso {
  51. struct list_head node;
  52. struct rb_root syms;
  53. struct symbol *(*find_symbol)(struct dso *, u64 ip);
  54. u8 adjust_symbols:1;
  55. u8 slen_calculated:1;
  56. u8 loaded:1;
  57. u8 has_build_id:1;
  58. unsigned char origin;
  59. u8 build_id[BUILD_ID_SIZE];
  60. u16 long_name_len;
  61. const char *short_name;
  62. char *long_name;
  63. char name[0];
  64. };
  65. struct dso *dso__new(const char *name);
  66. void dso__delete(struct dso *self);
  67. struct symbol *dso__find_symbol(struct dso *self, u64 ip);
  68. int dsos__load_modules(void);
  69. struct dso *dsos__findnew(const char *name);
  70. int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
  71. int dso__load_kernel_sym(struct dso *self, symbol_filter_t filter, int modules);
  72. void dsos__fprintf(FILE *fp);
  73. size_t dsos__fprintf_buildid(FILE *fp);
  74. size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
  75. size_t dso__fprintf(struct dso *self, FILE *fp);
  76. char dso__symtab_origin(const struct dso *self);
  77. void dso__set_build_id(struct dso *self, void *build_id);
  78. int filename__read_build_id(const char *filename, void *bf, size_t size);
  79. int sysfs__read_build_id(const char *filename, void *bf, size_t size);
  80. bool dsos__read_build_ids(void);
  81. int build_id__sprintf(u8 *self, int len, char *bf);
  82. struct dso *dsos__load_kernel(void);
  83. int load_kernel(symbol_filter_t filter);
  84. void symbol__init(unsigned int priv_size);
  85. extern struct list_head dsos;
  86. extern struct map *kernel_map;
  87. extern struct dso *vdso;
  88. extern const char *vmlinux_name;
  89. extern int modules;
  90. #endif /* __PERF_SYMBOL */