unwind.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. struct map;
  7. struct perf_sample;
  8. struct symbol;
  9. struct thread;
  10. struct unwind_entry {
  11. struct map *map;
  12. struct symbol *sym;
  13. u64 ip;
  14. };
  15. typedef int (*unwind_entry_cb_t)(struct unwind_entry *entry, void *arg);
  16. struct unwind_libunwind_ops {
  17. int (*prepare_access)(struct thread *thread);
  18. void (*flush_access)(struct thread *thread);
  19. void (*finish_access)(struct thread *thread);
  20. int (*get_entries)(unwind_entry_cb_t cb, void *arg,
  21. struct thread *thread,
  22. struct perf_sample *data, int max_stack);
  23. };
  24. #ifdef HAVE_DWARF_UNWIND_SUPPORT
  25. int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
  26. struct thread *thread,
  27. struct perf_sample *data, int max_stack);
  28. /* libunwind specific */
  29. #ifdef HAVE_LIBUNWIND_SUPPORT
  30. #ifndef LIBUNWIND__ARCH_REG_ID
  31. #define LIBUNWIND__ARCH_REG_ID(regnum) libunwind__arch_reg_id(regnum)
  32. #endif
  33. #ifndef LIBUNWIND__ARCH_REG_SP
  34. #define LIBUNWIND__ARCH_REG_SP PERF_REG_SP
  35. #endif
  36. #ifndef LIBUNWIND__ARCH_REG_IP
  37. #define LIBUNWIND__ARCH_REG_IP PERF_REG_IP
  38. #endif
  39. int LIBUNWIND__ARCH_REG_ID(int regnum);
  40. int unwind__prepare_access(struct thread *thread, struct map *map,
  41. bool *initialized);
  42. void unwind__flush_access(struct thread *thread);
  43. void unwind__finish_access(struct thread *thread);
  44. #else
  45. static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
  46. struct map *map __maybe_unused,
  47. bool *initialized __maybe_unused)
  48. {
  49. return 0;
  50. }
  51. static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
  52. static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
  53. #endif
  54. #else
  55. static inline int
  56. unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
  57. void *arg __maybe_unused,
  58. struct thread *thread __maybe_unused,
  59. struct perf_sample *data __maybe_unused,
  60. int max_stack __maybe_unused)
  61. {
  62. return 0;
  63. }
  64. static inline int unwind__prepare_access(struct thread *thread __maybe_unused,
  65. struct map *map __maybe_unused,
  66. bool *initialized __maybe_unused)
  67. {
  68. return 0;
  69. }
  70. static inline void unwind__flush_access(struct thread *thread __maybe_unused) {}
  71. static inline void unwind__finish_access(struct thread *thread __maybe_unused) {}
  72. #endif /* HAVE_DWARF_UNWIND_SUPPORT */
  73. #endif /* __UNWIND_H */