map.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #ifndef __PERF_MAP_H
  2. #define __PERF_MAP_H
  3. #include <linux/compiler.h>
  4. #include <linux/list.h>
  5. #include <linux/rbtree.h>
  6. #include <stdio.h>
  7. #include <stdbool.h>
  8. #include "types.h"
  9. enum map_type {
  10. MAP__FUNCTION = 0,
  11. MAP__VARIABLE,
  12. };
  13. #define MAP__NR_TYPES (MAP__VARIABLE + 1)
  14. extern const char *map_type__name[MAP__NR_TYPES];
  15. struct dso;
  16. struct ip_callchain;
  17. struct ref_reloc_sym;
  18. struct map_groups;
  19. struct machine;
  20. struct perf_evsel;
  21. struct map {
  22. union {
  23. struct rb_node rb_node;
  24. struct list_head node;
  25. };
  26. u64 start;
  27. u64 end;
  28. u8 /* enum map_type */ type;
  29. bool referenced;
  30. bool erange_warned;
  31. u32 priv;
  32. u64 pgoff;
  33. u32 maj, min; /* only valid for MMAP2 record */
  34. u64 ino; /* only valid for MMAP2 record */
  35. u64 ino_generation;/* only valid for MMAP2 record */
  36. /* ip -> dso rip */
  37. u64 (*map_ip)(struct map *, u64);
  38. /* dso rip -> ip */
  39. u64 (*unmap_ip)(struct map *, u64);
  40. struct dso *dso;
  41. struct map_groups *groups;
  42. };
  43. struct kmap {
  44. struct ref_reloc_sym *ref_reloc_sym;
  45. struct map_groups *kmaps;
  46. };
  47. struct map_groups {
  48. struct rb_root maps[MAP__NR_TYPES];
  49. struct list_head removed_maps[MAP__NR_TYPES];
  50. struct machine *machine;
  51. };
  52. static inline struct kmap *map__kmap(struct map *map)
  53. {
  54. return (struct kmap *)(map + 1);
  55. }
  56. static inline u64 map__map_ip(struct map *map, u64 ip)
  57. {
  58. return ip - map->start + map->pgoff;
  59. }
  60. static inline u64 map__unmap_ip(struct map *map, u64 ip)
  61. {
  62. return ip + map->start - map->pgoff;
  63. }
  64. static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)
  65. {
  66. return ip;
  67. }
  68. /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
  69. u64 map__rip_2objdump(struct map *map, u64 rip);
  70. struct symbol;
  71. typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
  72. void map__init(struct map *map, enum map_type type,
  73. u64 start, u64 end, u64 pgoff, struct dso *dso);
  74. struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
  75. u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
  76. u64 ino_gen,
  77. char *filename, enum map_type type);
  78. struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
  79. void map__delete(struct map *map);
  80. struct map *map__clone(struct map *map);
  81. int map__overlap(struct map *l, struct map *r);
  82. size_t map__fprintf(struct map *map, FILE *fp);
  83. size_t map__fprintf_dsoname(struct map *map, FILE *fp);
  84. int map__load(struct map *map, symbol_filter_t filter);
  85. struct symbol *map__find_symbol(struct map *map,
  86. u64 addr, symbol_filter_t filter);
  87. struct symbol *map__find_symbol_by_name(struct map *map, const char *name,
  88. symbol_filter_t filter);
  89. void map__fixup_start(struct map *map);
  90. void map__fixup_end(struct map *map);
  91. void map__reloc_vmlinux(struct map *map);
  92. size_t __map_groups__fprintf_maps(struct map_groups *mg,
  93. enum map_type type, int verbose, FILE *fp);
  94. void maps__insert(struct rb_root *maps, struct map *map);
  95. void maps__remove(struct rb_root *maps, struct map *map);
  96. struct map *maps__find(struct rb_root *maps, u64 addr);
  97. struct map *maps__first(struct rb_root *maps);
  98. struct map *maps__next(struct map *map);
  99. void map_groups__init(struct map_groups *mg);
  100. void map_groups__exit(struct map_groups *mg);
  101. int map_groups__clone(struct map_groups *mg,
  102. struct map_groups *parent, enum map_type type);
  103. size_t map_groups__fprintf(struct map_groups *mg, int verbose, FILE *fp);
  104. size_t map_groups__fprintf_maps(struct map_groups *mg, int verbose, FILE *fp);
  105. int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
  106. u64 addr);
  107. static inline void map_groups__insert(struct map_groups *mg, struct map *map)
  108. {
  109. maps__insert(&mg->maps[map->type], map);
  110. map->groups = mg;
  111. }
  112. static inline void map_groups__remove(struct map_groups *mg, struct map *map)
  113. {
  114. maps__remove(&mg->maps[map->type], map);
  115. }
  116. static inline struct map *map_groups__find(struct map_groups *mg,
  117. enum map_type type, u64 addr)
  118. {
  119. return maps__find(&mg->maps[type], addr);
  120. }
  121. static inline struct map *map_groups__first(struct map_groups *mg,
  122. enum map_type type)
  123. {
  124. return maps__first(&mg->maps[type]);
  125. }
  126. static inline struct map *map_groups__next(struct map *map)
  127. {
  128. return maps__next(map);
  129. }
  130. struct symbol *map_groups__find_symbol(struct map_groups *mg,
  131. enum map_type type, u64 addr,
  132. struct map **mapp,
  133. symbol_filter_t filter);
  134. struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
  135. enum map_type type,
  136. const char *name,
  137. struct map **mapp,
  138. symbol_filter_t filter);
  139. static inline
  140. struct symbol *map_groups__find_function_by_name(struct map_groups *mg,
  141. const char *name, struct map **mapp,
  142. symbol_filter_t filter)
  143. {
  144. return map_groups__find_symbol_by_name(mg, MAP__FUNCTION, name, mapp, filter);
  145. }
  146. int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
  147. int verbose, FILE *fp);
  148. struct map *map_groups__find_by_name(struct map_groups *mg,
  149. enum map_type type, const char *name);
  150. void map_groups__flush(struct map_groups *mg);
  151. #endif /* __PERF_MAP_H */