map.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 <linux/types.h>
  7. enum map_type {
  8. MAP__FUNCTION = 0,
  9. MAP__VARIABLE,
  10. };
  11. #define MAP__NR_TYPES (MAP__VARIABLE + 1)
  12. extern const char *map_type__name[MAP__NR_TYPES];
  13. struct dso;
  14. struct ref_reloc_sym;
  15. struct map_groups;
  16. struct map {
  17. union {
  18. struct rb_node rb_node;
  19. struct list_head node;
  20. };
  21. u64 start;
  22. u64 end;
  23. enum map_type type;
  24. u64 pgoff;
  25. /* ip -> dso rip */
  26. u64 (*map_ip)(struct map *, u64);
  27. /* dso rip -> ip */
  28. u64 (*unmap_ip)(struct map *, u64);
  29. struct dso *dso;
  30. };
  31. struct kmap {
  32. struct ref_reloc_sym *ref_reloc_sym;
  33. struct map_groups *kmaps;
  34. };
  35. static inline struct kmap *map__kmap(struct map *self)
  36. {
  37. return (struct kmap *)(self + 1);
  38. }
  39. static inline u64 map__map_ip(struct map *map, u64 ip)
  40. {
  41. return ip - map->start + map->pgoff;
  42. }
  43. static inline u64 map__unmap_ip(struct map *map, u64 ip)
  44. {
  45. return ip + map->start - map->pgoff;
  46. }
  47. static inline u64 identity__map_ip(struct map *map __used, u64 ip)
  48. {
  49. return ip;
  50. }
  51. /* rip/ip <-> addr suitable for passing to `objdump --start-address=` */
  52. u64 map__rip_2objdump(struct map *map, u64 rip);
  53. u64 map__objdump_2ip(struct map *map, u64 addr);
  54. struct symbol;
  55. struct mmap_event;
  56. typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
  57. void map__init(struct map *self, enum map_type type,
  58. u64 start, u64 end, u64 pgoff, struct dso *dso);
  59. struct map *map__new(struct mmap_event *event, enum map_type,
  60. char *cwd, int cwdlen);
  61. void map__delete(struct map *self);
  62. struct map *map__clone(struct map *self);
  63. int map__overlap(struct map *l, struct map *r);
  64. size_t map__fprintf(struct map *self, FILE *fp);
  65. int map__load(struct map *self, symbol_filter_t filter);
  66. struct symbol *map__find_symbol(struct map *self,
  67. u64 addr, symbol_filter_t filter);
  68. struct symbol *map__find_symbol_by_name(struct map *self, const char *name,
  69. symbol_filter_t filter);
  70. void map__fixup_start(struct map *self);
  71. void map__fixup_end(struct map *self);
  72. void map__reloc_vmlinux(struct map *self);
  73. #endif /* __PERF_MAP_H */