unwind-libunwind.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <errno.h>
  3. #include "../../util/debug.h"
  4. #ifndef REMOTE_UNWIND_LIBUNWIND
  5. #include <libunwind.h>
  6. #include "perf_regs.h"
  7. #include "../../util/unwind.h"
  8. #endif
  9. #ifdef HAVE_ARCH_X86_64_SUPPORT
  10. int LIBUNWIND__ARCH_REG_ID(int regnum)
  11. {
  12. int id;
  13. switch (regnum) {
  14. case UNW_X86_64_RAX:
  15. id = PERF_REG_X86_AX;
  16. break;
  17. case UNW_X86_64_RDX:
  18. id = PERF_REG_X86_DX;
  19. break;
  20. case UNW_X86_64_RCX:
  21. id = PERF_REG_X86_CX;
  22. break;
  23. case UNW_X86_64_RBX:
  24. id = PERF_REG_X86_BX;
  25. break;
  26. case UNW_X86_64_RSI:
  27. id = PERF_REG_X86_SI;
  28. break;
  29. case UNW_X86_64_RDI:
  30. id = PERF_REG_X86_DI;
  31. break;
  32. case UNW_X86_64_RBP:
  33. id = PERF_REG_X86_BP;
  34. break;
  35. case UNW_X86_64_RSP:
  36. id = PERF_REG_X86_SP;
  37. break;
  38. case UNW_X86_64_R8:
  39. id = PERF_REG_X86_R8;
  40. break;
  41. case UNW_X86_64_R9:
  42. id = PERF_REG_X86_R9;
  43. break;
  44. case UNW_X86_64_R10:
  45. id = PERF_REG_X86_R10;
  46. break;
  47. case UNW_X86_64_R11:
  48. id = PERF_REG_X86_R11;
  49. break;
  50. case UNW_X86_64_R12:
  51. id = PERF_REG_X86_R12;
  52. break;
  53. case UNW_X86_64_R13:
  54. id = PERF_REG_X86_R13;
  55. break;
  56. case UNW_X86_64_R14:
  57. id = PERF_REG_X86_R14;
  58. break;
  59. case UNW_X86_64_R15:
  60. id = PERF_REG_X86_R15;
  61. break;
  62. case UNW_X86_64_RIP:
  63. id = PERF_REG_X86_IP;
  64. break;
  65. default:
  66. pr_err("unwind: invalid reg id %d\n", regnum);
  67. return -1;
  68. }
  69. return id;
  70. }
  71. #else
  72. int LIBUNWIND__ARCH_REG_ID(int regnum)
  73. {
  74. int id;
  75. switch (regnum) {
  76. case UNW_X86_EAX:
  77. id = PERF_REG_X86_AX;
  78. break;
  79. case UNW_X86_EDX:
  80. id = PERF_REG_X86_DX;
  81. break;
  82. case UNW_X86_ECX:
  83. id = PERF_REG_X86_CX;
  84. break;
  85. case UNW_X86_EBX:
  86. id = PERF_REG_X86_BX;
  87. break;
  88. case UNW_X86_ESI:
  89. id = PERF_REG_X86_SI;
  90. break;
  91. case UNW_X86_EDI:
  92. id = PERF_REG_X86_DI;
  93. break;
  94. case UNW_X86_EBP:
  95. id = PERF_REG_X86_BP;
  96. break;
  97. case UNW_X86_ESP:
  98. id = PERF_REG_X86_SP;
  99. break;
  100. case UNW_X86_EIP:
  101. id = PERF_REG_X86_IP;
  102. break;
  103. default:
  104. pr_err("unwind: invalid reg id %d\n", regnum);
  105. return -1;
  106. }
  107. return id;
  108. }
  109. #endif /* HAVE_ARCH_X86_64_SUPPORT */