unwind-libunwind.c 1.9 KB

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