Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 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 | |
| 17 | #ifndef _LIBUNWINDSTACK_ARM_EXIDX_H |
| 18 | #define _LIBUNWINDSTACK_ARM_EXIDX_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <deque> |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 23 | #include <map> |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 24 | |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 25 | namespace unwindstack { |
| 26 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 27 | // Forward declarations. |
| 28 | class Memory; |
| 29 | class RegsArm; |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 30 | |
| 31 | enum ArmStatus : size_t { |
| 32 | ARM_STATUS_NONE = 0, |
| 33 | ARM_STATUS_NO_UNWIND, |
| 34 | ARM_STATUS_FINISH, |
| 35 | ARM_STATUS_RESERVED, |
| 36 | ARM_STATUS_SPARE, |
| 37 | ARM_STATUS_TRUNCATED, |
| 38 | ARM_STATUS_READ_FAILED, |
| 39 | ARM_STATUS_MALFORMED, |
| 40 | ARM_STATUS_INVALID_ALIGNMENT, |
| 41 | ARM_STATUS_INVALID_PERSONALITY, |
| 42 | }; |
| 43 | |
| 44 | enum ArmOp : uint8_t { |
| 45 | ARM_OP_FINISH = 0xb0, |
| 46 | }; |
| 47 | |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 48 | enum ArmLogType : uint8_t { |
| 49 | ARM_LOG_NONE, |
| 50 | ARM_LOG_FULL, |
| 51 | ARM_LOG_BY_REG, |
| 52 | }; |
| 53 | |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 54 | class ArmExidx { |
| 55 | public: |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 56 | ArmExidx(RegsArm* regs, Memory* elf_memory, Memory* process_memory) |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 57 | : regs_(regs), elf_memory_(elf_memory), process_memory_(process_memory) {} |
| 58 | virtual ~ArmExidx() {} |
| 59 | |
| 60 | void LogRawData(); |
| 61 | |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 62 | void LogByReg(); |
| 63 | |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 64 | bool ExtractEntryData(uint32_t entry_offset); |
| 65 | |
| 66 | bool Eval(); |
| 67 | |
| 68 | bool Decode(); |
| 69 | |
| 70 | std::deque<uint8_t>* data() { return &data_; } |
| 71 | |
| 72 | ArmStatus status() { return status_; } |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 73 | uint64_t status_address() { return status_address_; } |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 74 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 75 | RegsArm* regs() { return regs_; } |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 76 | |
| 77 | uint32_t cfa() { return cfa_; } |
| 78 | void set_cfa(uint32_t cfa) { cfa_ = cfa; } |
| 79 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 80 | bool pc_set() { return pc_set_; } |
| 81 | void set_pc_set(bool pc_set) { pc_set_ = pc_set; } |
| 82 | |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 83 | void set_log(ArmLogType log_type) { log_type_ = log_type; } |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 84 | void set_log_skip_execution(bool skip_execution) { log_skip_execution_ = skip_execution; } |
| 85 | void set_log_indent(uint8_t indent) { log_indent_ = indent; } |
| 86 | |
| 87 | private: |
| 88 | bool GetByte(uint8_t* byte); |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 89 | void AdjustRegisters(int32_t offset); |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 90 | |
| 91 | bool DecodePrefix_10_00(uint8_t byte); |
| 92 | bool DecodePrefix_10_01(uint8_t byte); |
| 93 | bool DecodePrefix_10_10(uint8_t byte); |
| 94 | bool DecodePrefix_10_11_0000(); |
| 95 | bool DecodePrefix_10_11_0001(); |
| 96 | bool DecodePrefix_10_11_0010(); |
| 97 | bool DecodePrefix_10_11_0011(); |
| 98 | bool DecodePrefix_10_11_01nn(); |
| 99 | bool DecodePrefix_10_11_1nnn(uint8_t byte); |
| 100 | bool DecodePrefix_10(uint8_t byte); |
| 101 | |
| 102 | bool DecodePrefix_11_000(uint8_t byte); |
| 103 | bool DecodePrefix_11_001(uint8_t byte); |
| 104 | bool DecodePrefix_11_010(uint8_t byte); |
| 105 | bool DecodePrefix_11(uint8_t byte); |
| 106 | |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 107 | RegsArm* regs_ = nullptr; |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 108 | uint32_t cfa_ = 0; |
| 109 | std::deque<uint8_t> data_; |
| 110 | ArmStatus status_ = ARM_STATUS_NONE; |
Christopher Ferris | 2fcf4cf | 2018-01-23 17:52:23 -0800 | [diff] [blame] | 111 | uint64_t status_address_ = 0; |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 112 | |
| 113 | Memory* elf_memory_; |
| 114 | Memory* process_memory_; |
| 115 | |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 116 | ArmLogType log_type_ = ARM_LOG_NONE; |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 117 | uint8_t log_indent_ = 0; |
| 118 | bool log_skip_execution_ = false; |
Christopher Ferris | 3958f80 | 2017-02-01 15:44:40 -0800 | [diff] [blame] | 119 | bool pc_set_ = false; |
Christopher Ferris | 4cc36d2 | 2018-06-06 14:47:31 -0700 | [diff] [blame] | 120 | int32_t log_cfa_offset_ = 0; |
| 121 | std::map<uint8_t, int32_t> log_regs_; |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Christopher Ferris | d226a51 | 2017-07-14 10:37:19 -0700 | [diff] [blame] | 124 | } // namespace unwindstack |
| 125 | |
Christopher Ferris | 723cf9b | 2017-01-19 20:08:48 -0800 | [diff] [blame] | 126 | #endif // _LIBUNWINDSTACK_ARM_EXIDX_H |