rvbacktrace.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef RV_BACKTRANCE_H
  2. #define RV_BACKTRANCE_H
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. #include "backtrace_config.h"
  6. #if (RV_BACKTRACE_ENV == RV_BACKTRACE_RTTHREAD)
  7. #include "rtthread.h"
  8. #define BACKTRACE_PRINTF rt_kprintf
  9. #ifdef BACKTRACE_USE_FP
  10. #define RV_BACKTRACE_USE_FP_RTTHREAD
  11. #endif
  12. #elif (RV_BACKTRACE_ENV == RV_BACKTRACE_BAREMETAL)
  13. #define BACKTRACE_PRINTF printf
  14. #ifdef BACKTRACE_USE_FP
  15. #define RV_BACKTRACE_USE_FP_BAREMETAL
  16. #endif
  17. #elif
  18. #define BACKTRACE_PRINTF printf
  19. #endif
  20. /* Backtrace All Threads */
  21. #if defined(BACKTRACE_USE_FP) && defined(BACKTRACE_ALL)
  22. #define BACKTRACE_ALL_THREAD
  23. #define BACKTRACE_FP_POS (8)
  24. #endif /* BACKTRACE_USE_FP && defined BACKTRACE_ALL */
  25. /* User Parameter */
  26. #define STACK_FRAME_LEN (10)
  27. #define STACK_BUFFER_LEN (100)
  28. #if __riscv_xlen == 32
  29. #define BACKTRACE_LEN 8
  30. #endif
  31. #if __riscv_xlen == 64
  32. #define BACKTRACE_LEN 16
  33. #endif
  34. #ifdef BACKTRACE_USE_FP
  35. #define RV_BACKTRACE_USE_FP
  36. #endif /* BACKTRACE_USE_FP */
  37. #define BACKTRACE_TRAP_DEPTH (3)
  38. #define BACKTRACE_FP_P0S_GCC_ISR (1)
  39. #define BACKTRACE_FP_POS_NORMAL (2)
  40. #define BACKTRACE_FP_POS_TRAP (5)
  41. #if defined(__ICCARM__) || defined(__ICCRX__) || defined(__ICCRISCV__)
  42. extern const uint32_t CSTACK$$Limit[];
  43. #define _stack CSTACK$$Limit
  44. #else
  45. extern char *_stack;
  46. #endif
  47. struct stackframe
  48. {
  49. unsigned long s_fp; // frame pointer
  50. unsigned long s_ra; // return address
  51. };
  52. static inline void rvbacktrace_get_stack(uintptr_t *estack)
  53. {
  54. *estack = (uintptr_t)&_stack;
  55. }
  56. void rvbacktrace(void); // backtrace function for usr
  57. void rvbacktrace_trap(void *casue, void *epc); // backtrace function used in trap
  58. void rvbacktrace_fno(int (*print_func)(const char *fmt, ...));
  59. void rvbacktrace_fno_bm(int (*print_func)(const char *fmt, ...));
  60. int rvbacktrace_fomit(int (*print_func)(const char *fmt, ...));
  61. int rvbacktrace_fomit_trap(int (*print_func)(const char *fmt, ...));
  62. void rvbacktrace_addr2line(uint32_t *frame, int (*print_func)(const char *fmt, ...));
  63. #endif /* RV_BACKTRANCE_H */