dso.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #ifndef __PERF_DSO
  2. #define __PERF_DSO
  3. #include <linux/types.h>
  4. #include <linux/rbtree.h>
  5. #include "types.h"
  6. #include "map.h"
  7. enum dso_binary_type {
  8. DSO_BINARY_TYPE__KALLSYMS = 0,
  9. DSO_BINARY_TYPE__GUEST_KALLSYMS,
  10. DSO_BINARY_TYPE__VMLINUX,
  11. DSO_BINARY_TYPE__GUEST_VMLINUX,
  12. DSO_BINARY_TYPE__JAVA_JIT,
  13. DSO_BINARY_TYPE__DEBUGLINK,
  14. DSO_BINARY_TYPE__BUILD_ID_CACHE,
  15. DSO_BINARY_TYPE__FEDORA_DEBUGINFO,
  16. DSO_BINARY_TYPE__UBUNTU_DEBUGINFO,
  17. DSO_BINARY_TYPE__BUILDID_DEBUGINFO,
  18. DSO_BINARY_TYPE__SYSTEM_PATH_DSO,
  19. DSO_BINARY_TYPE__GUEST_KMODULE,
  20. DSO_BINARY_TYPE__SYSTEM_PATH_KMODULE,
  21. DSO_BINARY_TYPE__NOT_FOUND,
  22. };
  23. enum dso_kernel_type {
  24. DSO_TYPE_USER = 0,
  25. DSO_TYPE_KERNEL,
  26. DSO_TYPE_GUEST_KERNEL
  27. };
  28. enum dso_swap_type {
  29. DSO_SWAP__UNSET,
  30. DSO_SWAP__NO,
  31. DSO_SWAP__YES,
  32. };
  33. #define DSO__SWAP(dso, type, val) \
  34. ({ \
  35. type ____r = val; \
  36. BUG_ON(dso->needs_swap == DSO_SWAP__UNSET); \
  37. if (dso->needs_swap == DSO_SWAP__YES) { \
  38. switch (sizeof(____r)) { \
  39. case 2: \
  40. ____r = bswap_16(val); \
  41. break; \
  42. case 4: \
  43. ____r = bswap_32(val); \
  44. break; \
  45. case 8: \
  46. ____r = bswap_64(val); \
  47. break; \
  48. default: \
  49. BUG_ON(1); \
  50. } \
  51. } \
  52. ____r; \
  53. })
  54. #define DSO__DATA_CACHE_SIZE 4096
  55. #define DSO__DATA_CACHE_MASK ~(DSO__DATA_CACHE_SIZE - 1)
  56. struct dso_cache {
  57. struct rb_node rb_node;
  58. u64 offset;
  59. u64 size;
  60. char data[0];
  61. };
  62. struct dso {
  63. struct list_head node;
  64. struct rb_root symbols[MAP__NR_TYPES];
  65. struct rb_root symbol_names[MAP__NR_TYPES];
  66. struct rb_root cache;
  67. enum dso_kernel_type kernel;
  68. enum dso_swap_type needs_swap;
  69. enum dso_binary_type symtab_type;
  70. enum dso_binary_type data_type;
  71. u8 adjust_symbols:1;
  72. u8 has_build_id:1;
  73. u8 hit:1;
  74. u8 annotate_warned:1;
  75. u8 sname_alloc:1;
  76. u8 lname_alloc:1;
  77. u8 sorted_by_name;
  78. u8 loaded;
  79. u8 build_id[BUILD_ID_SIZE];
  80. const char *short_name;
  81. char *long_name;
  82. u16 long_name_len;
  83. u16 short_name_len;
  84. char name[0];
  85. };
  86. static inline void dso__set_loaded(struct dso *dso, enum map_type type)
  87. {
  88. dso->loaded |= (1 << type);
  89. }
  90. struct dso *dso__new(const char *name);
  91. void dso__delete(struct dso *dso);
  92. void dso__set_short_name(struct dso *dso, const char *name);
  93. void dso__set_long_name(struct dso *dso, char *name);
  94. int dso__name_len(const struct dso *dso);
  95. bool dso__loaded(const struct dso *dso, enum map_type type);
  96. bool dso__sorted_by_name(const struct dso *dso, enum map_type type);
  97. void dso__set_sorted_by_name(struct dso *dso, enum map_type type);
  98. void dso__sort_by_name(struct dso *dso, enum map_type type);
  99. void dso__set_build_id(struct dso *dso, void *build_id);
  100. bool dso__build_id_equal(const struct dso *dso, u8 *build_id);
  101. void dso__read_running_kernel_build_id(struct dso *dso,
  102. struct machine *machine);
  103. int dso__kernel_module_get_build_id(struct dso *dso, const char *root_dir);
  104. char dso__symtab_origin(const struct dso *dso);
  105. int dso__binary_type_file(struct dso *dso, enum dso_binary_type type,
  106. char *root_dir, char *file, size_t size);
  107. int dso__data_fd(struct dso *dso, struct machine *machine);
  108. ssize_t dso__data_read_offset(struct dso *dso, struct machine *machine,
  109. u64 offset, u8 *data, ssize_t size);
  110. ssize_t dso__data_read_addr(struct dso *dso, struct map *map,
  111. struct machine *machine, u64 addr,
  112. u8 *data, ssize_t size);
  113. struct map *dso__new_map(const char *name);
  114. struct dso *dso__kernel_findnew(struct machine *machine, const char *name,
  115. const char *short_name, int dso_type);
  116. void dsos__add(struct list_head *head, struct dso *dso);
  117. struct dso *dsos__find(struct list_head *head, const char *name);
  118. struct dso *__dsos__findnew(struct list_head *head, const char *name);
  119. bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
  120. size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
  121. bool with_hits);
  122. size_t __dsos__fprintf(struct list_head *head, FILE *fp);
  123. size_t dso__fprintf_buildid(struct dso *dso, FILE *fp);
  124. size_t dso__fprintf_symbols_by_name(struct dso *dso,
  125. enum map_type type, FILE *fp);
  126. size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp);
  127. #endif /* __PERF_DSO */