DwarfOp.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2016 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _LIBUNWINDSTACK_DWARF_OP_H
  17. #define _LIBUNWINDSTACK_DWARF_OP_H
  18. #include <stdint.h>
  19. #include <deque>
  20. #include <string>
  21. #include <type_traits>
  22. #include <vector>
  23. #include <unwindstack/DwarfError.h>
  24. #include "DwarfEncoding.h"
  25. #include "RegsInfo.h"
  26. namespace unwindstack {
  27. // Forward declarations.
  28. class DwarfMemory;
  29. class Memory;
  30. template <typename AddressType>
  31. class RegsImpl;
  32. template <typename AddressType>
  33. class DwarfOp {
  34. // Signed version of AddressType
  35. typedef typename std::make_signed<AddressType>::type SignedType;
  36. public:
  37. DwarfOp(DwarfMemory* memory, Memory* regular_memory)
  38. : memory_(memory), regular_memory_(regular_memory) {}
  39. virtual ~DwarfOp() = default;
  40. bool Decode();
  41. bool Eval(uint64_t start, uint64_t end);
  42. void GetLogInfo(uint64_t start, uint64_t end, std::vector<std::string>* lines);
  43. AddressType StackAt(size_t index) { return stack_[index]; }
  44. size_t StackSize() { return stack_.size(); }
  45. void set_regs_info(RegsInfo<AddressType>* regs_info) { regs_info_ = regs_info; }
  46. const DwarfErrorData& last_error() { return last_error_; }
  47. DwarfErrorCode LastErrorCode() { return last_error_.code; }
  48. uint64_t LastErrorAddress() { return last_error_.address; }
  49. bool dex_pc_set() { return dex_pc_set_; }
  50. bool is_register() { return is_register_; }
  51. uint8_t cur_op() { return cur_op_; }
  52. Memory* regular_memory() { return regular_memory_; }
  53. protected:
  54. AddressType OperandAt(size_t index) { return operands_[index]; }
  55. size_t OperandsSize() { return operands_.size(); }
  56. AddressType StackPop() {
  57. AddressType value = stack_.front();
  58. stack_.pop_front();
  59. return value;
  60. }
  61. private:
  62. DwarfMemory* memory_;
  63. Memory* regular_memory_;
  64. RegsInfo<AddressType>* regs_info_;
  65. bool dex_pc_set_ = false;
  66. bool is_register_ = false;
  67. DwarfErrorData last_error_{DWARF_ERROR_NONE, 0};
  68. uint8_t cur_op_;
  69. std::vector<AddressType> operands_;
  70. std::deque<AddressType> stack_;
  71. inline AddressType bool_to_dwarf_bool(bool value) { return value ? 1 : 0; }
  72. // Op processing functions.
  73. bool op_deref();
  74. bool op_deref_size();
  75. bool op_push();
  76. bool op_dup();
  77. bool op_drop();
  78. bool op_over();
  79. bool op_pick();
  80. bool op_swap();
  81. bool op_rot();
  82. bool op_abs();
  83. bool op_and();
  84. bool op_div();
  85. bool op_minus();
  86. bool op_mod();
  87. bool op_mul();
  88. bool op_neg();
  89. bool op_not();
  90. bool op_or();
  91. bool op_plus();
  92. bool op_plus_uconst();
  93. bool op_shl();
  94. bool op_shr();
  95. bool op_shra();
  96. bool op_xor();
  97. bool op_bra();
  98. bool op_eq();
  99. bool op_ge();
  100. bool op_gt();
  101. bool op_le();
  102. bool op_lt();
  103. bool op_ne();
  104. bool op_skip();
  105. bool op_lit();
  106. bool op_reg();
  107. bool op_regx();
  108. bool op_breg();
  109. bool op_bregx();
  110. bool op_nop();
  111. bool op_not_implemented();
  112. using OpHandleFuncPtr = bool (DwarfOp::*)();
  113. static const OpHandleFuncPtr kOpHandleFuncList[];
  114. };
  115. } // namespace unwindstack
  116. #endif // _LIBUNWINDSTACK_DWARF_OP_H