map.h 2.0 KB

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