unwind.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __UNWIND_H
  3. #define __UNWIND_H
  4. #include <linux/compiler.h>
  5. #include <linux/types.h>
  6. #include "util/map_symbol.h"
  7. struct maps;
  8. struct perf_sample;
  9. struct thread;
  10. struct unwind_entry {
  11. struct map_symbol ms;
  12. u64 ip;
  13. };
  14. typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
  15. struct unwind_libunwind_ops {
  16. int (*prepare_access)(struct maps *maps);
  17. void (*flush_access)(struct maps *maps);
  18. void (*finish_access)(struct maps *maps);
  19. int (*get_entries)(unwind_entry_cb_t cb, void *arg,
  20. struct thread *thread,
  21. struct perf_sample *data, int max_stack);
  22. };
  23. #ifdef HAVE_DWARF_UNWIND_SUPPORT
  24. int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
  25. struct thread *thread,
  26. struct perf_sample *data, int max_stack);
  27. /* libunwind specific */
  28. #ifdef HAVE_LIBUNWIND_SUPPORT
  29. #ifndef LIBUNWIND__ARCH_REG_ID
  30. #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
  31. #endif
  32. #ifndef LIBUNWIND__ARCH_REG_SP
  33. #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP
  34. #endif
  35. #ifndef LIBUNWIND__ARCH_REG_IP
  36. #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP
  37. #endif
  38. int LIBUNWIND__ARCH_REG_ID(int regnum);
  39. int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized);
  40. void unwind__flush_access(struct maps *maps);
  41. void unwind__finish_access(struct maps *maps);
  42. #else
  43. static inline int unwind__prepare_access(struct maps *maps __maybe_unused,
  44. struct map *map __maybe_unused,
  45. bool *initialized __maybe_unused)
  46. {
  47. return 0;
  48. }
  49. static inline void unwind__flush_access(struct maps *maps __maybe_unused) {}
  50. static inline void unwind__finish_access(struct maps *maps __maybe_unused) {}
  51. #endif
  52. #else
  53. static inline int
  54. unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
  55. void *arg __maybe_unused,
  56. struct thread *thread __maybe_unused,
  57. struct perf_sample *data __maybe_unused,
  58. int max_stack __maybe_unused)
  59. {
  60. return 0;
  61. }
  62. static inline int unwind__prepare_access(struct maps *maps __maybe_unused,
  63. struct map *map __maybe_unused,
  64. bool *initialized __maybe_unused)
  65. {
  66. return 0;
  67. }
  68. static inline void unwind__flush_access(struct maps *maps __maybe_unused) {}
  69. static inline void unwind__finish_access(struct maps *maps __maybe_unused) {}
  70. #endif /* HAVE_DWARF_UNWIND_SUPPORT */
  71. #endif /* __UNWIND_H */