map.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. u64 reloc;
  34. u32 maj, min; /* only valid for MMAP2 record */
  35. u64 ino; /* only valid for MMAP2 record */
  36. u64 ino_generation;/* only valid for MMAP2 record */
  37. /* ip -> dso rip */
  38. u64 (*map_ip)(struct map *, u64);
  39. /* dso rip -> ip */
  40. u64 (*unmap_ip)(struct map *, u64);
  41. struct dso *dso;
  42. struct map_groups *groups;
  43. };
  44. struct kmap {
  45. struct ref_reloc_sym *ref_reloc_sym;
  46. struct map_groups *kmaps;
  47. };
  48. struct map_groups {
  49. struct rb_root maps[MAP__NR_TYPES];
  50. struct list_head removed_maps[MAP__NR_TYPES];
  51. struct machine *machine;
  52. };
  53. static inline struct kmap *map__kmap(struct map *map)
  54. {
  55. return (struct kmap *)(map + 1);
  56. }
  57. static inline u64 map__map_ip(struct map *map, u64 ip)
  58. {
  59. return ip - map->start + map->pgoff;
  60. }
  61. static inline u64 map__unmap_ip(struct map *map, u64 ip)
  62. {
  63. return ip + map->start - map->pgoff;
  64. }
  65. static inline u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)
  66. {
  67. return ip;
  68. }
  69. /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
  70. u64 map__rip_2objdump(struct map *map, u64 rip);
  71. /* objdump address -> memory address */
  72. u64 map__objdump_2mem(struct map *map, u64 ip);
  73. struct symbol;
  74. typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
  75. void map__init(struct map *map, enum map_type type,
  76. u64 start, u64 end, u64 pgoff, struct dso *dso);
  77. struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
  78. u64 pgoff, u32 pid, u32 d_maj, u32 d_min, u64 ino,
  79. u64 ino_gen,
  80. char *filename, enum map_type type);
  81. struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
  82. void map__delete(struct map *map);
  83. struct map *map__clone(struct map *map);
  84. int map__overlap(struct map *l, struct map *r);
  85. size_t map__fprintf(struct map *map, FILE *fp);
  86. size_t map__fprintf_dsoname(struct map *map, FILE *fp);
  87. int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix,
  88. FILE *fp);
  89. int map__load(struct map *map, symbol_filter_t filter);
  90. struct symbol *map__find_symbol(struct map *map,
  91. u64 addr, symbol_filter_t filter);
  92. struct symbol *map__find_symbol_by_name(struct map *map, const char *name,
  93. symbol_filter_t filter);
  94. void map__fixup_start(struct map *map);
  95. void map__fixup_end(struct map *map);
  96. void map__reloc_vmlinux(struct map *map);
  97. size_t __map_groups__fprintf_maps(struct map_groups *mg,
  98. enum map_type type, int verbose, FILE *fp);
  99. void maps__insert(struct rb_root *maps, struct map *map);
  100. void maps__remove(struct rb_root *maps, struct map *map);
  101. struct map *maps__find(struct rb_root *maps, u64 addr);
  102. struct map *maps__first(struct rb_root *maps);
  103. struct map *maps__next(struct map *map);
  104. void map_groups__init(struct map_groups *mg);
  105. void map_groups__exit(struct map_groups *mg);
  106. int map_groups__clone(struct map_groups *mg,
  107. struct map_groups *parent, enum map_type type);
  108. size_t map_groups__fprintf(struct map_groups *mg, int verbose, FILE *fp);
  109. size_t map_groups__fprintf_maps(struct map_groups *mg, int verbose, FILE *fp);
  110. int maps__set_kallsyms_ref_reloc_sym(struct map **maps, const char *symbol_name,
  111. u64 addr);
  112. static inline void map_groups__insert(struct map_groups *mg, struct map *map)
  113. {
  114. maps__insert(&mg->maps[map->type], map);
  115. map->groups = mg;
  116. }
  117. static inline void map_groups__remove(struct map_groups *mg, struct map *map)
  118. {
  119. maps__remove(&mg->maps[map->type], map);
  120. }
  121. static inline struct map *map_groups__find(struct map_groups *mg,
  122. enum map_type type, u64 addr)
  123. {
  124. return maps__find(&mg->maps[type], addr);
  125. }
  126. static inline struct map *map_groups__first(struct map_groups *mg,
  127. enum map_type type)
  128. {
  129. return maps__first(&mg->maps[type]);
  130. }
  131. static inline struct map *map_groups__next(struct map *map)
  132. {
  133. return maps__next(map);
  134. }
  135. struct symbol *map_groups__find_symbol(struct map_groups *mg,
  136. enum map_type type, u64 addr,
  137. struct map **mapp,
  138. symbol_filter_t filter);
  139. struct symbol *map_groups__find_symbol_by_name(struct map_groups *mg,
  140. enum map_type type,
  141. const char *name,
  142. struct map **mapp,
  143. symbol_filter_t filter);
  144. struct addr_map_symbol;
  145. int map_groups__find_ams(struct addr_map_symbol *ams, symbol_filter_t filter);
  146. static inline
  147. struct symbol *map_groups__find_function_by_name(struct map_groups *mg,
  148. const char *name, struct map **mapp,
  149. symbol_filter_t filter)
  150. {
  151. return map_groups__find_symbol_by_name(mg, MAP__FUNCTION, name, mapp, filter);
  152. }
  153. int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map,
  154. int verbose, FILE *fp);
  155. struct map *map_groups__find_by_name(struct map_groups *mg,
  156. enum map_type type, const char *name);
  157. void map_groups__flush(struct map_groups *mg);
  158. #endif /* __PERF_MAP_H */