map.h 4.5 KB

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