dso.h 4.5 KB

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